Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


required fails if used in the global space #34

jdarling opened this Issue · 3 comments

3 participants


From sample:

    "title": "Example Schema",
    "type": "object",
    "properties": {
        "firstName": {
            "type": "string"
        "lastName": {
            "type": "string"
        "age": {
            "description": "Age in years",
            "type": "integer",
            "minimum": 0
    "required": ["firstName", "lastName"]

If you use this schema and don't pass in a firstName or lastName it still validates. Looks like the current code base looks for each property to have a required on each.

If this isn't supposed to support the definition then this is something to note some place :)


The spec described at is most likely the latest draft, v4. For the most part, it seems that this library supports v3, and as such the definition for the required keyword is described as

This attribute indicates if the instance must have a value, and not
be undefined. This is false by default, making the instance


This library indeed supports v3. It has some v4 additions (in master).
I've changed the README to make this more clear. is not really clear on this.

@tdegrunt tdegrunt closed this

Thanks for the update. As I just ran across JSON-Schema I didn't realize that v4 was a newer addition version. I have found a work around that allows for the v4 requires to work, just in case someone else wants to use that style as well;

var enhanceRequired = function(root){
  var required;
  if((root.required instanceof Array)||(root.required&&root.required.length)){
    required =;
    required = [];
    var keys = Object.keys(, value;
      value =[key];
        value.required = true;

Long and short of it, this runs through each each value in the passed in schema and if it find the required array outside the properties it adds the required flag to each property. Probably a better way of doing this, but it is a quick work around that works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.