Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
🐛 Unable to compose schema with reference
Browse files Browse the repository at this point in the history
  • Loading branch information
timstott committed Sep 21, 2018
1 parent 5d5a792 commit 503a54e
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions spec/pack_validate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,44 @@ describe('module for a single validation function', function() {
assert.strictEqual(packedValidate('baz'), false);
});

it('should support schema compostion', function() {
ajv = new Ajv({sourceCode: true, inlineRefs: false});
ajv.addSchema({ id: 'country', enum: ['GBR', 'USA'] });

var schema = {
definitions: {
foo: {
properties: {
foo: { $ref: 'country' }
}
},
bar: {
properties: {
bar: { type: 'string' }
}
}
},
allOf: [
{
properties: {
baz: { type: 'string' },
}
},
{
oneOf: [
{ '$ref': '#/definitions/foo' },
{ '$ref': '#/definitions/bar' }
]
}
]
};

var packedValidate = packCompile(schema);
console.log(packedValidate);
const result = packedValidate({baz: 'bob', foo: 'USA'});
assert.strictEqual(result, true);
});

it('should support format keyword', function() {
var schema = { type: 'string', format: 'date' };
var packedValidate = packCompile(schema);
Expand Down

0 comments on commit 503a54e

Please sign in to comment.