Closed byrnedo closed 1 year ago
{
"foobar": [
{
"first": "A",
"second": true
},
{
"first": "X"
}
]
}
the complete error I get when %#v
is used:
[I#] [S#] doesn't validate with https://foo.com/test/definitions.json#
[I#/foobar/1] [S#/properties/foobar/items/oneOf] oneOf failed
[I#/foobar/1] [S#/properties/foobar/items/oneOf/0]
[I#/foobar/1] [S#/properties/foobar/items/oneOf/0/required] missing properties: 'second'
[I#/foobar/1/first] [S#/properties/foobar/items/oneOf/0/properties/first/const] value must be "A"
[I#/foobar/1/first] [S#/properties/foobar/items/oneOf/1/properties/first/const] value must be "B"
[I#/foobar/1/first] [S#/properties/foobar/items/oneOf/2/properties/first/const] value must be "C"```
this is the expected result. the instance json you passed does not validate with the provided schema:
let me clarify why it is invalid:
second item {"first": "X" }
does not satisfy:
oneOf
because: "second" property is missing && value of first
must be A
But it is X
oneOf
because: value of first
must be B
but it is X
oneOf
because: value of first
must be C
but it is X
i.e none of oneOf
schemas satisfied. so validation fails.just to clarify: both const
and required
are independent validations and both must be satisfied.
Ah I'm sorry @santhosh-tekuri , that was an incorrect reproduction I gave you to begin with. Should have checked that twice. I'll open a new ticket with a correct reproduction. Thanks for the quick and thorough reply.
if you are ok in sharing your schema and instance, then you can raise issue. no need to struggle for minimal reproduction
After actually looking through this the problem is on our side. 🤦
It was the same scenario but on of the oneOf
had an extra field that could be type [ "string", "null"]
and which was also required, and that was not being sent in the payload, so of course that won't pass validation.
Hi!
We're trying to migrate to your library instead of https://github.com/xeipuuv/gojsonschema which we currently use and came across the following that we didn't expect to fail:
If you have an array referring to
oneOfs
that have a const discriminator and required fields, the validation will fail.Here's a minimal reproduction:
Error is: