Skip to content

Commit 2f0c07f

Browse files
committed
Used same resolved schema while faking the data instead of original oas schema
1 parent 5433ccf commit 2f0c07f

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

libV2/validationUtils.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,7 +1428,7 @@ function checkValueAgainstSchema (context, property, jsonPathPrefix, txnParamNam
14281428
mismatchObj.suggestedFix = {
14291429
key: txnParamName,
14301430
actualValue: valueToUse,
1431-
suggestedValue: safeSchemaFaker(context, openApiSchemaObj || {}, PROCESSING_TYPE.VALIDATION,
1431+
suggestedValue: safeSchemaFaker(context, schema || {}, PROCESSING_TYPE.VALIDATION,
14321432
parameterSourceOption, components, SCHEMA_FORMATS.DEFAULT, schemaCache)
14331433
};
14341434
}
@@ -1444,7 +1444,7 @@ function checkValueAgainstSchema (context, property, jsonPathPrefix, txnParamNam
14441444
if (!_.isEmpty(filteredValidationError)) {
14451445
let mismatchObj,
14461446
suggestedValue,
1447-
fakedValue = safeSchemaFaker(context, openApiSchemaObj || {}, PROCESSING_TYPE.VALIDATION,
1447+
fakedValue = safeSchemaFaker(context, schema || {}, PROCESSING_TYPE.VALIDATION,
14481448
parameterSourceOption, components, SCHEMA_FORMATS.DEFAULT, schemaCache);
14491449

14501450
// Show detailed validation mismatches for only request/response body
@@ -1700,12 +1700,14 @@ function checkPathVariables (context, matchedPathData, transactionPathPrefix, sc
17001700
};
17011701

17021702
if (options.suggestAvailableFixes) {
1703+
const resolvedSchema = resolveSchema(context, pathVar.schema, 0, PROCESSING_TYPE.VALIDATION);
1704+
17031705
mismatchObj.suggestedFix = {
17041706
key: pathVar.name,
17051707
actualValue,
17061708
suggestedValue: {
17071709
key: pathVar.name,
1708-
value: safeSchemaFaker(context, pathVar.schema || {}, PROCESSING_TYPE.VALIDATION,
1710+
value: safeSchemaFaker(context, resolvedSchema || {}, PROCESSING_TYPE.VALIDATION,
17091711
PARAMETER_SOURCE.REQUEST, components, SCHEMA_FORMATS.DEFAULT, schemaCache),
17101712
description: getParameterDescription(pathVar)
17111713
}
@@ -1838,12 +1840,14 @@ function checkQueryParams (context, queryParams, transactionPathPrefix, schemaPa
18381840
};
18391841

18401842
if (options.suggestAvailableFixes) {
1843+
const resolvedSchema = resolveSchema(context, qp.schema, 0, PROCESSING_TYPE.VALIDATION);
1844+
18411845
mismatchObj.suggestedFix = {
18421846
key: qp.name,
18431847
actualValue: null,
18441848
suggestedValue: {
18451849
key: qp.name,
1846-
value: safeSchemaFaker(context, qp.schema || {}, PROCESSING_TYPE.VALIDATION,
1850+
value: safeSchemaFaker(context, resolvedSchema || {}, PROCESSING_TYPE.VALIDATION,
18471851
PARAMETER_SOURCE.REQUEST, components, SCHEMA_FORMATS.DEFAULT, schemaCache),
18481852
description: getParameterDescription(qp)
18491853
}
@@ -1960,12 +1964,14 @@ function checkRequestHeaders (context, headers, transactionPathPrefix, schemaPat
19601964
};
19611965

19621966
if (options.suggestAvailableFixes) {
1967+
const resolvedSchema = resolveSchema(context, header.schema, 0, PROCESSING_TYPE.VALIDATION);
1968+
19631969
mismatchObj.suggestedFix = {
19641970
key: header.name,
19651971
actualValue: null,
19661972
suggestedValue: {
19671973
key: header.name,
1968-
value: safeSchemaFaker(context, header.schema || {}, PROCESSING_TYPE.VALIDATION,
1974+
value: safeSchemaFaker(context, resolvedSchema || {}, PROCESSING_TYPE.VALIDATION,
19691975
PARAMETER_SOURCE.REQUEST, components, SCHEMA_FORMATS.DEFAULT, schemaCache),
19701976
description: getParameterDescription(header)
19711977
}
@@ -2078,12 +2084,14 @@ function checkResponseHeaders (context, schemaResponse, headers, transactionPath
20782084
};
20792085

20802086
if (options.suggestAvailableFixes) {
2087+
const resolvedSchema = resolveSchema(context, header.schema, 0, PROCESSING_TYPE.VALIDATION);
2088+
20812089
mismatchObj.suggestedFix = {
20822090
key: header.name,
20832091
actualValue: null,
20842092
suggestedValue: {
20852093
key: header.name,
2086-
value: safeSchemaFaker(context, header.schema || {}, PROCESSING_TYPE.VALIDATION,
2094+
value: safeSchemaFaker(context, resolvedSchema || {}, PROCESSING_TYPE.VALIDATION,
20872095
PARAMETER_SOURCE.REQUEST, components, SCHEMA_FORMATS.DEFAULT, schemaCache),
20882096
description: getParameterDescription(header)
20892097
}
@@ -2248,12 +2256,14 @@ function checkRequestBody (context, requestBody, transactionPathPrefix, schemaPa
22482256
};
22492257

22502258
if (options.suggestAvailableFixes) {
2259+
const resolvedSchema = resolveSchema(context, uParam.schema, 0, PROCESSING_TYPE.VALIDATION);
2260+
22512261
mismatchObj.suggestedFix = {
22522262
key: uParam.name,
22532263
actualValue: null,
22542264
suggestedValue: {
22552265
key: uParam.name,
2256-
value: safeSchemaFaker(context, uParam.schema || {}, PROCESSING_TYPE.VALIDATION,
2266+
value: safeSchemaFaker(context, resolvedSchema || {}, PROCESSING_TYPE.VALIDATION,
22572267
PARAMETER_SOURCE.REQUEST, components, SCHEMA_FORMATS.DEFAULT, schemaCache),
22582268
description: getParameterDescription(uParam)
22592269
}

0 commit comments

Comments
 (0)