Dependencies

50 views
Skip to first unread message

Bryan Garretson

unread,
Nov 12, 2014, 7:25:14 PM11/12/14
to ruby-jso...@googlegroups.com
Hello - I am having trouble getting the gem to fully_validate dependencies - hopefully I'm missing something obvious. In the following JSON schema, I have made a simple dependency between a type and a refinedType (in one example) and a type and a default value property type in another. 

I have verified in my own schema and other production schema that utilize dependencies, that violating the dependency has no effect on validation. 

The following object, validated against the following schema, is expected to fail validation and passes when invoking .fully_validate

[Test Object]
[
{
"name": "isMagic",
"type": "integer",
"refinedType": "float"
}
]

[Schema]
{
    "type": "array",
    "items": [
        {
            "$ref": "#/definitions/apiParameter"
        }
    ],
    "additionalProperties": false,
    "definitions": {
        "apiParameter": {
            "type": "object",
            "allOf": [
                {
                    "$ref": "#/definitions/parameter"
                },
                {
                    "$ref": "#/definitions/typeDefinition"
                }
            ]
        },
        "parameter": {
            "type": "object",
            "required": [ "name" ],
            "properties": {
                "id": {
                    "type": "string"
                },
                "name": {
                    "type": "string"
                },
                "location": {
                    "type": "string",
                    "enum": [ "query", "pathReplace", "body", "header" ]
                },
                "description": {
                    "type": "string"
                },
                "required": {
                    "type": "boolean",
                    "default": false
                },
                "enum": {
                    "type": "array",
                    "minItems": 1,
                    "uniqueItems": true
                },
                "enumDescriptions": {
                    "type": "array"
                }
            }
        },
        "typeDefinition": {
            "type": "object",
            "required": [ "type" ],
            "properties": {
                "type": {
                    "type": "string",
                    "enum": [ "boolean", "integer", "number", "string" ]
                },
                "refinedType": {
                    "type": "string"
                },
                "default": {
                    "not": { 
                        "type": [ "array", "object", "null" ] 
                    }
                },
                "minimum": {
                    "type": { "enum": [ "integer", "number" ] }
                },
                "maximum": {
                    "type": { "enum": [ "integer", "number" ] }
                }
            },
            "dependencies": {
                "refinedType": {
                    "oneOf": [
                        {
                            "properties": {
                                "type": { "enum": [ "integer" ] },
                                "refinedType": { "enum": [ "int16", "int32", "int64" ] }
                            }
                        },
                        {
                            "properties": { 
                                "type": { "enum": [ "number" ] },
                                "refinedType": { "enum": [ "float", "double" ] }
                            }
                        }
                    ]
                },
                "type": {
                    "oneOf": [
                        {
                            "properties": {
                                "default": { "type": { "enum": [ "integer" ] } },
                                "type": { "enum": [ "integer" ] }
                            }
                        },
                        {
                            "properties": {
                                "default": { "type": { "enum": [ "number" ] } },
                                "type": { "enum": [ "number" ] }
                            }
                        },
                        {
                            "properties": {
                                "default": { "type": { "enum": [ "boolean" ] } },
                                "type": { "enum": [ "boolean" ] }
                            }
                        },
                        {
                            "properties": {
                                "default": { "type": { "enum": [ "string" ] } },
                                "type": { "enum": [ "string" ] }
                            }
                        }
                    ]
                }
            }
        }
    }
}
Reply all
Reply to author
Forward
0 new messages