Skip to content

[Java][Spring] useRecords: oneOf members as records - #25273

Merged
wing328 merged 1 commit into
OpenAPITools:masterfrom
Sekator778:spring-records-step3
Oct 19, 2026
Merged

wing328 merged 1 commit into
OpenAPITools:masterfrom
Sekator778:spring-records-step3

Conversation

@Sekator778

@Sekator778 Sekator778 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Third step towards #10490, after #25238. With useRecords, a oneOf member now becomes a record that implements its interface (sealed with useSealed) and gets the discriminator getter of each interface above it, nested oneOf included. A member stays a class for the reasons already logged, or when a discriminator property is missing or nullable. With useRecords off the output is unchanged.

@cachescrubber @welshm @MelleD @atextor @manedev79 @javisst @borsch @banlevente @Zomzog @martin-mfg @KannaKim

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    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.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

With useRecords, members of a oneOf interface are now generated as Java records that implement the (sealed) interface, including an accessor for each discriminator getter declared by the interfaces above them.

  • The accessor is annotated with @JsonProperty so Jackson serializes the discriminator once under its JSON name, including for enum discriminators and nested oneOf interfaces.
  • A member stays a class for the existing reasons (inheritance, additionalProperties, byte[] properties, property names a record can't have, builder clashes, request-parameter binding, component count) and when a discriminator property is missing or nullable under openApiNullable.
  • If two interfaces in the chain declare the same getter name for different properties, the member stays a class as well.
  • Added tests and regenerated samples; the spring-boot-records petstore sample now includes Animal and Zoo oneOf examples.

Written for commit b8cdbaf. 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.

No issues found across 24 files

Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

View guided diff | Re-trigger cubic

@wing328
wing328 merged commit 8cbd177 into OpenAPITools:master Oct 19, 2026
109 of 110 checks passed
@wing328 wing328 added this to the 7.27.0 milestone Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants