具有嵌套对象的JSON模式

时间:2013-06-20 19:54:39

标签: json dojo

我正在尝试使用dojox JSON schema validator验证一些JSON对象,但我是这类新手,我无法正确使用我的架构。我主要是试图确保我的对象中没有任何遗漏的字段。

基本上,我有一个对象有两个叫做类型和描述的字段。该对象还可以具有包含任意数量的其他对象字段的属性字段。如果有帮助,我会在下面放一点语法表示

Args:类型描述[属性]

属性:Args +

我的对象的一个​​例子如下:

{
        "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",
                            }
                        }
                    }
                }
            }
        }
    }

我设法制作了一个似乎很接近但仍未验证的架构。这是我试过的 编辑:它现在似乎验证但它不会捕获额外的字段或缺少字段

{
        "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
    }

任何帮助将不胜感激

0 个答案:

没有答案
相关问题