Skip to content

[BUG][jaxrs-spec] @JsonTypeName does not use specified discriminator mapping #10822

@languitar

Description

@languitar

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

https://swagger.io/specification/#discriminator-object describes how the mapping key in a discriminator object can be used to control the contents of the discriminator field in case of polymorphism. When providing a mapping, instead of the type name the declared map key has to be used per type as the content of the discriminator field.

The current code used to generate the @JsonTypeName annotation that is used to provide the discriminator value with jackson mapping in many generators (including jaxrs-spec) always uses the data type name, ignoring a potential mapping.

For the example from the linked specification:

    MyResponseType:
      oneOf:
      - $ref: '#/components/schemas/Cat'
      - $ref: '#/components/schemas/Dog'
      - $ref: '#/components/schemas/Lizard'
      - $ref: 'https://gigantic-server.com/schemas/Monster/schema.json'
      discriminator:
        propertyName: petType
        mapping:
          dog: '#/components/schemas/Dog'
          monster: 'https://gigantic-server.com/schemas/Monster/schema.json'

The generated Dog Java class should have the following annotation: @JsonTypeName("dog"). At the moment, it will always be @JsonTypeName("Dog").

openapi-generator version

5.3.x

OpenAPI declaration file content or url
components:
  schemas:
    MyResponseType:
      oneOf:
      - $ref: '#/components/schemas/Dog'
      discriminator:
        propertyName: petType
        mapping:
          dog: '#/components/schemas/Dog'
    Dog:
      type: object
      properties:
        test:
          type: string
Generation Details

nothing fancy, jaxrs-spec with library Quarkus and Jackson mapping is enough to trigger this.

Steps to reproduce

Just generate the code.

Related issues/PRs
Suggest a fix

I suspect there are some actual Java code changes required to compute the intended name from a potentially existing mapping.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions