Baggz / Amanda

JSON Schema validator
https://github.com/Baggz/Amanda
MIT License
144 stars 36 forks source link

Required Objects Without Properties Dont Validate Against Empty Objects #58

Open pixelshaded opened 11 years ago

pixelshaded commented 11 years ago
var messageSchema = {
    type: 'object',
    properties: {
        Action: {
            required: true,
            type: 'string'
        },
        Data: {
            required: true,
            type: 'object',
        }
    }
};

if I validate against

{
        Action: "GetAllPools",
        Data: {  }
}

I will get an error message saying that Data is required. I have not required any properties be on Data however with my schema. If I add a random property to Data it will validate against the schema.

Baggz commented 11 years ago

I will get an error message saying that Data is required. I have not required any properties be on Data however with my schema. If I add a random property to Data it will validate against the schema.

@pixelshaded Actually, Amanda takes an empty object as a falsy value, that's why it throws an error. There's no prescribed behaviour for the required validator (http://json-schema.org/latest/json-schema-validation.html#anchor61).