-
-
Notifications
You must be signed in to change notification settings - Fork 218
/
index.ts
178 lines (169 loc) · 3.96 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import { Spectral } from '../../../../../index';
import { commonOasRuleset } from '../../../index';
const ruleset = commonOasRuleset();
describe('oasPathParam', () => {
const s = new Spectral({
rulesets: [
{
functions: ruleset.functions,
rules: {
oas2: {
'path-params': Object.assign(ruleset.rules.oas2['path-params'], {
enabled: true,
}),
},
},
},
],
});
test('No error if templated path is not used', () => {
const results = s.run({
spec: 'oas2',
target: {},
resTarget: {
paths: {
'/foo': {
get: {},
},
},
},
});
expect(results.length).toEqual(0);
});
test('Error if no path parameter definition', () => {
const results = s.run({
spec: 'oas2',
target: {},
resTarget: {
paths: {
'/foo/{bar}': {
get: {},
},
},
},
});
expect(results.length).toEqual(1);
expect(results[0].path).toEqual(['$', 'paths', '/foo/{bar}']);
expect(results[0].message).toContain('bar');
});
test('No error if path parameter definition is used (at the path level)', () => {
const results = s.run({
spec: 'oas2',
target: {},
resTarget: {
paths: {
'/foo/{bar}': {
parameters: [
{
name: 'bar',
in: 'path',
required: true,
},
],
get: {},
},
},
},
});
expect(results.length).toEqual(0);
});
test('No error if path parameter definition is set (at the operation level)', () => {
const results = s.run({
spec: 'oas2',
target: {},
resTarget: {
paths: {
'/foo/{bar}': {
get: {
parameters: [
{
name: 'bar',
in: 'path',
required: true,
},
],
},
},
},
},
});
expect(results.length).toEqual(0);
});
test('Error if duplicate path parameters with same name are used', () => {
const results = s.run({
spec: 'oas2',
target: {},
resTarget: {
paths: {
'/foo/{bar}/{bar}': {
parameters: [
{
name: 'bar',
in: 'path',
required: true,
},
],
get: {},
},
},
},
});
expect(results.length).toEqual(1);
expect(results[0].path).toEqual(['$', 'paths', '/foo/{bar}/{bar}']);
expect(results[0].message).toContain('bar');
});
test('Error if path parameter definition is not required', () => {
const results = s.run({
spec: 'oas2',
target: {},
resTarget: {
paths: {
'/foo/{bar}': {
parameters: [
{
name: 'bar',
in: 'path',
required: false,
},
],
get: {},
},
},
},
});
expect(results.length).toEqual(1);
expect(results[0].path).toEqual(['$', 'paths', '/foo/{bar}', 'parameters']);
});
test('Error if paths are functionally equivalent', () => {
const results = s.run({
spec: 'oas2',
target: {},
resTarget: {
paths: {
'/foo/{boo}': {
parameters: [
{
name: 'boo',
in: 'path',
required: true,
},
],
get: {},
},
'/foo/{bar}': {
parameters: [
{
name: 'bar',
in: 'path',
required: true,
},
],
get: {},
},
},
},
});
expect(results.length).toEqual(1);
expect(results[0].path).toEqual(['$', 'paths']);
});
});