1
0
mirror of https://github.com/thangisme/notes.git synced 2024-11-01 02:07:20 -04:00
notes/node_modules/ajv-keywords/keywords/switch.js

40 lines
1002 B
JavaScript
Raw Normal View History

2017-03-09 13:16:08 -05:00
'use strict';
module.exports = function defFunc(ajv) {
if (ajv.RULES.keywords.switch)
return console.warn('Keyword switch is already defined');
var metaSchemaUri = ajv._opts.v5
? 'https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/json-schema-v5.json#'
: 'http://json-schema.org/draft-04/schema#';
defFunc.definition = {
inline: require('./dotjs/switch'),
statements: true,
errors: 'full',
metaSchema: {
type: 'array',
items: {
required: [ 'then' ],
properties: {
'if': { $ref: metaSchemaUri },
'then': {
anyOf: [
{ type: 'boolean' },
{ $ref: metaSchemaUri }
]
},
'continue': { type: 'boolean' }
},
additionalProperties: false,
dependencies: {
'continue': [ 'if' ]
}
}
}
};
ajv.addKeyword('switch', defFunc.definition);
return ajv;
};