Skip to content

Commit 5433ccf

Browse files
committed
Fixed an issue where for validateTransactionV2() interface, when mismatches were found there were issues reported for valid data as well due to scheam mutation
1 parent 1c0f4d8 commit 5433ccf

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

libV2/validationUtils.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,12 @@ function safeSchemaFaker (context, oldSchema, resolveFor, parameterSourceOption,
150150
resolveTo = _.get(options, 'parametersResolution', 'example'),
151151
indentCharacter = options.indentCharacter;
152152

153-
resolvedSchema = resolveSchema(context, oldSchema, 0, PROCESSING_TYPE.VALIDATION);
153+
/**
154+
* Schema is cloned here as resolveSchema() when called for CONVERSION use cases, will mutate schema in certain way.
155+
* i.e. For array it'll add maxItems = 2. This should be avoided as we'll again be needing non-mutated schema
156+
* in further VALIDATION use cases as needed.
157+
*/
158+
resolvedSchema = resolveSchema(context, _.cloneDeep(oldSchema), 0, _.toLower(PROCESSING_TYPE.CONVERSION));
154159

155160
resolvedSchema = concreteUtils.fixExamplesByVersion(resolvedSchema);
156161
key = JSON.stringify(resolvedSchema);
@@ -171,7 +176,6 @@ function safeSchemaFaker (context, oldSchema, resolveFor, parameterSourceOption,
171176

172177
if (resolveFor === PROCESSING_TYPE.VALIDATION) {
173178
schemaFaker.option({
174-
useDefaultValue: false,
175179
avoidExampleItemsLength: false
176180
});
177181
}

test/unit/ValidateV2.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ describe('The Validation option', function () {
537537
let schema = fs.readFileSync(specData.path, 'utf8'),
538538
collection = fs.readFileSync(suggestAvailableFixesCollection, 'utf8'),
539539
schemaPack = new Converter.SchemaPack({ type: 'string', data: schema },
540-
{ suggestAvailableFixes: true }),
540+
{ suggestAvailableFixes: true, parametersResolution: 'Example' }),
541541
historyRequest = [],
542542
resultObj,
543543
responseResult,
@@ -980,7 +980,8 @@ describe('VALIDATE FUNCTION TESTS ', function () {
980980
ignoreUnresolvedVariables: true,
981981
validateMetadata: true,
982982
suggestAvailableFixes: true,
983-
detailedBlobValidation: true
983+
detailedBlobValidation: true,
984+
parametersResolution: 'Example'
984985
},
985986
schemaPack = new Converter.SchemaPack({ type: 'string', data: primitiveDataTypeBodySpec }, options);
986987

0 commit comments

Comments
 (0)