anyOf returns repeated errors
See original GitHub issueWhat version of Ajv are you using? Does the issue happen if you use the latest version?
"ajv": "^8.11.0",
"ajv-formats": "^2.1.1",
Ajv options object
I am using Ajv with allErrors
option, a few keywords and formats as well
const ajv = new Ajv({allErrors: true})
const formats: FormatName[] = ['date']
this.validator = addFormats(ajv, formats).addKeyword('kind').addKeyword('modifier')
JSON Schema
My schema is being generated through another package called typebox. This is what the schema looks like when it’s passed to Ajv for the validation.
{
kind: Symbol(ObjectKind),
type: 'object',
properties: {
enumProperty: {
kind: Symbol(EnumKind),
anyOf: [Array],
modifier: Symbol(OptionalModifier)
}
}
}
Sample data
{
"enumProperty": "invalid-value"
}
Your code
Not relevant at this point, I think.
Validation result, data AFTER validation, error messages
"data/enumProperty must be equal to constant, data/enumProperty must be equal to constant, data/enumProperty must be equal to constant, data/enumProperty must be equal to constant, data/enumProperty must be equal to constant, data/enumProperty must be equal to constant, data/enumProperty must match a schema in anyOf"
What results did you expect?
I would like to have a simple message indicating that the value is not valid for the schema and the acceptable values for that property:
"data/enumProperty must match a schema in anyOf: ["value1", "value2"]"
If that’s not possible, than just the first part would suffice:
"data/enumProperty must match a schema in anyOf"
Are you going to resolve the issue?
Unlikely
Issue Analytics
- State:
- Created a year ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Error Json Validation against JsonSchema and anyOf [closed]
I have a json to validate against jsonSchema, I don't understand why i have an error with the first anyOf, indeed, we can...
Read more >Strict mode - Ajv JSON schema validator
Strict mode intends to prevent any unexpected behaviours or silently ignored mistakes in user schemas. It does not change any validation results compared ......
Read more >Understanding JSON Schema
JSON Schema is a powerful tool for validating the structure of JSON data. However, learning to use it by reading its.
Read more >Improved Error Messages for Schema Validation in MongoDB ...
The error returns information about failure for two rules: "array did not match specified length" and "found a duplicate item," and it also...
Read more >Applying multiple subschemas | Opis JSON Schema
The value of this keyword must be an array of valid JSON schemas (objects or booleans). Schema. { "type": "array", "anyOf ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@felixjb Refer to comment https://github.com/sinclairzx81/typebox/issues/174#issuecomment-1134944761 for reasoning behind TypeBox’s preference for
anyOf
overenum
.Thank you so much!