Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add operation #173

Merged
merged 3 commits into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions test/transforms/paths/parameters.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe('params tests', () => {
/**
* GET /api/v1
* @param {string} name.query.required - name param description
* @operationId getInfo
*/
`];
const expected = {
Expand All @@ -18,6 +19,7 @@ describe('params tests', () => {
responses: {},
tags: [],
security: [],
operationId: 'getInfo',
parameters: [{
deprecated: false,
description: 'name param description',
Expand Down
11 changes: 11 additions & 0 deletions transforms/paths/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 */
Expand All @@ -60,6 +68,7 @@ const pathValues = tags => {
bodyValues,
securityValues,
examples,
operationId: operationId[0],
};
};

Expand All @@ -80,6 +89,7 @@ const parsePath = (path, state) => {
tagsValues,
securityValues,
examples,
operationId,
} = pathValues(tags);
const requestExamples = examples.filter(example => example.type === 'request');
return {
Expand All @@ -95,6 +105,7 @@ const parsePath = (path, state) => {
parameters,
tags: formatTags(tagsValues),
...(setRequestBody(lowerCaseMethod, bodyValues, requestExamples)),
...(getOperationId(operationId)),
},
},
};
Expand Down