Reusing extended schemas #32

Closed
pospi opened this Issue Feb 27, 2012 · 1 comment

Projects

None yet

2 participants

@pospi
pospi commented Feb 27, 2012

It appears that JSV's implementation of schema extension is buggy when reusing extended schemas. I'm not sure what is happening internally, but it manifests when adding required properties to multiple extensions of a single schema. It appears that all additional constraints from the extending schemas are merged into a single base one, resulting in every instance failing due to the absence of different required properties.

Code to reproduce follows.

Main schema:

{
    "id"            : "http://example.com/schemas/extendTest",
    "$schema"       : "http://json-schema.org/draft-03/schema",
    "description"   : "Testing extending the same schema multiple times",

    "type" : "object",
    "properties" : {
        "set1" : {
            "type" : "array",
            "items" : {
                "extends" : {"$ref" : "http://example.com/schemas/extendTest/subrecord"},
                "properties" : {
                    "newVar1" : {
                        "type" : "string",
                        "required" : true
                    }
                },
                "additionalProperties" : false
            },
            "additionalItems" : false
        },
        "set2" : {
            "type" : "array",
            "items" : {
                "extends" : {"$ref" : "http://example.com/schemas/extendTest/subrecord"},
                "properties" : {
                    "newVar2" : {
                        "type" : "string",
                        "required" : true
                    }
                },
                "additionalProperties" : false
            },
            "additionalItems" : false
        }
    },
    "additionalProperties" : false
}

Child schema:

{
    "id" : "http://example.com/schemas/extendTest/subrecord",
    "$schema"       : "http://json-schema.org/draft-03/schema",
    "type" : "object",
    "properties" : {
        "someVar" : {
            "type" : "string"
        }
    }
}

I feel like this should be working, but perhaps I am implementing the inheritance incorrectly.
Cheers!

@garycourt
Owner

The attribute "additionalProperties" when set to false seals the schema, so that you can no longer extend it. To do what you are trying to do, you need to have a third schema that doesn't have those restrictions in it.

@garycourt garycourt closed this Mar 1, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment