@@ -15,7 +15,9 @@ var _ = require('lodash'),
15
15
{
16
16
handleExclusiveMaximum,
17
17
handleExclusiveMinimum
18
- } = require('./../lib/common/schemaUtilsCommon');
18
+ } = require('./../lib/common/schemaUtilsCommon'),
19
+ hash = require('object-hash'),
20
+ seenSchemaMap = new Map();
19
21
20
22
(function (global, factory) {
21
23
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@@ -24667,28 +24669,38 @@ function extend() {
24667
24669
function traverse(schema, path, resolve, rootSchema) {
24668
24670
schema = resolve(schema);
24669
24671
if (!schema) {
24670
- return;
24672
+ return;
24671
24673
}
24672
24674
if (optionAPI('useExamplesValue') && 'example' in schema) {
24673
24675
var clonedSchema,
24674
- result;
24676
+ result,
24677
+ finalResult,
24678
+ hashSchema = hash(schema);
24675
24679
24676
- // avoid minItems and maxItems while checking for valid examples
24677
- if (optionAPI('avoidExampleItemsLength') && _.get(schema, 'type') === 'array') {
24678
- clonedSchema = _.clone(schema);
24679
- _.unset(clonedSchema, 'minItems');
24680
- _.unset(clonedSchema, 'maxItems');
24681
-
24682
- // avoid validation of values that are in pm variable format (i.e. '{{userId}}')
24683
- result = validateSchema(clonedSchema, schema.example, { ignoreUnresolvedVariables: true });
24680
+ if(seenSchemaMap.has(hashSchema)) {
24681
+ finalResult = seenSchemaMap.get(hashSchema);
24684
24682
}
24685
24683
else {
24686
- // avoid validation of values that are in pm variable format (i.e. '{{userId}}')
24687
- result = validateSchema(schema, schema.example, { ignoreUnresolvedVariables: true });
24684
+ // avoid minItems and maxItems while checking for valid examples
24685
+ if (optionAPI('avoidExampleItemsLength') && _.get(schema, 'type') === 'array') {
24686
+ clonedSchema = _.clone(schema);
24687
+ _.unset(clonedSchema, 'minItems');
24688
+ _.unset(clonedSchema, 'maxItems');
24689
+
24690
+ // avoid validation of values that are in pm variable format (i.e. '{{userId}}')
24691
+ result = validateSchema(clonedSchema, schema.example, { ignoreUnresolvedVariables: true });
24692
+ }
24693
+ else {
24694
+ // avoid validation of values that are in pm variable format (i.e. '{{userId}}')
24695
+ result = validateSchema(schema, schema.example, { ignoreUnresolvedVariables: true });
24696
+ }
24688
24697
}
24689
24698
24699
+ finalResult = result && result.length === 0;
24700
+
24701
+ seenSchemaMap.set(hashSchema, finalResult);
24690
24702
// Use example only if valid
24691
- if (result && result.length === 0 ) {
24703
+ if (finalResult ) {
24692
24704
return schema.example;
24693
24705
}
24694
24706
}
0 commit comments