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
  • #3310
Closed
Open
Issue created Jul 08, 2019 by Administrator@rootContributor

[BUG] [Spring] Generated @JsonTypeInfo property value is incorrect for discriminators with underscores

Created by: jburgess

Description

Given a specification which contains a discriminator containing an underscore the @JsonTypeInfo property is incorrectly formatted to camel case. For instance a discriminator defined with _type produces the @JsonTypeInfo property type in the super class:

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", visible = true)

the expected @JsonTypeInfo property is _type:

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "_type", visible = true)

This produces an API server definition which is incorrect and not able to evaluate the discriminator to instantiate the correct sub class.

openapi-generator version

4.0.3-SNAPSHOT

OpenAPI declaration file content or url
openapi: 3.0.0
servers:
  - url: https://api.example.com/v1
info:
  version: 0.0.0
  title: test
paths:
  /pet:
    get:
      responses:
        '200':
          description: 'A Pet'
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/Cat'
                  - $ref: '#/components/schemas/Dog'
                discriminator:
                  propertyName: _type
                  mapping:
                    Cat: '#/components/schemas/Cat'
                    Dog: '#/components/schemas/Dog'
components:
  schemas:
    Pet:
      type: object
      required:
        - name
      properties:
        name:
          type: string
        _type:
          type: string
      discriminator:
        propertyName: _type
    Dog:     # "Dog" is a value for the pet_type property (the discriminator value)
      allOf: # Combines the main `Pet` schema with `Dog`-specific properties
        - $ref: '#/components/schemas/Pet'
        - type: object
          # all other properties specific to a `Dog`
          properties:
            bark:
              type: boolean
            breed:
              type: string
              enum: [Dingo, Husky, Retriever, Shepherd]
    Cat:     # "Cat" is a value for the pet_type property (the discriminator value)
      allOf: # Combines the main `Pet` schema with `Cat`-specific properties
        - $ref: '#/components/schemas/Pet'
        - type: object
          # all other properties specific to a `Cat`
          properties:
            hunts:
              type: boolean
            age:
              type: integer
Command line used for generation
openapi-generator-cli generate -g spring
Steps to reproduce

Generate the server stubs with the above API definition.

Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/issues/1699

Assignee
Assign to
Time tracking