Skip to content

Commit

Permalink
Merge pull request #6 from bardzusny/master
Browse files Browse the repository at this point in the history
Handling inline references in the main schema even when subSchemas are provided
  • Loading branch information
tlivings committed Mar 18, 2015
2 parents 2db9269 + dd68e6c commit b5d9a6d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/enjoi.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = function enjoi(schema, subSchemas) {
id = value.substr(0, value.indexOf('#') + 1);
path = value.substr(value.indexOf('#') + 1);

if (id && subSchemas) {
if (id && id.length > 1 && subSchemas) {
refschema = subSchemas[id] || subSchemas[id.substr(0, id.length - 1)];
}
else {
Expand Down
32 changes: 32 additions & 0 deletions test/test-enjoi.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,38 @@ Test('enjoi', function (t) {
});
});

t.test('with both inline and external refs', function (t) {
t.plan(1);

var schema = Enjoi({
'title': 'Example Schema',
'type': 'object',
'properties': {
'firstname': {
'$ref': '#/definitions/firstname'
},
'surname': {
'$ref': 'definitions#/surname'
}
},
'definitions': {
'firstname': {
'type': 'string'
}
}
}, {
'definitions': {
'surname': {
'type': 'string'
}
}
});

Joi.validate({firstname: 'Joe', surname: 'Doe'}, schema, function (error, value) {
t.ok(!error, 'no error.');
});
});

});

Test('types', function (t) {
Expand Down

0 comments on commit b5d9a6d

Please sign in to comment.