strictRequired error when required properties exists and are declared inside oneOf
See original GitHub issueUsing version 8.1.0 with strict
mode enabled, an error of type strictRequired
is thrown when required
properties are declared inside oneOf
even if those properties are defined next to oneOf
.
Ajv options object
const ajv = new Ajv({
strict: true,
})
JSON Schema
{
"type": "object",
"properties": {
"property_a": {
"type": "string",
},
"property_b": {
"type": "string",
},
},
"anyOf": [
{ "required": [ "property_a" ] },
{ "required": [ "property_b" ] }
]
}
Sample data
{
property_a: 'ok'
}
Your code
The code posted on runkit throw an error with the message strict mode: required property "property_a" is not defined at "#/anyOf/0" (strictRequired)
(after switching from stack trace viewer to properties viewer in the UI)
What results did you expect?
Unless I am misunderstanding something, I expect the code to be valid since property_a
is defined inside properties
.
Are you going to resolve the issue?
This probably requires a deep understanding of Ajv internals.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:6 (3 by maintainers)
Top Results From Across the Web
JSON Schema oneof without required - Stack Overflow
[EDITED - SEE THIRD SOLUTION BELOW]. Solution 1 - At least one, but not both (verbose). I would add an allOf with a...
Read more >Strict mode - Ajv JSON schema validator
With option strictRequired set to "log" or true Ajv logs warning or throws exception if the property used in "required" keyword is not...
Read more >mod_ssl - Apache HTTP Server Version 2.4
Require ssl-verify-client. The ssl provider allows access if the user is authenticated with a valid client certificate. This is only useful if SSLVerifyClient ......
Read more >Re: Dependencies between two "enums" - Google Groups
All I have to do in addition is to find out which of the "oneOf" Schemas are actually valid and ... property is...
Read more >Model | Ts.ED - A Node.js and TypeScript Framework on top of ...
Sometimes, it can be useful to create model with additional properties. By default, Json schema is strict over extra properties not declared in...
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
Have you planned a fix for this issue? When?
You’re welcome. Let’s keep it open - it’s a limitation, not the optimal behaviour.