Updated resolution of schemas to not happen before hand making sure both validation and coversion flows has same input schema

This commit is contained in:
Vishal Shingala
2022-02-16 18:18:03 +05:30
parent bd7ce342c2
commit e6065048c0

View File

@@ -915,7 +915,7 @@ module.exports = {
convertPathVariables: function(type, providedPathVars, commonPathVars, components, options, schemaCache) { convertPathVariables: function(type, providedPathVars, commonPathVars, components, options, schemaCache) {
options = _.merge({}, defaultOptions, options); options = _.merge({}, defaultOptions, options);
var variables = providedPathVars; var variables = [];
// converting the base uri path variables, if any // converting the base uri path variables, if any
// commonPathVars is an object for type = root/method // commonPathVars is an object for type = root/method
// array otherwise // array otherwise
@@ -948,7 +948,8 @@ module.exports = {
}); });
} }
return variables; // keep already provided varables (server variables) at last
return _.concat(variables, providedPathVars);
}, },
/** /**
@@ -1429,8 +1430,13 @@ module.exports = {
else if (bodyObj.schema) { else if (bodyObj.schema) {
if (bodyObj.schema.hasOwnProperty('$ref')) { if (bodyObj.schema.hasOwnProperty('$ref')) {
let outerProps = concreteUtils.getOuterPropsIfIsSupported(bodyObj.schema), let outerProps = concreteUtils.getOuterPropsIfIsSupported(bodyObj.schema),
resolvedSchema;
// skip beforehand resolution for OAS 3.0
if (outerProps) {
resolvedSchema = this.getRefObject(bodyObj.schema.$ref, components, options); resolvedSchema = this.getRefObject(bodyObj.schema.$ref, components, options);
bodyObj.schema = concreteUtils.addOuterPropsToRefSchemaIfIsSupported(resolvedSchema, outerProps); bodyObj.schema = concreteUtils.addOuterPropsToRefSchemaIfIsSupported(resolvedSchema, outerProps);
}
} }
if (options.schemaFaker) { if (options.schemaFaker) {
if (this.getHeaderFamily(contentType) === HEADER_TYPE.XML) { if (this.getHeaderFamily(contentType) === HEADER_TYPE.XML) {
@@ -1438,7 +1444,7 @@ module.exports = {
} }
// Do not fake schemas if the complexity score is 10 // Do not fake schemas if the complexity score is 10
if (options.complexityScore === 10) { if (options.complexityScore === 10) {
schemaType = bodyObj.schema.type; schemaType = _.get(this.getRefObject(bodyObj.schema.$ref, components, options), 'type');
if (schemaType === 'object') { if (schemaType === 'object') {
return { return {
value: '<Error: Spec size too large, skipping faking of schemas>' value: '<Error: Spec size too large, skipping faking of schemas>'
@@ -1760,12 +1766,14 @@ module.exports = {
// handling for the urlencoded media type // handling for the urlencoded media type
if (contentObj.hasOwnProperty(URLENCODED)) { if (contentObj.hasOwnProperty(URLENCODED)) {
rDataMode = 'urlencoded'; rDataMode = 'urlencoded';
if (contentObj[URLENCODED].hasOwnProperty('schema') && contentObj[URLENCODED].schema.hasOwnProperty('$ref')) {
contentObj[URLENCODED].schema = this.getRefObject(contentObj[URLENCODED].schema.$ref, components, options);
}
bodyData = this.convertToPmBodyData(contentObj[URLENCODED], requestType, URLENCODED, bodyData = this.convertToPmBodyData(contentObj[URLENCODED], requestType, URLENCODED,
PARAMETER_SOURCE.REQUEST, options.indentCharacter, components, options, schemaCache); PARAMETER_SOURCE.REQUEST, options.indentCharacter, components, options, schemaCache);
encoding = contentObj[URLENCODED].encoding ? contentObj[URLENCODED].encoding : {}; encoding = contentObj[URLENCODED].encoding ? contentObj[URLENCODED].encoding : {};
if (contentObj[URLENCODED].hasOwnProperty('schema') && contentObj[URLENCODED].schema.hasOwnProperty('$ref')) {
contentObj[URLENCODED].schema = this.getRefObject(contentObj[URLENCODED].schema.$ref, components, options);
}
// create query parameters and add it to the request body object // create query parameters and add it to the request body object
_.forOwn(bodyData, (value, key) => { _.forOwn(bodyData, (value, key) => {