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 support for @returns tag #153

Merged
merged 2 commits into from
Apr 30, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions test/transforms/paths/responses.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,56 @@ describe('response tests', () => {
.toEqual(expected);
});

it('should parse jsdoc with responses, whether @return or @returns tags are used', () => {
const jsdocInput = [`
/**
* GET /api/v1
* @summary This is the summary of the endpoint
* @return {object} 200 - success response - application/json
* @returns {object} 400 - Bad request response
*/
`];
const expected = {
paths: {
'/api/v1': {
get: {
deprecated: false,
summary: 'This is the summary of the endpoint',
parameters: [],
tags: [],
security: [],
responses: {
200: {
description: 'success response',
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
400: {
description: 'Bad request response',
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
},
},
},
},
},
};
const parsedJSDocs = jsdocInfo()(jsdocInput);
const result = setPaths({}, parsedJSDocs);
expect(result)
.toEqual(expected);
});

it('should not parse jsdoc with wrong info and return warning in the console', () => {
global.console = {
...global.console,
Expand Down
5 changes: 4 additions & 1 deletion transforms/paths/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ const pathValues = tags => {
const deprecated = getTagInfo(tags, 'deprecated');
const isDeprecated = !!deprecated;
/* Response info */
const returnValues = getTagsInfo(tags, 'return');
const returnValues = [
...getTagsInfo(tags, 'return'),
...getTagsInfo(tags, 'returns'),
];
const responseExamples = examples.filter(example => example.type === 'response');
const responses = responsesGenerator(returnValues, responseExamples);
/* Parameters info */
Expand Down