5

我正在尝试使用dojox JSON 模式验证器验证一些 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
    }

任何帮助,将不胜感激

4

0 回答 0