@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.
Files changed (193) hide show
  1. package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +0 -1
  2. package/lib/benchmark/benches/resolve-with-no-external.bench.js +1 -1
  3. package/lib/bundle.d.ts +1 -1
  4. package/lib/bundle.js +9 -6
  5. package/lib/config/all.js +5 -3
  6. package/lib/config/config-resolvers.js +32 -14
  7. package/lib/config/config.d.ts +3 -5
  8. package/lib/config/config.js +7 -4
  9. package/lib/config/load.d.ts +7 -0
  10. package/lib/config/load.js +14 -6
  11. package/lib/config/minimal.js +7 -4
  12. package/lib/config/recommended.js +7 -4
  13. package/lib/config/rules.d.ts +1 -1
  14. package/lib/config/rules.js +1 -1
  15. package/lib/config/types.d.ts +7 -0
  16. package/lib/config/utils.d.ts +2 -2
  17. package/lib/config/utils.js +49 -11
  18. package/lib/decorators/common/registry-dependencies.js +2 -2
  19. package/lib/env.d.ts +3 -0
  20. package/lib/env.js +8 -0
  21. package/lib/format/codeframes.js +16 -10
  22. package/lib/format/format.d.ts +1 -1
  23. package/lib/format/format.js +49 -26
  24. package/lib/index.d.ts +5 -5
  25. package/lib/index.js +3 -1
  26. package/lib/js-yaml/index.js +1 -0
  27. package/lib/lint.js +2 -2
  28. package/lib/logger.d.ts +10 -0
  29. package/lib/logger.js +31 -0
  30. package/lib/output.d.ts +3 -0
  31. package/lib/output.js +9 -0
  32. package/lib/redocly/index.js +10 -9
  33. package/lib/redocly/registry-api-types.d.ts +28 -30
  34. package/lib/redocly/registry-api.d.ts +3 -3
  35. package/lib/redocly/registry-api.js +7 -1
  36. package/lib/ref-utils.js +2 -1
  37. package/lib/resolve.d.ts +1 -1
  38. package/lib/resolve.js +4 -2
  39. package/lib/rules/ajv.d.ts +1 -1
  40. package/lib/rules/ajv.js +7 -7
  41. package/lib/rules/common/assertions/asserts.js +4 -4
  42. package/lib/rules/common/assertions/index.js +1 -1
  43. package/lib/rules/common/no-ambiguous-paths.js +1 -1
  44. package/lib/rules/common/no-identical-paths.js +1 -1
  45. package/lib/rules/common/no-invalid-parameter-examples.js +3 -3
  46. package/lib/rules/common/no-invalid-schema-examples.js +3 -3
  47. package/lib/rules/common/operation-2xx-response.js +1 -1
  48. package/lib/rules/common/operation-4xx-response.js +1 -1
  49. package/lib/rules/common/operation-operationId.js +1 -1
  50. package/lib/rules/common/operation-tag-defined.js +1 -1
  51. package/lib/rules/common/path-not-include-query.js +1 -1
  52. package/lib/rules/common/security-defined.d.ts +2 -0
  53. package/lib/rules/common/{operation-security-defined.js → security-defined.js} +19 -5
  54. package/lib/rules/common/spec.js +14 -3
  55. package/lib/rules/common/tags-alphabetical.js +1 -1
  56. package/lib/rules/oas2/index.d.ts +1 -1
  57. package/lib/rules/oas2/index.js +2 -2
  58. package/lib/rules/oas2/remove-unused-components.js +3 -3
  59. package/lib/rules/oas2/request-mime-type.js +1 -1
  60. package/lib/rules/oas2/response-mime-type.js +1 -1
  61. package/lib/rules/oas3/index.js +8 -4
  62. package/lib/rules/oas3/no-empty-servers.js +1 -1
  63. package/lib/rules/oas3/no-invalid-media-type-examples.js +2 -2
  64. package/lib/rules/oas3/no-server-variables-empty-enum.d.ts +2 -0
  65. package/lib/rules/oas3/{no-servers-empty-enum.js → no-server-variables-empty-enum.js} +5 -5
  66. package/lib/rules/oas3/no-unused-components.js +2 -2
  67. package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.d.ts +5 -0
  68. package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.js +36 -0
  69. package/lib/rules/oas3/remove-unused-components.js +4 -4
  70. package/lib/rules/oas3/request-mime-type.js +1 -1
  71. package/lib/rules/oas3/response-mime-type.js +1 -1
  72. package/lib/rules/oas3/spec-components-invalid-map-name.d.ts +2 -0
  73. package/lib/rules/oas3/spec-components-invalid-map-name.js +46 -0
  74. package/lib/rules/other/stats.d.ts +2 -2
  75. package/lib/rules/other/stats.js +2 -2
  76. package/lib/rules/utils.d.ts +3 -2
  77. package/lib/rules/utils.js +16 -4
  78. package/lib/types/oas2.js +5 -5
  79. package/lib/types/oas3.js +27 -20
  80. package/lib/types/oas3_1.js +3 -3
  81. package/lib/types/redocly-yaml.js +47 -56
  82. package/lib/utils.d.ts +6 -1
  83. package/lib/utils.js +24 -7
  84. package/lib/visitors.d.ts +12 -12
  85. package/lib/visitors.js +15 -3
  86. package/lib/walk.d.ts +2 -1
  87. package/lib/walk.js +6 -3
  88. package/package.json +2 -2
  89. package/src/__tests__/__snapshots__/bundle.test.ts.snap +3 -3
  90. package/src/__tests__/fixtures/extension.js +3 -3
  91. package/src/__tests__/format.test.ts +76 -0
  92. package/src/__tests__/lint.test.ts +106 -131
  93. package/src/__tests__/logger-browser.test.ts +53 -0
  94. package/src/__tests__/logger.test.ts +47 -0
  95. package/src/__tests__/output-browser.test.ts +18 -0
  96. package/src/__tests__/output.test.ts +15 -0
  97. package/src/__tests__/resolve-http.test.ts +1 -1
  98. package/src/__tests__/resolve.test.ts +9 -9
  99. package/src/__tests__/utils-browser.test.ts +11 -0
  100. package/src/__tests__/utils.test.ts +7 -0
  101. package/src/__tests__/walk.test.ts +78 -10
  102. package/src/benchmark/benches/lint-with-top-level-rule-report.bench.ts +0 -1
  103. package/src/benchmark/benches/resolve-with-no-external.bench.ts +1 -1
  104. package/src/bundle.ts +10 -7
  105. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +12 -6
  106. package/src/config/__tests__/config.test.ts +35 -0
  107. package/src/config/__tests__/fixtures/plugin-config.yaml +2 -3
  108. package/src/config/__tests__/fixtures/resolve-config/api/nested-config.yaml +11 -12
  109. package/src/config/__tests__/fixtures/resolve-config/local-config-with-circular.yaml +7 -8
  110. package/src/config/__tests__/fixtures/resolve-config/local-config-with-file.yaml +18 -19
  111. package/src/config/__tests__/fixtures/resolve-config/local-config.yaml +9 -10
  112. package/src/config/__tests__/fixtures/resolve-remote-configs/nested-remote-config.yaml +3 -4
  113. package/src/config/__tests__/fixtures/resolve-remote-configs/remote-config.yaml +4 -5
  114. package/src/config/__tests__/load.test.ts +76 -1
  115. package/src/config/__tests__/utils.test.ts +64 -4
  116. package/src/config/all.ts +5 -3
  117. package/src/config/config-resolvers.ts +45 -19
  118. package/src/config/config.ts +10 -8
  119. package/src/config/load.ts +31 -7
  120. package/src/config/minimal.ts +7 -4
  121. package/src/config/recommended.ts +7 -4
  122. package/src/config/rules.ts +2 -2
  123. package/src/config/types.ts +11 -0
  124. package/src/config/utils.ts +115 -25
  125. package/src/decorators/common/registry-dependencies.ts +2 -2
  126. package/src/env.ts +5 -0
  127. package/src/format/codeframes.ts +15 -9
  128. package/src/format/format.ts +59 -34
  129. package/src/index.ts +6 -4
  130. package/src/js-yaml/index.ts +1 -0
  131. package/src/lint.ts +2 -2
  132. package/src/logger.ts +34 -0
  133. package/src/output.ts +7 -0
  134. package/src/redocly/index.ts +7 -4
  135. package/src/redocly/registry-api-types.ts +27 -29
  136. package/src/redocly/registry-api.ts +18 -7
  137. package/src/ref-utils.ts +2 -1
  138. package/src/resolve.ts +7 -5
  139. package/src/rules/__tests__/utils.test.ts +39 -1
  140. package/src/rules/ajv.ts +7 -7
  141. package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +1 -0
  142. package/src/rules/common/__tests__/operation-2xx-response.test.ts +1 -1
  143. package/src/rules/common/__tests__/operation-4xx-response.test.ts +26 -3
  144. package/src/rules/common/__tests__/security-defined.test.ts +175 -0
  145. package/src/rules/common/__tests__/spec.test.ts +79 -0
  146. package/src/rules/common/assertions/__tests__/utils.test.ts +2 -2
  147. package/src/rules/common/assertions/asserts.ts +4 -4
  148. package/src/rules/common/assertions/index.ts +1 -1
  149. package/src/rules/common/no-ambiguous-paths.ts +1 -1
  150. package/src/rules/common/no-identical-paths.ts +1 -1
  151. package/src/rules/common/no-invalid-parameter-examples.ts +4 -4
  152. package/src/rules/common/no-invalid-schema-examples.ts +4 -4
  153. package/src/rules/common/operation-2xx-response.ts +1 -1
  154. package/src/rules/common/operation-4xx-response.ts +1 -1
  155. package/src/rules/common/operation-operationId.ts +1 -1
  156. package/src/rules/common/operation-tag-defined.ts +1 -1
  157. package/src/rules/common/path-not-include-query.ts +1 -1
  158. package/src/rules/common/{operation-security-defined.ts → security-defined.ts} +20 -5
  159. package/src/rules/common/spec.ts +17 -3
  160. package/src/rules/common/tags-alphabetical.ts +1 -1
  161. package/src/rules/oas2/index.ts +2 -2
  162. package/src/rules/oas2/remove-unused-components.ts +3 -3
  163. package/src/rules/oas2/request-mime-type.ts +1 -1
  164. package/src/rules/oas2/response-mime-type.ts +1 -1
  165. package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +16 -16
  166. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +5 -5
  167. package/src/rules/oas3/__tests__/operation-4xx-problem-details-rfc7807.test.ts +145 -0
  168. package/src/rules/oas3/__tests__/spec/spec.test.ts +10 -0
  169. package/src/rules/oas3/__tests__/spec-components-invalid-map-name.test.ts +217 -0
  170. package/src/rules/oas3/index.ts +8 -4
  171. package/src/rules/oas3/no-empty-servers.ts +1 -1
  172. package/src/rules/oas3/no-invalid-media-type-examples.ts +3 -3
  173. package/src/rules/oas3/{no-servers-empty-enum.ts → no-server-variables-empty-enum.ts} +3 -3
  174. package/src/rules/oas3/no-unused-components.ts +2 -2
  175. package/src/rules/oas3/operation-4xx-problem-details-rfc7807.ts +36 -0
  176. package/src/rules/oas3/remove-unused-components.ts +5 -5
  177. package/src/rules/oas3/request-mime-type.ts +1 -1
  178. package/src/rules/oas3/response-mime-type.ts +1 -1
  179. package/src/rules/oas3/spec-components-invalid-map-name.ts +53 -0
  180. package/src/rules/other/stats.ts +2 -2
  181. package/src/rules/utils.ts +17 -3
  182. package/src/types/index.ts +2 -2
  183. package/src/types/oas2.ts +5 -5
  184. package/src/types/oas3.ts +27 -20
  185. package/src/types/oas3_1.ts +3 -3
  186. package/src/types/redocly-yaml.ts +53 -41
  187. package/src/utils.ts +31 -4
  188. package/src/visitors.ts +34 -18
  189. package/src/walk.ts +15 -11
  190. package/tsconfig.tsbuildinfo +1 -1
  191. package/lib/rules/common/operation-security-defined.d.ts +0 -2
  192. package/lib/rules/oas3/no-servers-empty-enum.d.ts +0 -2
  193. 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
- openapi: 3.0.0
16
- info:
17
- title: Test API
18
- version: "1.0"
19
- description: Test
20
- license: Fail
15
+ openapi: 3.0.0
16
+ info:
17
+ title: Test API
18
+ version: "1.0"
19
+ description: Test
20
+ license: Fail
21
21
 
22
- servers:
23
- - url: http://example.com
24
- paths: {}
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
- apis: error string
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
- 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'
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
- api:
114
- name@version:
115
- root: ./file.yaml
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
- apiDefinitions:
164
- entry: ./file.yaml
165
- lint:
150
+ apis:
151
+ entry:
152
+ root: ./file.yaml
166
153
  rules:
167
154
  operation-2xx-response: warn
168
- referenceDocs:
169
- showConsole: true
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' -> 'styleguide' field", async () => {
165
+ it("'plugins' shouldn't be allowed in 'apis'", async () => {
179
166
  const document = parseYamlToDocument(
180
167
  outdent`
181
- apis:
182
- styleguide:
183
- plugins:
168
+ apis:
169
+ main:
170
+ root: ./main.yaml
171
+ plugins:
184
172
  - './local-plugin.js'
185
- styleguide:
186
173
  plugins:
187
- - './local-plugin.js'
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/styleguide",
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
- openapi: "3.1.0"
229
- info:
230
- version: 1.0.0
231
- title: Swagger Petstore
232
- description: Information about Petstore
233
- license:
234
- name: MIT
235
- url: https://opensource.org/licenses/MIT
236
- servers:
237
- - url: http://petstore.swagger.io/v1
238
- paths:
239
- /pets:
240
- get:
241
- summary: List all pets
242
- operationId: listPets
243
- tags:
244
- - pets
245
- responses:
246
- 200:
247
- description: An paged array of pets
248
- content:
249
- application/json:
250
- schema:
251
- type: string
252
- const: ABC
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
- openapi: 3.0
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
- openapi: 3.1.0
282
- info:
283
- title: Callback test
284
- version: 'alpha'
285
- components:
286
- callbacks:
287
- resultCallback:
288
- '{$url}':
289
- post:
290
- requestBody:
291
- description: Callback payload
292
- content:
293
- 'application/json':
294
- schema:
295
- type: object
296
- properties:
297
- test:
298
- type: string
299
- responses:
300
- '200':
301
- description: callback successfully processed
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
- openapi: 3.0.0
320
- info:
321
- version: 1.0.0
322
- title: Example OpenAPI 3 definition.
323
- description: Information about API
324
- license:
325
- name: MIT
326
- url: 'https://opensource.org/licenses/MIT'
327
- servers:
328
- - url: 'https://redocly.com/v1'
329
- paths:
330
- '/pets/{petId}':
331
- post:
332
- responses:
333
- '201':
334
- summary: Exist
335
- description: example description
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
+ });
@@ -43,7 +43,7 @@ describe('Resolve http-headers', () => {
43
43
  ],
44
44
  },
45
45
  }),
46
- rootType: normalizeTypes(Oas3Types).DefinitionRoot,
46
+ rootType: normalizeTypes(Oas3Types).Root,
47
47
  });
48
48
 
49
49
  expect(fetchMock).toBeCalledTimes(3);
@@ -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).DefinitionRoot,
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).DefinitionRoot,
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).DefinitionRoot,
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).DefinitionRoot,
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).DefinitionRoot,
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).DefinitionRoot,
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).DefinitionRoot,
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).DefinitionRoot,
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).DefinitionRoot,
395
+ rootType: normalizeTypes(Oas3Types).Root,
396
396
  });
397
397
 
398
398
  expect(resolvedRefs).toBeDefined();
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+
5
+ import { isBrowser } from '../env';
6
+
7
+ describe('isBrowser', () => {
8
+ it('should be browser', () => {
9
+ expect(isBrowser).toBe(true);
10
+ });
11
+ });
@@ -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
  });