Skip to content

Commit 061b09b

Browse files
SamerJaser96dpopp07
authored andcommitted
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
1 parent 2135c5d commit 061b09b

File tree

2 files changed

+52
-1
lines changed
  • src/plugins/validation/2and3/semantic-validators
  • test/plugins/validation/2and3

2 files changed

+52
-1
lines changed

src/plugins/validation/2and3/semantic-validators/walker.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ module.exports.validate = function({ jsSpec, isOAS3 }, config) {
127127
// values are globs!
128128
const unacceptableRefPatternsS2 = {
129129
responses: ['!*#/responses*'],
130+
links: ['!*#/links*'],
130131
schema: ['!*#/definitions*'],
131132
parameters: ['!*#/parameters*']
132133
};
@@ -139,7 +140,8 @@ const unacceptableRefPatternsOAS3 = {
139140
security: ['!*#/components/securitySchemes*'],
140141
callbacks: ['!*#/components/callbacks*'],
141142
examples: ['!*#/components/examples*'],
142-
headers: ['!*#/components/headers*']
143+
headers: ['!*#/components/headers*'],
144+
links: ['!*#/components/links*']
143145
};
144146

145147
const exceptionedParents = ['properties'];

test/plugins/validation/2and3/walker.js

+49
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,55 @@ describe('validation plugin - semantic - spec walker', () => {
600600
'description'
601601
]);
602602
});
603+
it('should return a problem for a links $ref that does not have the correct format', function() {
604+
const spec = {
605+
paths: {
606+
'/CoolPath/{id}': {
607+
responses: {
608+
'200': {
609+
desciption: 'hi',
610+
content: {
611+
'application/json': {
612+
schema: {
613+
type: 'string'
614+
}
615+
}
616+
},
617+
headers: {
618+
Location: {
619+
description: 'hi',
620+
schema: {
621+
type: 'string'
622+
}
623+
}
624+
},
625+
links: {
626+
link1: {
627+
$ref: '#/parameters/abc'
628+
}
629+
}
630+
}
631+
}
632+
}
633+
}
634+
};
635+
636+
const res = validate({ jsSpec: spec }, config);
637+
expect(res.errors.length).toEqual(0);
638+
expect(res.warnings.length).toEqual(1);
639+
expect(res.warnings[0].path).toEqual([
640+
'paths',
641+
'/CoolPath/{id}',
642+
'responses',
643+
'200',
644+
'links',
645+
'link1',
646+
'$ref'
647+
]);
648+
expect(res.warnings[0].message).toEqual(
649+
'links $refs must follow this format: *#/links*'
650+
);
651+
});
603652
});
604653
});
605654
});

0 commit comments

Comments
 (0)