@redocly/openapi-core 1.0.0-beta.102 → 1.0.0-beta.103
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/config/config.d.ts +3 -3
- package/lib/config/load.d.ts +1 -1
- package/lib/config/load.js +15 -2
- package/lib/config/rules.d.ts +1 -1
- package/lib/config/types.d.ts +4 -2
- package/lib/decorators/common/filters/filter-helper.d.ts +3 -0
- package/lib/decorators/common/filters/filter-helper.js +67 -0
- package/lib/decorators/common/filters/filter-in.d.ts +2 -0
- package/lib/decorators/common/filters/filter-in.js +17 -0
- package/lib/decorators/common/filters/filter-out.d.ts +2 -0
- package/lib/decorators/common/filters/filter-out.js +17 -0
- package/lib/decorators/oas2/index.d.ts +2 -0
- package/lib/decorators/oas2/index.js +5 -1
- package/lib/decorators/oas3/index.d.ts +2 -0
- package/lib/decorators/oas3/index.js +5 -1
- package/lib/index.d.ts +1 -1
- package/lib/lint.d.ts +2 -0
- package/lib/lint.js +2 -2
- package/lib/redocly/registry-api-types.d.ts +2 -0
- package/lib/redocly/registry-api.d.ts +1 -1
- package/lib/redocly/registry-api.js +3 -1
- package/lib/rules/common/assertions/asserts.d.ts +6 -1
- package/lib/rules/common/assertions/asserts.js +81 -51
- package/lib/rules/common/assertions/utils.d.ts +2 -1
- package/lib/rules/common/assertions/utils.js +27 -8
- package/lib/types/redocly-yaml.js +316 -27
- package/lib/utils.d.ts +2 -1
- package/lib/utils.js +5 -1
- package/lib/walk.d.ts +2 -0
- package/lib/walk.js +16 -7
- package/package.json +1 -1
- package/src/__tests__/lint.test.ts +17 -4
- package/src/config/__tests__/load.test.ts +6 -0
- package/src/config/load.ts +28 -5
- package/src/config/types.ts +6 -5
- package/src/decorators/__tests__/filter-in.test.ts +310 -0
- package/src/decorators/__tests__/filter-out.test.ts +227 -0
- package/src/decorators/common/filters/filter-helper.ts +72 -0
- package/src/decorators/common/filters/filter-in.ts +18 -0
- package/src/decorators/common/filters/filter-out.ts +18 -0
- package/src/decorators/oas2/index.ts +5 -1
- package/src/decorators/oas3/index.ts +5 -1
- package/src/index.ts +1 -0
- package/src/lint.ts +4 -3
- package/src/redocly/registry-api-types.ts +2 -0
- package/src/redocly/registry-api.ts +4 -0
- package/src/rules/common/assertions/__tests__/asserts.test.ts +149 -146
- package/src/rules/common/assertions/asserts.ts +97 -52
- package/src/rules/common/assertions/utils.ts +41 -16
- package/src/types/redocly-yaml.ts +321 -34
- package/src/utils.ts +10 -7
- package/src/walk.ts +39 -19
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -85,7 +85,7 @@ describe('lint', () => {
|
|
|
85
85
|
},
|
|
86
86
|
],
|
|
87
87
|
"message": "Expected type \`ConfigApis\` (object) but got \`string\`",
|
|
88
|
-
"ruleId": "spec",
|
|
88
|
+
"ruleId": "configuration spec",
|
|
89
89
|
"severity": "error",
|
|
90
90
|
"suggest": Array [],
|
|
91
91
|
},
|
|
@@ -97,8 +97,8 @@ describe('lint', () => {
|
|
|
97
97
|
"source": "",
|
|
98
98
|
},
|
|
99
99
|
],
|
|
100
|
-
"message": "
|
|
101
|
-
"ruleId": "spec",
|
|
100
|
+
"message": "\`layout\` can be one of the following only: \\"stacked\\", \\"three-panel\\".",
|
|
101
|
+
"ruleId": "configuration spec",
|
|
102
102
|
"severity": "error",
|
|
103
103
|
"suggest": Array [],
|
|
104
104
|
},
|
|
@@ -123,6 +123,19 @@ describe('lint', () => {
|
|
|
123
123
|
|
|
124
124
|
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
|
|
125
125
|
Array [
|
|
126
|
+
Object {
|
|
127
|
+
"location": Array [
|
|
128
|
+
Object {
|
|
129
|
+
"pointer": "#/apis/lint",
|
|
130
|
+
"reportOnKey": true,
|
|
131
|
+
"source": "",
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
"message": "The field \`root\` must be present on this level.",
|
|
135
|
+
"ruleId": "configuration spec",
|
|
136
|
+
"severity": "error",
|
|
137
|
+
"suggest": Array [],
|
|
138
|
+
},
|
|
126
139
|
Object {
|
|
127
140
|
"location": Array [
|
|
128
141
|
Object {
|
|
@@ -132,7 +145,7 @@ describe('lint', () => {
|
|
|
132
145
|
},
|
|
133
146
|
],
|
|
134
147
|
"message": "Property \`plugins\` is not expected here.",
|
|
135
|
-
"ruleId": "spec",
|
|
148
|
+
"ruleId": "configuration spec",
|
|
136
149
|
"severity": "error",
|
|
137
150
|
"suggest": Array [],
|
|
138
151
|
},
|
|
@@ -44,6 +44,12 @@ describe('loadConfig', () => {
|
|
|
44
44
|
},
|
|
45
45
|
]);
|
|
46
46
|
});
|
|
47
|
+
|
|
48
|
+
it('should call callback if such passed', async () => {
|
|
49
|
+
const mockFn = jest.fn();
|
|
50
|
+
await loadConfig(undefined, undefined, mockFn);
|
|
51
|
+
expect(mockFn).toHaveBeenCalled();
|
|
52
|
+
});
|
|
47
53
|
});
|
|
48
54
|
|
|
49
55
|
describe('findConfig', () => {
|
package/src/config/load.ts
CHANGED
|
@@ -8,11 +8,16 @@ import { resolveConfig } from './config-resolvers';
|
|
|
8
8
|
|
|
9
9
|
import type { RawConfig, Region } from './types';
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
customExtends
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
async function addConfigMetadata({
|
|
12
|
+
rawConfig,
|
|
13
|
+
customExtends,
|
|
14
|
+
configPath
|
|
15
|
+
}: {
|
|
16
|
+
rawConfig: RawConfig;
|
|
17
|
+
customExtends?: string[];
|
|
18
|
+
configPath?: string;
|
|
19
|
+
|
|
20
|
+
}): Promise<Config> {
|
|
16
21
|
if (customExtends !== undefined) {
|
|
17
22
|
rawConfig.lint = rawConfig.lint || {};
|
|
18
23
|
rawConfig.lint.extends = customExtends;
|
|
@@ -56,6 +61,24 @@ export async function loadConfig(
|
|
|
56
61
|
return resolveConfig(rawConfig, configPath);
|
|
57
62
|
}
|
|
58
63
|
|
|
64
|
+
export async function loadConfig(
|
|
65
|
+
configPath: string | undefined = findConfig(),
|
|
66
|
+
customExtends?: string[],
|
|
67
|
+
processRawConfig?: (rawConfig: RawConfig) => void | Promise<void>,
|
|
68
|
+
): Promise<Config> {
|
|
69
|
+
const rawConfig = await getConfig(configPath);
|
|
70
|
+
|
|
71
|
+
if (typeof processRawConfig === 'function') {
|
|
72
|
+
await processRawConfig(rawConfig);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return await addConfigMetadata({
|
|
76
|
+
rawConfig,
|
|
77
|
+
customExtends,
|
|
78
|
+
configPath,
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
|
|
59
82
|
export const CONFIG_FILE_NAMES = ['redocly.yaml', 'redocly.yml', '.redocly.yaml', '.redocly.yml'];
|
|
60
83
|
|
|
61
84
|
export function findConfig(dir?: string): string | undefined {
|
package/src/config/types.ts
CHANGED
|
@@ -11,17 +11,18 @@ import type {
|
|
|
11
11
|
} from '../oas-types';
|
|
12
12
|
import type { NodeType } from '../types';
|
|
13
13
|
|
|
14
|
+
export type RuleSeverity = ProblemSeverity | 'off';
|
|
15
|
+
|
|
16
|
+
export type PreprocessorSeverity = RuleSeverity | 'on';
|
|
17
|
+
|
|
14
18
|
export type RuleConfig =
|
|
15
|
-
|
|
|
16
|
-
| 'off'
|
|
19
|
+
| RuleSeverity
|
|
17
20
|
| ({
|
|
18
21
|
severity?: ProblemSeverity;
|
|
19
22
|
} & Record<string, any>);
|
|
20
23
|
|
|
21
24
|
export type PreprocessorConfig =
|
|
22
|
-
|
|
|
23
|
-
| 'off'
|
|
24
|
-
| 'on'
|
|
25
|
+
| PreprocessorSeverity
|
|
25
26
|
| ({
|
|
26
27
|
severity?: ProblemSeverity;
|
|
27
28
|
} & Record<string, any>);
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { outdent } from 'outdent';
|
|
2
|
+
import { bundleDocument } from '../../bundle';
|
|
3
|
+
import { BaseResolver } from '../../resolve';
|
|
4
|
+
import { makeConfig, parseYamlToDocument, yamlSerializer } from '../../../__tests__/utils';
|
|
5
|
+
|
|
6
|
+
describe('oas3 filter-in', () => {
|
|
7
|
+
expect.addSnapshotSerializer(yamlSerializer);
|
|
8
|
+
|
|
9
|
+
const inputDoc = parseYamlToDocument(
|
|
10
|
+
outdent`
|
|
11
|
+
openapi: 3.0.0
|
|
12
|
+
paths:
|
|
13
|
+
/pet:
|
|
14
|
+
x-audience: Global
|
|
15
|
+
post:
|
|
16
|
+
summary: test
|
|
17
|
+
/user:
|
|
18
|
+
x-audience: [Public, Global]
|
|
19
|
+
post:
|
|
20
|
+
summary: test
|
|
21
|
+
/post:
|
|
22
|
+
get:
|
|
23
|
+
summary: test
|
|
24
|
+
/order:
|
|
25
|
+
x-audience: [Public, Protected]
|
|
26
|
+
post:
|
|
27
|
+
operationId: storeOrder
|
|
28
|
+
callbacks:
|
|
29
|
+
x-access: protected`
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
it('should include /user path and remove y parameter', async () => {
|
|
33
|
+
const testDocument = parseYamlToDocument(
|
|
34
|
+
outdent`
|
|
35
|
+
openapi: 3.0.0
|
|
36
|
+
paths:
|
|
37
|
+
/pet:
|
|
38
|
+
x-access: private
|
|
39
|
+
get:
|
|
40
|
+
parameters:
|
|
41
|
+
- $ref: '#/components/parameters/x'
|
|
42
|
+
/user:
|
|
43
|
+
x-access: public
|
|
44
|
+
get:
|
|
45
|
+
parameters:
|
|
46
|
+
- $ref: '#/components/parameters/y'
|
|
47
|
+
components:
|
|
48
|
+
parameters:
|
|
49
|
+
x:
|
|
50
|
+
name: x
|
|
51
|
+
y:
|
|
52
|
+
x-access: private
|
|
53
|
+
name: y
|
|
54
|
+
`
|
|
55
|
+
);
|
|
56
|
+
const { bundle: res } = await bundleDocument({
|
|
57
|
+
document: testDocument,
|
|
58
|
+
externalRefResolver: new BaseResolver(),
|
|
59
|
+
config: await makeConfig({}, { 'filter-in': { value: 'public', property: 'x-access' } }),
|
|
60
|
+
});
|
|
61
|
+
expect(res.parsed).toMatchInlineSnapshot(`
|
|
62
|
+
openapi: 3.0.0
|
|
63
|
+
paths:
|
|
64
|
+
/user:
|
|
65
|
+
x-access: public
|
|
66
|
+
get: {}
|
|
67
|
+
components:
|
|
68
|
+
parameters:
|
|
69
|
+
x:
|
|
70
|
+
name: x
|
|
71
|
+
|
|
72
|
+
`);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('should include /order and /post paths', async () => {
|
|
76
|
+
const { bundle: res } = await bundleDocument({
|
|
77
|
+
document: inputDoc,
|
|
78
|
+
externalRefResolver: new BaseResolver(),
|
|
79
|
+
config: await makeConfig(
|
|
80
|
+
{},
|
|
81
|
+
{
|
|
82
|
+
'filter-in': {
|
|
83
|
+
property: 'x-audience',
|
|
84
|
+
value: ['Public', 'Protected'],
|
|
85
|
+
matchStrategy: 'all',
|
|
86
|
+
},
|
|
87
|
+
}
|
|
88
|
+
),
|
|
89
|
+
});
|
|
90
|
+
expect(res.parsed).toMatchInlineSnapshot(`
|
|
91
|
+
openapi: 3.0.0
|
|
92
|
+
paths:
|
|
93
|
+
/post:
|
|
94
|
+
get:
|
|
95
|
+
summary: test
|
|
96
|
+
/order:
|
|
97
|
+
x-audience:
|
|
98
|
+
- Public
|
|
99
|
+
- Protected
|
|
100
|
+
post:
|
|
101
|
+
operationId: storeOrder
|
|
102
|
+
callbacks:
|
|
103
|
+
x-access: protected
|
|
104
|
+
components: {}
|
|
105
|
+
|
|
106
|
+
`);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('should include all paths', async () => {
|
|
110
|
+
const testDoc = parseYamlToDocument(
|
|
111
|
+
outdent`
|
|
112
|
+
openapi: 3.0.0
|
|
113
|
+
paths:
|
|
114
|
+
/pet:
|
|
115
|
+
x-audience: Global
|
|
116
|
+
post:
|
|
117
|
+
summary: test
|
|
118
|
+
/user:
|
|
119
|
+
x-audience: [Public, Global]
|
|
120
|
+
post:
|
|
121
|
+
summary: test
|
|
122
|
+
/order:
|
|
123
|
+
x-audience: [Public, Protected]
|
|
124
|
+
post:
|
|
125
|
+
operationId: storeOrder
|
|
126
|
+
parameters:
|
|
127
|
+
- name: api_key
|
|
128
|
+
`
|
|
129
|
+
);
|
|
130
|
+
const { bundle: res } = await bundleDocument({
|
|
131
|
+
document: testDoc,
|
|
132
|
+
externalRefResolver: new BaseResolver(),
|
|
133
|
+
config: await makeConfig(
|
|
134
|
+
{},
|
|
135
|
+
{
|
|
136
|
+
'filter-in': {
|
|
137
|
+
property: 'x-audience',
|
|
138
|
+
value: ['Public', 'Global'],
|
|
139
|
+
matchStrategy: 'any',
|
|
140
|
+
},
|
|
141
|
+
}
|
|
142
|
+
),
|
|
143
|
+
});
|
|
144
|
+
expect(res.parsed).toMatchInlineSnapshot(`
|
|
145
|
+
openapi: 3.0.0
|
|
146
|
+
paths:
|
|
147
|
+
/pet:
|
|
148
|
+
x-audience: Global
|
|
149
|
+
post:
|
|
150
|
+
summary: test
|
|
151
|
+
/user:
|
|
152
|
+
x-audience:
|
|
153
|
+
- Public
|
|
154
|
+
- Global
|
|
155
|
+
post:
|
|
156
|
+
summary: test
|
|
157
|
+
/order:
|
|
158
|
+
x-audience:
|
|
159
|
+
- Public
|
|
160
|
+
- Protected
|
|
161
|
+
post:
|
|
162
|
+
operationId: storeOrder
|
|
163
|
+
parameters:
|
|
164
|
+
- name: api_key
|
|
165
|
+
components: {}
|
|
166
|
+
|
|
167
|
+
`);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('should include path without x-audience property ', async () => {
|
|
171
|
+
const { bundle: res } = await bundleDocument({
|
|
172
|
+
document: inputDoc,
|
|
173
|
+
externalRefResolver: new BaseResolver(),
|
|
174
|
+
config: await makeConfig(
|
|
175
|
+
{},
|
|
176
|
+
{
|
|
177
|
+
'filter-in': {
|
|
178
|
+
property: 'x-audience',
|
|
179
|
+
value: 'non-existing-audience',
|
|
180
|
+
matchStrategy: 'any',
|
|
181
|
+
},
|
|
182
|
+
}
|
|
183
|
+
),
|
|
184
|
+
});
|
|
185
|
+
expect(res.parsed).toMatchInlineSnapshot(`
|
|
186
|
+
openapi: 3.0.0
|
|
187
|
+
paths:
|
|
188
|
+
/post:
|
|
189
|
+
get:
|
|
190
|
+
summary: test
|
|
191
|
+
components: {}
|
|
192
|
+
|
|
193
|
+
`);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('should include /pet and /account without post method', async () => {
|
|
197
|
+
const testDoc = parseYamlToDocument(
|
|
198
|
+
outdent`
|
|
199
|
+
openapi: 3.0.0
|
|
200
|
+
paths:
|
|
201
|
+
/pet:
|
|
202
|
+
x-audience: Global
|
|
203
|
+
post:
|
|
204
|
+
summary: test
|
|
205
|
+
/user:
|
|
206
|
+
x-audience: Private
|
|
207
|
+
post:
|
|
208
|
+
summary: test
|
|
209
|
+
get:
|
|
210
|
+
summary: get
|
|
211
|
+
x-audience: [Public, Global]
|
|
212
|
+
/account:
|
|
213
|
+
get:
|
|
214
|
+
summary: get
|
|
215
|
+
post:
|
|
216
|
+
summary: test
|
|
217
|
+
x-audience: Private
|
|
218
|
+
`
|
|
219
|
+
);
|
|
220
|
+
const { bundle: res } = await bundleDocument({
|
|
221
|
+
document: testDoc,
|
|
222
|
+
externalRefResolver: new BaseResolver(),
|
|
223
|
+
config: await makeConfig(
|
|
224
|
+
{},
|
|
225
|
+
{
|
|
226
|
+
'filter-in': {
|
|
227
|
+
property: 'x-audience',
|
|
228
|
+
value: ['Public', 'Global'],
|
|
229
|
+
matchStrategy: 'any',
|
|
230
|
+
},
|
|
231
|
+
}
|
|
232
|
+
),
|
|
233
|
+
});
|
|
234
|
+
expect(res.parsed).toMatchInlineSnapshot(`
|
|
235
|
+
openapi: 3.0.0
|
|
236
|
+
paths:
|
|
237
|
+
/pet:
|
|
238
|
+
x-audience: Global
|
|
239
|
+
post:
|
|
240
|
+
summary: test
|
|
241
|
+
/account:
|
|
242
|
+
get:
|
|
243
|
+
summary: get
|
|
244
|
+
components: {}
|
|
245
|
+
|
|
246
|
+
`);
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
describe('oas2 filter-in', () => {
|
|
251
|
+
it('should include only one parameter and not include response', async () => {
|
|
252
|
+
const testDoc = parseYamlToDocument(
|
|
253
|
+
outdent`
|
|
254
|
+
swagger: '2.0'
|
|
255
|
+
host: api.instagram.com
|
|
256
|
+
paths:
|
|
257
|
+
'/geographies/{geo-id}/media/recent':
|
|
258
|
+
get:
|
|
259
|
+
parameters:
|
|
260
|
+
- description: The geography ID.
|
|
261
|
+
x-access: private
|
|
262
|
+
in: path
|
|
263
|
+
name: geo-id
|
|
264
|
+
required: true
|
|
265
|
+
type: string
|
|
266
|
+
- description: Max number of media to return.
|
|
267
|
+
x-access: public
|
|
268
|
+
format: int32
|
|
269
|
+
in: query
|
|
270
|
+
name: count
|
|
271
|
+
required: false
|
|
272
|
+
type: integer
|
|
273
|
+
responses:
|
|
274
|
+
'200':
|
|
275
|
+
description: List of recent media entries.
|
|
276
|
+
x-access: [private, protected]
|
|
277
|
+
`
|
|
278
|
+
);
|
|
279
|
+
const { bundle: res } = await bundleDocument({
|
|
280
|
+
document: testDoc,
|
|
281
|
+
externalRefResolver: new BaseResolver(),
|
|
282
|
+
config: await makeConfig(
|
|
283
|
+
{},
|
|
284
|
+
{
|
|
285
|
+
'filter-in': {
|
|
286
|
+
property: 'x-access',
|
|
287
|
+
value: ['public', 'global'],
|
|
288
|
+
matchStrategy: 'any',
|
|
289
|
+
},
|
|
290
|
+
}
|
|
291
|
+
),
|
|
292
|
+
});
|
|
293
|
+
expect(res.parsed).toMatchInlineSnapshot(`
|
|
294
|
+
swagger: '2.0'
|
|
295
|
+
host: api.instagram.com
|
|
296
|
+
paths:
|
|
297
|
+
/geographies/{geo-id}/media/recent:
|
|
298
|
+
get:
|
|
299
|
+
parameters:
|
|
300
|
+
- description: Max number of media to return.
|
|
301
|
+
x-access: public
|
|
302
|
+
format: int32
|
|
303
|
+
in: query
|
|
304
|
+
name: count
|
|
305
|
+
required: false
|
|
306
|
+
type: integer
|
|
307
|
+
|
|
308
|
+
`);
|
|
309
|
+
});
|
|
310
|
+
});
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { outdent } from 'outdent';
|
|
2
|
+
import { bundleDocument } from '../../bundle';
|
|
3
|
+
import { BaseResolver } from '../../resolve';
|
|
4
|
+
import { makeConfig, parseYamlToDocument, yamlSerializer } from '../../../__tests__/utils';
|
|
5
|
+
|
|
6
|
+
describe('oas3 filter-out', () => {
|
|
7
|
+
expect.addSnapshotSerializer(yamlSerializer);
|
|
8
|
+
|
|
9
|
+
const inputDoc = parseYamlToDocument(
|
|
10
|
+
outdent`
|
|
11
|
+
openapi: 3.0.0
|
|
12
|
+
paths:
|
|
13
|
+
/pet:
|
|
14
|
+
x-audience: Private
|
|
15
|
+
post:
|
|
16
|
+
summary: test
|
|
17
|
+
/user:
|
|
18
|
+
x-audience: Protected
|
|
19
|
+
post:
|
|
20
|
+
summary: test
|
|
21
|
+
/order:
|
|
22
|
+
x-audience: [Private, Protected]
|
|
23
|
+
post:
|
|
24
|
+
operationId: storeOrder
|
|
25
|
+
parameters:
|
|
26
|
+
- name: api_key
|
|
27
|
+
callbacks:
|
|
28
|
+
x-access: protected
|
|
29
|
+
orderInProgress:
|
|
30
|
+
x-internal: true
|
|
31
|
+
`
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
it('should remove /pet path and y parameter', async () => {
|
|
35
|
+
const testDocument = parseYamlToDocument(
|
|
36
|
+
outdent`
|
|
37
|
+
openapi: 3.0.0
|
|
38
|
+
paths:
|
|
39
|
+
/pet:
|
|
40
|
+
x-access: private
|
|
41
|
+
get:
|
|
42
|
+
parameters:
|
|
43
|
+
- $ref: '#/components/parameters/y'
|
|
44
|
+
components:
|
|
45
|
+
parameters:
|
|
46
|
+
x:
|
|
47
|
+
name: x
|
|
48
|
+
y:
|
|
49
|
+
x-access: private
|
|
50
|
+
name: y
|
|
51
|
+
`
|
|
52
|
+
);
|
|
53
|
+
const { bundle: res } = await bundleDocument({
|
|
54
|
+
document: testDocument,
|
|
55
|
+
externalRefResolver: new BaseResolver(),
|
|
56
|
+
config: await makeConfig({}, { 'filter-out': { property: 'x-access', value: 'private' } }),
|
|
57
|
+
});
|
|
58
|
+
expect(res.parsed).toMatchInlineSnapshot(`
|
|
59
|
+
openapi: 3.0.0
|
|
60
|
+
components:
|
|
61
|
+
parameters:
|
|
62
|
+
x:
|
|
63
|
+
name: x
|
|
64
|
+
|
|
65
|
+
`);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('should remove only /order path', async () => {
|
|
69
|
+
const { bundle: res } = await bundleDocument({
|
|
70
|
+
document: inputDoc,
|
|
71
|
+
externalRefResolver: new BaseResolver(),
|
|
72
|
+
config: await makeConfig(
|
|
73
|
+
{},
|
|
74
|
+
{
|
|
75
|
+
'filter-out': {
|
|
76
|
+
property: 'x-audience',
|
|
77
|
+
value: ['Private', 'Protected'],
|
|
78
|
+
matchStrategy: 'all',
|
|
79
|
+
},
|
|
80
|
+
}
|
|
81
|
+
),
|
|
82
|
+
});
|
|
83
|
+
expect(res.parsed).toMatchInlineSnapshot(`
|
|
84
|
+
openapi: 3.0.0
|
|
85
|
+
paths:
|
|
86
|
+
/pet:
|
|
87
|
+
x-audience: Private
|
|
88
|
+
post:
|
|
89
|
+
summary: test
|
|
90
|
+
/user:
|
|
91
|
+
x-audience: Protected
|
|
92
|
+
post:
|
|
93
|
+
summary: test
|
|
94
|
+
components: {}
|
|
95
|
+
|
|
96
|
+
`);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('should remove all paths', async () => {
|
|
100
|
+
const { bundle: res } = await bundleDocument({
|
|
101
|
+
document: inputDoc,
|
|
102
|
+
externalRefResolver: new BaseResolver(),
|
|
103
|
+
config: await makeConfig(
|
|
104
|
+
{},
|
|
105
|
+
{
|
|
106
|
+
'filter-out': {
|
|
107
|
+
property: 'x-audience',
|
|
108
|
+
value: ['Private', 'Protected'],
|
|
109
|
+
matchStrategy: 'any',
|
|
110
|
+
},
|
|
111
|
+
}
|
|
112
|
+
),
|
|
113
|
+
});
|
|
114
|
+
expect(res.parsed).toMatchInlineSnapshot(`
|
|
115
|
+
openapi: 3.0.0
|
|
116
|
+
components: {}
|
|
117
|
+
|
|
118
|
+
`);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('should remove requestBody', async () => {
|
|
122
|
+
const testDoc = parseYamlToDocument(
|
|
123
|
+
outdent`
|
|
124
|
+
openapi: 3.0.0
|
|
125
|
+
paths:
|
|
126
|
+
/pet:
|
|
127
|
+
post:
|
|
128
|
+
summary: test
|
|
129
|
+
requestBody:
|
|
130
|
+
content:
|
|
131
|
+
x-access: private
|
|
132
|
+
application/x-www-form-urlencoded:
|
|
133
|
+
schema:
|
|
134
|
+
type: object
|
|
135
|
+
components: {}
|
|
136
|
+
|
|
137
|
+
`
|
|
138
|
+
);
|
|
139
|
+
const { bundle: res } = await bundleDocument({
|
|
140
|
+
document: testDoc,
|
|
141
|
+
externalRefResolver: new BaseResolver(),
|
|
142
|
+
config: await makeConfig(
|
|
143
|
+
{},
|
|
144
|
+
{
|
|
145
|
+
'filter-out': {
|
|
146
|
+
property: 'x-access',
|
|
147
|
+
value: 'private',
|
|
148
|
+
matchStrategy: 'any',
|
|
149
|
+
},
|
|
150
|
+
}
|
|
151
|
+
),
|
|
152
|
+
});
|
|
153
|
+
expect(res.parsed).toMatchInlineSnapshot(`
|
|
154
|
+
openapi: 3.0.0
|
|
155
|
+
paths:
|
|
156
|
+
/pet:
|
|
157
|
+
post:
|
|
158
|
+
summary: test
|
|
159
|
+
components: {}
|
|
160
|
+
|
|
161
|
+
`);
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
describe('oas2 filter-out', () => {
|
|
166
|
+
it('should clean all parameters and responses ', async () => {
|
|
167
|
+
const testDoc = parseYamlToDocument(
|
|
168
|
+
outdent`
|
|
169
|
+
swagger: '2.0'
|
|
170
|
+
host: api.instagram.com
|
|
171
|
+
paths:
|
|
172
|
+
'/geographies/{geo-id}/media/recent':
|
|
173
|
+
get:
|
|
174
|
+
parameters:
|
|
175
|
+
- description: The geography ID.
|
|
176
|
+
x-access: private
|
|
177
|
+
in: path
|
|
178
|
+
name: geo-id
|
|
179
|
+
required: true
|
|
180
|
+
type: string
|
|
181
|
+
- description: Max number of media to return.
|
|
182
|
+
x-access: protected
|
|
183
|
+
format: int32
|
|
184
|
+
in: query
|
|
185
|
+
name: count
|
|
186
|
+
required: false
|
|
187
|
+
type: integer
|
|
188
|
+
responses:
|
|
189
|
+
$ref: '#/components/response/200'
|
|
190
|
+
components:
|
|
191
|
+
response:
|
|
192
|
+
'200':
|
|
193
|
+
description: List of recent media entries.
|
|
194
|
+
x-access: [protected, public]
|
|
195
|
+
`
|
|
196
|
+
);
|
|
197
|
+
const { bundle: res } = await bundleDocument({
|
|
198
|
+
document: testDoc,
|
|
199
|
+
externalRefResolver: new BaseResolver(),
|
|
200
|
+
config: await makeConfig(
|
|
201
|
+
{},
|
|
202
|
+
{
|
|
203
|
+
'filter-out': {
|
|
204
|
+
property: 'x-access',
|
|
205
|
+
value: ['private', 'protected'],
|
|
206
|
+
matchStrategy: 'any',
|
|
207
|
+
},
|
|
208
|
+
}
|
|
209
|
+
),
|
|
210
|
+
});
|
|
211
|
+
expect(res.parsed).toMatchInlineSnapshot(`
|
|
212
|
+
swagger: '2.0'
|
|
213
|
+
host: api.instagram.com
|
|
214
|
+
paths:
|
|
215
|
+
/geographies/{geo-id}/media/recent:
|
|
216
|
+
get: {}
|
|
217
|
+
components:
|
|
218
|
+
response:
|
|
219
|
+
'200':
|
|
220
|
+
description: List of recent media entries.
|
|
221
|
+
x-access:
|
|
222
|
+
- protected
|
|
223
|
+
- public
|
|
224
|
+
|
|
225
|
+
`);
|
|
226
|
+
});
|
|
227
|
+
});
|