Skip to content

DRAFT: Jaxrs-spec: Resolve @JsonTypeName with the mapping key of the discriminator in the child models when OpenAPI specification uses OneOf for polymorphism#23075

Draft
Ignacio-Vidal wants to merge 6 commits intoOpenAPITools:masterfrom
Ignacio-Vidal:jaxrs-spec-discriminator
Draft

DRAFT: Jaxrs-spec: Resolve @JsonTypeName with the mapping key of the discriminator in the child models when OpenAPI specification uses OneOf for polymorphism#23075
Ignacio-Vidal wants to merge 6 commits intoOpenAPITools:masterfrom
Ignacio-Vidal:jaxrs-spec-discriminator

Conversation

@Ignacio-Vidal
Copy link

@Ignacio-Vidal Ignacio-Vidal commented Feb 28, 2026

The Jaxrx-spec adds the class name to the @JsonTypeName annotation in child classes when the OpenAPI specification has a OneOf with a discriminator mapping. Instead, the generator should add the mapping key of the discriminator.

This MR updates the POJO mustache template to inject the vendor extension x-discriminator-value to the @JsonTypeName annotation when the discriminator has a mapping or defaults to the original behaviour with the class name when not available.

This MR will fix #10822 and will fix #17343


Summary by cubic

Fixes wrong @JsonTypeName in the JAX-RS spec generator for oneOf + discriminator mappings. Child models now use the discriminator mapping key (e.g., CAT); parents keep their names. Fixes #17343, #10822.

  • Bug Fixes
    • Set vendorExtensions.x-discriminator-value on child models in postProcessAllModels by matching the parent discriminator.mappedModels.
    • Update pojo.mustache to use that value in @JsonTypeName, falling back to the model name if absent.
    • Add tests and a sample spec (PetRequest/CatRequest/DogRequest) to confirm parents keep names and children use mapping values.

Written for commit 763a354. Summary will update on new commits.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

@Ignacio-Vidal Ignacio-Vidal changed the title Fix 17343: Resolve JsonTypeName for child classes in Jaxrs-spec generator when OpenAPI specification uses OneOf with a discriminator mapping DRAFT: Jaxrs-spec: Resolve JsonTypeName for child classes when OpenAPI specification uses OneOf with a discriminator mapping Feb 28, 2026
@Ignacio-Vidal Ignacio-Vidal changed the title DRAFT: Jaxrs-spec: Resolve JsonTypeName for child classes when OpenAPI specification uses OneOf with a discriminator mapping Jaxrs-spec: Resolve @JsonTypeName with discriminator mapping key of the discriminator when OpenAPI specification uses OneOf for polymorphism Feb 28, 2026
@Ignacio-Vidal Ignacio-Vidal changed the title Jaxrs-spec: Resolve @JsonTypeName with discriminator mapping key of the discriminator when OpenAPI specification uses OneOf for polymorphism Jaxrs-spec: Resolve @JsonTypeName with the mapping key of the discriminator when OpenAPI specification uses OneOf for polymorphism Feb 28, 2026
@Ignacio-Vidal Ignacio-Vidal changed the title Jaxrs-spec: Resolve @JsonTypeName with the mapping key of the discriminator when OpenAPI specification uses OneOf for polymorphism Jaxrs-spec: Resolve @JsonTypeName with the mapping key of the discriminator in the child models when OpenAPI specification uses OneOf for polymorphism Feb 28, 2026
@Ignacio-Vidal Ignacio-Vidal changed the title Jaxrs-spec: Resolve @JsonTypeName with the mapping key of the discriminator in the child models when OpenAPI specification uses OneOf for polymorphism DRAFT: Jaxrs-spec: Resolve @JsonTypeName with the mapping key of the discriminator in the child models when OpenAPI specification uses OneOf for polymorphism Feb 28, 2026
@Ignacio-Vidal Ignacio-Vidal marked this pull request as draft February 28, 2026 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant