我正在尝试使用dojox JSON 模式验证器验证一些 JSON 对象 but I am new to this sort of thing and I can't get my schema right. I'm mostly trying to make sure that there aren't any missing fields in my objects.
基本上,我有一个对象,它有两个字段,称为类型和描述。该对象还可以有一个属性字段,其中包含任意数量的附加对象字段。如果有帮助的话,我在下面放了一些语法表示
参数:类型描述[属性]
属性:参数+
我的对象的示例如下所示:
{
"type": "object",
"description": "The point of interest location description.",
"properties": {
"pageIndex": {
"type": "number",
"description": "The page index to view"
},
"points": {
"description": "Used if viewState.zoomWidth is true; specifies 4 corners of the rectangle to make visible.",
"type": "array of point objects {x: y:}"
},
"viewState": {
"type": "object",
"description": "The view state information",
"properties": {
"hasViewState": {
"type": "boolean",
"description": "Whether there is view state information to use"
},
"rotate": {
"type": "number",
"description": "Degrees of rotation"
},
"extents": {
"type": "boolean",
"description": "Whether the view should scale to fit extents or not"
},
"zoomWidth": {
"type": "boolean",
"description": "Whether the view should scale to fit width or not"
},
"scaleFactor": {
"type": "number",
"description": "The scale factor for the view state"
},
"deviceRect": {
"type": "object",
"description": "The device rectangle geometry",
"properties": {
"left": {
"type": "number",
"description": "The left edge of the device rectangle"
},
"right": {
"type": "number",
"description": "The right edge of the device rectangle"
},
"top": {
"type": "number",
"description": "The top edge of the device rectangle"
},
"bottom": {
"type": "number",
"description": "The bottom edge of the device rectangle"
}
}
},
"eyePoint": {
"type": "object",
"description": "The eyepoint coordinate",
"properties": {
"x": {
"type": "number",
"description": "The x coordinate of the eyepoint"
},
"y": {
"type": "number",
"description": "The y coordinate of the eyepoint",
}
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我设法制作了一个看起来很接近但仍然无法验证它的模式。这就是我尝试过的编辑:它现在似乎可以验证,但不会捕获额外的字段或丢失的字段
{
"id" : "arg",
"type" : "object",
"properties" : {
"type" : { "type" : "string", "optional" : false },
"description" : { "type" : "string", "optional" : false },
"properties" : {
"type" : "object",
"patternProperties" : {
"[A-Za-z0-9]" : { "$ref" : "arg" }
}
}
},
"additionalProperties" : false
}
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激