Skip to content

[BUG] [Spring] Generated @JsonSubTypes.Type value is incorrect for a model name with underscores #1699

@ErikGrimes

Description

@ErikGrimes
Description

Given a model with an underscore in the name, the generated

@JsonSubTypes.Type.value 

does not match the generated model class file name.

openapi-generator version

3.3.4

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: Sample API
  description: API description in Markdown.
  version: 1.0.0
paths:
  /animals:
    get:
      summary: Returns all animals.
      description: Optional extended description in Markdown.
      responses:
        200:
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Animal'
components:
  schemas:
    Dog_Animal:
      allOf:
        - $ref: '#/components/schemas/Animal'
        - type: object
          properties:
            breed:
              type: string
    Cat_Animal:
      allOf:
        - $ref: '#/components/schemas/Animal'
        - type: object
          properties:
            breed:
              type: string
    Animal:
      type: object
      discriminator:
        propertyName: className
      required:
        - className
      properties:
        className:
          type: string
        color:
          type: string
          default: red
               

(for YAML code) or

Command line used for generation

openapi-generator generate -g spring

Steps to reproduce

Invoke the command line above with the provided API definition.

Suggest a fix

Transform the name when adding the MappedModel to the discriminator in DefaultCodegen.createDiscriminator using DefaultCodegent.toModelName().

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