mafintosh/is-my-json-valid

Default `required : true`?

Closed this issue · 1 comments

AJB99 commented

I'd like to have all properties of any given data object being validated to be required by default. Additionally, I'd like additionalProperties to default to false.

Is this currently possible without hacking the code?

This is not currently possibly, but might I suggest that you use your own function that does this for you, something like this:

function createSchema (properties) {
  return {
    type: 'object',
    additionalProperties: false,
    required: Object.keys(properties),
    properties: properties
  }
}

also, instead of setting required to true, I would recommend using the new format (4) where required is an array of the keys that should be required.