Using `allOf` and `nullable` in combination yields unexpected validation errors
See original GitHub issueWhat version of Ajv are you using? Does the issue happen if you use the latest version?
I am using oas3-chow-chow which is using version ^6.12.3
Ajv options object oas3-chow-chow defines the AJV options as seen here.
const options: Ajv.Options = {
/**
* Ignore following formats for now because they are not supported by AJV by default.
* TODO: Add custom format supports for following formats.
*/
unknownFormats: [
'int32',
'int64',
'float',
'double',
'byte',
'binary',
'password',
],
nullable: true,
jsonPointers: true,
};
export default function ajv(opts: Ajv.Options = {}) {
return new Ajv({
...options,
...opts,
});
}
JSON Schema
Unfortunately I’m locked into using OAS 3.0.x and have to use the "nullable": true
declaration
"MyArrayOfReferences": {
"type": "array",
"example": [
"prefix/14691d5de8f424c75558dd7375",
"prefix/6591827d39d443e983199e1cb7",
"prefix/ec403e0c81074d8db34a6c9431"
],
"items": { "type": "string" }
},
"UpdateMyArrayOfReferences": {
"properties": {
"myArrayOfReferences": {
"description": "Group settings. Set to `null` to remove.",
"allOf": [
{
"$ref": "#/components/schemas/MyArrayOfReferences"
}
],
"nullable": true
}
}
}
Sample data
{
"myArrayOfReferences": null
}
Validation result, data AFTER validation, error messages
"dataPath": "/myArrayOfReferences",
"error message": "RequestValidationError: Schema validation error: type should be array",
What results did you expect?
I expect to be able to provide a null
value without producing a validation error.
It seems related to this issue #983 because if I remove the $ref
and make everything inline, then the null
value is accepted.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
JSON Schema puts null values when validation fails on ...
When I use this online schema validator the validation fails as expected when the response doesn't match one of the schemas provided in...
Read more >Modifying data during validation - Ajv JSON schema validator
Unexpected results when modifying data. While pure schema validation produces the results independent of the keywords and subschema order, enabling any ...
Read more >Solved: Parse JSON - validation failed for null values - h...
Solved: I have a PowerApps instant cloud flow which receives a JSON array as a string I am attempting to parse the JSON,...
Read more >gMock Cookbook | GoogleTest
You can build complex matchers from existing ones using AllOf() ... An unexpected call is always an error, as the code under test...
Read more >OpenAPI Specification - Version 2.0 - Swagger
Swagger allows combining and extending model definitions using the allOf property of JSON Schema, in effect offering model composition. allOf takes in an...
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
Helping out @denver-HJS here.
Here is a runkit link: https://runkit.com/crizo23/611437b007a03a001a5b80e7 I couldn’t import AJV v6 though, so it won’t compile. I pasted the output I get on line 104
I believe this is by design, “nullable” was defined as an extension of type keyword, not as an extension of the schema. If you have a schema that doesn’t allow
null
and you want to acceptnull
you can just do:Below is not supposed to work: