-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[POWERSHELL] fix: keep array context when converting to json #19535
[POWERSHELL] fix: keep array context when converting to json #19535
Conversation
Thanks for the PR but your commit (as shown in the Commits tab) is not linked to your Github account, which means this PR won't count as your contribution in https://github.com/OpenAPITools/openapi-generator/graphs/contributors. Let me know if you need help fixing it. |
@syd-besco thanks for the PR @canadaduane can you please review and test the PR locally when you've time? |
Hi,
It looks like I did not perform all the necessary tests. Indeed the comma operator works well in PowerShell 7 but creates extra fields in PowerShell 5.1. Or probably it is due to a different ConvertTo-Json in PS 5.
I see another issue with the mustache, though, and it is due to the Process{} block failing to deal with array input from the pipeline. Only the first element goes through, then the function returns.
Other than rebuilding the array to create the JSON body - which is against the purpose of using a pipeline - and removing the ValueFromPipeline parameter, I do not have ideas of how to solve this.
[https://www.kyos.ch/wp-content/uploads/2021/07/01.kyos_.logo_.noir300px-1.png]
Alessandro Miotto
[https://www.kyos.ch/wp-content/uploads/2021/06/Arrow_small_2.png] Security Architect
[https://www.kyos.ch/wp-content/uploads/2021/06/line.gif]
41 22 577 65 37
+41 78 647 22 59
***@***.*** Ch. Frank-Thomas 32
CH-1208 Geneva
Rue de l'Avenir 28
CH-1020 Renens
[cid:icon-kyos-apps-20px_99676364-2eff-4a8d-9cb0-4407fa145510.png] <https://www.kyos.ch> [cid:linkedin_20_6701f2a8-5961-41d7-b778-7ce26f100dda.png] <https://www.linkedin.com/company/kyos/> [cid:github-mark_20_088212c5-510d-44b9-a36d-4aaffcd29802.png] <https://github.com/swisskyos>
[https://www.kyos.ch/wp-content/uploads/2021/06/line.gif]
[https://kyoswebpublic.blob.core.windows.net/public/openeye.png]
[https://www.kyos.ch/wp-content/uploads/2021/06/line.gif]
“The information contained in this message is intended for the addressee only and may contain classified information. If you are not the addressee, please delete this message and notify the sender; you should not copy or distribute this message or disclose its contents to anyone. Any views or opinions expressed in this message are those of the individual(s) and not necessarily of the organization. No reliance may be placed on this message without written confirmation from an authorised representative of its contents. No guarantee is implied that this message or any attachment is virus free or has not been intercepted and amended.”
<https://www.linkedin.com/company/1672641>
On 5 Sep 2024, at 15:45, Syd Besco ***@***.***> wrote:
This PR aims to correct Issue #18427 <#18427> . The fix submitted by @condorcorde<https://github.com/condorcorde> in PR #19262 <#19262> seems to give a different behavior than the one expected.
When using $LocalVarBodyParameter = ,$User | ConvertTo-Json -Depth 100, $User being a 1-element array, the output will look something like this :
{ "Value" : _content of $User_, "Length" : 1 }
Which is different from the expected behavior, that is to only get the array itself. This PR fixes this by forcing the cast of $User to an array using the @() syntax before converting it to Json.
PR checklist
* Read the contribution guidelines<https://github.com/openapitools/openapi-generator/blob/master/CONTRIBUTING.md>.
* Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
* Run the following to build the project<https://github.com/OpenAPITools/openapi-generator#14---build-projects> and update samples:
./mvnw clean package
./bin/generate-samples.sh ./bin/configs/*.yaml
./bin/utils/export_docs_generators.sh
(For Windows users, please run the script in Git BASH<https://gitforwindows.org/>)
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
* File the PR against the correct branch<https://github.com/OpenAPITools/openapi-generator/wiki/Git-Branches>: master (upcoming 7.6.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
* If your PR is targeting a particular programming language, @mention the technical committee<https://github.com/openapitools/openapi-generator/#62---openapi-generator-technical-committee> members, so they are more likely to review the pull request. @wing328<https://github.com/wing328>
…________________________________
You can view, comment on, or merge this pull request online at:
#19535
Commit Summary
* f0d3d90<f0d3d90> [POWERSHELL] fix: keep array context when converting to json
File Changes
(2 files<https://github.com/OpenAPITools/openapi-generator/pull/19535/files>)
* M modules/openapi-generator/src/main/resources/powershell/api.mustache<https://github.com/OpenAPITools/openapi-generator/pull/19535/files#diff-527faa928a4e08e45f398712f7087085349533421ae8ceca7ec16030d01a8a1b> (2)
* M samples/client/petstore/powershell/src/PSPetstore/Api/PSUserApi.ps1<https://github.com/OpenAPITools/openapi-generator/pull/19535/files#diff-c691c170046a20ef6d9a91b32903c2ccbaa75c1848f14259994b0621630354f4> (4)
Patch Links:
* https://github.com/OpenAPITools/openapi-generator/pull/19535.patch
* https://github.com/OpenAPITools/openapi-generator/pull/19535.diff
—
Reply to this email directly, view it on GitHub<#19535>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AL42JW6IMYLQNTWN5OTIU6LZVBOA3AVCNFSM6AAAAABNWQKH22VHI2DSMVQWIX3LMV43ASLTON2WKOZSGUYDOOBSGM4TMOI>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
For the record, this link provides an explanation of the issue: Why does powershell give different result in one-liner than two-liner when converting JSON?
|
Hi, thank you @condorcorde for your answers. The fix I submitted aims to fix this issue for both versions, so I think it would be preferable to include it in the next release of OpenApi generator. |
Agreed |
if no further feedback/question, i'll merge this PR coming week before v7.8.0 release |
This PR aims to correct Issue #18427 . The fix submitted by @condorcorde in PR #19262 seems to give a different behavior than the one expected.
When using
$LocalVarBodyParameter = ,$User | ConvertTo-Json -Depth 100
,$User
being a 1-element array, the output will look something like this :{ "Value" : _content of $User_, "Length" : 1 }
Which is different from the expected behavior, that is to only get the array itself. This PR fixes this by forcing the cast of $User to an array using the
@()
syntax before converting it to Json.PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master
(upcoming 7.6.0 minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)