5

dojox JSON スキーマ・バリデーターを使用していくつかの JSON オブジェクトを検証しようとしていますが、この種のことは初めてで、スキーマを正しく取得できません。私は主に、オブジェクトに欠落しているフィールドがないことを確認しようとしています。

基本的に、type と description という 2 つのフィールドを持つオブジェクトがあります。オブジェクトは、任意の数の追加オブジェクト フィールドを含むプロパティ フィールドを持つこともできます。それが役立つ場合は、以下に少し文法表現を入れます

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

近いと思われるスキーマを作成することができましたが、まだ検証されていません。これは私が試したものです EDIT:今では検証されているようですが、余分なフィールドや欠落しているフィールドをキャッチしません

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