Skip to content

[BUG][JAVA][Spring] Unexpected JsonTypeInfo and JsonSubTypes annotations on the subclass #14910

@WojciechZankowski

Description

@WojciechZankowski

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

v6.4.0

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

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