question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with "required" in combination with "additionalProperties: false"

See original GitHub issue

Expected 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

  1. 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"
    }
  }
}
  1. Then enter anything in the “description” field.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
reinesvscommented, Mar 7, 2019

@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.

0reactions
germanbisurgicommented, Apr 7, 2021

clarified in #943

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found