mirror of
https://github.com/thangisme/notes.git
synced 2024-11-01 03:17:30 -04:00
22 lines
618 B
JavaScript
22 lines
618 B
JavaScript
|
'use strict';
|
||
|
|
||
|
module.exports = function defFunc(ajv) {
|
||
|
if (!ajv._opts.v5) console.warn('keywords if/then/else require v5 option');
|
||
|
|
||
|
defFunc.definition = {
|
||
|
macro: function (schema, parentSchema) {
|
||
|
if (parentSchema.then === undefined)
|
||
|
throw new Error('keyword "then" is absent');
|
||
|
var cases = [ { 'if': schema, 'then': parentSchema.then } ];
|
||
|
if (parentSchema.else !== undefined)
|
||
|
cases[1] = { 'then': parentSchema.else };
|
||
|
return { switch: cases };
|
||
|
}
|
||
|
};
|
||
|
|
||
|
ajv.addKeyword('if', defFunc.definition);
|
||
|
ajv.addKeyword('then');
|
||
|
ajv.addKeyword('else');
|
||
|
return ajv;
|
||
|
};
|