Skip to content

[kotlin-server] Add configurable inheritance modes - #24090

Open
rm127 wants to merge 9 commits into
OpenAPITools:masterfrom
rm127:feat/kotlin-server-inheritance-mode
Open

rm127 wants to merge 9 commits into
OpenAPITools:masterfrom
rm127:feat/kotlin-server-inheritance-mode

Conversation

@rm127

@rm127 rm127 commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Addresses #11552.
Related to #12065; this does not add a dedicated Quarkus generator.

Adds configurable inheritance handling to kotlin-server so discriminator-based models can compile and round-trip through Jackson, including with jaxrs-spec.

  • inheritanceMode=none|sealed|abstract|composition; defaults to abstract for JAX-RS and sealed for Ktor/Javalin. Invalid combinations are rejected.
  • JAX-RS abstract parents and children preserve inherited optional-property nullability, constructor forwarding and discriminator mappings without duplicating the discriminator in JSON.
  • Required nullable properties accept null but require JSON presence; required non-null properties reject explicit null, including primitives. Nullable properties do not receive @NotNull.
  • Nullable responses and bodyless Mutiny responses retain nullable Kotlin types.

none is non-polymorphic; composition produces wrappers rather than wire-compatible polymorphism. Discriminated object allOf/oneOf/anyOf hierarchies are covered; arbitrary JSON Schema unions and missing-versus-null tracking are not.

Verification

45 targeted generator tests pass, including nested discriminator inheritance, flat union models, configured visibility, compilation across supported JAX-RS modes with serialization enabled/disabled, discriminator round trips and invalid-input rejection. Checkstyle passes. Regression fixtures are synthetic; no application-specific code or contracts are included.

See the JAX-RS guide for nullability semantics and limitations; the option reference is generated from the code.

PR checklist

  • Read the contribution guidelines.
  • Run the full project build, regenerate all affected samples and export generator documentation. Targeted reactor builds/tests and generator documentation updates are complete; the full repository-wide regeneration has not been run.
  • Request review from the Kotlin technical committee.

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

3 issues found across 7 files

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

Re-trigger cubic

Comment thread docs/generators/kotlin-server.md Resolved
Comment thread docs/generators/kotlin-server.md Resolved
@wing328

wing328 commented Jun 24, 2026

Copy link
Copy Markdown
Member

thanks for the PR

cc @karismann (2019/03) @Zomzog (2019/04) @andrewemery (2019/10) @4brunu (2019/11) @yutaka0m (2020/03) @stefankoppier (2022/06) @e5l (2024/10) @dennisameling (2026/02)

@wing328

wing328 commented Jun 24, 2026

Copy link
Copy Markdown
Member

please review the build failure and the feedback from cubic-dev-ai when you've time.

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

1 issue found across 3 files (changes from recent commits).

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

Re-trigger cubic

@wing328

wing328 commented Jun 25, 2026

Copy link
Copy Markdown
Member

Thanks for the PR but your commit (as shown in the Commits tab) is not linked to your Github account, which means this PR won't count as your contribution in https://github.com/OpenAPITools/openapi-generator/graphs/contributors.

Let me know if you need help fixing it.

Ref: https://github.com/OpenAPITools/openapi-generator/wiki/FAQ#how-can-i-update-commits-that-are-not-linked-to-my-github-account

@rm127
rm127 force-pushed the feat/kotlin-server-inheritance-mode branch from 7561bc3 to 7facfa2 Compare June 25, 2026 11:54
@rm127

rm127 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the PR but your commit (as shown in the Commits tab) is not linked to your Github account, which means this PR won't count as your contribution in https://github.com/OpenAPITools/openapi-generator/graphs/contributors.

Let me know if you need help fixing it.

Ref: https://github.com/OpenAPITools/openapi-generator/wiki/FAQ#how-can-i-update-commits-that-are-not-linked-to-my-github-account

Thanks for the heads up! I've altered the history to reflect my GH user

@jpfinne

jpfinne commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

@rm127 I don't use Kotlin...
Can't INHERITANCE_MODE_NONE and INHERITANCE_MODE_COMPOSITION be done in the OpenApiNormalizer?

Then all languages can use the feature

Just my 2 cents

@rm127

rm127 commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor Author

@jpfinne

@rm127 I don't use Kotlin... Can't INHERITANCE_MODE_NONE and INHERITANCE_MODE_COMPOSITION be done in the OpenApiNormalizer?

Then all languages can use the feature

Just my 2 cents

I'm not sure I follow how these would be relevant in the normalization stage? Furthermore I don't think having the different "modes" split across multiple classes helps with readability.

@wing328 wing328 modified the milestones: 7.24.0, 7.25.0 Jul 20, 2026
@wing328 wing328 modified the milestones: 7.25.0, 7.26.0 Aug 24, 2026
@wing328 wing328 modified the milestones: 7.26.0, 7.27.0 Oct 6, 2026
Preserve inherited optional types and discriminator round trips, enforce required JSON field semantics, and retain nullable Mutiny responses. Add synthetic compilation and Jackson regressions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rm127

rm127 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Following up after roughly three months: I revisited this PR while validating an end-to-end Kotlin/JAX-RS migration, rather than just inspecting the generated source.

Compiling and exercising the generated models exposed gaps in the original implementation: optional inherited properties could have incompatible nullability, discriminated unions were not consistently emitted as usable Jackson hierarchies, and required-nullable fields and bodyless Mutiny responses needed their Kotlin/JSON semantics preserved.

The new commit addresses those findings and adds synthetic compilation and Jackson regression tests. This is a correctness follow-up to the original inheritance work, not a rebase or unrelated cleanup.

44 targeted generator tests and Checkstyle pass. The PR description now states the supported modes, limitations and remaining repository-wide checks explicitly.

@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 14 files

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

View guided diff | Re-trigger cubic

Preserve overrides and immediate-parent constructor arguments in nested hierarchies, flatten union metadata in none mode, and honor discriminator visibility. Make the fixture discriminator required and keep handwritten guidance outside generated docs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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

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

View guided diff | Re-trigger cubic

Comment thread docs/kotlin-server-jaxrs-spec.md Resolved
Explicitly reject nullable forms of inherited required properties in source assertions and clarify that optional properties preserve declared schema defaults.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@wing328 wing328 modified the milestones: 7.27.0, 7.28.0 Nov 2, 2026

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants