{
"$schema": "http://json-schema.org/schema#",
"definitions": {
"uuid": {
"title": "uuid",
"description": "UUID ( http://regex101.com/r/eJ7gN2 )",
"type": "string",
"minLength": 36,
"maxLength": 36,
"pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"
},
"reference": {
"title": "reference",
"description": "A reference to an object by UUID",
"type": "object",
"properties" : {
"id": {
"$ref": "#/definitions/uuid"
}
},
"required": [ "id" ]
},
"imageref": {
"title": "imageref",
"description": "Reference to an image using an internal UUID",
"type": "object",
"properties": {
"size": {
"description": "Largest side of the image, depends on aspect ratio",
"type": "integer",
"minimum": 0,
"maximum": 1600
},
"crop": {
"description": "Flag to tell the system to crop the image or not",
"type": "boolean",
"default": false
}
}
}
}
}
imageref
应继承reference
,以便imageref
具有id
中的reference
属性?我还有很多其他的reference
类型的东西,我试图一遍又一遍地消除重复这个定义。
答案 0 :(得分:3)
要从其他架构继承,请使用allOf
并结合$ref
:
{
"title": "Extension schema",
"allOf": [{"$ref": "/path/to/base/schema"}]
}
继承同一文件中的另一个模式是一样的 - 您使用片段引用它,就像您在其他地方一样:
{
"title": "Extension schema",
"allOf": [{"$ref": "#/definitions/reference"}]
}