Skip to content

discriminator seems not to be supported to manage polymorphism #520

@hbelmiro

Description

@hbelmiro

Discussed in #518

Originally posted by mexavier October 9, 2023
Hi

I use quarkus-openapi-generator with a contract first approach for a new project. The team has a 6-month experience with quarkus.

However we failed to manage correctly polymorphism with quarkus-openapi-generator. The goal is to have operations that can manage multiple sub-types in the request or response.
We tried to use the discriminator keyword on setting it on the parent class and specifying the children implementations in the mapping part.

Hereunder is a exerpt :

    CloudEvent:
      type: object
      discriminator:
        propertyName: type
        mapping:
            CloudEventChild1: '#/components/schemas/CloudEventChild1'
            CloudEventChild2: '#/components/schemas/CloudEventChild2'
      properties:
        specVersion:
          $ref: '#/components/schemas/SpecVersion'
        id:
          type: string
        type:
          type: string
        source:
          format: uri
          type: string
        dataContentType:
          type: string
        dataSchema:
          format: uri
          type: string
        subject:
          type: string
        time:
          format: date-time
          type: string
        attributeNames:
          uniqueItems: true
          type: array
          items:
            type: string
        extensionNames:
          uniqueItems: true
          type: array
          items:
            type: string
        data:
          $ref: '#/components/schemas/CloudEventData'
    CloudEventChild1:
      type: object
      allOf:
        - $ref: '#/components/schemas/CloudEvent'
      properties:
        child1:
          type: string
    CloudEventChild2:
      type: object
      allOf:
          - $ref: '#/components/schemas/CloudEvent'
      properties:
          child2:
            type: string

When I generate the classes the classes does not hold the annotations @JsonTypeInfo and @JsonSubTypes managed by Jackson.

If do the same with "openapi generator 6" with jaxrs-resteasy, the generated class holds correcly those annotations :

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaResteasyServerCodegen", date = "2023-10-09T12:40:51.890826200+02:00[Europe/Zurich]")@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", visible = true)
@JsonSubTypes({
  @JsonSubTypes.Type(value = CloudEventChild1.class, name = "CloudEventChild1"),
  @JsonSubTypes.Type(value = CloudEventChild2.class, name = "CloudEventChild2"),
})

public class CloudEvent   {
...

Is it a limitation of the Quarkus OpenApi Generator or is there an other way to manage polymorphism ?

Thank you.

Xavier

Metadata

Metadata

Assignees

No one assigned

    Labels

    added to backlogThe issue was added to backlogarea:clientThis item is related to the client extensionpinnedIssues and PRs that must not stale

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions