Comparing version 0.2.2 to 0.2.3
@@ -17,2 +17,11 @@ 'use strict'; | ||
if (current.anyOf) { | ||
return resolveAnyOf(current); | ||
} | ||
if (current.allOf) { | ||
return resolveAllOf(current); | ||
} | ||
if (current.$ref) { | ||
@@ -83,2 +92,18 @@ return resolve(refresolver(current.$ref)); | ||
function resolveAnyOf(current) { | ||
Assert.ok(Thing.isArray(current.anyOf), 'Expected anyOf to be an array.'); | ||
return Joi.alternatives().try(current.anyOf.map(function (schema) { | ||
return resolve(schema); | ||
})); | ||
} | ||
function resolveAllOf(current) { | ||
Assert.ok(Thing.isArray(current.allOf), 'Expected allOf to be an array.'); | ||
return new All().try(current.allOf.map(function (schema) { | ||
return resolve(schema); | ||
})); | ||
} | ||
function resolveproperties(current) { | ||
@@ -163,1 +188,45 @@ var schemas = {}; | ||
}; | ||
function All() { | ||
All.super_.call(this); | ||
this._type = 'all'; | ||
this._invalids.remove(null); | ||
this._inner.matches = []; | ||
} | ||
require('util').inherits(All, Object.getPrototypeOf(require('joi/lib/alternatives')).constructor); | ||
All.prototype._base = function (value, state, options) { | ||
var errors = []; | ||
var results = []; | ||
if (!options) { | ||
options = {}; | ||
} | ||
options.stripUnknown = true; | ||
for (var i = 0, il = this._inner.matches.length; i < il; ++i) { | ||
var item = this._inner.matches[i]; | ||
var schema = item.schema; | ||
if (!schema) { | ||
var failed = item.is._validate(item.ref(state.parent, options), null, options, state.parent).errors; | ||
schema = failed ? item.otherwise : item.then; | ||
if (!schema) { | ||
continue; | ||
} | ||
} | ||
var result = schema._validate(value, state, options); | ||
if (!result.errors) { | ||
results.push(result.value); | ||
} | ||
else { | ||
errors = errors.concat(result.errors); | ||
} | ||
} | ||
return { value: value, errors: errors }; | ||
}; |
{ | ||
"name": "enjoi", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "Converts json-schema to Joi schema for validation.", | ||
@@ -5,0 +5,0 @@ "main": "lib/enjoi.js", |
11863
169