Added {useDefault: true}
option flag to substituted in default
values
#55
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.
Fixing issues #48.
Basically the
useDefault
option flag will allow substitution ofdefault
values from JSON schema.These will nest and they will not work for
required
properties. Validation will also validate the default value. Ideally we could do this at compile-time.It works by mutating the input, so it only works if top-level value is an object or array. But this seems like a reasonable limitation. It's very very nice that we get default substituted in along with validation.
Proper warnings about this being a non-standard feature and it being mutating the input object have been added to
README.md
.I generally agree that features like
useDefault
andfilter
are dangerous. And they should definitely be hidden behind feature flags. But hiding them in methods likevalidator.filter
seems to make little sense, one of the primary features is this being fast and getting the validation done along with default value substitution. + the ability to combinefilter
anduseDefault
.Note, I understand anyone having mixed feelings about adding non-standard features like this. But in practice they are very useful and they have no performance overhead as they are enabled/disabled at compile-time.