[英]JSON Schema - How to define object in object recursive
Situation is following: 情况如下:
1.) In an object, I can have a "string", "array" or another "object". 1.)在一个对象中,我可以有一个“字符串”,“数组”或另一个“对象”。
2.) The "array" can contain only "string". 2.)“数组”只能包含“字符串”。
3.) The "object" can contain 1.) which means that I can have an object in a object which only can have a string or array though (or even more nested objects) 3.)“对象”可以包含1.),这意味着我可以在一个对象中拥有一个对象,尽管该对象只能具有字符串或数组(甚至更多的嵌套对象)
Problem is now that 1.) and 2.) work but as soon as I add "$ref" to the "object" to get 3.) my validation server crashes with a stack overflow. 现在的问题是1.)和2.)可以工作,但是只要我将“ $ ref”添加到“ object”以得到3.),验证服务器就会因堆栈溢出而崩溃。
{
"$schema": "http://json-schema.org/draft-04/schema",
"type": "object",
"properties": {
"value": {
"oneOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
},
{
"type": "object",
"patternProperties": {
".*": {
"$ref": "#/properties/value"
}
}
}
]
}
}
}
The line "$ref": "#/properties/value"
breaks my code. "$ref": "#/properties/value"
破坏了我的代码。
How do I get this to work ? 我该如何工作?
Fixed it myself. 自己修复。 The line
"$ref": "#/properties/value"
has to be changed to "$ref": "#/properties"
行
"$ref": "#/properties/value"
必须更改为"$ref": "#/properties"
I thought that #/properties would mean only the property "value" is allowed inside these objects which is not what I wanted. 我认为#/ properties表示这些对象中只允许使用属性“ value”,这不是我想要的。 I wanted to have the contents of "value" so I went one step deeper.
我想拥有“价值”的内容,所以我更深入了一步。
Looks like "$ref": "#/properties"
doesn't mean that only "value" is allowed instead it means only the properties of "value". 看起来像
"$ref": "#/properties"
并不意味着只允许“ value”,而是仅意味着“ value”的属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.