Skip to content
This repository has been archived by the owner on Mar 5, 2018. It is now read-only.

Issue 12 #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
34 changes: 17 additions & 17 deletions jjve.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
(function() {
'use strict';

function isArray(obj) {
if (typeof Array.isArray === 'function') {
return Array.isArray(obj);
}
return Object.prototype.toString.call(obj) === '[object Array]';
}

function allowsType(schema, type) {
if (typeof schema.type === 'string') {
return schema.type === type;
}
if (isArray(schema.type)) {
return schema.type.indexOf(type) !== -1;
}
return false;
}

function make(o) {
var errors = [];

Expand Down Expand Up @@ -278,23 +295,6 @@
return errors;
}

function allowsType(schema, type) {
if (typeof schema.type === 'string') {
return schema.type === type;
}
if (isArray(schema.type)) {
return schema.type.indexOf(type) !== -1;
}
return false;
}

function isArray(obj) {
if (typeof Array.isArray === 'function') {
return Array.isArray(obj);
}
return Object.prototype.toString.call(obj) === '[object Array]';
}

function formatPath(options) {
var root = options.hasOwnProperty('root') ?
options.root : '$';
Expand Down
37 changes: 37 additions & 0 deletions test/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,43 @@ describe('jjve', function() {
]);
});

it('should handle schema ref which is an array and has definition with required properties', function() {
var data = { one: [{}] };
var ref = {
id: 'one',
type: 'array',
items: { $ref: '#/definitions/rest' },
definitions: {
rest: {
properties: {
two: {
type: 'boolean'
}
},
required: ['two']
}
}
};

var schema = {
type: 'object',
properties: {
one: { $ref: 'one' }
},
};

this.env.addSchema(ref);

this.run(schema, data).should.eql([
{
code: 'VALIDATION_MIN_LENGTH',
message: 'String is too short (0 chars), minimum 1',
data: '',
path: '$.one.two'
}
]);
});

it('should handle type property given as array where leaf schema is needed',
function() {
var data = { test: 'xyz' };
Expand Down