In OpenAPI, inheritance is achieved with allof. For instance, in this example:
"definitions": {
"Pet": {
"type": "object",
"allOf": [
{
"$ref": "#/definitions/NewPet" # <--- here
},
[...]
]
},
"NewPet": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
}
},
I didn't find in the spec anything about multiple inheritance. For instance, if Pet inherits from both NewPet and OldPet.
In Python, I would write
class Pet(NewPet, OldPet):
...
and the Method Resolution Order is deterministic about which parent class should be checked first for methods/attributes, so I can tell if Pet.age will be NewPet.age or OldPet.age.
So what if I let Pet inherit from both NewPet and OldPet, where name property is defined in both schemas, with a different value in each? What will be Pet.name?
"definitions": {
"Pet": {
"type": "object",
"allOf": [
{
"$ref": "#/definitions/NewPet" # <--- multiple inheritance
"$ref": "#/definitions/OldPet"
},
[...]
]
},
"NewPet": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
}
},
"OldPet": {
"type": "object",
"properties": {
"name": {
"type": "integer" # <-- name redefined here, different type
},
}
},
Will OldPet take precedence? NewPet? It is undefined/invalid? Is it application defined?
I tried this in swagger-editor. Apparently, the schema with two refs is valid, but swagger-editor does not resolve the properties. If just displays allof with the two references.
Edit: According to this tutorial, having several refs in the same allof is valid. But nothing is said about the case where both schemas have a different attribute with the same name.
NewPet.nametoNewPet.new_name.