Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,9 @@ validators.dependencies = function validateDependencies (instance, schema, optio
* @return {ValidatorResult|null}
*/
validators['enum'] = function validateEnum (instance, schema, options, ctx) {
if(!schema['enum']) {
return null;
}
if (!(schema['enum'] instanceof Array)) {
throw new SchemaError("enum expects an array", schema);
}
Expand Down
5 changes: 5 additions & 0 deletions test/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@ describe('Attributes', function () {
it('should validate if a required field has a value out of enum', function () {
return this.validator.validate({'the_field':'bar'}, {'type': 'object', 'properties':{'the_field': {'enum': ['foo', 'bar', 'baz'], 'required': true}}}).valid.should.be.true;
});

it('should validate if number enum is undefined', function () {
return this.validator.validate(1, {'type': 'number', 'enum': undefined}).valid.should.be.true;
});

});

describe('description', function () {
Expand Down