Problem with "required" in combination with "additionalProperties: false"
See original GitHub issueExpected behavior
Required properties should be required, all other properties specified in JSON schema should be allowed.
Actual behavior
If there is “additionalProperties”: false, and some properties in : “required” then any value of non-required property is interpreted as error: “No additional properties allowed, but property XYZ is set”
Steps to reproduce the behavior
- Create the folowing JSON schema and load it into the JSON Editor:
{
"type": "object",
"title": "Error: Only required properties are allowed",
"description": "If required properties are specified, non-required properties are considered as errors",
"additionalProperties": false,
"required": ["name"],
"properties": {
"name": {
"type": "string",
"title": "name"
},
"description": {
"type": "string",
"title": "description"
}
}
}
- Then enter anything in the “description” field.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7
Top Results From Across the Web
JSON schema : "allof" with "additionalProperties"
Your definition should not have "additionalProperties": false if you want to combine his properties with other ones. Yves M. Yves M.
Read more >Schema defines combining operations when ...
The schema defines combining operations allOf , anyOf , or oneOf while additionalProperties is set to false . This may result in all...
Read more >Frequently Asked Questions - Ajv JSON schema validator
Why the keyword additionalProperties: false fails validation when some properties are "declared" inside a subschema in anyOf/etc.
Read more >object — Understanding JSON Schema 2020-12 documentation
If we provide the number in the wrong type, it is invalid: ... You can use additionalProperties with a combination of properties and...
Read more >"additionalProperties" and "allOf", here we go again!
with regards to this, but this problem has made it on StackOverflow: ... 5. specify properties which are merged or combined (e.g. properties,...
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
@pmk65 Where in the specification is the relation between required and additionalProperties described as you have interpreted above? Accordning to Required Properties there is no relation between required properties and disallowing any other properties defined in the schema. additionalProperties only controls if you can add properties not defined in the schema. Thus all properties defined in the schema is allowed, regardless of what subset is marked as required.
clarified in #943