OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA][Spring] Unexpected JsonTypeInfo and JsonSubTypes annotations on the subclass
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Openapi-generator equal or greater than 6.0.0 creates subclasses containing unexpected @JsonTypeInfo and @JsonSubTypes annotations. As per my understanding it should be only put on the Base class.
@JsonIgnoreProperties(
value = "category", // ignore manually set category, it will be automatically generated by Jackson during serialization
allowSetters = true // allows the category to be set during deserialization
)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "category", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = First.class, name = "FIRST")
})
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2023-03-09T00:15:05.886973600+01:00[Europe/Warsaw]")
public class First extends Base implements Serializable {
Meanwhile the code generated by version 5.3.1 looks like I would expect it:
/**
* First
*/
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2023-03-09T00:30:16.351405400+01:00[Europe/Warsaw]")
public class First extends Base implements Serializable {
openapi-generator version
but happens pretty much with every version equal or greater than 6.0.0, including 6.5.0 and 7.0.0
OpenAPI declaration file content or url
Full example: https://github.com/WojciechZankowski/openapi-defects/blob/master/src/main/resources/openapi-inheritance-test.yaml
openapi: 3.0.3
info:
title: OpenAPI test
version: 1.0.0
paths: { }
components:
schemas:
Base:
type: object
required:
- category
properties:
category:
type: string
enum:
- FIRST
discriminator:
propertyName: category
mapping:
FIRST: '#/components/schemas/First'
First:
allOf:
- $ref: '#/components/schemas/Base'
required:
- value
properties:
value:
type: number
Generation Details
Code generation triggered through maven using openapi-maven-generator plugin. Command: mvn clean install
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 by running mvn clean install with src/main/resources/openapi-inheritance-test.yaml from the linked reproduction and inspect the generated Base and First classes. Compare the output for version 6.4.0 with the shown 5.3.1 output; done means the subclass no longer receives the unexpected @JsonTypeInfo and @JsonSubTypes annotations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- backend, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100