Given the schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"oneOf": [
{
"$ref": "#/definitions/First"
},
{
"$ref": "#/definitions/Second"
}
],
"definitions": {
"First": {
"type": "object",
"properties": {
"type": {"const": "one"},
"value": {"type": "number"}
},
"required": ["type", "value"]
},
"Second": {
"type": "object",
"properties": {
"type": {"const": "two"},
"value": {"type": "number"}
},
"required": ["type", "value"]
}
}
}
I would expect these two schemas to be seen as different shapes and should correctly match these two examples
{"type": "one", "value": 5}
{"type": "two", "value": 5}
And for this to be invald
{"type": "three", "value": 5}
Using the python-rapidjson library:
>>> import rapidjson
>>> compiled = rapidjson.Validator(open('example.schema.json').read())
>>> compiled('{"type": "one", "value": 5}')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
rapidjson.ValidationError: ('oneOf', '#', '#')
>>> compiled('{"type": "two", "value": 5}')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
rapidjson.ValidationError: ('oneOf', '#', '#')
>>> compiled('{"type": "three", "value": 5}')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
rapidjson.ValidationError: ('oneOf', '#', '#')
If I change the type from using const to something like enum: ["one"] this works.
I would expect const as a shape discriminator to work.
Given the schema
{ "$schema": "http://json-schema.org/draft-07/schema#", "oneOf": [ { "$ref": "#/definitions/First" }, { "$ref": "#/definitions/Second" } ], "definitions": { "First": { "type": "object", "properties": { "type": {"const": "one"}, "value": {"type": "number"} }, "required": ["type", "value"] }, "Second": { "type": "object", "properties": { "type": {"const": "two"}, "value": {"type": "number"} }, "required": ["type", "value"] } } }I would expect these two schemas to be seen as different shapes and should correctly match these two examples
{"type": "one", "value": 5}{"type": "two", "value": 5}And for this to be invald
{"type": "three", "value": 5}Using the python-rapidjson library:
If I change the
typefrom usingconstto something likeenum: ["one"]this works.I would expect const as a shape discriminator to work.