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

validateMultiple() and banUnknownProperties incompatible with (certain) anyOf #74

Open
dertseha opened this issue Nov 20, 2013 · 3 comments · May be fixed by #166
Open

validateMultiple() and banUnknownProperties incompatible with (certain) anyOf #74

dertseha opened this issue Nov 20, 2013 · 3 comments · May be fixed by #166

Comments

@dertseha
Copy link

Using grunt-tv4, I'm trying to validate my schema files. One of them is topicName.json:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "id": "http://host.com/schema/topicName",

  "type": "string",
  "minLength": 1
}

Running it with the options

      options: {
        root: grunt.file.readJSON("json-v4.json"),
        banUnknownProperties: true
      },

Produces no errors, it is a valid schema. (json-v4.json is the meta schema from json-schema.org)

But, if I also enable multi: true, then the following error is reported:

fail: src/lib/schema/topicName.json !== http://json-schema.org/draft-04/schema#
   invalid type: string (expected array)
      /type
      -> value: string -> "string"
      -> schema: array -> /properties/type/anyOf/1/type

As it turns out, validateAnyOf() does not properly handle a true this.trackUnknownProperties.

Note that type: "string" is invalid, type: ["string"] is valid. This is because the loop in ValidatorContext.validateAnyOf() only properly resets the this.error array when the last checked subSchema was valid. In the given case, the last subSchema (checking an array) fails, and the errors are kept in the this.errors array, bleeding through.

validateAnyOf() should report all errors of all subSchemas only if all of them failed during validateMultiple().

@geraintluff
Copy link
Owner

Thanks for the bug (as well as the very helpful diagnosis!).

I'm pretty busy right now, but I'll try and get a fix to you by the end of Friday - sorry for the delay.

@ahultgren
Copy link

Still having this same issue. @geraintluff do you have any plans on fixing this? Or any hints in case I need to fix it myself?

@domoritz
Copy link

👍 please fix

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

Successfully merging a pull request may close this issue.

4 participants