From eb658fa9b6962a7add4ffe7adb35d4ba82803faa Mon Sep 17 00:00:00 2001 From: kevinccbsg Date: Tue, 3 Aug 2021 00:02:24 +0200 Subject: [PATCH 1/2] feat: add operation id condition --- test/transforms/paths/parameters.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/transforms/paths/parameters.test.js b/test/transforms/paths/parameters.test.js index 21c5f93..76239be 100644 --- a/test/transforms/paths/parameters.test.js +++ b/test/transforms/paths/parameters.test.js @@ -7,6 +7,7 @@ describe('params tests', () => { /** * GET /api/v1 * @param {string} name.query.required - name param description + * @operationId getInfo */ `]; const expected = { @@ -18,6 +19,7 @@ describe('params tests', () => { responses: {}, tags: [], security: [], + operationId: 'getInfo', parameters: [{ deprecated: false, description: 'name param description', From 7bde43165aba73d8f9523ad4cb8f3fd5bcf41716 Mon Sep 17 00:00:00 2001 From: kevinccbsg Date: Tue, 3 Aug 2021 00:04:17 +0200 Subject: [PATCH 2/2] feat: add operationid as a valid option in the comments --- transforms/paths/index.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/transforms/paths/index.js b/transforms/paths/index.js index dbc6106..10229c5 100644 --- a/transforms/paths/index.js +++ b/transforms/paths/index.js @@ -26,6 +26,13 @@ const setRequestBody = (lowerCaseMethod, bodyValues, requestExamples) => { const bodyParams = ({ name }) => name.includes('request.body') || name.includes('.form'); +const getOperationId = operationIdTag => { + if (!operationIdTag) return {}; + return { + operationId: operationIdTag.description, + }; +}; + const pathValues = tags => { const examplesValues = getTagsInfo(tags, 'example'); const examples = examplesGenerator(examplesValues); @@ -42,6 +49,7 @@ const pathValues = tags => { const responseExamples = examples.filter(example => example.type === 'response'); const responses = responsesGenerator(returnValues, responseExamples); /* Parameters info */ + const operationId = getTagsInfo(tags, 'operationId'); const paramValues = getTagsInfo(tags, 'param'); const parameters = parametersGenerator(paramValues); /* Tags info */ @@ -60,6 +68,7 @@ const pathValues = tags => { bodyValues, securityValues, examples, + operationId: operationId[0], }; }; @@ -80,6 +89,7 @@ const parsePath = (path, state) => { tagsValues, securityValues, examples, + operationId, } = pathValues(tags); const requestExamples = examples.filter(example => example.type === 'request'); return { @@ -95,6 +105,7 @@ const parsePath = (path, state) => { parameters, tags: formatTags(tagsValues), ...(setRequestBody(lowerCaseMethod, bodyValues, requestExamples)), + ...(getOperationId(operationId)), }, }, };