Skip to content

Fix null defaults for Spring query parameters - #25464

Open
dmunozfer wants to merge 3 commits into
OpenAPITools:masterfrom
dmunozfer:fix/spring-optional-array-query-default
Open

dmunozfer wants to merge 3 commits into
OpenAPITools:masterfrom
dmunozfer:fix/spring-optional-array-query-default

Conversation

@dmunozfer

@dmunozfer dmunozfer commented Oct 29, 2026 •

Copy link
Copy Markdown

Fixes #25463

Problem

The source contract has an optional array query parameter with no default. The openapi-yaml bundling pass emits default: null for 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 literal null.

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

SpringCodegen treats 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" on ids and passes after it. Separately, running openapi-yaml 7.25.0 and 7.26.0 on a minimal source specification with no array default reproduces the intermediate default: null value.

Compatibility

No global DefaultCodegen behavior 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 has default: null, which made Spring treat an omitted parameter as the literal string null.

SpringCodegen now treats a Jackson null node as no default at all, while all other defaults keep the existing conversion behavior. For $ref schemas, the parameter's own explicit default is preserved even when the referenced schema declares default: 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 $ref schemas with and without overridden defaults.

  • Bug Fixes
    • Null JsonNode defaults, including those inherited from $ref schemas, are no longer stringified into Spring @RequestParam annotations.
    • Non-null explicit defaults and literal string "null" values are preserved, including overrides on $ref schemas.

Written for commit f9c19a1. Summary will update on new commits.

View guided diff

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@wing328

wing328 commented Oct 29, 2026

Copy link
Copy Markdown
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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][Java/Spring] Bundled array query parameter without a default generates defaultValue = "null"

2 participants