json-schema-to-joi
Version:
Converts JSON schema to Joi typescript code
42 lines • 1.48 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.allOfExtension = void 0;
const Joi = require("joi");
const allOfExtension = {
name: 'allOf',
language: {
items: 'Value \"{{!label}}\" doesn\'t match at least 1 schema, ' +
'indices of which are {{!index}}, errors are {{!errorMsg}}'
},
rules: [{
name: 'items',
params: {
items: Joi.array().items(Joi.object()).required(),
},
validate(params, value, _state, options) {
let error;
const index = [];
const errorMsg = [];
params.items.forEach((item, i) => {
const ret = Joi.validate(value, item, options);
if (ret.error) {
error = ret.error.details[0];
errorMsg.push(error.message);
index.push(i);
}
});
if (index.length === 0) {
return value;
}
return this.createError('allOf.items', {
index: JSON.stringify(index),
errorMsg: JSON.stringify(errorMsg),
}, {
key: JSON.stringify(value),
path: '',
}, options);
}
}]
};
exports.allOfExtension = allOfExtension;
//# sourceMappingURL=allOf.js.map
;