diff options
Diffstat (limited to 'node_modules/json-schema-traverse/index.js')
-rw-r--r-- | node_modules/json-schema-traverse/index.js | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/node_modules/json-schema-traverse/index.js b/node_modules/json-schema-traverse/index.js index 79eeb6a05..d4a18dfc7 100644 --- a/node_modules/json-schema-traverse/index.js +++ b/node_modules/json-schema-traverse/index.js @@ -1,11 +1,17 @@ 'use strict'; var traverse = module.exports = function (schema, opts, cb) { + // Legacy support for v0.3.1 and earlier. if (typeof opts == 'function') { cb = opts; opts = {}; } - _traverse(opts, cb, schema, '', schema); + + cb = opts.cb || cb; + var pre = (typeof cb == 'function') ? cb : cb.pre || function() {}; + var post = cb.post || function() {}; + + _traverse(opts, pre, post, schema, '', schema); }; @@ -33,6 +39,7 @@ traverse.propsKeywords = { }; traverse.skipKeywords = { + default: true, enum: true, const: true, required: true, @@ -53,25 +60,26 @@ traverse.skipKeywords = { }; -function _traverse(opts, cb, schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex) { +function _traverse(opts, pre, post, schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex) { if (schema && typeof schema == 'object' && !Array.isArray(schema)) { - cb(schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex); + pre(schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex); for (var key in schema) { var sch = schema[key]; if (Array.isArray(sch)) { if (key in traverse.arrayKeywords) { for (var i=0; i<sch.length; i++) - _traverse(opts, cb, sch[i], jsonPtr + '/' + key + '/' + i, rootSchema, jsonPtr, key, schema, i); + _traverse(opts, pre, post, sch[i], jsonPtr + '/' + key + '/' + i, rootSchema, jsonPtr, key, schema, i); } } else if (key in traverse.propsKeywords) { if (sch && typeof sch == 'object') { for (var prop in sch) - _traverse(opts, cb, sch[prop], jsonPtr + '/' + key + '/' + escapeJsonPtr(prop), rootSchema, jsonPtr, key, schema, prop); + _traverse(opts, pre, post, sch[prop], jsonPtr + '/' + key + '/' + escapeJsonPtr(prop), rootSchema, jsonPtr, key, schema, prop); } } else if (key in traverse.keywords || (opts.allKeys && !(key in traverse.skipKeywords))) { - _traverse(opts, cb, sch, jsonPtr + '/' + key, rootSchema, jsonPtr, key, schema); + _traverse(opts, pre, post, sch, jsonPtr + '/' + key, rootSchema, jsonPtr, key, schema); } } + post(schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex); } } |