Skip to content

Commit

Permalink
tools.js rename methodObj in API generation to operationObj
Browse files Browse the repository at this point in the history
  • Loading branch information
NickOvt committed Nov 2, 2023
1 parent 2d31d2b commit 5e4a20a
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions lib/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -923,22 +923,22 @@ tags:
}

mapPathToMethods[spec.path][spec.method.toLowerCase()] = {};
const methodObj = mapPathToMethods[spec.path][spec.method.toLowerCase()];
const operationObj = mapPathToMethods[spec.path][spec.method.toLowerCase()];
// 1) add tags
methodObj.tags = spec.tags;
operationObj.tags = spec.tags;

// 2) add summary
methodObj.summary = spec.summary || '';
operationObj.summary = spec.summary || '';

// 3) add description
methodObj.description = spec.description || '';
operationObj.description = spec.description || '';

// 4) add operationId
methodObj.operationId = spec.name || route.name;
operationObj.operationId = spec.name || route.name;

// 5) add requestBody
const applicationType = spec.applicationType || 'application/json';
methodObj.requestBody = {
operationObj.requestBody = {
content: {
[applicationType]: {
schema: {
Expand All @@ -953,11 +953,11 @@ tags:
for (const reqBodyKey in spec.validationObjs?.requestBody) {
const reqBodyKeyData = spec.validationObjs.requestBody[reqBodyKey];

parseJoiObject(reqBodyKey, reqBodyKeyData, methodObj.requestBody.content[applicationType].schema.properties);
parseJoiObject(reqBodyKey, reqBodyKeyData, operationObj.requestBody.content[applicationType].schema.properties);
}

// 6) add parameters (queryParams + pathParams).
methodObj.parameters = [];
operationObj.parameters = [];
for (const paramKey in spec.validationObjs?.pathParams) {
const paramKeyData = spec.validationObjs.pathParams[paramKey];

Expand All @@ -967,7 +967,7 @@ tags:
obj.description = paramKeyData._flags.description || '';
obj.required = paramKeyData._flags.presence === 'required';
obj.schema = { type: paramKeyData.type };
methodObj.parameters.push(obj);
operationObj.parameters.push(obj);
}

for (const paramKey in spec.validationObjs?.queryParams) {
Expand All @@ -979,17 +979,17 @@ tags:
obj.description = paramKeyData._flags.description || '';
obj.required = paramKeyData._flags.presence === 'required';
obj.schema = { type: paramKeyData.type };
methodObj.parameters.push(obj);
operationObj.parameters.push(obj);
}

// 7) add responses
const responseType = spec.responseType || 'application/json';
methodObj.responses = {};
operationObj.responses = {};

for (const resHttpCode in spec.validationObjs?.response) {
const resBodyData = spec.validationObjs.response[resHttpCode];

methodObj.responses[resHttpCode] = {
operationObj.responses[resHttpCode] = {
description: resBodyData.description || '',
content: {
[responseType]: {
Expand All @@ -998,7 +998,7 @@ tags:
}
};

const obj = methodObj.responses[resHttpCode];
const obj = operationObj.responses[resHttpCode];

parseJoiObject('schema', resBodyData.model, obj.content[responseType]);
}
Expand Down

0 comments on commit 5e4a20a

Please sign in to comment.