可以使用$ref关键字来引用已定义的JSON schema属性,从而在JSON schema中包含其他属性。
示例代码:
{ "$schema": "http://json-schema.org/draft-07/schema#",
"definitions": { "person": { "type": "object", "properties": { "name": {"type": "string"}, "age": {"type": "integer"} }, "required": ["name"] } },
"type": "object", "properties": { "title": {"type": "string"}, "author": {"$ref": "#/definitions/person"} }, "required": ["title", "author"] }
在上面的例子中,我们定义了一个名为“person”的JSON schema,它有两个属性:name和age。然后我们在主JSON schema中使用$ref关键字引用了“person”JSON schema,并将其作为“author”属性的值。这样,我们就可以在JSON schema中包含其他JSON schema属性。