swagger-parser icon indicating copy to clipboard operation
swagger-parser copied to clipboard

Parser does not Dereference Discriminator Mapping Targets

Open da1910 opened this issue 2 years ago • 0 comments

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.

da1910 avatar Jan 19 '23 13:01 da1910