Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #13150
Closed
Open
Issue created Aug 10, 2022 by Administrator@rootContributor

Spring generates duplicated JsonSubTypes

Created by: 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

Assignee
Assign to
Time tracking