@redocly/openapi-core 1.0.0-beta.106 → 1.0.0-beta.109
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/benchmark/benches/lint-with-top-level-rule-report.bench.js +0 -1
- package/lib/benchmark/benches/resolve-with-no-external.bench.js +1 -1
- package/lib/bundle.d.ts +1 -1
- package/lib/bundle.js +9 -6
- package/lib/config/all.js +5 -3
- package/lib/config/config-resolvers.js +32 -14
- package/lib/config/config.d.ts +3 -5
- package/lib/config/config.js +7 -4
- package/lib/config/load.d.ts +7 -0
- package/lib/config/load.js +14 -6
- package/lib/config/minimal.js +7 -4
- package/lib/config/recommended.js +7 -4
- package/lib/config/rules.d.ts +1 -1
- package/lib/config/rules.js +1 -1
- package/lib/config/types.d.ts +7 -0
- package/lib/config/utils.d.ts +2 -2
- package/lib/config/utils.js +49 -11
- package/lib/decorators/common/registry-dependencies.js +2 -2
- package/lib/env.d.ts +3 -0
- package/lib/env.js +8 -0
- package/lib/format/codeframes.js +16 -10
- package/lib/format/format.d.ts +1 -1
- package/lib/format/format.js +49 -26
- package/lib/index.d.ts +5 -5
- package/lib/index.js +3 -1
- package/lib/js-yaml/index.js +1 -0
- package/lib/lint.js +2 -2
- package/lib/logger.d.ts +10 -0
- package/lib/logger.js +31 -0
- package/lib/output.d.ts +3 -0
- package/lib/output.js +9 -0
- package/lib/redocly/index.js +10 -9
- package/lib/redocly/registry-api-types.d.ts +28 -30
- package/lib/redocly/registry-api.d.ts +3 -3
- package/lib/redocly/registry-api.js +7 -1
- package/lib/ref-utils.js +2 -1
- package/lib/resolve.d.ts +1 -1
- package/lib/resolve.js +4 -2
- package/lib/rules/ajv.d.ts +1 -1
- package/lib/rules/ajv.js +7 -7
- package/lib/rules/common/assertions/asserts.js +4 -4
- package/lib/rules/common/assertions/index.js +1 -1
- package/lib/rules/common/no-ambiguous-paths.js +1 -1
- package/lib/rules/common/no-identical-paths.js +1 -1
- package/lib/rules/common/no-invalid-parameter-examples.js +3 -3
- package/lib/rules/common/no-invalid-schema-examples.js +3 -3
- 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} +19 -5
- package/lib/rules/common/spec.js +14 -3
- 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 +3 -3
- 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 +8 -4
- package/lib/rules/oas3/no-empty-servers.js +1 -1
- package/lib/rules/oas3/no-invalid-media-type-examples.js +2 -2
- package/lib/rules/oas3/no-server-variables-empty-enum.d.ts +2 -0
- package/lib/rules/oas3/{no-servers-empty-enum.js → no-server-variables-empty-enum.js} +5 -5
- package/lib/rules/oas3/no-unused-components.js +2 -2
- 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 +4 -4
- 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.d.ts +3 -2
- package/lib/rules/utils.js +16 -4
- 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 +47 -56
- package/lib/utils.d.ts +6 -1
- package/lib/utils.js +24 -7
- package/lib/visitors.d.ts +12 -12
- package/lib/visitors.js +15 -3
- package/lib/walk.d.ts +2 -1
- package/lib/walk.js +6 -3
- package/package.json +2 -2
- 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 +106 -131
- package/src/__tests__/logger-browser.test.ts +53 -0
- package/src/__tests__/logger.test.ts +47 -0
- package/src/__tests__/output-browser.test.ts +18 -0
- package/src/__tests__/output.test.ts +15 -0
- package/src/__tests__/resolve-http.test.ts +1 -1
- package/src/__tests__/resolve.test.ts +9 -9
- package/src/__tests__/utils-browser.test.ts +11 -0
- package/src/__tests__/utils.test.ts +7 -0
- package/src/__tests__/walk.test.ts +78 -10
- package/src/benchmark/benches/lint-with-top-level-rule-report.bench.ts +0 -1
- package/src/benchmark/benches/resolve-with-no-external.bench.ts +1 -1
- package/src/bundle.ts +10 -7
- package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +12 -6
- package/src/config/__tests__/config.test.ts +35 -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-file.yaml +18 -19
- package/src/config/__tests__/fixtures/resolve-config/local-config.yaml +9 -10
- 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 +76 -1
- package/src/config/__tests__/utils.test.ts +64 -4
- package/src/config/all.ts +5 -3
- package/src/config/config-resolvers.ts +45 -19
- package/src/config/config.ts +10 -8
- package/src/config/load.ts +31 -7
- package/src/config/minimal.ts +7 -4
- package/src/config/recommended.ts +7 -4
- package/src/config/rules.ts +2 -2
- package/src/config/types.ts +11 -0
- package/src/config/utils.ts +115 -25
- package/src/decorators/common/registry-dependencies.ts +2 -2
- package/src/env.ts +5 -0
- package/src/format/codeframes.ts +15 -9
- package/src/format/format.ts +59 -34
- package/src/index.ts +6 -4
- package/src/js-yaml/index.ts +1 -0
- package/src/lint.ts +2 -2
- package/src/logger.ts +34 -0
- package/src/output.ts +7 -0
- package/src/redocly/index.ts +7 -4
- package/src/redocly/registry-api-types.ts +27 -29
- package/src/redocly/registry-api.ts +18 -7
- package/src/ref-utils.ts +2 -1
- package/src/resolve.ts +7 -5
- package/src/rules/__tests__/utils.test.ts +39 -1
- package/src/rules/ajv.ts +7 -7
- 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__/utils.test.ts +2 -2
- package/src/rules/common/assertions/asserts.ts +4 -4
- package/src/rules/common/assertions/index.ts +1 -1
- package/src/rules/common/no-ambiguous-paths.ts +1 -1
- package/src/rules/common/no-identical-paths.ts +1 -1
- package/src/rules/common/no-invalid-parameter-examples.ts +4 -4
- package/src/rules/common/no-invalid-schema-examples.ts +4 -4
- 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} +20 -5
- package/src/rules/common/spec.ts +17 -3
- 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 +3 -3
- 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-empty-enum-servers.com.test.ts +16 -16
- package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +5 -5
- 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 +8 -4
- package/src/rules/oas3/no-empty-servers.ts +1 -1
- package/src/rules/oas3/no-invalid-media-type-examples.ts +3 -3
- package/src/rules/oas3/{no-servers-empty-enum.ts → no-server-variables-empty-enum.ts} +3 -3
- package/src/rules/oas3/no-unused-components.ts +2 -2
- package/src/rules/oas3/operation-4xx-problem-details-rfc7807.ts +36 -0
- package/src/rules/oas3/remove-unused-components.ts +5 -5
- 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 +17 -3
- 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 +53 -41
- package/src/utils.ts +31 -4
- package/src/visitors.ts +34 -18
- package/src/walk.ts +15 -11
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/rules/common/operation-security-defined.d.ts +0 -2
- package/lib/rules/oas3/no-servers-empty-enum.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,16 +60,16 @@ describe('lint', () => {
|
|
|
60
60
|
no-invalid-media-type-examples: error
|
|
61
61
|
path-http-verbs-order: error
|
|
62
62
|
boolean-parameter-prefixes: off
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
63
|
+
features.openapi:
|
|
64
|
+
showConsole: true
|
|
65
|
+
layout:
|
|
66
|
+
scope: section
|
|
67
|
+
routingStrategy: browser
|
|
68
|
+
theme:
|
|
69
|
+
rightPanel:
|
|
70
|
+
backgroundColor: '#263238'
|
|
71
|
+
links:
|
|
72
|
+
color: '#6CC496'
|
|
73
73
|
`,
|
|
74
74
|
''
|
|
75
75
|
);
|
|
@@ -78,6 +78,7 @@ describe('lint', () => {
|
|
|
78
78
|
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
|
|
79
79
|
Array [
|
|
80
80
|
Object {
|
|
81
|
+
"from": undefined,
|
|
81
82
|
"location": Array [
|
|
82
83
|
Object {
|
|
83
84
|
"pointer": "#/apis",
|
|
@@ -91,6 +92,7 @@ describe('lint', () => {
|
|
|
91
92
|
"suggest": Array [],
|
|
92
93
|
},
|
|
93
94
|
Object {
|
|
95
|
+
"from": undefined,
|
|
94
96
|
"location": Array [
|
|
95
97
|
Object {
|
|
96
98
|
"pointer": "#/features.openapi/layout",
|
|
@@ -110,10 +112,9 @@ describe('lint', () => {
|
|
|
110
112
|
it('lintConfig should detect wrong fields and suggest correct ones', async () => {
|
|
111
113
|
const document = parseYamlToDocument(
|
|
112
114
|
outdent`
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
syleguide:
|
|
115
|
+
api:
|
|
116
|
+
name@version:
|
|
117
|
+
root: ./file.yaml
|
|
117
118
|
rules:
|
|
118
119
|
operation-2xx-response: warn
|
|
119
120
|
`,
|
|
@@ -124,6 +125,7 @@ describe('lint', () => {
|
|
|
124
125
|
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
|
|
125
126
|
Array [
|
|
126
127
|
Object {
|
|
128
|
+
"from": undefined,
|
|
127
129
|
"location": Array [
|
|
128
130
|
Object {
|
|
129
131
|
"pointer": "#/api",
|
|
@@ -138,21 +140,6 @@ describe('lint', () => {
|
|
|
138
140
|
"apis",
|
|
139
141
|
],
|
|
140
142
|
},
|
|
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
143
|
]
|
|
157
144
|
`);
|
|
158
145
|
});
|
|
@@ -160,13 +147,13 @@ describe('lint', () => {
|
|
|
160
147
|
it('lintConfig should work with legacy fields', async () => {
|
|
161
148
|
const document = parseYamlToDocument(
|
|
162
149
|
outdent`
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
150
|
+
apis:
|
|
151
|
+
entry:
|
|
152
|
+
root: ./file.yaml
|
|
166
153
|
rules:
|
|
167
154
|
operation-2xx-response: warn
|
|
168
|
-
|
|
169
|
-
|
|
155
|
+
referenceDocs:
|
|
156
|
+
showConsole: true
|
|
170
157
|
`,
|
|
171
158
|
''
|
|
172
159
|
);
|
|
@@ -175,16 +162,16 @@ describe('lint', () => {
|
|
|
175
162
|
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
|
|
176
163
|
});
|
|
177
164
|
|
|
178
|
-
it("'plugins' shouldn't be allowed in 'apis'
|
|
165
|
+
it("'plugins' shouldn't be allowed in 'apis'", async () => {
|
|
179
166
|
const document = parseYamlToDocument(
|
|
180
167
|
outdent`
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
168
|
+
apis:
|
|
169
|
+
main:
|
|
170
|
+
root: ./main.yaml
|
|
171
|
+
plugins:
|
|
184
172
|
- './local-plugin.js'
|
|
185
|
-
styleguide:
|
|
186
173
|
plugins:
|
|
187
|
-
|
|
174
|
+
- './local-plugin.js'
|
|
188
175
|
`,
|
|
189
176
|
''
|
|
190
177
|
);
|
|
@@ -193,22 +180,10 @@ describe('lint', () => {
|
|
|
193
180
|
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
|
|
194
181
|
Array [
|
|
195
182
|
Object {
|
|
183
|
+
"from": undefined,
|
|
196
184
|
"location": Array [
|
|
197
185
|
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",
|
|
186
|
+
"pointer": "#/apis/main/plugins",
|
|
212
187
|
"reportOnKey": true,
|
|
213
188
|
"source": "",
|
|
214
189
|
},
|
|
@@ -225,31 +200,31 @@ describe('lint', () => {
|
|
|
225
200
|
it("'const' can have any type", async () => {
|
|
226
201
|
const document = parseYamlToDocument(
|
|
227
202
|
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
|
-
|
|
203
|
+
openapi: "3.1.0"
|
|
204
|
+
info:
|
|
205
|
+
version: 1.0.0
|
|
206
|
+
title: Swagger Petstore
|
|
207
|
+
description: Information about Petstore
|
|
208
|
+
license:
|
|
209
|
+
name: MIT
|
|
210
|
+
url: https://opensource.org/licenses/MIT
|
|
211
|
+
servers:
|
|
212
|
+
- url: http://petstore.swagger.io/v1
|
|
213
|
+
paths:
|
|
214
|
+
/pets:
|
|
215
|
+
get:
|
|
216
|
+
summary: List all pets
|
|
217
|
+
operationId: listPets
|
|
218
|
+
tags:
|
|
219
|
+
- pets
|
|
220
|
+
responses:
|
|
221
|
+
200:
|
|
222
|
+
description: An paged array of pets
|
|
223
|
+
content:
|
|
224
|
+
application/json:
|
|
225
|
+
schema:
|
|
226
|
+
type: string
|
|
227
|
+
const: ABC
|
|
253
228
|
`,
|
|
254
229
|
'foobar.yaml'
|
|
255
230
|
);
|
|
@@ -266,8 +241,8 @@ describe('lint', () => {
|
|
|
266
241
|
it('detect OpenAPI should throw an error when version is not string', () => {
|
|
267
242
|
const testDocument = parseYamlToDocument(
|
|
268
243
|
outdent`
|
|
269
|
-
|
|
270
|
-
|
|
244
|
+
openapi: 3.0
|
|
245
|
+
`,
|
|
271
246
|
''
|
|
272
247
|
);
|
|
273
248
|
expect(() => detectOpenAPI(testDocument.parsed)).toThrow(
|
|
@@ -278,28 +253,28 @@ describe('lint', () => {
|
|
|
278
253
|
it("spec rule shouldn't throw an error for named callback", async () => {
|
|
279
254
|
const document = parseYamlToDocument(
|
|
280
255
|
outdent`
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
256
|
+
openapi: 3.1.0
|
|
257
|
+
info:
|
|
258
|
+
title: Callback test
|
|
259
|
+
version: 'alpha'
|
|
260
|
+
components:
|
|
261
|
+
callbacks:
|
|
262
|
+
resultCallback:
|
|
263
|
+
'{$url}':
|
|
264
|
+
post:
|
|
265
|
+
requestBody:
|
|
266
|
+
description: Callback payload
|
|
267
|
+
content:
|
|
268
|
+
'application/json':
|
|
269
|
+
schema:
|
|
270
|
+
type: object
|
|
271
|
+
properties:
|
|
272
|
+
test:
|
|
273
|
+
type: string
|
|
274
|
+
responses:
|
|
275
|
+
'200':
|
|
276
|
+
description: callback successfully processed
|
|
277
|
+
`,
|
|
303
278
|
'foobar.yaml'
|
|
304
279
|
);
|
|
305
280
|
|
|
@@ -316,23 +291,23 @@ describe('lint', () => {
|
|
|
316
291
|
const absoluteRef = path.join(__dirname, 'fixtures/openapi.yaml');
|
|
317
292
|
const document = parseYamlToDocument(
|
|
318
293
|
outdent`
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
294
|
+
openapi: 3.0.0
|
|
295
|
+
info:
|
|
296
|
+
version: 1.0.0
|
|
297
|
+
title: Example OpenAPI 3 definition.
|
|
298
|
+
description: Information about API
|
|
299
|
+
license:
|
|
300
|
+
name: MIT
|
|
301
|
+
url: 'https://opensource.org/licenses/MIT'
|
|
302
|
+
servers:
|
|
303
|
+
- url: 'https://redocly.com/v1'
|
|
304
|
+
paths:
|
|
305
|
+
'/pets/{petId}':
|
|
306
|
+
post:
|
|
307
|
+
responses:
|
|
308
|
+
'201':
|
|
309
|
+
summary: Exist
|
|
310
|
+
description: example description
|
|
336
311
|
`,
|
|
337
312
|
absoluteRef
|
|
338
313
|
);
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as colorette from 'colorette';
|
|
6
|
+
import { logger, colorize } from '../logger';
|
|
7
|
+
|
|
8
|
+
describe('Logger in Browser', () => {
|
|
9
|
+
it('should call "console.error"', () => {
|
|
10
|
+
const error = jest.spyOn(console, 'error').mockImplementation();
|
|
11
|
+
|
|
12
|
+
logger.error('error');
|
|
13
|
+
|
|
14
|
+
expect(error).toBeCalledTimes(1);
|
|
15
|
+
expect(error).toBeCalledWith('error');
|
|
16
|
+
|
|
17
|
+
error.mockRestore();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should call "console.log"', () => {
|
|
21
|
+
const log = jest.spyOn(console, 'log').mockImplementation();
|
|
22
|
+
|
|
23
|
+
logger.info('info');
|
|
24
|
+
|
|
25
|
+
expect(log).toBeCalledTimes(1);
|
|
26
|
+
expect(log).toBeCalledWith('info');
|
|
27
|
+
|
|
28
|
+
log.mockRestore();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('should call "console.warn"', () => {
|
|
32
|
+
const warn = jest.spyOn(console, 'warn').mockImplementation();
|
|
33
|
+
|
|
34
|
+
logger.warn('warn');
|
|
35
|
+
|
|
36
|
+
expect(warn).toBeCalledTimes(1);
|
|
37
|
+
expect(warn).toBeCalledWith('warn');
|
|
38
|
+
|
|
39
|
+
warn.mockRestore();
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('colorize in Browser', () => {
|
|
44
|
+
it('should not call original colorette lib', () => {
|
|
45
|
+
const color = 'cyan';
|
|
46
|
+
const spyingCyan = jest.spyOn(colorette, color);
|
|
47
|
+
|
|
48
|
+
const colorized = colorize.cyan(color);
|
|
49
|
+
|
|
50
|
+
expect(spyingCyan).not.toBeCalled();
|
|
51
|
+
expect(colorized).toEqual(color);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as colorette from 'colorette';
|
|
2
|
+
import { logger, colorize } from '../logger';
|
|
3
|
+
|
|
4
|
+
describe('Logger in nodejs', () => {
|
|
5
|
+
let spyingStderr: jest.SpyInstance;
|
|
6
|
+
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
spyingStderr = jest.spyOn(process.stderr, 'write').mockImplementation();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
afterEach(() => {
|
|
12
|
+
spyingStderr.mockRestore();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should call "process.stderr.write" for error severity', () => {
|
|
16
|
+
logger.error('error');
|
|
17
|
+
|
|
18
|
+
expect(spyingStderr).toBeCalledTimes(1);
|
|
19
|
+
expect(spyingStderr).toBeCalledWith(colorette.red('error'));
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('should call "process.stderr.write" for warn severity', () => {
|
|
23
|
+
logger.warn('warn');
|
|
24
|
+
|
|
25
|
+
expect(spyingStderr).toBeCalledTimes(1);
|
|
26
|
+
expect(spyingStderr).toBeCalledWith(colorette.yellow('warn'));
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should call "process.stderr.write" for info severity', () => {
|
|
30
|
+
logger.info('info');
|
|
31
|
+
|
|
32
|
+
expect(spyingStderr).toBeCalledTimes(1);
|
|
33
|
+
expect(spyingStderr).toBeCalledWith('info');
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('colorize in nodejs', () => {
|
|
38
|
+
it('should call original colorette lib', () => {
|
|
39
|
+
const color = 'cyan';
|
|
40
|
+
const spyingCyan = jest.spyOn(colorette, color);
|
|
41
|
+
|
|
42
|
+
const colorized = colorize.cyan(color);
|
|
43
|
+
|
|
44
|
+
expect(spyingCyan).toBeCalledWith(color);
|
|
45
|
+
expect(colorized).toEqual(colorette[color](color));
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { output } from '../output';
|
|
6
|
+
|
|
7
|
+
describe('output', () => {
|
|
8
|
+
it('should ignore all parsable data in browser', () => {
|
|
9
|
+
const spyingStdout = jest.spyOn(process.stdout, 'write').mockImplementation();
|
|
10
|
+
const data = '{ "errors" : [] }';
|
|
11
|
+
|
|
12
|
+
output.write(data);
|
|
13
|
+
|
|
14
|
+
expect(spyingStdout).not.toBeCalled();
|
|
15
|
+
|
|
16
|
+
spyingStdout.mockRestore();
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { output } from '../output';
|
|
2
|
+
|
|
3
|
+
describe('output', () => {
|
|
4
|
+
it('should write all parsable data to stdout', () => {
|
|
5
|
+
const spyingStdout = jest.spyOn(process.stdout, 'write').mockImplementation();
|
|
6
|
+
const data = '{ "errors" : [] }';
|
|
7
|
+
|
|
8
|
+
output.write(data);
|
|
9
|
+
|
|
10
|
+
expect(spyingStdout).toBeCalledTimes(1);
|
|
11
|
+
expect(spyingStdout).toBeCalledWith(data);
|
|
12
|
+
|
|
13
|
+
spyingStdout.mockRestore();
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -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();
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
getMatchingStatusCodeRange,
|
|
6
6
|
doesYamlFileExist,
|
|
7
7
|
} from '../utils';
|
|
8
|
+
import { isBrowser } from '../env';
|
|
8
9
|
import * as fs from 'fs';
|
|
9
10
|
import * as path from 'path';
|
|
10
11
|
|
|
@@ -122,5 +123,11 @@ describe('utils', () => {
|
|
|
122
123
|
expect(doesYamlFileExist('redocly.yam')).toBe(false);
|
|
123
124
|
});
|
|
124
125
|
});
|
|
126
|
+
|
|
127
|
+
describe('isBrowser', () => {
|
|
128
|
+
it('should not be browser', () => {
|
|
129
|
+
expect(isBrowser).toBe(false);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
125
132
|
});
|
|
126
133
|
});
|