UNPKG

json-schema-to-joi

Version:

Converts JSON schema to Joi typescript code

37 lines 1.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.oneOfExtension = void 0; const Joi = require("joi"); const oneOfExtension = { name: 'oneOf', language: { items: 'Value \"{{label}}\" matches zero or multiple schemas, indices of which are {{!index}}', }, rules: [{ name: 'items', params: { items: Joi.array().items(Joi.object()).required(), }, validate(params, value, _state, options) { const index = []; params.items.forEach((item, i) => { const ret = Joi.validate(value, item, options); if (ret.error) { return; } index.push(i); }); if (index.length === 1) { return value; } return this.createError('oneOf.items', { index: JSON.stringify(index), }, { key: JSON.stringify(value), path: '', }, options); } }] }; exports.oneOfExtension = oneOfExtension; //# sourceMappingURL=oneOf.js.map