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

applyDefault option #75

Closed
Duncan00 opened this issue Nov 23, 2015 · 3 comments
Closed

applyDefault option #75

Duncan00 opened this issue Nov 23, 2015 · 3 comments

Comments

@Duncan00
Copy link

Does ajv have an option to apply default value from schema to input json if the property is not exist?
It would be nice to have feature.

@epoberezkin
Copy link
Member

Duplicate of #42. Not yet, but it's in the plan :)

@Duncan00
Copy link
Author

Thanks~ i just use https://www.npmjs.com/package/json-schema-defaults before doing validation now.

var defaults = require('json-schema-defaults');
var default_json = defaults(validate.schema); // <~ cannot set default value to $ref properties
_.defaultsDeep(payload, default_json);

@epoberezkin
Copy link
Member

Ah, interesting, thanks. I will look at this package... I though to do it after async validation but I will do it before. Without catering for edge-cases that are not that important it's pretty easy actually. And it will be much faster, as it will be compiled into the validating function.

Closing this one now, feel free to post to #42 if you have any questions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants