Open
Description
Description
Given an object with oneOf
and a discriminator mapping, the generator erroneously still allows the schema names as aliases during de-/serialization (even if an explicit mapping for a respective referenced schema exists).
The spec says that only the explicit mappings should be usable. (See https://swagger.io/docs/specification/v3_0/data-models/inheritance-and-polymorphism/#discriminator)
For example:
Fruit:
discriminator:
mapping:
APPLE: '#/components/schemas/Apple'
BANANA: '#/components/schemas/Banana'
propertyName: fruitType
oneOf:
- $ref: '#/components/schemas/Apple'
- $ref: '#/components/schemas/Banana'
properties:
fruitType:
$ref: '#/components/schemas/FruitType'
required:
- fruitType
type: object
x-one-of-name: Fruit
Apple:
properties:
seeds:
type: integer
required:
- seeds
type: object
Banana:
properties:
length:
type: integer
required:
- length
type: object
@JsonSubTypes({
@JsonSubTypes.Type(value = Apple.class, name = "APPLE"),
@JsonSubTypes.Type(value = Banana.class, name = "BANANA"),
@JsonSubTypes.Type(value = Apple.class, name = "Apple"), // <-- Wrong
@JsonSubTypes.Type(value = Banana.class, name = "Banana") // <-- Wrong
})
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.13.0-SNAPSHOT")
public interface Fruit {
openapi-generator version
This is present on master
and affects at least 7.11.0
and 7.12.0
. After digging into the code and git history, I have no reason to believe that there are unaffected versions.
OpenAPI declaration file content or URL
Generation Details
No special set up required. Just use the sample.
Steps to reproduce
Just use the sample.