Open ngouy opened 2 years ago
I think I am seeing the same thing. I want a nullable object, which if it does exist has two optional keys
schema = {
"type"=>"object",
"required" => ["a"],
"properties" => {
"a" => {
"type" => "integer",
"default" => 42
},
"b" => {
"type" => "object",
"properties" => {
"x" => {
"type" => "integer"
}
}
}
},
'oneOf': [
{ required: ['a'] },
{ required: ['b'] },
]
}
JSON::Validator.validate!(schema, { 'a' => 1 })
JSON::Validator.validate!(schema, { 'b' => { 'x' => 1 } })
json-schema-3.0.0/lib/json-schema/attribute.rb:18:in `validation_error': The property '#/' did not contain a required property of 'a' (JSON::Schema::ValidationError)
But I don't wish to have a required value of 'a' :S
Let's have a schema with required property, and some other that are OR null, OR XOR required
I want this to validate like that :
{ "first_name": "Some", "last_name": "One" }
OK{ "first_name": "Some", "last_name": "One", "xor_property_1": null }
OK{ "first_name": "Some", "last_name": "One", "xor_property_1": null, xor_property_2: null }
OK{ "first_name": "Some", "last_name": "One", "xor_property_1": null, xor_property_2: "value" }
OK{ "first_name": "Some", "last_name": "One", "xor_property_1": "value", xor_property_2: "value" }
KOPer : https://json-schema.org/implementations.html#validator-web%20(online) When I validate the first example with any online validator, we are good (I'm adding the top level
additionalProperties: false
key to simulate the "strict")With the gem :
The thing is that the oneOf code is forwarding the
strict: true
in the options here https://github.com/voxpupuli/json-schema/blob/master/lib/json-schema/attributes/oneof.rb#L21But the schema, initiated line 18, that runs the validation is completely blind when it comes to the "root" allowed properties, so it considers that the
oneOf
schema is invalid, regarding its own schema vs the dataAlso even if we are in strict mode, if we just remove the strict from oneOf it just works. Indeed if the parent is "strict" anyway, the validation error will append on the prior parent validation anyway