[Groovy] Fix parameter names with {{baseName}} #5030
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR checklist
./bin/to update Petstore sample so that CIs can verify the change.→ bin/groovy-petstore.sh
Description of the PR
This fixes (or hopes to fix) part of #4898 for the
groovygenerator.The problem likely occurred when a query or header parameter name (as declared in the OpenAPI definition) is of a form which doesn't match the form used in Groovy, or is a reserved word there. In this case the parameter gets renamed for use in the code, and the parameter will be sent with the sanitized name instead of the original one.
This commit changes the replacement to using
{{baseName}}(which is the original name of the parameter definition as parsed from the API definition) instead of{{paramName}}(which is the sanitized version of the parameter name).Note that it looks like the Groovy generator has no support at all for path, form or body parameters – those are accepted by the generated code, but then ignored, and not passed to the server. I didn't try to fix this, as my Groovy knowledge is too rusty for this, but added some TODOs in the template. Related issue: #4289
Our Petstore sample API definition doesn't seem to contain any query parameter which would get modified by the sanitation, so the regenerated samples just have a single difference in a header parameter (which looks better now to me).
I don't know anything about Groovy, so this needs review by Groovy experts.