Skip to content

Commit 1c0f4d8

Browse files
committed
Used conversion as processing type for safeschemafaker for validation
1 parent 4230274 commit 1c0f4d8

File tree

2 files changed

+25
-27
lines changed

2 files changed

+25
-27
lines changed

libV2/validationUtils.js

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ const _ = require('lodash'),
6464
'accept',
6565
'authorization'
6666
],
67-
DEFAULT_SCHEMA_UTILS = require('../lib/30XUtils/schemaUtils30X'),
6867

6968
OAS_NOT_SUPPORTED = '<Error: Not supported in OAS>',
7069

@@ -133,24 +132,23 @@ function shouldAddDeprecatedOperation (operation, options) {
133132
* removes things that might make schemaFaker crash
134133
* @param {Object} context - Required context from related SchemaPack function
135134
* @param {*} oldSchema the schema to fake
136-
* @param {string} resolveTo The desired JSON-generation mechanism (schema: prefer using the JSONschema to
137135
* generate a fake object, example: use specified examples as-is). Default: schema
138136
* @param {*} resolveFor - resolve refs for flow validation/conversion (value to be one of VALIDATION/CONVERSION)
139137
* @param {string} parameterSourceOption Specifies whether the schema being faked is from a request or response.
140138
* @param {*} components list of predefined components (with schemas)
141139
* @param {string} schemaFormat default or xml
142140
* @param {object} schemaCache - object storing schemaFaker and schemaResolution caches
143-
* @param {object} options - a standard list of options that's globally passed around. Check options.js for more.
144141
* @returns {object} fakedObject
145142
*/
146-
function safeSchemaFaker (context, oldSchema, resolveTo, resolveFor, parameterSourceOption, components,
147-
schemaFormat, schemaCache, options) {
148-
var prop, key, resolvedSchema, fakedSchema,
149-
schemaFakerCache = _.get(schemaCache, 'schemaFakerCache', {});
150-
let concreteUtils = components && components.hasOwnProperty('concreteUtils') ?
151-
components.concreteUtils :
152-
DEFAULT_SCHEMA_UTILS;
153-
const indentCharacter = options.indentCharacter;
143+
function safeSchemaFaker (context, oldSchema, resolveFor, parameterSourceOption, components,
144+
schemaFormat, schemaCache) {
145+
let prop, key, resolvedSchema, fakedSchema,
146+
schemaFakerCache = _.get(schemaCache, 'schemaFakerCache', {}),
147+
concreteUtils = context.concreteUtils;
148+
149+
const options = context.computedOptions,
150+
resolveTo = _.get(options, 'parametersResolution', 'example'),
151+
indentCharacter = options.indentCharacter;
154152

155153
resolvedSchema = resolveSchema(context, oldSchema, 0, PROCESSING_TYPE.VALIDATION);
156154

@@ -1426,8 +1424,8 @@ function checkValueAgainstSchema (context, property, jsonPathPrefix, txnParamNam
14261424
mismatchObj.suggestedFix = {
14271425
key: txnParamName,
14281426
actualValue: valueToUse,
1429-
suggestedValue: safeSchemaFaker(context, openApiSchemaObj || {}, 'example', PROCESSING_TYPE.VALIDATION,
1430-
parameterSourceOption, components, SCHEMA_FORMATS.DEFAULT, schemaCache, options.includeDeprecated)
1427+
suggestedValue: safeSchemaFaker(context, openApiSchemaObj || {}, PROCESSING_TYPE.VALIDATION,
1428+
parameterSourceOption, components, SCHEMA_FORMATS.DEFAULT, schemaCache)
14311429
};
14321430
}
14331431

@@ -1442,8 +1440,8 @@ function checkValueAgainstSchema (context, property, jsonPathPrefix, txnParamNam
14421440
if (!_.isEmpty(filteredValidationError)) {
14431441
let mismatchObj,
14441442
suggestedValue,
1445-
fakedValue = safeSchemaFaker(context, openApiSchemaObj || {}, 'example', PROCESSING_TYPE.VALIDATION,
1446-
parameterSourceOption, components, SCHEMA_FORMATS.DEFAULT, schemaCache, options);
1443+
fakedValue = safeSchemaFaker(context, openApiSchemaObj || {}, PROCESSING_TYPE.VALIDATION,
1444+
parameterSourceOption, components, SCHEMA_FORMATS.DEFAULT, schemaCache);
14471445

14481446
// Show detailed validation mismatches for only request/response body
14491447
if (options.detailedBlobValidation && needJsonMatching) {
@@ -1703,8 +1701,8 @@ function checkPathVariables (context, matchedPathData, transactionPathPrefix, sc
17031701
actualValue,
17041702
suggestedValue: {
17051703
key: pathVar.name,
1706-
value: safeSchemaFaker(context, pathVar.schema || {}, 'example', PROCESSING_TYPE.VALIDATION,
1707-
PARAMETER_SOURCE.REQUEST, components, SCHEMA_FORMATS.DEFAULT, schemaCache, options),
1704+
value: safeSchemaFaker(context, pathVar.schema || {}, PROCESSING_TYPE.VALIDATION,
1705+
PARAMETER_SOURCE.REQUEST, components, SCHEMA_FORMATS.DEFAULT, schemaCache),
17081706
description: getParameterDescription(pathVar)
17091707
}
17101708
};
@@ -1841,8 +1839,8 @@ function checkQueryParams (context, queryParams, transactionPathPrefix, schemaPa
18411839
actualValue: null,
18421840
suggestedValue: {
18431841
key: qp.name,
1844-
value: safeSchemaFaker(context, qp.schema || {}, 'example', PROCESSING_TYPE.VALIDATION,
1845-
PARAMETER_SOURCE.REQUEST, components, SCHEMA_FORMATS.DEFAULT, schemaCache, options),
1842+
value: safeSchemaFaker(context, qp.schema || {}, PROCESSING_TYPE.VALIDATION,
1843+
PARAMETER_SOURCE.REQUEST, components, SCHEMA_FORMATS.DEFAULT, schemaCache),
18461844
description: getParameterDescription(qp)
18471845
}
18481846
};
@@ -1963,8 +1961,8 @@ function checkRequestHeaders (context, headers, transactionPathPrefix, schemaPat
19631961
actualValue: null,
19641962
suggestedValue: {
19651963
key: header.name,
1966-
value: safeSchemaFaker(context, header.schema || {}, 'example', PROCESSING_TYPE.VALIDATION,
1967-
PARAMETER_SOURCE.REQUEST, components, SCHEMA_FORMATS.DEFAULT, schemaCache, options),
1964+
value: safeSchemaFaker(context, header.schema || {}, PROCESSING_TYPE.VALIDATION,
1965+
PARAMETER_SOURCE.REQUEST, components, SCHEMA_FORMATS.DEFAULT, schemaCache),
19681966
description: getParameterDescription(header)
19691967
}
19701968
};
@@ -2081,8 +2079,8 @@ function checkResponseHeaders (context, schemaResponse, headers, transactionPath
20812079
actualValue: null,
20822080
suggestedValue: {
20832081
key: header.name,
2084-
value: safeSchemaFaker(context, header.schema || {}, 'example', PROCESSING_TYPE.VALIDATION,
2085-
PARAMETER_SOURCE.REQUEST, components, SCHEMA_FORMATS.DEFAULT, schemaCache, options),
2082+
value: safeSchemaFaker(context, header.schema || {}, PROCESSING_TYPE.VALIDATION,
2083+
PARAMETER_SOURCE.REQUEST, components, SCHEMA_FORMATS.DEFAULT, schemaCache),
20862084
description: getParameterDescription(header)
20872085
}
20882086
};
@@ -2251,8 +2249,8 @@ function checkRequestBody (context, requestBody, transactionPathPrefix, schemaPa
22512249
actualValue: null,
22522250
suggestedValue: {
22532251
key: uParam.name,
2254-
value: safeSchemaFaker(context, uParam.schema || {}, 'example', PROCESSING_TYPE.VALIDATION,
2255-
PARAMETER_SOURCE.REQUEST, components, SCHEMA_FORMATS.DEFAULT, schemaCache, options),
2252+
value: safeSchemaFaker(context, uParam.schema || {}, PROCESSING_TYPE.VALIDATION,
2253+
PARAMETER_SOURCE.REQUEST, components, SCHEMA_FORMATS.DEFAULT, schemaCache),
22562254
description: getParameterDescription(uParam)
22572255
}
22582256
};

test/unit/ValidateV2.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ describe('VALIDATE FUNCTION TESTS ', function () {
11031103
resultObj,
11041104
historyRequest = [],
11051105
schemaPack = new Converter.SchemaPack({ type: 'string', data: queryParamDeepObjectSpec },
1106-
{ suggestAvailableFixes: true, showMissingInSchemaErrors: true });
1106+
{ suggestAvailableFixes: true, showMissingInSchemaErrors: true, parametersResolution: 'Example' });
11071107

11081108
getAllTransactions(JSON.parse(queryParamDeepObjectCollection), historyRequest);
11091109

@@ -1152,7 +1152,7 @@ describe('VALIDATE FUNCTION TESTS ', function () {
11521152
resultObjAllOf,
11531153
historyRequest = [],
11541154
schemaPack = new Converter.SchemaPack({ type: 'string', data: compositeSchemaSpec },
1155-
{ suggestAvailableFixes: true, showMissingInSchemaErrors: true });
1155+
{ suggestAvailableFixes: true, showMissingInSchemaErrors: true, parametersResolution: 'Example' });
11561156

11571157
getAllTransactions(JSON.parse(compositeSchemaCollection), historyRequest);
11581158

0 commit comments

Comments
 (0)