Closed Carl-Foster closed 1 year ago
Hi.
Thank you for reporting this issue. I can confirm that oneOf
resolution on root level does not invalidate the input, but if it is contained on an object it does. This is inconsistend and I will fix this.
Note that json-schema-library
usually requires a defined property type. If you pass in a schema with an type-array, the validation works as expected. Still, type-arrays are not fully supported in helper functions yet (e.g. getTemplate
), so this might not be an option for you:
draft = new Draft07({
type: ["string", "number"],
oneOf: [{ type: "string" }, { type: "number" }]
});
const valid = draft.validate([]);
assert.notEqual(valid.length, 0);
I have published a patch to adress this issue with json-schema-library@7.4.6
and json-schema-library@8.0.0-rc5
.
Cheers.
Reproduce
Expectation
Validation should properly validate a top level schema that does not specify a top level type
Notes
validate
andgetJsonSchemaType
where it will default to the received value when no type is found.Edit
On further inspection, this may only occur when non-object values are passed with the "oneOf" top level schema.