Recursive references not expanded
esiegel opened this issue · 1 comments
esiegel commented
Below is a schema for parsing arrays of objects where each value in the object is either a string or another object. I'm finding the situation where things that should not validate are in fact passing validation.
#examples
# good
[{a: "a", b: "b", c: "c", "nested": {d: "a", e: "b"}}]
# bad where any of the values are not a,b,c or another object
[{a: "BAD", b: {c: "BAD2 }}]
schema = JsonSchema.parse!(
{
"$schema" => "http://json-schema.org/draft-04/schema#",
type: "array", items: { "$ref" => "#/definitions/obj_abc" },
definitions: {
abc: { type: "string", enum: ["a", "b", "c"] },
obj_abc: {
type: "object",
additionalProperties: {
oneOf: [
{ "$ref" => "#/definitions/abc" },
{ "$ref" => "#/definitions/obj_abc" }
]
}
}
}
}.with_indifferent_access
)
schema.expand_references!
data = [{
a: "a",
b: "b",
c: "c",
a_obj: { a: "a"},
bad_obj: { bad: "BAD"},
}]
success, errors = schema.validate(data)
I tried debugging this and found myself in the additionProperties validation where the get_extra_keys
was returning nil
. I'm assuming that the reference expander is doing something funky, or maybe I am myself.
Thanks for any and all help.
esiegel commented
Ok, this seems to be a problem with additionalProperties not returning a boolean on success. Creating a pull request now.