Indeed, the example given here is not valid, since $ref cannot coexist with other properties in the same object. $ref is a JSON reference and by definition ignores other properties.
Based on your question, I assume that you are looking for a basic composition (not inheritance). This is achievable with the allOf word allOf .
So, in the example you provided, you will get something like this:
{ "baseProperties": { "type": "object", "properties": { ... } }, "complexModel": { "allOf": [ { "$ref": "#/definitions/baseProperties" }, { "type": "object", "properties": { "unique_thing": { "type": "string" }, "another_unique_thing": { "type": "string" } } } ] } }
YAML version:
definitions: baseProperties: type: object properties: ... complexModel: allOf: - $ref: '#/definitions/baseProperties' - type: object properties: unique_thing: type: string another_unique_thing: type: string
You can also check an example in the specification .
Ron
source share