例如,文件系统的模式,目录包含文件列表.该模式包括文件的规范,接下来是子类型"图像"和另一个"文本".
底部有主目录模式.目录具有属性内容,该属性内容是应该是文件的子类型的项目数组.
基本上我正在寻找的是一种告诉验证器从被验证的json对象中的属性中查找"$ ref"的值的方法.
示例json:
{
"name":"A directory",
"content":[
{
"fileType":"http://x.y.z/fs-schema.json#definitions/image",
"name":"an-image.png",
"width":1024,
"height":800
}
{
"fileType":"http://x.y.z/fs-schema.json#definitions/text",
"name":"readme.txt",
"lineCount":101
}
{
"fileType":"http://x.y.z/extended-fs-schema-video.json",
"name":"demo.mp4",
"hd":true
}
]
}
Run Code Online (Sandbox Code Playgroud)
"伪"架构注意到"图像"和"文本"定义包含在同一模式中,但它们可能在别处定义
{
"id": "http://x.y.z/fs-schema.json",
"definitions": {
"file": {
"type": "object",
"properties": {
"name": { "type": "string" },
"fileType": {
"type": "string",
"format": "uri"
}
}
},
"image": {
"allOf": [
{ "$ref": "#definitions/file" },
{
"properties": {
"width": { "type": "integer" },
"height": { "type": "integer"}
}
}
]
},
"text": { …Run Code Online (Sandbox Code Playgroud) 我正在尝试实现这个条件:根据另一个字段的值需要字段,即如果请求带有"index":"true",则需要"id"元素:true.
这是一个示例模式:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "test title",
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/Item"
},
"minItems": 0
}
},
"required": [
"data"
],
"definitions": {
"Item": {
"type": "object",
"properties": {
"id": {
"type": [
"integer",
"string"
]
},
"type": {
"type": "string"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
如何实施?
任何指针都会有所帮助.