Type safe error handling in kotlin spring server with useSealedResponseInterfaces flag#23003
Merged
wing328 merged 3 commits intoOpenAPITools:masterfrom Feb 24, 2026
Merged
Conversation
809b1df to
c674e09
Compare
ab3f529 to
f4be6bd
Compare
Contributor
Author
|
@dennisameling / @stefankoppier / @e5l / @4brunu - could I grab a review from one or more of you? Thanks |
Contributor
Author
|
cc other technical committee members: @andrewemery / @Zomzog / @karismann |
Contributor
There was a problem hiding this comment.
1 issue found across 32 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/api/PetApi.kt">
<violation number="1" location="samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/api/PetApi.kt:146">
P2: Optional @RequestPart is declared with a non-nullable MultipartFile. When the file part is omitted (allowed by required=false), Spring provides null, which conflicts with Kotlin non-nullable type and can cause binding/NPE errors. Make the parameter nullable or mark it required.</violation>
</file>
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Add one-off context when rerunning by tagging
@cubic-dev-aiwith guidance or docs links (includingllms.txt) - Ask questions if you need clarification on any suggestion
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
...rver/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/api/PetApi.kt
Show resolved
Hide resolved
wing328
reviewed
Feb 23, 2026
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.
Summary
Adds
useSealedResponseInterfacesoption to the Kotlin Spring generator to provide type-safe response handling for operations with multiple response schemas.What it does
When enabled, generates sealed interfaces for each operation's possible response types:
Key benefits
Implementation notes
Resolves #23004, resolves #1096. Note that #1096 was closed after an option to switch to ResponseEntity<*> was added, but this is not type safe - any response can be returned from an endpoint with ResponseEntity<*> - they no longer need to match the API yaml.
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.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)Summary by cubic
Adds an opt-in feature for Kotlin Spring to generate sealed response interfaces per operation, letting controllers return type-safe responses. Enable useSealedResponseInterfaces to have models implement Response and API methods return that interface; operations without response bodies keep normal Unit/standard returns.
New Features
Bug Fixes
Written for commit b68eacf. Summary will update on new commits.