OpenAPITools / OpenAPITools/openapi-generator

[JAVA] generate a wrong class using inheritence and discriminator

Open
#2,080 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

Given this config:

  riskObject:
      type: object
      discriminator:
        propertyName: riskType
      properties:
        riskType:
          type: string

classOne:
  type: object
 allOff:
    - $ref: ''#/components/schemas/riskObject'
......

After Generating a class with prefix "Api" the result is:
`@Validated @javax.annotation.Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2019-01-30T15:17:33.825+01:00[Europe/Paris]") @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", visible = true ) @JsonSubTypes({ @JsonSubTypes.Type(value = **classRiskOne.class**, name = "classRiskOne") })`

this result is wrong. i excpet **ApiClassRiskOne.class**, this is wok fin with generator version **3.1.2** but there is a regression since version **3.2.0**

in pom conf
modelNamePrefix>Api</modelNamePrefix>
is ignored for inheritence

openapi-generator version

Since 3.2.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the generated Java classes from the supplied discriminator schema with modelNamePrefix set to Api, comparing generator versions 3.1.2 and 3.2.0. Trace the inheritance and discriminator model-naming path, then verify that the generated @JsonSubTypes reference uses ApiClassRiskOne.class rather than classRiskOne.class.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
backend-api-design, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.