Repository navigation
Conversation
…params
Query params whose schema wraps a $ref to a named model in oneOf/allOf
(e.g. oneOf: [$ref: Price]) resolve to isModel=true, so the {{^isModel}}
guard added in OpenAPITools#2710 (for OpenAPITools#2655) dropped their @RequestParam.
Add a {{#isModel}}{{^hasVars}} branch in JavaSpring/queryParams.mustache
so these params get @RequestParam again. Inline object query params
(hasVars=true) still get no @RequestParam, as OpenAPITools#2655 requires.
Fixes OpenAPITools#25210
Contributor
There was a problem hiding this comment.
1 issue found across 3 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="modules/openapi-generator/src/main/resources/JavaSpring/queryParams.mustache">
<violation number="1" location="modules/openapi-generator/src/main/resources/JavaSpring/queryParams.mustache:1">
P1: `hasVars` is never populated for query parameters, so this branch also adds `@RequestParam` to ordinary model `$ref`s and changes their existing binding behavior. Gate this annotation on the wrapped `oneOf`/`allOf` case instead.</violation>
</file>
Reply to a comment to ask cubic a question or push back. It learns from your replies.
View guided diff | Re-trigger cubic
| @@ -1 +1 @@ | |||
| {{#isQueryParam}}{{#vendorExtensions.x-field-extra-annotation}}{{{.}}} {{/vendorExtensions.x-field-extra-annotation}}{{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{>paramDoc}}{{#useBeanValidation}}{{^isContainer}}{{#isModel}} @Valid{{/isModel}}{{^isModel}}{{^useOptional}} @Valid{{/useOptional}}{{#useOptional}}{{#required}} @Valid{{/required}}{{/useOptional}}{{/isModel}}{{/isContainer}}{{/useBeanValidation}}{{^isModel}} @RequestParam(value = {{#isMap}}""{{/isMap}}{{^isMap}}"{{baseName}}"{{/isMap}}{{#required}}, required = true{{/required}}{{^required}}, required = false{{/required}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}){{/isModel}}{{>dateTimeParam}}{{#isDeprecated}} @Deprecated{{/isDeprecated}} {{>nullableAnnotation}}{{>optionalDataType}} {{paramName}}{{/isQueryParam}} No newline at end of file | |||
| {{#isQueryParam}}{{#vendorExtensions.x-field-extra-annotation}}{{{.}}} {{/vendorExtensions.x-field-extra-annotation}}{{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{>paramDoc}}{{#useBeanValidation}}{{^isContainer}}{{#isModel}} @Valid{{/isModel}}{{^isModel}}{{^useOptional}} @Valid{{/useOptional}}{{#useOptional}}{{#required}} @Valid{{/required}}{{/useOptional}}{{/isModel}}{{/isContainer}}{{/useBeanValidation}}{{#isModel}}{{^hasVars}} @RequestParam(value = {{#isMap}}""{{/isMap}}{{^isMap}}"{{baseName}}"{{/isMap}}{{#required}}, required = true{{/required}}{{^required}}, required = false{{/required}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}){{/hasVars}}{{/isModel}}{{^isModel}} @RequestParam(value = {{#isMap}}""{{/isMap}}{{^isMap}}"{{baseName}}"{{/isMap}}{{#required}}, required = true{{/required}}{{^required}}, required = false{{/required}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}){{/isModel}}{{>dateTimeParam}}{{#isDeprecated}} @Deprecated{{/isDeprecated}} {{>nullableAnnotation}}{{>optionalDataType}} {{paramName}}{{/isQueryParam}} No newline at end of file | |||
Contributor
There was a problem hiding this comment.
P1: hasVars is never populated for query parameters, so this branch also adds @RequestParam to ordinary model $refs and changes their existing binding behavior. Gate this annotation on the wrapped oneOf/allOf case instead.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At modules/openapi-generator/src/main/resources/JavaSpring/queryParams.mustache, line 1:
<comment>`hasVars` is never populated for query parameters, so this branch also adds `@RequestParam` to ordinary model `$ref`s and changes their existing binding behavior. Gate this annotation on the wrapped `oneOf`/`allOf` case instead.</comment>
<file context>
@@ -1 +1 @@
-{{#isQueryParam}}{{#vendorExtensions.x-field-extra-annotation}}{{{.}}} {{/vendorExtensions.x-field-extra-annotation}}{{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{>paramDoc}}{{#useBeanValidation}}{{^isContainer}}{{#isModel}} @Valid{{/isModel}}{{^isModel}}{{^useOptional}} @Valid{{/useOptional}}{{#useOptional}}{{#required}} @Valid{{/required}}{{/useOptional}}{{/isModel}}{{/isContainer}}{{/useBeanValidation}}{{^isModel}} @RequestParam(value = {{#isMap}}""{{/isMap}}{{^isMap}}"{{baseName}}"{{/isMap}}{{#required}}, required = true{{/required}}{{^required}}, required = false{{/required}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}){{/isModel}}{{>dateTimeParam}}{{#isDeprecated}} @Deprecated{{/isDeprecated}} {{>nullableAnnotation}}{{>optionalDataType}} {{paramName}}{{/isQueryParam}}
\ No newline at end of file
+{{#isQueryParam}}{{#vendorExtensions.x-field-extra-annotation}}{{{.}}} {{/vendorExtensions.x-field-extra-annotation}}{{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{>paramDoc}}{{#useBeanValidation}}{{^isContainer}}{{#isModel}} @Valid{{/isModel}}{{^isModel}}{{^useOptional}} @Valid{{/useOptional}}{{#useOptional}}{{#required}} @Valid{{/required}}{{/useOptional}}{{/isModel}}{{/isContainer}}{{/useBeanValidation}}{{#isModel}}{{^hasVars}} @RequestParam(value = {{#isMap}}""{{/isMap}}{{^isMap}}"{{baseName}}"{{/isMap}}{{#required}}, required = true{{/required}}{{^required}}, required = false{{/required}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}){{/hasVars}}{{/isModel}}{{^isModel}} @RequestParam(value = {{#isMap}}""{{/isMap}}{{^isMap}}"{{baseName}}"{{/isMap}}{{#required}}, required = true{{/required}}{{^required}}, required = false{{/required}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}){{/isModel}}{{>dateTimeParam}}{{#isDeprecated}} @Deprecated{{/isDeprecated}} {{>nullableAnnotation}}{{>optionalDataType}} {{paramName}}{{/isQueryParam}}
\ No newline at end of file
</file context>
…s in test Extend the regression test for OpenAPITools#25210 to assert that allOf-wrapped model query params also get @RequestParam, while direct $ref and inline object query params keep their existing behaviour (no @RequestParam). Rename the test to reflect its wider coverage. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fix #25210
Problem
When a query parameter's schema wraps a
$refto a named model inoneOforallOf, e.g.the
springgenerator leaves out@RequestParamon the generated parameter. The parameter resolves toisModel=true, andJavaSpring/queryParams.mustacheonly emits@RequestParaminside a{{^isModel}}guard. That guard was added in #2710 (for #2655) so that inline object query params are bound as a model attribute. It also catches these wrapped model refs.Fix
Keep the existing
{{^isModel}}branch and add an identical@RequestParambranch for models without vars:Behaviour by query param schema (all
isModel=true):hasVarsoneOf: [$ref: Price]false@RequestParam@RequestParamallOf: [$ref: Price]false@RequestParam@RequestParam$ref: Pricetrue@RequestParamtype: object(#2655)true@RequestParamBefore:
After:
Tests
SpringCodegenTest#shouldGenerateRequestParamForOneOfRefQueryParamwith the spec3_0/spring/issue-model-query-param-requestparam.yaml.doNotGenerateRequestParamForObjectQueryParam([BUG] Query Parameter Serialization (Spring) #2655) anddoGenerateRequestParamForSimpleParamstill pass.spring*andjava-camel*samples: no changes, since no sample uses aoneOf/allOf-wrapped model query param.kotlin-spring/queryParams.mustachehas the same{{^isModel}}guard but is not changed in this PR.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.
cc Java Spring technical committee: @cachescrubber @welshm @MelleD @atextor @manedev79 @javisst @borsch @banlevente @Zomzog @martin-mfg @KannaKim
Summary by cubic
Fixes
@RequestParambeing dropped from query parameters whose schema wraps a model$refinsideoneOforallOf(e.g.oneOf: [$ref: Price]), which prevented Spring from binding them.@RequestParamfor model query params without variables; inline object params and direct$refparams keep their existing behavior.oneOf- andallOf-wrapped model query params, plus negative cases for direct$refand inline object params.Written for commit d02ff07. Summary will update on new commits.