@@ -16,8 +16,7 @@ var _ = require('lodash'),
16
16
handleExclusiveMaximum,
17
17
handleExclusiveMinimum
18
18
} = require('./../lib/common/schemaUtilsCommon'),
19
- hash = require('object-hash'),
20
- seenSchemaMap = new Map();
19
+ hash = require('object-hash');
21
20
22
21
(function (global, factory) {
23
22
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@@ -24102,7 +24101,7 @@ function extend() {
24102
24101
var nullType = nullGenerator;
24103
24102
24104
24103
// TODO provide types
24105
- function unique(path, items, value, sample, resolve, traverseCallback) {
24104
+ function unique(path, items, value, sample, resolve, traverseCallback, seenSchemaCache ) {
24106
24105
var tmp = [], seen = [];
24107
24106
function walk(obj) {
24108
24107
var json = JSON.stringify(obj);
@@ -24115,15 +24114,15 @@ function extend() {
24115
24114
// TODO: find a better solution?
24116
24115
var limit = 10;
24117
24116
while (tmp.length !== items.length) {
24118
- walk(traverseCallback(value.items || sample, path, resolve));
24117
+ walk(traverseCallback(value.items || sample, path, resolve, null, seenSchemaCache ));
24119
24118
if (!limit--) {
24120
24119
break;
24121
24120
}
24122
24121
}
24123
24122
return tmp;
24124
24123
}
24125
24124
// TODO provide types
24126
- var arrayType = function arrayType(value, path, resolve, traverseCallback) {
24125
+ var arrayType = function arrayType(value, path, resolve, traverseCallback, seenSchemaCache ) {
24127
24126
var items = [];
24128
24127
if (!(value.items || value.additionalItems)) {
24129
24128
if (utils.hasProperties(value, 'minItems', 'maxItems', 'uniqueItems')) {
@@ -24138,7 +24137,7 @@ function extend() {
24138
24137
if (tmpItems instanceof Array) {
24139
24138
return Array.prototype.concat.call(items, tmpItems.map(function (item, key) {
24140
24139
var itemSubpath = path.concat(['items', key + '']);
24141
- return traverseCallback(item, itemSubpath, resolve);
24140
+ return traverseCallback(item, itemSubpath, resolve, null, seenSchemaCache );
24142
24141
}));
24143
24142
}
24144
24143
var minItems = value.minItems;
@@ -24167,11 +24166,11 @@ function extend() {
24167
24166
sample = typeof value.additionalItems === 'object' ? value.additionalItems : {};
24168
24167
for (var current = items.length; current < length; current++) {
24169
24168
var itemSubpath = path.concat(['items', current + '']);
24170
- var element = traverseCallback(value.items || sample, itemSubpath, resolve);
24169
+ var element = traverseCallback(value.items || sample, itemSubpath, resolve, null, seenSchemaCache );
24171
24170
items.push(element);
24172
24171
}
24173
24172
if (value.uniqueItems) {
24174
- return unique(path.concat(['items']), items, value, sample, resolve, traverseCallback);
24173
+ return unique(path.concat(['items']), items, value, sample, resolve, traverseCallback, seenSchemaCache );
24175
24174
}
24176
24175
return items;
24177
24176
};
@@ -24235,7 +24234,7 @@ function extend() {
24235
24234
var anyType = { type: ['string', 'number', 'integer', 'boolean'] };
24236
24235
// TODO provide types
24237
24236
// Updated objectType definition to latest version (0.5.0-rcv.41)
24238
- var objectType = function objectType(value, path, resolve, traverseCallback) {
24237
+ var objectType = function objectType(value, path, resolve, traverseCallback, seenSchemaCache ) {
24239
24238
const props = {};
24240
24239
24241
24240
const properties = value.properties || {};
@@ -24271,7 +24270,7 @@ function extend() {
24271
24270
}
24272
24271
});
24273
24272
24274
- return traverseCallback(props, path.concat(['properties']), resolve, value);
24273
+ return traverseCallback(props, path.concat(['properties']), resolve, value, seenSchemaCache );
24275
24274
}
24276
24275
24277
24276
const optionalsProbability = optionAPI('alwaysFakeOptionals') === true ? 1.0 : optionAPI('optionalsProbability');
@@ -24327,7 +24326,7 @@ function extend() {
24327
24326
24328
24327
return traverseCallback({
24329
24328
allOf: _defns.concat(value),
24330
- }, path.concat(['properties']), resolve, value);
24329
+ }, path.concat(['properties']), resolve, value, seenSchemaCache );
24331
24330
}
24332
24331
}
24333
24332
@@ -24480,7 +24479,7 @@ function extend() {
24480
24479
}
24481
24480
}
24482
24481
24483
- return traverseCallback(props, path.concat(['properties']), resolve, value);
24482
+ return traverseCallback(props, path.concat(['properties']), resolve, value, seenSchemaCache );
24484
24483
};
24485
24484
24486
24485
/**
@@ -24666,7 +24665,7 @@ function extend() {
24666
24665
};
24667
24666
24668
24667
// TODO provide types
24669
- function traverse(schema, path, resolve, rootSchema) {
24668
+ function traverse(schema, path, resolve, rootSchema, seenSchemaCache ) {
24670
24669
schema = resolve(schema);
24671
24670
if (!schema) {
24672
24671
return;
@@ -24677,8 +24676,8 @@ function extend() {
24677
24676
isExampleValid,
24678
24677
hashSchema = hash(schema);
24679
24678
24680
- if(seenSchemaMap .has(hashSchema)) {
24681
- isExampleValid = seenSchemaMap .get(hashSchema);
24679
+ if(seenSchemaCache && seenSchemaCache .has(hashSchema)) {
24680
+ isExampleValid = seenSchemaCache .get(hashSchema);
24682
24681
}
24683
24682
else {
24684
24683
// avoid minItems and maxItems while checking for valid examples
@@ -24697,7 +24696,7 @@ function extend() {
24697
24696
24698
24697
// Store the final result that needs to be used in the seen map
24699
24698
isExampleValid = result && result.length === 0;
24700
- seenSchemaMap .set(hashSchema, isExampleValid);
24699
+ seenSchemaCache && seenSchemaCache .set(hashSchema, isExampleValid);
24701
24700
}
24702
24701
24703
24702
// Use example only if valid
@@ -24720,7 +24719,7 @@ function extend() {
24720
24719
}
24721
24720
// thunks can return sub-schemas
24722
24721
if (typeof schema.thunk === 'function') {
24723
- return traverse(schema.thunk(), path, resolve);
24722
+ return traverse(schema.thunk(), path, resolve, null, seenSchemaCache );
24724
24723
}
24725
24724
if (typeof schema.generate === 'function') {
24726
24725
return utils.typecast(schema, function () { return schema.generate(rootSchema); });
@@ -24748,7 +24747,7 @@ function extend() {
24748
24747
}
24749
24748
else {
24750
24749
try {
24751
- var result = typeMap[type](schema, path, resolve, traverse);
24750
+ var result = typeMap[type](schema, path, resolve, traverse, seenSchemaCache );
24752
24751
var required = schema.items
24753
24752
? schema.items.required
24754
24753
: schema.required;
@@ -24768,7 +24767,7 @@ function extend() {
24768
24767
}
24769
24768
for (var prop in schema) {
24770
24769
if (typeof schema[prop] === 'object' && prop !== 'definitions') {
24771
- copy[prop] = traverse(schema[prop], path.concat([prop]), resolve, copy);
24770
+ copy[prop] = traverse(schema[prop], path.concat([prop]), resolve, copy, seenSchemaCache );
24772
24771
}
24773
24772
else {
24774
24773
copy[prop] = schema[prop];
@@ -24838,7 +24837,7 @@ function extend() {
24838
24837
return obj;
24839
24838
}
24840
24839
// TODO provide types
24841
- function run(refs, schema, container) {
24840
+ function run(refs, schema, container, seenSchemaCache ) {
24842
24841
try {
24843
24842
var result = traverse(schema, [], function reduce(sub, maxReduceDepth) {
24844
24843
if (typeof maxReduceDepth === 'undefined') {
@@ -24907,7 +24906,7 @@ function extend() {
24907
24906
}
24908
24907
}
24909
24908
return container.wrap(sub);
24910
- });
24909
+ }, null, seenSchemaCache );
24911
24910
if (optionAPI('resolveJsonPath')) {
24912
24911
return resolve(result);
24913
24912
}
@@ -24949,7 +24948,7 @@ function extend() {
24949
24948
}
24950
24949
}
24951
24950
}
24952
- var jsf = function (schema, refs) {
24951
+ var jsf = function (schema, refs, seenSchemaCache ) {
24953
24952
var ignore = optionAPI('ignoreMissingRefs');
24954
24953
var $ = deref(function (id, refs) {
24955
24954
// FIXME: allow custom callback?
@@ -24958,7 +24957,7 @@ function extend() {
24958
24957
}
24959
24958
});
24960
24959
var $refs = getRefs(refs);
24961
- return run($refs, $(schema, $refs, true), container);
24960
+ return run($refs, $(schema, $refs, true), container, seenSchemaCache );
24962
24961
};
24963
24962
jsf.resolve = function (schema, refs, cwd) {
24964
24963
if (typeof refs === 'string') {
0 commit comments