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

Error when reading property of JSON that may be null if not type is assigned. #147

Open
fofi opened this issue Oct 4, 2017 · 0 comments

Comments

@fofi
Copy link

fofi commented Oct 4, 2017

I came across a bug where we try to read the properties of a possible null value when type is not assigned to the model.

It's not really a bug because type is not there, but it should not break.

var validator = require('is-my-json-valid')
var model = {
  oneOf: [
    {
      additionalProperties: false,
      properties: {
        name: {
          type: 'string',
          required: true
        }
      }
    }
  ]
}
var validate = validator(model)
validate(null)
      if (data.name === undefined) {
              ^

TypeError: Cannot read property 'name' of null

version: 2.16.1

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

No branches or pull requests

1 participant