OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Spring] Generated @JsonSubTypes.Type value is incorrect for a model name with underscores
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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().
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in DefaultCodegen.createDiscriminator and inspect how MappedModel names are added, then compare that with toModelName(). Run the supplied OpenAPI definition with the spring generator and inspect the generated @JsonSubTypes.Type.value and model class file names. Done means the discriminator value matches the generated model class name for underscored models.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100