@redocly/openapi-core 1.0.0-beta.108 → 1.0.0-beta.110
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/README.md +2 -2
- package/lib/benchmark/benches/resolve-with-no-external.bench.js +1 -1
- package/lib/bundle.d.ts +1 -1
- package/lib/bundle.js +4 -4
- package/lib/config/all.js +3 -1
- package/lib/config/config-resolvers.js +22 -4
- package/lib/config/config.d.ts +1 -0
- package/lib/config/config.js +1 -0
- package/lib/config/load.d.ts +8 -2
- package/lib/config/load.js +4 -2
- package/lib/config/minimal.js +3 -1
- package/lib/config/recommended.js +3 -1
- package/lib/config/rules.js +1 -1
- package/lib/config/types.d.ts +17 -0
- package/lib/config/utils.d.ts +2 -2
- package/lib/config/utils.js +44 -6
- package/lib/decorators/common/registry-dependencies.js +1 -1
- package/lib/format/format.d.ts +1 -1
- package/lib/format/format.js +22 -1
- package/lib/lint.js +2 -2
- package/lib/redocly/registry-api.d.ts +0 -1
- package/lib/redocly/registry-api.js +5 -4
- package/lib/resolve.js +3 -1
- package/lib/rules/ajv.d.ts +1 -1
- package/lib/rules/ajv.js +5 -5
- package/lib/rules/common/assertions/asserts.d.ts +3 -5
- package/lib/rules/common/assertions/asserts.js +137 -97
- package/lib/rules/common/assertions/index.js +2 -6
- package/lib/rules/common/assertions/utils.d.ts +12 -6
- package/lib/rules/common/assertions/utils.js +33 -20
- package/lib/rules/common/no-ambiguous-paths.js +1 -1
- package/lib/rules/common/no-identical-paths.js +1 -1
- package/lib/rules/common/operation-2xx-response.js +1 -1
- package/lib/rules/common/operation-4xx-response.js +1 -1
- package/lib/rules/common/operation-operationId.js +1 -1
- package/lib/rules/common/operation-tag-defined.js +1 -1
- package/lib/rules/common/path-not-include-query.js +1 -1
- package/lib/rules/common/security-defined.d.ts +2 -0
- package/lib/rules/common/{operation-security-defined.js → security-defined.js} +18 -4
- package/lib/rules/common/spec.js +12 -1
- package/lib/rules/common/tags-alphabetical.js +1 -1
- package/lib/rules/oas2/index.d.ts +1 -1
- package/lib/rules/oas2/index.js +2 -2
- package/lib/rules/oas2/remove-unused-components.js +1 -1
- package/lib/rules/oas2/request-mime-type.js +1 -1
- package/lib/rules/oas2/response-mime-type.js +1 -1
- package/lib/rules/oas3/index.js +6 -2
- package/lib/rules/oas3/no-empty-servers.js +1 -1
- package/lib/rules/oas3/no-server-variables-empty-enum.js +1 -1
- package/lib/rules/oas3/no-unused-components.js +1 -1
- package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.d.ts +5 -0
- package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.js +36 -0
- package/lib/rules/oas3/remove-unused-components.js +1 -1
- package/lib/rules/oas3/request-mime-type.js +1 -1
- package/lib/rules/oas3/response-mime-type.js +1 -1
- package/lib/rules/oas3/spec-components-invalid-map-name.d.ts +2 -0
- package/lib/rules/oas3/spec-components-invalid-map-name.js +46 -0
- package/lib/rules/other/stats.d.ts +2 -2
- package/lib/rules/other/stats.js +2 -2
- package/lib/rules/utils.js +1 -1
- package/lib/types/oas2.js +5 -5
- package/lib/types/oas3.js +27 -20
- package/lib/types/oas3_1.js +3 -3
- package/lib/types/redocly-yaml.js +60 -54
- package/lib/utils.d.ts +3 -3
- package/lib/utils.js +5 -5
- package/lib/visitors.d.ts +11 -11
- package/lib/visitors.js +13 -1
- package/package.json +3 -5
- package/src/__tests__/__snapshots__/bundle.test.ts.snap +3 -3
- package/src/__tests__/fixtures/extension.js +3 -3
- package/src/__tests__/format.test.ts +76 -0
- package/src/__tests__/lint.test.ts +184 -121
- package/src/__tests__/resolve-http.test.ts +1 -1
- package/src/__tests__/resolve.test.ts +9 -9
- package/src/__tests__/walk.test.ts +78 -10
- package/src/benchmark/benches/resolve-with-no-external.bench.ts +1 -1
- package/src/bundle.ts +4 -4
- package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +6 -2
- package/src/config/__tests__/config-resolvers.test.ts +37 -1
- package/src/config/__tests__/config.test.ts +5 -0
- package/src/config/__tests__/fixtures/plugin-config.yaml +2 -3
- package/src/config/__tests__/fixtures/resolve-config/api/nested-config.yaml +11 -12
- package/src/config/__tests__/fixtures/resolve-config/local-config-with-circular.yaml +7 -8
- package/src/config/__tests__/fixtures/resolve-config/local-config-with-custom-function.yaml +16 -0
- package/src/config/__tests__/fixtures/resolve-config/local-config-with-file.yaml +18 -19
- package/src/config/__tests__/fixtures/resolve-config/local-config-with-wrong-custom-function.yaml +16 -0
- package/src/config/__tests__/fixtures/resolve-config/local-config.yaml +9 -10
- package/src/config/__tests__/fixtures/resolve-config/plugin.js +11 -0
- package/src/config/__tests__/fixtures/resolve-remote-configs/nested-remote-config.yaml +3 -4
- package/src/config/__tests__/fixtures/resolve-remote-configs/remote-config.yaml +4 -5
- package/src/config/__tests__/load.test.ts +13 -16
- package/src/config/__tests__/resolve-plugins.test.ts +3 -3
- package/src/config/__tests__/utils.test.ts +64 -4
- package/src/config/all.ts +3 -1
- package/src/config/config-resolvers.ts +30 -7
- package/src/config/config.ts +2 -0
- package/src/config/load.ts +13 -6
- package/src/config/minimal.ts +3 -1
- package/src/config/recommended.ts +3 -1
- package/src/config/rules.ts +2 -2
- package/src/config/types.ts +24 -0
- package/src/config/utils.ts +103 -13
- package/src/decorators/common/registry-dependencies.ts +1 -1
- package/src/format/format.ts +32 -2
- package/src/lint.ts +2 -2
- package/src/redocly/registry-api.ts +5 -4
- package/src/resolve.ts +3 -1
- package/src/rules/__tests__/utils.test.ts +1 -1
- package/src/rules/ajv.ts +4 -4
- package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +1 -0
- package/src/rules/common/__tests__/operation-2xx-response.test.ts +1 -1
- package/src/rules/common/__tests__/operation-4xx-response.test.ts +26 -3
- package/src/rules/common/__tests__/security-defined.test.ts +175 -0
- package/src/rules/common/__tests__/spec.test.ts +79 -0
- package/src/rules/common/assertions/__tests__/asserts.test.ts +491 -428
- package/src/rules/common/assertions/__tests__/utils.test.ts +2 -2
- package/src/rules/common/assertions/asserts.ts +155 -97
- package/src/rules/common/assertions/index.ts +2 -11
- package/src/rules/common/assertions/utils.ts +66 -36
- package/src/rules/common/no-ambiguous-paths.ts +1 -1
- package/src/rules/common/no-identical-paths.ts +1 -1
- package/src/rules/common/operation-2xx-response.ts +1 -1
- package/src/rules/common/operation-4xx-response.ts +1 -1
- package/src/rules/common/operation-operationId.ts +1 -1
- package/src/rules/common/operation-tag-defined.ts +1 -1
- package/src/rules/common/path-not-include-query.ts +1 -1
- package/src/rules/common/{operation-security-defined.ts → security-defined.ts} +19 -4
- package/src/rules/common/spec.ts +15 -1
- package/src/rules/common/tags-alphabetical.ts +1 -1
- package/src/rules/oas2/index.ts +2 -2
- package/src/rules/oas2/remove-unused-components.ts +1 -1
- package/src/rules/oas2/request-mime-type.ts +1 -1
- package/src/rules/oas2/response-mime-type.ts +1 -1
- package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +51 -2
- package/src/rules/oas3/__tests__/operation-4xx-problem-details-rfc7807.test.ts +145 -0
- package/src/rules/oas3/__tests__/spec/spec.test.ts +10 -0
- package/src/rules/oas3/__tests__/spec-components-invalid-map-name.test.ts +217 -0
- package/src/rules/oas3/index.ts +6 -2
- package/src/rules/oas3/no-empty-servers.ts +1 -1
- package/src/rules/oas3/no-server-variables-empty-enum.ts +1 -1
- package/src/rules/oas3/no-unused-components.ts +1 -1
- package/src/rules/oas3/operation-4xx-problem-details-rfc7807.ts +36 -0
- package/src/rules/oas3/remove-unused-components.ts +1 -1
- package/src/rules/oas3/request-mime-type.ts +1 -1
- package/src/rules/oas3/response-mime-type.ts +1 -1
- package/src/rules/oas3/spec-components-invalid-map-name.ts +53 -0
- package/src/rules/other/stats.ts +2 -2
- package/src/rules/utils.ts +2 -1
- package/src/types/index.ts +2 -2
- package/src/types/oas2.ts +5 -5
- package/src/types/oas3.ts +27 -20
- package/src/types/oas3_1.ts +3 -3
- package/src/types/redocly-yaml.ts +66 -38
- package/src/utils.ts +11 -7
- package/src/visitors.ts +29 -13
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/rules/common/operation-security-defined.d.ts +0 -2
- package/src/rules/common/__tests__/operation-security-defined.test.ts +0 -69
|
@@ -12,16 +12,16 @@ describe('lint', () => {
|
|
|
12
12
|
const results = await lintFromString({
|
|
13
13
|
absoluteRef: '/test/spec.yaml',
|
|
14
14
|
source: outdent`
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
openapi: 3.0.0
|
|
16
|
+
info:
|
|
17
|
+
title: Test API
|
|
18
|
+
version: "1.0"
|
|
19
|
+
description: Test
|
|
20
|
+
license: Fail
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
servers:
|
|
23
|
+
- url: http://example.com
|
|
24
|
+
paths: {}
|
|
25
25
|
`,
|
|
26
26
|
config: await loadConfig(),
|
|
27
27
|
});
|
|
@@ -29,6 +29,7 @@ describe('lint', () => {
|
|
|
29
29
|
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
|
|
30
30
|
Array [
|
|
31
31
|
Object {
|
|
32
|
+
"from": undefined,
|
|
32
33
|
"location": Array [
|
|
33
34
|
Object {
|
|
34
35
|
"pointer": "#/info/license",
|
|
@@ -48,8 +49,7 @@ describe('lint', () => {
|
|
|
48
49
|
it('lintConfig should work', async () => {
|
|
49
50
|
const document = parseYamlToDocument(
|
|
50
51
|
outdent`
|
|
51
|
-
|
|
52
|
-
styleguide:
|
|
52
|
+
apis: error string
|
|
53
53
|
plugins:
|
|
54
54
|
- './local-plugin.js'
|
|
55
55
|
extends:
|
|
@@ -60,6 +60,12 @@ describe('lint', () => {
|
|
|
60
60
|
no-invalid-media-type-examples: error
|
|
61
61
|
path-http-verbs-order: error
|
|
62
62
|
boolean-parameter-prefixes: off
|
|
63
|
+
assert/operation-summary-length:
|
|
64
|
+
subject: Operation
|
|
65
|
+
property: summary
|
|
66
|
+
message: Operation summary should start with an active verb
|
|
67
|
+
local/checkWordsCount:
|
|
68
|
+
min: 3
|
|
63
69
|
features.openapi:
|
|
64
70
|
showConsole: true
|
|
65
71
|
layout:
|
|
@@ -70,6 +76,16 @@ describe('lint', () => {
|
|
|
70
76
|
backgroundColor: '#263238'
|
|
71
77
|
links:
|
|
72
78
|
color: '#6CC496'
|
|
79
|
+
features.openapi:
|
|
80
|
+
showConsole: true
|
|
81
|
+
layout:
|
|
82
|
+
scope: section
|
|
83
|
+
routingStrategy: browser
|
|
84
|
+
theme:
|
|
85
|
+
rightPanel:
|
|
86
|
+
backgroundColor: '#263238'
|
|
87
|
+
links:
|
|
88
|
+
color: '#6CC496'
|
|
73
89
|
`,
|
|
74
90
|
''
|
|
75
91
|
);
|
|
@@ -78,6 +94,79 @@ describe('lint', () => {
|
|
|
78
94
|
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
|
|
79
95
|
Array [
|
|
80
96
|
Object {
|
|
97
|
+
"from": undefined,
|
|
98
|
+
"location": Array [
|
|
99
|
+
Object {
|
|
100
|
+
"pointer": "#/atures.openapi",
|
|
101
|
+
"reportOnKey": true,
|
|
102
|
+
"source": "",
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
"message": "Property \`atures.openapi\` is not expected here.",
|
|
106
|
+
"ruleId": "configuration spec",
|
|
107
|
+
"severity": "error",
|
|
108
|
+
"suggest": Array [
|
|
109
|
+
"features.openapi",
|
|
110
|
+
],
|
|
111
|
+
},
|
|
112
|
+
Object {
|
|
113
|
+
"from": undefined,
|
|
114
|
+
"location": Array [
|
|
115
|
+
Object {
|
|
116
|
+
"pointer": "#/showConsole",
|
|
117
|
+
"reportOnKey": true,
|
|
118
|
+
"source": "",
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
"message": "Property \`showConsole\` is not expected here.",
|
|
122
|
+
"ruleId": "configuration spec",
|
|
123
|
+
"severity": "error",
|
|
124
|
+
"suggest": Array [],
|
|
125
|
+
},
|
|
126
|
+
Object {
|
|
127
|
+
"from": undefined,
|
|
128
|
+
"location": Array [
|
|
129
|
+
Object {
|
|
130
|
+
"pointer": "#/layout",
|
|
131
|
+
"reportOnKey": true,
|
|
132
|
+
"source": "",
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
"message": "Property \`layout\` is not expected here.",
|
|
136
|
+
"ruleId": "configuration spec",
|
|
137
|
+
"severity": "error",
|
|
138
|
+
"suggest": Array [],
|
|
139
|
+
},
|
|
140
|
+
Object {
|
|
141
|
+
"from": undefined,
|
|
142
|
+
"location": Array [
|
|
143
|
+
Object {
|
|
144
|
+
"pointer": "#/routingStrategy",
|
|
145
|
+
"reportOnKey": true,
|
|
146
|
+
"source": "",
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
"message": "Property \`routingStrategy\` is not expected here.",
|
|
150
|
+
"ruleId": "configuration spec",
|
|
151
|
+
"severity": "error",
|
|
152
|
+
"suggest": Array [],
|
|
153
|
+
},
|
|
154
|
+
Object {
|
|
155
|
+
"from": undefined,
|
|
156
|
+
"location": Array [
|
|
157
|
+
Object {
|
|
158
|
+
"pointer": "#/theme",
|
|
159
|
+
"reportOnKey": true,
|
|
160
|
+
"source": "",
|
|
161
|
+
},
|
|
162
|
+
],
|
|
163
|
+
"message": "Property \`theme\` is not expected here.",
|
|
164
|
+
"ruleId": "configuration spec",
|
|
165
|
+
"severity": "error",
|
|
166
|
+
"suggest": Array [],
|
|
167
|
+
},
|
|
168
|
+
Object {
|
|
169
|
+
"from": undefined,
|
|
81
170
|
"location": Array [
|
|
82
171
|
Object {
|
|
83
172
|
"pointer": "#/apis",
|
|
@@ -91,6 +180,7 @@ describe('lint', () => {
|
|
|
91
180
|
"suggest": Array [],
|
|
92
181
|
},
|
|
93
182
|
Object {
|
|
183
|
+
"from": undefined,
|
|
94
184
|
"location": Array [
|
|
95
185
|
Object {
|
|
96
186
|
"pointer": "#/features.openapi/layout",
|
|
@@ -110,10 +200,9 @@ describe('lint', () => {
|
|
|
110
200
|
it('lintConfig should detect wrong fields and suggest correct ones', async () => {
|
|
111
201
|
const document = parseYamlToDocument(
|
|
112
202
|
outdent`
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
syleguide:
|
|
203
|
+
api:
|
|
204
|
+
name@version:
|
|
205
|
+
root: ./file.yaml
|
|
117
206
|
rules:
|
|
118
207
|
operation-2xx-response: warn
|
|
119
208
|
`,
|
|
@@ -124,6 +213,7 @@ describe('lint', () => {
|
|
|
124
213
|
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
|
|
125
214
|
Array [
|
|
126
215
|
Object {
|
|
216
|
+
"from": undefined,
|
|
127
217
|
"location": Array [
|
|
128
218
|
Object {
|
|
129
219
|
"pointer": "#/api",
|
|
@@ -138,21 +228,6 @@ describe('lint', () => {
|
|
|
138
228
|
"apis",
|
|
139
229
|
],
|
|
140
230
|
},
|
|
141
|
-
Object {
|
|
142
|
-
"location": Array [
|
|
143
|
-
Object {
|
|
144
|
-
"pointer": "#/syleguide",
|
|
145
|
-
"reportOnKey": true,
|
|
146
|
-
"source": "",
|
|
147
|
-
},
|
|
148
|
-
],
|
|
149
|
-
"message": "Property \`syleguide\` is not expected here.",
|
|
150
|
-
"ruleId": "configuration spec",
|
|
151
|
-
"severity": "error",
|
|
152
|
-
"suggest": Array [
|
|
153
|
-
"styleguide",
|
|
154
|
-
],
|
|
155
|
-
},
|
|
156
231
|
]
|
|
157
232
|
`);
|
|
158
233
|
});
|
|
@@ -160,13 +235,13 @@ describe('lint', () => {
|
|
|
160
235
|
it('lintConfig should work with legacy fields', async () => {
|
|
161
236
|
const document = parseYamlToDocument(
|
|
162
237
|
outdent`
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
238
|
+
apis:
|
|
239
|
+
entry:
|
|
240
|
+
root: ./file.yaml
|
|
166
241
|
rules:
|
|
167
242
|
operation-2xx-response: warn
|
|
168
|
-
|
|
169
|
-
|
|
243
|
+
referenceDocs:
|
|
244
|
+
showConsole: true
|
|
170
245
|
`,
|
|
171
246
|
''
|
|
172
247
|
);
|
|
@@ -175,16 +250,16 @@ describe('lint', () => {
|
|
|
175
250
|
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
|
|
176
251
|
});
|
|
177
252
|
|
|
178
|
-
it("'plugins' shouldn't be allowed in 'apis'
|
|
253
|
+
it("'plugins' shouldn't be allowed in 'apis'", async () => {
|
|
179
254
|
const document = parseYamlToDocument(
|
|
180
255
|
outdent`
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
256
|
+
apis:
|
|
257
|
+
main:
|
|
258
|
+
root: ./main.yaml
|
|
259
|
+
plugins:
|
|
184
260
|
- './local-plugin.js'
|
|
185
|
-
styleguide:
|
|
186
261
|
plugins:
|
|
187
|
-
|
|
262
|
+
- './local-plugin.js'
|
|
188
263
|
`,
|
|
189
264
|
''
|
|
190
265
|
);
|
|
@@ -193,22 +268,10 @@ describe('lint', () => {
|
|
|
193
268
|
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
|
|
194
269
|
Array [
|
|
195
270
|
Object {
|
|
271
|
+
"from": undefined,
|
|
196
272
|
"location": Array [
|
|
197
273
|
Object {
|
|
198
|
-
"pointer": "#/apis/
|
|
199
|
-
"reportOnKey": true,
|
|
200
|
-
"source": "",
|
|
201
|
-
},
|
|
202
|
-
],
|
|
203
|
-
"message": "The field \`root\` must be present on this level.",
|
|
204
|
-
"ruleId": "configuration spec",
|
|
205
|
-
"severity": "error",
|
|
206
|
-
"suggest": Array [],
|
|
207
|
-
},
|
|
208
|
-
Object {
|
|
209
|
-
"location": Array [
|
|
210
|
-
Object {
|
|
211
|
-
"pointer": "#/apis/styleguide/plugins",
|
|
274
|
+
"pointer": "#/apis/main/plugins",
|
|
212
275
|
"reportOnKey": true,
|
|
213
276
|
"source": "",
|
|
214
277
|
},
|
|
@@ -225,31 +288,31 @@ describe('lint', () => {
|
|
|
225
288
|
it("'const' can have any type", async () => {
|
|
226
289
|
const document = parseYamlToDocument(
|
|
227
290
|
outdent`
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
291
|
+
openapi: "3.1.0"
|
|
292
|
+
info:
|
|
293
|
+
version: 1.0.0
|
|
294
|
+
title: Swagger Petstore
|
|
295
|
+
description: Information about Petstore
|
|
296
|
+
license:
|
|
297
|
+
name: MIT
|
|
298
|
+
url: https://opensource.org/licenses/MIT
|
|
299
|
+
servers:
|
|
300
|
+
- url: http://petstore.swagger.io/v1
|
|
301
|
+
paths:
|
|
302
|
+
/pets:
|
|
303
|
+
get:
|
|
304
|
+
summary: List all pets
|
|
305
|
+
operationId: listPets
|
|
306
|
+
tags:
|
|
307
|
+
- pets
|
|
308
|
+
responses:
|
|
309
|
+
200:
|
|
310
|
+
description: An paged array of pets
|
|
311
|
+
content:
|
|
312
|
+
application/json:
|
|
313
|
+
schema:
|
|
314
|
+
type: string
|
|
315
|
+
const: ABC
|
|
253
316
|
`,
|
|
254
317
|
'foobar.yaml'
|
|
255
318
|
);
|
|
@@ -266,8 +329,8 @@ describe('lint', () => {
|
|
|
266
329
|
it('detect OpenAPI should throw an error when version is not string', () => {
|
|
267
330
|
const testDocument = parseYamlToDocument(
|
|
268
331
|
outdent`
|
|
269
|
-
|
|
270
|
-
|
|
332
|
+
openapi: 3.0
|
|
333
|
+
`,
|
|
271
334
|
''
|
|
272
335
|
);
|
|
273
336
|
expect(() => detectOpenAPI(testDocument.parsed)).toThrow(
|
|
@@ -278,28 +341,28 @@ describe('lint', () => {
|
|
|
278
341
|
it("spec rule shouldn't throw an error for named callback", async () => {
|
|
279
342
|
const document = parseYamlToDocument(
|
|
280
343
|
outdent`
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
344
|
+
openapi: 3.1.0
|
|
345
|
+
info:
|
|
346
|
+
title: Callback test
|
|
347
|
+
version: 'alpha'
|
|
348
|
+
components:
|
|
349
|
+
callbacks:
|
|
350
|
+
resultCallback:
|
|
351
|
+
'{$url}':
|
|
352
|
+
post:
|
|
353
|
+
requestBody:
|
|
354
|
+
description: Callback payload
|
|
355
|
+
content:
|
|
356
|
+
'application/json':
|
|
357
|
+
schema:
|
|
358
|
+
type: object
|
|
359
|
+
properties:
|
|
360
|
+
test:
|
|
361
|
+
type: string
|
|
362
|
+
responses:
|
|
363
|
+
'200':
|
|
364
|
+
description: callback successfully processed
|
|
365
|
+
`,
|
|
303
366
|
'foobar.yaml'
|
|
304
367
|
);
|
|
305
368
|
|
|
@@ -316,23 +379,23 @@ describe('lint', () => {
|
|
|
316
379
|
const absoluteRef = path.join(__dirname, 'fixtures/openapi.yaml');
|
|
317
380
|
const document = parseYamlToDocument(
|
|
318
381
|
outdent`
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
382
|
+
openapi: 3.0.0
|
|
383
|
+
info:
|
|
384
|
+
version: 1.0.0
|
|
385
|
+
title: Example OpenAPI 3 definition.
|
|
386
|
+
description: Information about API
|
|
387
|
+
license:
|
|
388
|
+
name: MIT
|
|
389
|
+
url: 'https://opensource.org/licenses/MIT'
|
|
390
|
+
servers:
|
|
391
|
+
- url: 'https://redocly.com/v1'
|
|
392
|
+
paths:
|
|
393
|
+
'/pets/{petId}':
|
|
394
|
+
post:
|
|
395
|
+
responses:
|
|
396
|
+
'201':
|
|
397
|
+
summary: Exist
|
|
398
|
+
description: example description
|
|
336
399
|
`,
|
|
337
400
|
absoluteRef
|
|
338
401
|
);
|
|
@@ -24,7 +24,7 @@ describe('collect refs', () => {
|
|
|
24
24
|
const resolvedRefs = await resolveDocument({
|
|
25
25
|
rootDocument,
|
|
26
26
|
externalRefResolver: new BaseResolver(),
|
|
27
|
-
rootType: normalizeTypes(Oas3Types).
|
|
27
|
+
rootType: normalizeTypes(Oas3Types).Root,
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
expect(resolvedRefs).toBeDefined();
|
|
@@ -63,7 +63,7 @@ describe('collect refs', () => {
|
|
|
63
63
|
await resolveDocument({
|
|
64
64
|
rootDocument,
|
|
65
65
|
externalRefResolver: new BaseResolver(),
|
|
66
|
-
rootType: normalizeTypes(Oas3Types).
|
|
66
|
+
rootType: normalizeTypes(Oas3Types).Root,
|
|
67
67
|
});
|
|
68
68
|
} catch (e) {
|
|
69
69
|
expect(e.message).toEqual('Self-referencing circular pointer');
|
|
@@ -95,7 +95,7 @@ describe('collect refs', () => {
|
|
|
95
95
|
const resolvedRefs = await resolveDocument({
|
|
96
96
|
rootDocument,
|
|
97
97
|
externalRefResolver: new BaseResolver(),
|
|
98
|
-
rootType: normalizeTypes(Oas3Types).
|
|
98
|
+
rootType: normalizeTypes(Oas3Types).Root,
|
|
99
99
|
});
|
|
100
100
|
|
|
101
101
|
expect(resolvedRefs).toBeDefined();
|
|
@@ -132,7 +132,7 @@ describe('collect refs', () => {
|
|
|
132
132
|
await resolveDocument({
|
|
133
133
|
rootDocument,
|
|
134
134
|
externalRefResolver: new BaseResolver(),
|
|
135
|
-
rootType: normalizeTypes(Oas3Types).
|
|
135
|
+
rootType: normalizeTypes(Oas3Types).Root,
|
|
136
136
|
});
|
|
137
137
|
} catch (e) {
|
|
138
138
|
expect(e.message).toEqual('Self-referencing circular pointer');
|
|
@@ -153,7 +153,7 @@ describe('collect refs', () => {
|
|
|
153
153
|
const resolvedRefs = await resolveDocument({
|
|
154
154
|
rootDocument,
|
|
155
155
|
externalRefResolver: new BaseResolver(),
|
|
156
|
-
rootType: normalizeTypes(Oas3Types).
|
|
156
|
+
rootType: normalizeTypes(Oas3Types).Root,
|
|
157
157
|
});
|
|
158
158
|
|
|
159
159
|
expect(resolvedRefs).toBeDefined();
|
|
@@ -187,7 +187,7 @@ describe('collect refs', () => {
|
|
|
187
187
|
const resolvedRefs = await resolveDocument({
|
|
188
188
|
rootDocument: rootDocument as Document,
|
|
189
189
|
externalRefResolver: externalRefResolver,
|
|
190
|
-
rootType: normalizeTypes(Oas3Types).
|
|
190
|
+
rootType: normalizeTypes(Oas3Types).Root,
|
|
191
191
|
});
|
|
192
192
|
|
|
193
193
|
expect(resolvedRefs).toBeDefined();
|
|
@@ -263,7 +263,7 @@ describe('collect refs', () => {
|
|
|
263
263
|
const resolvedRefs = await resolveDocument({
|
|
264
264
|
rootDocument: rootDocument as Document,
|
|
265
265
|
externalRefResolver: externalRefResolver,
|
|
266
|
-
rootType: normalizeTypes(Oas3Types).
|
|
266
|
+
rootType: normalizeTypes(Oas3Types).Root,
|
|
267
267
|
});
|
|
268
268
|
|
|
269
269
|
expect(resolvedRefs).toBeDefined();
|
|
@@ -358,7 +358,7 @@ describe('collect refs', () => {
|
|
|
358
358
|
const resolvedRefs = await resolveDocument({
|
|
359
359
|
rootDocument: rootDocument as Document,
|
|
360
360
|
externalRefResolver: externalRefResolver,
|
|
361
|
-
rootType: normalizeTypes(Oas3Types).
|
|
361
|
+
rootType: normalizeTypes(Oas3Types).Root,
|
|
362
362
|
});
|
|
363
363
|
|
|
364
364
|
expect(resolvedRefs).toBeDefined();
|
|
@@ -392,7 +392,7 @@ describe('collect refs', () => {
|
|
|
392
392
|
const resolvedRefs = await resolveDocument({
|
|
393
393
|
rootDocument,
|
|
394
394
|
externalRefResolver: new BaseResolver(),
|
|
395
|
-
rootType: normalizeTypes(Oas3Types).
|
|
395
|
+
rootType: normalizeTypes(Oas3Types).Root,
|
|
396
396
|
});
|
|
397
397
|
|
|
398
398
|
expect(resolvedRefs).toBeDefined();
|
|
@@ -16,7 +16,7 @@ import { Oas3RuleSet } from '../oas-types';
|
|
|
16
16
|
describe('walk order', () => {
|
|
17
17
|
it('should run visitors', async () => {
|
|
18
18
|
const visitors = {
|
|
19
|
-
|
|
19
|
+
Root: {
|
|
20
20
|
enter: jest.fn(),
|
|
21
21
|
leave: jest.fn(),
|
|
22
22
|
},
|
|
@@ -63,6 +63,74 @@ describe('walk order', () => {
|
|
|
63
63
|
}
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
+
it('should run legacy visitors', async () => {
|
|
67
|
+
const visitors = {
|
|
68
|
+
DefinitionRoot: {
|
|
69
|
+
enter: jest.fn(),
|
|
70
|
+
leave: jest.fn(),
|
|
71
|
+
},
|
|
72
|
+
PathMap: {
|
|
73
|
+
enter: jest.fn(),
|
|
74
|
+
leave: jest.fn(),
|
|
75
|
+
},
|
|
76
|
+
ServerVariableMap: {
|
|
77
|
+
enter: jest.fn(),
|
|
78
|
+
leave: jest.fn(),
|
|
79
|
+
},
|
|
80
|
+
MediaTypeMap: {
|
|
81
|
+
enter: jest.fn(),
|
|
82
|
+
leave: jest.fn(),
|
|
83
|
+
},
|
|
84
|
+
ExampleMap: {
|
|
85
|
+
enter: jest.fn(),
|
|
86
|
+
leave: jest.fn(),
|
|
87
|
+
},
|
|
88
|
+
HeaderMap: {
|
|
89
|
+
enter: jest.fn(),
|
|
90
|
+
leave: jest.fn(),
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const testRuleSet: Oas3RuleSet = {
|
|
95
|
+
test: jest.fn(() => {
|
|
96
|
+
return visitors;
|
|
97
|
+
}),
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const document = parseYamlToDocument(
|
|
101
|
+
outdent`
|
|
102
|
+
openapi: 3.0.0
|
|
103
|
+
servers:
|
|
104
|
+
- url: http://{test}.url
|
|
105
|
+
variables:
|
|
106
|
+
test: test
|
|
107
|
+
paths:
|
|
108
|
+
/test-path:
|
|
109
|
+
get:
|
|
110
|
+
responses:
|
|
111
|
+
200:
|
|
112
|
+
headers: {}
|
|
113
|
+
content:
|
|
114
|
+
application/json:
|
|
115
|
+
schema: {}
|
|
116
|
+
examples: {}
|
|
117
|
+
`,
|
|
118
|
+
''
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
await lintDocument({
|
|
122
|
+
externalRefResolver: new BaseResolver(),
|
|
123
|
+
document,
|
|
124
|
+
config: makeConfigForRuleset(testRuleSet),
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
expect(testRuleSet.test).toBeCalledTimes(1);
|
|
128
|
+
for (const fns of Object.values(visitors)) {
|
|
129
|
+
expect(fns.enter).toBeCalled();
|
|
130
|
+
expect(fns.leave).toBeCalled();
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
|
|
66
134
|
it('should run nested visitors correctly', async () => {
|
|
67
135
|
const calls: string[] = [];
|
|
68
136
|
|
|
@@ -1046,8 +1114,8 @@ describe('walk order', () => {
|
|
|
1046
1114
|
|
|
1047
1115
|
expect(calls).toMatchInlineSnapshot(`
|
|
1048
1116
|
Array [
|
|
1049
|
-
"enter
|
|
1050
|
-
"enter
|
|
1117
|
+
"enter Root",
|
|
1118
|
+
"enter PathsMap",
|
|
1051
1119
|
"enter PathItem",
|
|
1052
1120
|
"enter ParameterList",
|
|
1053
1121
|
"enter Parameter",
|
|
@@ -1066,7 +1134,7 @@ describe('walk order', () => {
|
|
|
1066
1134
|
"leave ParameterList",
|
|
1067
1135
|
"leave Operation",
|
|
1068
1136
|
"leave PathItem",
|
|
1069
|
-
"leave
|
|
1137
|
+
"leave PathsMap",
|
|
1070
1138
|
"enter Components",
|
|
1071
1139
|
"enter NamedParameters",
|
|
1072
1140
|
"leave NamedParameters",
|
|
@@ -1075,7 +1143,7 @@ describe('walk order', () => {
|
|
|
1075
1143
|
"leave Schema",
|
|
1076
1144
|
"leave NamedSchemas",
|
|
1077
1145
|
"leave Components",
|
|
1078
|
-
"leave
|
|
1146
|
+
"leave Root",
|
|
1079
1147
|
]
|
|
1080
1148
|
`);
|
|
1081
1149
|
});
|
|
@@ -1378,10 +1446,10 @@ describe('type extensions', () => {
|
|
|
1378
1446
|
parameters: listOf('Parameter'),
|
|
1379
1447
|
},
|
|
1380
1448
|
},
|
|
1381
|
-
|
|
1382
|
-
...types.
|
|
1449
|
+
Root: {
|
|
1450
|
+
...types.Root,
|
|
1383
1451
|
properties: {
|
|
1384
|
-
...types.
|
|
1452
|
+
...types.Root.properties,
|
|
1385
1453
|
'x-webhooks': 'XWebHooks',
|
|
1386
1454
|
},
|
|
1387
1455
|
},
|
|
@@ -1393,7 +1461,7 @@ describe('type extensions', () => {
|
|
|
1393
1461
|
|
|
1394
1462
|
expect(calls).toMatchInlineSnapshot(`
|
|
1395
1463
|
Array [
|
|
1396
|
-
"enter
|
|
1464
|
+
"enter Root",
|
|
1397
1465
|
"enter XWebHooks",
|
|
1398
1466
|
"enter hook test",
|
|
1399
1467
|
"enter ParameterList",
|
|
@@ -1402,7 +1470,7 @@ describe('type extensions', () => {
|
|
|
1402
1470
|
"leave ParameterList",
|
|
1403
1471
|
"leave hook test",
|
|
1404
1472
|
"leave XWebHooks",
|
|
1405
|
-
"leave
|
|
1473
|
+
"leave Root",
|
|
1406
1474
|
]
|
|
1407
1475
|
`);
|
|
1408
1476
|
});
|