Skip to content

Commit

Permalink
Feat/add empty responses (#172)
Browse files Browse the repository at this point in the history
* feat: add test with empty responses

* feat: add empty responses as a valid configuration

* feat: remove test with old validation
  • Loading branch information
kevinccbsg authored Aug 3, 2021
1 parent c5d3fc6 commit c2aac84
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 35 deletions.
25 changes: 0 additions & 25 deletions test/e2e/errors/errors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,6 @@
const chalk = require('chalk');
const processSwagger = require('../../../processSwagger');

test('should give a nice error message for responses', async () => {
const options = {
info: {
version: '1.0.0',
title: 'Albums store',
license: {
name: 'MIT',
},
},
filesPattern: './jsdoc-response-error.js',
baseDir: __dirname,
};
global.console = { ...global.console, warn: jest.fn() };
await processSwagger(options);
expect(console.warn).toHaveBeenCalledTimes(2);
expect(console.warn).toHaveBeenNthCalledWith(
1,
chalk.yellow('[express-jsdoc-swagger] Entity: @return could not be parsed. Value: "200 - success response - application/json" is wrong'),
);
expect(console.warn).toHaveBeenNthCalledWith(
2,
chalk.yellow('[express-jsdoc-swagger] Entity: @return could not be parsed. Value: "400 - Bad request response" is wrong'),
);
});

test('should give a nice error message for parameters', async () => {
const options = {
info: {
Expand Down
6 changes: 0 additions & 6 deletions test/e2e/errors/jsdoc-response-error.js

This file was deleted.

36 changes: 36 additions & 0 deletions test/transforms/paths/responses.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,42 @@ const jsdocInfo = require('../../../consumers/jsdocInfo');
const setPaths = require('../../../transforms/paths');

describe('response tests', () => {
it('should parse jsdoc path spec with more than one response without type', () => {
const jsodInput = [`
/**
* GET /api/v1
* @summary This is the summary of the endpoint
* @return 200 - success response - application/json
* @return 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',
},
400: {
description: 'Bad request response',
},
},
},
},
},
};
const parsedJSDocs = jsdocInfo()(jsodInput);
const result = setPaths({}, parsedJSDocs);
expect(result)
.toEqual(expected);
});

it('should parse jsdoc path spec with more than one response', () => {
const jsodInput = [`
/**
Expand Down
10 changes: 6 additions & 4 deletions transforms/paths/responses.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ const formatResponses = (values, examples) => values.reduce((acc, value) => {
...acc,
[status]: {
description,
content: {
...(hasOldContent(acc, status) ? { ...acc[status].content } : {}),
...getContent(value.type, contentType, value.description, exampleList),
},
...(value.type ? {
content: {
...(hasOldContent(acc, status) ? { ...acc[status].content } : {}),
...getContent(value.type, contentType, value.description, exampleList),
},
} : {}),
},
};
}, {});
Expand Down

0 comments on commit c2aac84

Please sign in to comment.