tdegrunt/jsonschema

skipAttributes does not seem to work?

asc-netlight opened this issue · 2 comments

Current behaviour

Trying to use skipAttributes does not seem to skip the validation of a certain key.

Looking at the below code, the key gender is still validated.

var schema = {
  "id": "/SimplePerson",
  "type": "object",
  "properties": {
    "name": { "type": "string" },
    "votes": { "type": "integer", "minimum": 1 },
    "gender": { "type": "string" }
  }
};

var p = {
  "name": "Barack Obama",
  "votes": 12,
  "gender": 1
};

var v = new Validator();
console.log(v.validate(p, schema, { skipAttributes: ["gender", "instance.gender", "properties.gender"] }));

The validation is false, but I want it to skip the validation of "gender" so that the above validationResult would be valid.

Desired behaviour

Want to be able to skip validation of certain keys.

The skipAttributes configuration specifies schema keywords to be ignored. The keyword can only be entirely ignored, you can't (for example) tell the "properties" keyword to ignore certain properties and validate others.

If you would like to ignore errors affecting a particular instance, I would suggest:

  1. Filter the errors list, e.g. result.errors.filter(function(v){ return v.path.indexOf('gender') <= 0; })

  2. Or just make a deep copy of the schema, and edit that.

I hope this helps. Please close this issue out if this answers your question.

Thank you for the clarification and suggestion.