swagger-api / swagger-parser

Swagger Spec to Java POJOs
http://swagger.io
Apache License 2.0
785 stars 531 forks source link

Parser does not Dereference Discriminator Mapping Targets #1875

Open da1910 opened 1 year ago

da1910 commented 1 year ago

When providing a discriminator for subtypes you can provide a reference to the target type for each discriminator value (see https://swagger.io/docs/specification/data-models/inheritance-and-polymorphism/)

I would expect this to be correctly resolved to the target schema object. Instead it is treated as a string and left as a reference. This means the Discriminator.getMapping() method returns data that is useless for deserializing a response.

The following OpenAPI json definition for the discriminator:

"discriminator": {
  "propertyName": "myDiscriminator",
  "mapping": {
    "type_a": "#/components/schemas/TypeA",
    "type_b": "#/components/schemas/TypeB"
  }
},

Produces a Discriminator instance (after python name mangling) like the following:

{
  "mapping": {
    "type_a": "#/components/schemas/TypeA",
    "type_b": "#/components/schemas/TypeB"
  },
  "propertyName": "my_discriminator"
}

I would expect the values of the mapping HashMap to actually be the target classes, so that this Discriminator object can be used to dispatch to the correct subclass.