Minor tweaks regarding required: true
(encourage v4-style required
)
#53
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
README.md
, encourage v4-stylerequired: ['prop', ...]
instead.undefined
is given as input (it's invalid JSON, hence, invalid input).required: true
.I've added the option
requiredV3
which defaults totrue
, to preserve backward compatibility.It's probably best to disable by default, because it's an implementation specific feature, like
filter
.(Note, there might be a better name for the option than
requiredV3
, suggestions are welcome).Long-term this is probably something that should be disabled by default, you can probably roll that out with a major version upgrade.
Breaking change, some of the test cases used
undefined
as input. This is not a valid JSON value, so it's IMO acceptable thatis-my-json-valid
exhibits undefined-behaviour. I would surely expect weird things to happen if I tried to run validate on aBuffer
object or some other non-JSON value :)The reason I'm phrasing like this is that, before code like:
Would not return a validation error. But if the schema had been
{type: 'array', required: true}
it would have returned an error.required: true
is not valid v4 JSON schema, and should not be necessary, however, strictly speaking there is nothing wrong with this behaviour becauseundefined
is invalid input -- so undefined/implementation-specific behavior is fine :)Implementation-specific behaviour is, however, a dangerous footgun. Powerful, but best hidden behind option flags, like
filter
.I suggest we throw a runtime error. I don't think we should return a validation error, because
undefined
is not a JSON value, hence, it's an input error, not a validation error (similar to someone providing aBuffer
object as input). It's probably not necessary to guard against all possible input errors, like circular object references etc. butundefined
is probably a common input error that people easily end up relying on.