I am new to JSON Schemas and JSON References, and I have run into an issue in combining them.
Can a JSON Schema contain a JSON reference in any slot?
For example, here are two schemas. The first schema works fine, but the second schema is rejected as invalid. Is schema2 really an invalid schema, or is this failure just a limitation of the implementation? Thanks.
import jsonschema
schema1 = {
"type" : "object",
"oneOf" : [
{ "properties" : { "a" : { "type" : "string" } }, "required" : ["a"] },
{ "properties" : { "b" : { "type" : "integer" } }, "required" : ["b"] },
],
}
# The following lines work as expected.
jsonschema.validate({"a" : "s"}, schema1)
jsonschema.validate({"b" : 1}, schema1)
schema2 = {
"type" : "object",
"oneOf" : {"$ref" : "#/objectChoice"},
"objectChoice" : [
{ "properties" : { "a" : { "type" : "string" } }, "required" : ["a"] },
{ "properties" : { "b" : { "type" : "integer" } }, "required" : ["b"] },
]
}
# The following lines throw an exception:
#
# jsonschema.exceptions.SchemaError: {'$ref': '#/objectChoice'} is not of type u'array'
jsonschema.validate({"a" : "s"}, schema2)
jsonschema.validate({"b" : 1}, schema2)