Skip to content

Commit

Permalink
fix: response links are not validated as responses (#63)
Browse files Browse the repository at this point in the history
they are validated as links - it is the only components section we were missing in the refs validator
  • Loading branch information
SamerJaser96 authored and dpopp07 committed Jun 19, 2019
1 parent 2135c5d commit 061b09b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/plugins/validation/2and3/semantic-validators/walker.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ module.exports.validate = function({ jsSpec, isOAS3 }, config) {
// values are globs!
const unacceptableRefPatternsS2 = {
responses: ['!*#/responses*'],
links: ['!*#/links*'],
schema: ['!*#/definitions*'],
parameters: ['!*#/parameters*']
};
Expand All @@ -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'];
Expand Down
49 changes: 49 additions & 0 deletions test/plugins/validation/2and3/walker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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*'
);
});
});
});
});

0 comments on commit 061b09b

Please sign in to comment.