diff --git a/src/plugins/validation/oas3/semantic-validators/responses.js b/src/plugins/validation/oas3/semantic-validators/responses.js index 0ba8666cf..ad2fb9a9f 100644 --- a/src/plugins/validation/oas3/semantic-validators/responses.js +++ b/src/plugins/validation/oas3/semantic-validators/responses.js @@ -50,8 +50,15 @@ module.exports.validate = function({ resolvedSpec }, config) { config.no_response_codes ); } else { - // default warnings for discouraged status code per IBM API Handbook for (const statusCode of statusCodes) { + if (!obj[statusCode].description) { + messages.addMessage( + path.concat([statusCode]), + `All responses must include a description.`, + 'error' + ); + } + // default warnings for discouraged status code per IBM API Handbook if (statusCode === '422') { messages.addMessage( path.concat(['422']), diff --git a/test/plugins/validation/oas3/responses.test.js b/test/plugins/validation/oas3/responses.test.js index 9860f3c96..be10c190a 100644 --- a/test/plugins/validation/oas3/responses.test.js +++ b/test/plugins/validation/oas3/responses.test.js @@ -83,6 +83,39 @@ describe('validation plugin - semantic - responses - oas3', function() { ); }); + it('should complain when a response is missing a description', function() { + const spec = { + paths: { + '/pets': { + get: { + summary: 'this is a summary', + operationId: 'operationId', + responses: { + '200': { + content: { + 'multipart/form-data': { + schema: { + type: 'string', + format: 'binary' + } + } + } + } + } + } + } + } + }; + + const res = validate({ resolvedSpec: spec }, config); + expect(res.warnings.length).toEqual(0); + expect(res.errors.length).toEqual(1); + expect(res.errors[0].path).toEqual(['paths', '/pets', 'get', 'responses', '200']); + expect(res.errors[0].message).toEqual( + 'All responses must include a description.' + ); + }); + it('should complain when 422 response code used', function() { const spec = { paths: {