Skip to content

Commit

Permalink
AB-289-resolved-comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AyushShri committed Jan 5, 2025
1 parent d226967 commit 8ae2fa5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 26 deletions.
6 changes: 3 additions & 3 deletions libV2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,17 @@ module.exports = {
let request = {},
collectionVariables = [],
requestObject = {},
extractedTypesObject = {};
typesObject = {};

try {
({ request, collectionVariables, extractedTypesObject } = resolvePostmanRequest(context,
({ request, collectionVariables, typesObject } = resolvePostmanRequest(context,
context.openapi.paths[node.meta.path],
node.meta.path,
node.meta.method
));

requestObject = generateRequestItemObject(request);
finalExtractedTypesObject = Object.assign({}, finalExtractedTypesObject, extractedTypesObject);
finalExtractedTypesObject = Object.assign({}, finalExtractedTypesObject, typesObject);

}
catch (error) {
Expand Down
54 changes: 31 additions & 23 deletions libV2/schemaUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -765,9 +765,6 @@ let QUERYPARAM = 'query',
if (requiredProperties.has(key) || parentRequired.has(key)) {
schemaDetails.required.push(key);
}
if (prop.$ref) {
propertyDetails.properties = processSchema(prop, parentRequired = requiredProperties);
}
else if (prop.properties) {
let res = processSchema(prop);
propertyDetails.properties = res.properties;
Expand Down Expand Up @@ -1993,11 +1990,15 @@ let QUERYPARAM = 'query',
param = resolveSchema(context, param);
}

if (_.has(param.schema, '$ref')) {
param.schema = resolveSchema(context, param.schema);
}

if (param.in !== QUERYPARAM || (!includeDeprecated && param.deprecated)) {
return;
}

let propertyDetails = {},
let queryParamTypeInfo = {},
properties = {},
keyName,
paramValue = resolveValueOfParameter(context, param);
Expand All @@ -2020,9 +2021,9 @@ let QUERYPARAM = 'query',
example: schema.example || undefined
};
}
propertyDetails = { keyName, properties };
queryParamTypeInfo = { keyName, properties };
if (keyName && param.schema && param.schema.type) {
queryParamTypes.push(propertyDetails);
queryParamTypes.push(queryParamTypeInfo);
}

if (typeof paramValue === 'number' || typeof paramValue === 'boolean') {
Expand Down Expand Up @@ -2056,11 +2057,15 @@ let QUERYPARAM = 'query',
param = resolveSchema(context, param);
}

if (_.has(param.schema, '$ref')) {
param.schema = resolveSchema(context, param.schema);
}

if (param.in !== PATHPARAM) {
return;
}

let propertyDetails = {},
let pathParamTypeInfo = {},
properties = {},
keyName,
paramValue = resolveValueOfParameter(context, param);
Expand All @@ -2083,9 +2088,9 @@ let QUERYPARAM = 'query',
example: schema.example || undefined
};
}
propertyDetails = { keyName, properties };
pathParamTypeInfo = { keyName, properties };
if (keyName && param.schema && param.schema.type) {
pathParamTypes.push(propertyDetails);
pathParamTypes.push(pathParamTypeInfo);
}

if (typeof paramValue === 'number' || typeof paramValue === 'boolean') {
Expand Down Expand Up @@ -2146,6 +2151,10 @@ let QUERYPARAM = 'query',
param = resolveSchema(context, param);
}

if (_.has(param.schema, '$ref')) {
param.schema = resolveSchema(context, param.schema);
}

if (param.in !== HEADER || (!includeDeprecated && param.deprecated)) {
return;
}
Expand All @@ -2154,7 +2163,7 @@ let QUERYPARAM = 'query',
return;
}

let propertyDetails = {},
let headerTypeInfo = {},
properties = {},
keyName,
paramValue = resolveValueOfParameter(context, param);
Expand All @@ -2177,10 +2186,10 @@ let QUERYPARAM = 'query',
example: schema.example || undefined
};
}
propertyDetails = { keyName, properties };
headerTypeInfo = { keyName, properties };

if (keyName && param.schema && param.schema.type) {
headerTypes.push(propertyDetails);
headerTypes.push(headerTypeInfo);
}

if (typeof paramValue === 'number' || typeof paramValue === 'boolean') {
Expand Down Expand Up @@ -2298,7 +2307,7 @@ let QUERYPARAM = 'query',
}

let headerValue = resolveValueOfParameter(context, value, { isResponseSchema: true }),
propertyDetails = {},
headerTypeInfo = {},
properties = {},
keyName;

Expand Down Expand Up @@ -2334,9 +2343,9 @@ let QUERYPARAM = 'query',
};

}
propertyDetails = { keyName, properties };
headerTypeInfo = { keyName, properties };
if (keyName && headerData.schema && headerData.schema.type) {
headerTypes.push(propertyDetails);
headerTypes.push(headerTypeInfo);
}
});

Expand Down Expand Up @@ -2560,7 +2569,6 @@ let QUERYPARAM = 'query',
responses.push(response);
});
});
// console.log('finalRespBlock is ', JSON.stringify(finalRespBlock, null, 2));
return {
responses,
acceptHeader: requestAcceptHeader,
Expand Down Expand Up @@ -2593,7 +2601,7 @@ module.exports = {
{ alwaysInheritAuthentication } = context.computedOptions,
methodPath,
requestBlock,
extractedTypesObject = {};
typesObject = {};
context.resolvedSchemaTypes = null;
headers.push(..._.get(requestBody, 'headers', []));
pathVariables.push(...baseUrlData.pathVariables);
Expand All @@ -2616,10 +2624,10 @@ module.exports = {
};

const unifiedRequestTypes = {
body: JSON.stringify(bodyTypes, null, 4),
headers: JSON.stringify(headerTypes, null, 4),
pathParam: JSON.stringify(pathParamTypes, null, 4),
queryParam: JSON.stringify(queryParamTypes, null, 4)
body: JSON.stringify(bodyTypes, null, 2),
headers: JSON.stringify(headerTypes, null, 2),
pathParam: JSON.stringify(pathParamTypes, null, 2),
queryParam: JSON.stringify(queryParamTypes, null, 2)
},

{
Expand All @@ -2630,7 +2638,7 @@ module.exports = {

methodPath = method + path;
requestBlock = { request: unifiedRequestTypes, response: resolvedExampleTypes };
Object.assign(extractedTypesObject, { [methodPath]: requestBlock });
Object.assign(typesObject, { [methodPath]: requestBlock });

// add accept header if found and not present already
if (!_.isEmpty(acceptHeader)) {
Expand All @@ -2645,7 +2653,7 @@ module.exports = {
})
},
collectionVariables,
extractedTypesObject
typesObject
};
},

Expand Down

0 comments on commit 8ae2fa5

Please sign in to comment.