Skip to content

Spring generates duplicated JsonSubTypes #13150

@xibz

Description

@xibz

Hello everyone,

When I use the openapi-generator with a discriminator and mapping, it generates two @JsonSubTypes

discriminator:
    propertyName: type
    mapping:
         foo: "#components/schemas/Foo"

Generates something like this

@JsonSubTypes.Type(value = Foo.class, name = "Foo")
@JsonSubTypes.Type(value = Foo.class, name = "foo")

Notice the duplication. The Foo is the class name of the class, and the lowercase foo is my mapping. Wtf is going on lol. This doesn't seem right.

The Foo class is defined something like

Foo:
    allOf:
         - $ref: "#components/schemas/someParent"
         - type: object
            properties:
                type:
                    type: string

I am using version 6.0.1 and the schema version is openapi: '3.0.0'

Here's the full spec to generate the incorrect thing:

openapi: '3.0.0'
info:
  version: '1.0.0'
  title: 'FooService'
paths:
  /parent:
    put:
      summary: put parent
      operationId: putParent
      parameters:
        - name: name
          in: path
          required: true
          description: Name of the account being updated.
          schema:
            type: string
      requestBody:
        description: The updated account definition to save.
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Parent'
      responses:
        '200':
          $ref: '#/components/responses/Parent'
components:
  schemas:
    Parent:
      type: object
      description: Defines an account by name.
      properties:
        name:
          type: string
          description: The account name.
        type:
          type: string
          description: The account type discriminator.
      required:
        - name
        - type
      discriminator:
        propertyName: type
        mapping:
          foo: '#/components/schemas/Foo'

    Foo:
      allOf:
        - $ref: "#/components/schemas/Parent"
        - type: object
          properties:
            fooType:
              type: string 
  responses:
    Parent:
      description: The saved account definition.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Parent'

I generated this by running
java -jar openapi-generator-cli.jar generate -i schema.yaml -o foo -g spring

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