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

Question Regarding Required #132

Closed
stetsmando opened this issue Aug 20, 2020 · 1 comment
Closed

Question Regarding Required #132

stetsmando opened this issue Aug 20, 2020 · 1 comment
Labels
question Issues that look for answers.

Comments

@stetsmando
Copy link

I wanted to see if anyone can point me in the right direction with an issue I'm having.
I'm sure this comes from my lack of understanding but is there a way to have validation fail if things are provided that are not part of the required key?

For example, I have a schema that looks like this:

const schema = {
  type: 'object',
  required: ['someProp'],
  properties: {
    someProp: {
      type: 'boolean'
    }
  }
}

Using that schema, if I validate the below object I would expect it to fail. This is not the case, is there a way to achieve that?

const myObj = {
  "another": true,
  "someProp": true
}

Thanks in advance for any help.

@ChALkeR
Copy link
Contributor

ChALkeR commented Aug 31, 2020

I recommend http://json-schema.org/ Slack (link) for general questions about JSON Schema itself.

Also, you are likely looking for additionalProperties: false or unevaluatedProperties: false.

Note that it should be specified on every object, as JSON Schema is open by default (i.e. anything passes).

schemasafe has a requireValidation: true option (which is not a part of the schema itself and has to be specified in options), the effect of it is that it refuses to use schemas that can allow unvalidated properties. I.e. it enforces the usage of additionalProperties or unevaluatedProperties and makes sure that it's not missed in any object.

I'm going to close this question as answered, as it's not an issue.

@ChALkeR ChALkeR closed this as completed Aug 31, 2020
@ChALkeR ChALkeR added the question Issues that look for answers. label Aug 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Issues that look for answers.
Projects
None yet
Development

No branches or pull requests

2 participants