From 061b09b5a977f69e520b72171abf1ccff130837f Mon Sep 17 00:00:00 2001 From: SamerJaser96 <49954147+SamerJaser96@users.noreply.github.com> Date: Wed, 19 Jun 2019 15:14:18 -0500 Subject: [PATCH] fix: response links are not validated as responses (#63) they are validated as links - it is the only components section we were missing in the refs validator --- .../2and3/semantic-validators/walker.js | 4 +- test/plugins/validation/2and3/walker.js | 49 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/plugins/validation/2and3/semantic-validators/walker.js b/src/plugins/validation/2and3/semantic-validators/walker.js index a55931116..89a88d5b2 100644 --- a/src/plugins/validation/2and3/semantic-validators/walker.js +++ b/src/plugins/validation/2and3/semantic-validators/walker.js @@ -127,6 +127,7 @@ module.exports.validate = function({ jsSpec, isOAS3 }, config) { // values are globs! const unacceptableRefPatternsS2 = { responses: ['!*#/responses*'], + links: ['!*#/links*'], schema: ['!*#/definitions*'], parameters: ['!*#/parameters*'] }; @@ -139,7 +140,8 @@ const unacceptableRefPatternsOAS3 = { security: ['!*#/components/securitySchemes*'], callbacks: ['!*#/components/callbacks*'], examples: ['!*#/components/examples*'], - headers: ['!*#/components/headers*'] + headers: ['!*#/components/headers*'], + links: ['!*#/components/links*'] }; const exceptionedParents = ['properties']; diff --git a/test/plugins/validation/2and3/walker.js b/test/plugins/validation/2and3/walker.js index a94a80d92..df0ae00e4 100644 --- a/test/plugins/validation/2and3/walker.js +++ b/test/plugins/validation/2and3/walker.js @@ -600,6 +600,55 @@ describe('validation plugin - semantic - spec walker', () => { 'description' ]); }); + it('should return a problem for a links $ref that does not have the correct format', function() { + const spec = { + paths: { + '/CoolPath/{id}': { + responses: { + '200': { + desciption: 'hi', + content: { + 'application/json': { + schema: { + type: 'string' + } + } + }, + headers: { + Location: { + description: 'hi', + schema: { + type: 'string' + } + } + }, + links: { + link1: { + $ref: '#/parameters/abc' + } + } + } + } + } + } + }; + + const res = validate({ jsSpec: spec }, config); + expect(res.errors.length).toEqual(0); + expect(res.warnings.length).toEqual(1); + expect(res.warnings[0].path).toEqual([ + 'paths', + '/CoolPath/{id}', + 'responses', + '200', + 'links', + 'link1', + '$ref' + ]); + expect(res.warnings[0].message).toEqual( + 'links $refs must follow this format: *#/links*' + ); + }); }); }); });