Skip to content

Fix null defaults for Spring query parameters - #25464

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

dmunozfer wants to merge 4 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; generating from that bundled contract can produce defaultValue = "null", changing the behavior of an omitted query parameter.

Root cause

The bundled document represents the null default as a Jackson NullNode. AbstractJavaCodegen.toDefaultParameterValue treated that node as a value and stringified it. Spring and Micronaut Java generators use this shared conversion path.

Solution

Null Jackson nodes are now treated as no parameter default in AbstractJavaCodegen. A schema-local default takes precedence over the referenced schema default, preserving explicit $ref sibling defaults such as the literal string "null".

Regression coverage

The OpenAPI 3.1 fixture and Spring spring-http-interface test cover null and absent defaults, explicit scalar and array defaults, literal string "null", and referenced schemas with and without a sibling override. The shared Java base conversion addresses the same behavior in Micronaut server and client.

Compatibility

The behavior change applies to generators extending AbstractJavaCodegen; non-Java generators and templates are unaffected.

@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)

@Sekator778 Sekator778 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.

Reproduced #25463 on master, and this fixes Spring. The same bundled spec still gives @QueryValue(value="ids", defaultValue="null") in java-micronaut-server and java-micronaut-client. The same null check in AbstractJavaCodegen.toDefaultParameterValue fixed both in my run; would you move it there?

@dmunozfer

Copy link
Copy Markdown
Author

Thanks for reproducing this in both Micronaut generators. You were right: AbstractJavaCodegen.toDefaultParameterValue is the shared conversion path. I moved the Jackson-null handling there, kept schema-local $ref sibling defaults ahead of the referenced default, and removed the Spring-only override. The change is in commit 19ac4e2; the existing Spring regression coverage remains in place, and CI will rerun on the updated head.

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"

3 participants