You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
2: Object instancePath: "/children/2" schemaPath: "#/properties/children/items/oneOf" keyword: "oneOf" params: Object {passingSchemas: null} message: "must match exactly one schema in oneOf"
In real use case I have 20+ properties. And if in the data there's a typo, I get 20+ errors, when I'm looking for only "must match exactly one schema in oneOf". Is there a way to update the schema such that I get only the oneOf error?
The text was updated successfully, but these errors were encountered:
I am still getting to grips with all the details of AJV but I do know that oneOf is one of (no pun intended) the most misunderstood and misused features of AJV. The most common advice I hear when dealing with oneOf is that you probably want to actually use anyOf. If the types in your oneOf have no overlap, then I think it's equivalent, but more efficient since it doesn't need to check ALL of the different types when it finds a match.
As for the error reporting I think that what you want may have once been the behaviour according to this response by EP so I can only assume it was changed to report all of the schemas that didn't match for good reasons.
So AFAIK this is not something that we'll be open to changing.
What version of Ajv you are you using?
8.12.0
What problem do you want to solve?
Schema:
var schema = { type: 'object', additionalProperties: false, properties: { children: { type: 'array', items: { oneOf: [{ type: 'object', properties: { a: { type: 'string' } }, required: ['a'], additionalProperties: false }, { type: 'object', properties: { b: { type: 'string' } }, required: ['b'], additionalProperties: false }] } } } };
Data:
const data = { "children": [ { a: 'a' }, { b: 'b' }, { c: 'c' } ] };
Code:
var Ajv = require('ajv'); var ajv = new Ajv(); ajv.validate(schema, data); console.log('Errors:', ajv.errors);
Errors:
Array of 3 items:
0: Object instancePath: "/children/2" schemaPath: "#/properties/children/items/oneOf/0/required" keyword: "required" params: Object {missingProperty: "a"} message: "must have required property 'a'"
1: Object instancePath: "/children/2" schemaPath: "#/properties/children/items/oneOf/1/required" keyword: "required" params: Object {missingProperty: "b"} message: "must have required property 'b'"
2: Object instancePath: "/children/2" schemaPath: "#/properties/children/items/oneOf" keyword: "oneOf" params: Object {passingSchemas: null} message: "must match exactly one schema in oneOf"
In real use case I have 20+ properties. And if in the data there's a typo, I get 20+ errors, when I'm looking for only "must match exactly one schema in oneOf". Is there a way to update the schema such that I get only the oneOf error?
The text was updated successfully, but these errors were encountered: