Skip to main content

Added Swagger Type Discriminator Support

· One min read

Swagger makes use of a property discriminator to support polymorphism in custom types. We have now added support for this property in our system. We also offer an extension that will allow you to specify a custom value for the discriminator to override its default value.

Details

In case of Swagger 1.2, a user can use the discriminator property in the Model Object as follows:

"Animal": {
"id": "Animal",
"required": [
"id",
"type"
],
"properties": {
"id": {
"type": "long"
},
"type": {
"type": "string"
}
},
"subTypes": ["Cat"],
"discriminator": "type"
}

In case of Swagger 2.0, the user can specify this property in a Definitions Object as follows:

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

We now support this property both during import/export of Swagger. The discriminator value will be the model/definition name of the parent model or the children model. We also allow our users to specify a custom discriminator value using the APIMATIC's Discriminator Value extension. More details on this extension can be viewed at Swagger CodeGen Extensions