Skip to content

Commit

Permalink
Merge branch 'willfarrell-feature/transform'
Browse files Browse the repository at this point in the history
  • Loading branch information
epoberezkin committed Feb 9, 2019
2 parents 10647aa + f3a159b commit 16a5695
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion keywords/transform.js
Expand Up @@ -30,7 +30,7 @@ module.exports = function defFunc (ajv) {
compile: function (schema, parentSchema) {
var cfg;

if (schema == 'toEnumCase') {
if (schema.indexOf('toEnumCase') !== -1) {
// build hash table to enum values
cfg = {hash: {}};

Expand Down
5 changes: 5 additions & 0 deletions spec/transform.spec.js
Expand Up @@ -115,6 +115,11 @@ describe('keyword "transform"', function () {
e.message.should.equal('Invalid enum uniqueness. To use `transform:["toEnumCase"]`, all values must be unique when case insensitive.');
}

data = [' ph '];
schema = {type: 'array', items: {type: 'string', transform: ['trim', 'toEnumCase'], enum:['pH']}};
ajv.validate(schema, data) .should.equal(true);
data.should.deep.equal(['pH']);

data = ['ab'];
schema = {type: 'array', items: {type: 'string', transform: ['toEnumCase'], enum:['pH']}};
ajv.validate(schema, data) .should.equal(false);
Expand Down

0 comments on commit 16a5695

Please sign in to comment.