Skip to content

feat(kotlin-spring): support generic ResponseEntity return types - #24805

Open
c19yamamoto wants to merge 5 commits into
OpenAPITools:masterfrom
c19yamamoto:codex/kotlin-spring-generic-response-entity
Open

feat(kotlin-spring): support generic ResponseEntity return types#24805
c19yamamoto wants to merge 5 commits into
OpenAPITools:masterfrom
c19yamamoto:codex/kotlin-spring-generic-response-entity

Conversation

@c19yamamoto

@c19yamamoto c19yamamoto commented Aug 29, 2026

Copy link
Copy Markdown

Adds an opt-in generateGenericResponseEntity option to the kotlin-spring generator.

When enabled, generated API methods use ResponseEntity<*>, allowing operations with different response body types to share a single method signature. The option defaults to false and is ignored when useResponseEntity=false.

Fixes #24804, where operations with different response shapes could be generated with an unusable ResponseEntity<Unit> signature. This supports controllers, API interfaces, delegates, generated API tests, and declarative HTTP interfaces.

Tests

  • KotlinSpringServerCodegenTest: 278 tests passed.
  • Verified CLI generation for standard and declarative HTTP interface libraries.

Kotlin technical committee: @karismann @Zomzog @andrewemery @4brunu @stefankoppier @e5l

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

Adds an opt-in generateGenericResponseEntity option to the kotlin-spring generator. Previously, operations with different response body types could be generated with an unusable ResponseEntity<Unit> signature; with this option enabled, methods use ResponseEntity<*> instead. The option defaults to false, is ignored when useResponseEntity=false, and preserves sealed response interface and delegate return types in all configurations, including when useResponseEntity is disabled.

  • Fixes #24804.
  • Applies to controllers, API interfaces, delegates, generated API tests, and declarative HTTP interfaces.

Written for commit 650c585. Summary will update on new commits.

Review in 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 9 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread modules/openapi-generator/src/main/resources/kotlin-spring/apiInterface.mustache Outdated
Comment thread modules/openapi-generator/src/main/resources/kotlin-spring/api.mustache Outdated

@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 5 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread modules/openapi-generator/src/main/resources/kotlin-spring/apiDelegate.mustache Outdated

@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 2 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread modules/openapi-generator/src/main/resources/kotlin-spring/apiDelegate.mustache Outdated
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.

[REQ][KOTLIN-SPRING] Add an opt-in generic ResponseEntity return type

1 participant