swagger-api / swagger-codegen-generators

Apache License 2.0
284 stars 425 forks source link

[Spring] duplicated disciminator field in REST response when existing property is used for polimorphism #459

Open rrobsonm opened 5 years ago

rrobsonm commented 5 years ago

I am using swagger-codegen-maven-plugin version: 2.4.8 If discriminator and property exists with the same name. Spring rest response has duplicated fields.

for such definition: "Pet": { "type": "object", "required": [ "name", "petType" ], "properties": { "name": { "type": "string" }, "petType": { "type": "string" } }, "discriminator": "petType", }

it is generated: @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "@type", visible = true )

JsonTypeInfo.As.PROPERTY is always generated(it is not parametrized anyway) It would be better to generate in such case: @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "@type", visible = true )

So fields won't be duplicated in rest response.

Zemke commented 3 years ago

OpenAPITools/openapi-generator#3796