openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[JAVA] generate a wrong class using inheritence and discriminator

Open nabil86 opened this issue 7 years ago • 6 comments

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

nabil86 avatar Feb 06 '19 18:02 nabil86

@nabil86 can you try the following instead (without type:object)?

classOne:
  allOff:
    - $ref: ''#/components/schemas/riskType'

wing328 avatar Feb 07 '19 03:02 wing328

It does'nt work. As mentioned before if I change generator's version from 3.3.4 to 3.1.2 it generates what I want.

nabil86 avatar Feb 07 '19 08:02 nabil86

Possible reference with #1963

hellboy81 avatar Feb 15 '19 13:02 hellboy81

No, this Example has the correct class name @JsonSubTypes.Type(value = ### EnumerationUDF.class, name = "EnumerationUDF"),

my probleme is the name class start with lower case letter This one @JsonSubTypes.Type(value = enumerationUDF.class, name = "EnumerationUDF"),

nabil86 avatar Feb 15 '19 15:02 nabil86

I found reason related with #1963

The in schema declared discriminator: type is not presented in response body.

Tests with Wiremock confirmed it.

[
  {
    "type": "BooleanUDF", // The missing  type descriminator
    "booleanUDFKey": {
      "serial": "312415926"
    },
]

hellboy81 avatar Feb 20 '19 11:02 hellboy81

FYI, there is a typo in the example. allOff should be allOf .

tedepstein avatar Mar 04 '19 11:03 tedepstein