Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow required to overwrite required_by_default #817

Closed
wants to merge 1 commit into from

Conversation

geryogam
Copy link

@geryogam geryogam commented Apr 18, 2018

In the README.md file, the required_by_default option is described as:

If true, all schemas that don't explicitly set the required property will be required.

But schemas that explicitly set the required property do not overwrite the required_by_default option as advertised, so they are always required (even with required = false using JSON Schema 3 syntax or required = [] using JSON Schema 4 syntax).

The issue can be demonstrated with this code snippet which does not pass validation:

var element = document.querySelector("#editor");
var options = {
  "required_by_default": true,
  "schema": {
    "type": "object",
    "properties": {
      "a": {"type": "string"},
      "b": {"type": "string"}
    },
    "required": ["a"]  // should overwrite `required_by_default` but does not
  }
};
var editor = new JSONEditor(element, options);
var errors = editor.validate({"a": "foobar"});

if (errors.length) {
  window.console.log(errors);
} else {
  window.console.log("OK");
}

In the README.md file, the `required_by_default` option is described as: "If `true`, all schemas that don't explicitly set the `required` property will be required." But schemas that explicitly set the `required` property did not overwrite the `required_by_default` option as advertised, so they were always required (even with `required = false` for JSON Schema 3 or `required = []` for JSON Schema 4).
@schmunk42
Copy link
Collaborator

@geryogam
Copy link
Author

@geryogam geryogam closed this Apr 25, 2018
@geryogam geryogam deleted the patch-1 branch April 25, 2018 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants