Repository navigation
Conversation
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 3 files
Reply to a comment to ask cubic a question or push back. It learns from your replies.
View guided diff | Re-trigger cubic
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 3 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
Member
|
thanks for the PR cc @cachescrubber (2022/02) @welshm (2022/02) @MelleD (2022/02) @atextor (2022/02) @manedev79 (2022/02) @javisst (2022/02) @borsch (2022/02) @banlevente (2022/02) @Zomzog (2022/09) @martin-mfg (2023/08) @KannaKim (2026/07) |
This branch has not been deployed
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.
Fixes #25463
Problem
The source contract has an optional array query parameter with no default. The
openapi-yamlbundling pass emitsdefault: nullfor that array schema; feeding the bundled file to Spring generation can produce@RequestParam(..., defaultValue = "null"). Spring then treats an omitted query parameter as if the caller supplied the literalnull.Root cause
The bundled document represents the default as a Jackson
NullNode. Java parameter-default conversion treats this non-Java-null object as a value and stringifies it. The Spring query-parameter template then writes the resulting string into the annotation.Solution
SpringCodegentreats a Jackson null node as having no parameter default, while delegating all other values to the existing conversion. The change is scoped to Spring and retains legitimate defaults, including a string default whose value is literally"null".Regression tests
Added an OpenAPI 3.1 fixture representing the bundled document and a generator test using
spring-http-interface. It checks the null default, an optional string without a default, an integer default, a required array, an explicit array default, and a literal string default of"null".The regression test failed before the change with
defaultValue = "null"onidsand passes after it. Separately, runningopenapi-yaml7.25.0 and 7.26.0 on a minimal source specification with no array default reproduces the intermediatedefault: nullvalue.Compatibility
No global
DefaultCodegenbehavior or Mustache templates changed. Non-null explicit defaults are handled by the existing Spring conversion. Other generators are unaffected.Validation
mvn -pl modules/openapi-generator -am '-Dtest=SpringCodegenTest#nullSchemaDefaultIsNotRenderedAsSpringRequestParamDefault' '-Dsurefire.failIfNoSpecifiedTests=false' test— passed (1 test).mvn -pl modules/openapi-generator -am '-Dtest=SpringCodegenTest' '-Dsurefire.failIfNoSpecifiedTests=false' test— passed (487 tests, 0 failures, 0 errors).git diff --check— passed.The targeted regression test failed before the fix, confirming the generated annotation regression.
Summary by cubic
Fixes the Spring generator emitting
defaultValue = "null"for optional query parameters whose schema hasdefault: null, which made Spring treat an omitted parameter as the literal stringnull.SpringCodegennow treats a Jackson null node as no default at all, while all other defaults keep the existing conversion behavior. For$refschemas, the parameter's own explicit default is preserved even when the referenced schema declaresdefault: null, and a referenced schema's null default with no override is ignored. Added a regression test covering null defaults, optional strings, numeric defaults, required arrays, explicit array defaults, literal"null"string defaults, and$refschemas with and without overridden defaults.JsonNodedefaults, including those inherited from$refschemas, are no longer stringified into Spring@RequestParamannotations."null"values are preserved, including overrides on$refschemas.Written for commit f9c19a1. Summary will update on new commits.