@redocly/openapi-core 1.0.0-beta.105 → 1.0.0-beta.108

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 (240) hide show
  1. package/README.md +4 -4
  2. package/__tests__/utils.ts +5 -5
  3. package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +0 -1
  4. package/lib/benchmark/benches/recommended-oas3.bench.js +1 -1
  5. package/lib/benchmark/utils.d.ts +2 -2
  6. package/lib/benchmark/utils.js +2 -2
  7. package/lib/bundle.d.ts +2 -2
  8. package/lib/bundle.js +7 -4
  9. package/lib/config/all.d.ts +2 -2
  10. package/lib/config/all.js +3 -3
  11. package/lib/config/builtIn.d.ts +2 -2
  12. package/lib/config/builtIn.js +2 -2
  13. package/lib/config/config-resolvers.d.ts +5 -5
  14. package/lib/config/config-resolvers.js +70 -49
  15. package/lib/config/config.d.ts +8 -10
  16. package/lib/config/config.js +10 -7
  17. package/lib/config/load.d.ts +7 -0
  18. package/lib/config/load.js +18 -10
  19. package/lib/config/minimal.d.ts +2 -2
  20. package/lib/config/minimal.js +5 -4
  21. package/lib/config/recommended.d.ts +2 -2
  22. package/lib/config/recommended.js +5 -4
  23. package/lib/config/rules.d.ts +3 -3
  24. package/lib/config/rules.js +1 -1
  25. package/lib/config/types.d.ts +23 -19
  26. package/lib/config/utils.d.ts +5 -5
  27. package/lib/config/utils.js +48 -31
  28. package/lib/decorators/common/registry-dependencies.js +1 -1
  29. package/lib/decorators/common/remove-x-internal.js +2 -2
  30. package/lib/env.d.ts +3 -0
  31. package/lib/env.js +8 -0
  32. package/lib/format/codeframes.js +16 -10
  33. package/lib/format/format.js +29 -27
  34. package/lib/index.d.ts +5 -5
  35. package/lib/index.js +4 -2
  36. package/lib/js-yaml/index.js +2 -6
  37. package/lib/lint.d.ts +2 -2
  38. package/lib/lint.js +16 -6
  39. package/lib/logger.d.ts +10 -0
  40. package/lib/logger.js +31 -0
  41. package/lib/output.d.ts +3 -0
  42. package/lib/output.js +9 -0
  43. package/lib/redocly/index.js +10 -9
  44. package/lib/redocly/registry-api-types.d.ts +28 -30
  45. package/lib/redocly/registry-api.d.ts +4 -3
  46. package/lib/redocly/registry-api.js +9 -4
  47. package/lib/ref-utils.js +2 -1
  48. package/lib/resolve.d.ts +1 -1
  49. package/lib/resolve.js +1 -1
  50. package/lib/rules/ajv.d.ts +1 -1
  51. package/lib/rules/ajv.js +7 -7
  52. package/lib/rules/common/assertions/asserts.js +4 -4
  53. package/lib/rules/common/assertions/index.js +1 -1
  54. package/lib/rules/common/info-license-url.d.ts +1 -1
  55. package/lib/rules/common/info-license-url.js +5 -10
  56. package/lib/rules/common/info-license.d.ts +2 -0
  57. package/lib/rules/common/info-license.js +17 -0
  58. package/lib/rules/common/no-enum-type-mismatch.js +1 -3
  59. package/lib/rules/common/no-invalid-parameter-examples.js +3 -3
  60. package/lib/rules/common/no-invalid-schema-examples.js +3 -3
  61. package/lib/rules/common/operation-operationId.js +1 -1
  62. package/lib/rules/common/operation-security-defined.js +1 -1
  63. package/lib/rules/common/path-not-include-query.js +1 -1
  64. package/lib/rules/common/paths-kebab-case.js +4 -1
  65. package/lib/rules/common/spec.js +3 -3
  66. package/lib/rules/oas2/index.js +4 -4
  67. package/lib/rules/oas2/remove-unused-components.js +5 -5
  68. package/lib/rules/oas3/index.js +6 -6
  69. package/lib/rules/oas3/no-empty-servers.js +1 -1
  70. package/lib/rules/oas3/no-invalid-media-type-examples.js +2 -2
  71. package/lib/rules/oas3/no-server-variables-empty-enum.d.ts +2 -0
  72. package/lib/rules/oas3/{no-servers-empty-enum.js → no-server-variables-empty-enum.js} +4 -4
  73. package/lib/rules/oas3/no-unused-components.js +1 -1
  74. package/lib/rules/oas3/remove-unused-components.js +5 -5
  75. package/lib/rules/other/stats.js +43 -14
  76. package/lib/rules/utils.d.ts +3 -2
  77. package/lib/rules/utils.js +20 -5
  78. package/lib/types/index.d.ts +2 -2
  79. package/lib/types/redocly-yaml.js +9 -8
  80. package/lib/utils.d.ts +5 -0
  81. package/lib/utils.js +22 -5
  82. package/lib/visitors.d.ts +1 -1
  83. package/lib/visitors.js +2 -2
  84. package/lib/walk.d.ts +2 -1
  85. package/lib/walk.js +6 -3
  86. package/package.json +2 -2
  87. package/src/__tests__/__snapshots__/bundle.test.ts.snap +141 -0
  88. package/src/__tests__/bundle.test.ts +68 -34
  89. package/src/__tests__/codeframes.test.ts +13 -14
  90. package/src/__tests__/js-yaml.test.ts +6 -4
  91. package/src/__tests__/lint.test.ts +74 -6
  92. package/src/__tests__/logger-browser.test.ts +53 -0
  93. package/src/__tests__/logger.test.ts +47 -0
  94. package/src/__tests__/login.test.ts +2 -2
  95. package/src/__tests__/normalizeVisitors.test.ts +4 -4
  96. package/src/__tests__/output-browser.test.ts +18 -0
  97. package/src/__tests__/output.test.ts +15 -0
  98. package/src/__tests__/ref-utils.test.ts +13 -13
  99. package/src/__tests__/resolve-http.test.ts +1 -1
  100. package/src/__tests__/resolve.test.ts +14 -11
  101. package/src/__tests__/utils-browser.test.ts +11 -0
  102. package/src/__tests__/utils.test.ts +7 -0
  103. package/src/__tests__/walk.test.ts +48 -56
  104. package/src/benchmark/benches/lint-with-many-rules.bench.ts +1 -1
  105. package/src/benchmark/benches/lint-with-nested-rule.bench.ts +1 -1
  106. package/src/benchmark/benches/lint-with-no-rules.bench.ts +1 -1
  107. package/src/benchmark/benches/lint-with-top-level-rule-report.bench.ts +1 -2
  108. package/src/benchmark/benches/lint-with-top-level-rule.bench.ts +1 -1
  109. package/src/benchmark/benches/recommended-oas3.bench.ts +3 -3
  110. package/src/benchmark/benches/resolve-with-no-external.bench.ts +1 -1
  111. package/src/benchmark/benchmark.js +9 -5
  112. package/src/benchmark/utils.ts +5 -5
  113. package/src/bundle.ts +24 -20
  114. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +7 -5
  115. package/src/config/__tests__/config-resolvers.test.ts +123 -121
  116. package/src/config/__tests__/config.test.ts +111 -76
  117. package/src/config/__tests__/fixtures/resolve-config/api/plugin.js +4 -2
  118. package/src/config/__tests__/fixtures/resolve-config/plugin.js +4 -1
  119. package/src/config/__tests__/load.test.ts +79 -1
  120. package/src/config/__tests__/resolve-plugins.test.ts +3 -3
  121. package/src/config/__tests__/utils.test.ts +83 -0
  122. package/src/config/all.ts +5 -6
  123. package/src/config/builtIn.ts +5 -5
  124. package/src/config/config-resolvers.ts +161 -96
  125. package/src/config/config.ts +15 -13
  126. package/src/config/load.ts +34 -11
  127. package/src/config/minimal.ts +7 -6
  128. package/src/config/recommended.ts +7 -6
  129. package/src/config/rules.ts +6 -6
  130. package/src/config/types.ts +28 -19
  131. package/src/config/utils.ts +78 -57
  132. package/src/decorators/__tests__/filter-out.test.ts +8 -4
  133. package/src/decorators/__tests__/remove-x-internal.test.ts +5 -5
  134. package/src/decorators/common/filters/filter-helper.ts +1 -1
  135. package/src/decorators/common/info-description-override.ts +1 -1
  136. package/src/decorators/common/operation-description-override.ts +1 -1
  137. package/src/decorators/common/registry-dependencies.ts +1 -1
  138. package/src/decorators/common/remove-x-internal.ts +4 -4
  139. package/src/decorators/common/tag-description-override.ts +1 -1
  140. package/src/env.ts +5 -0
  141. package/src/format/codeframes.ts +18 -12
  142. package/src/format/format.ts +37 -42
  143. package/src/index.ts +8 -7
  144. package/src/js-yaml/index.ts +4 -8
  145. package/src/lint.ts +22 -18
  146. package/src/logger.ts +34 -0
  147. package/src/oas-types.ts +1 -6
  148. package/src/output.ts +7 -0
  149. package/src/redocly/__tests__/redocly-client.test.ts +25 -19
  150. package/src/redocly/index.ts +12 -7
  151. package/src/redocly/registry-api-types.ts +27 -29
  152. package/src/redocly/registry-api.ts +22 -12
  153. package/src/ref-utils.ts +4 -3
  154. package/src/resolve.ts +11 -8
  155. package/src/rules/__tests__/no-unresolved-refs.test.ts +4 -4
  156. package/src/rules/__tests__/utils.test.ts +160 -0
  157. package/src/rules/ajv.ts +7 -8
  158. package/src/rules/common/__tests__/info-description.test.ts +3 -3
  159. package/src/rules/common/__tests__/info-license.test.ts +2 -2
  160. package/src/rules/common/__tests__/license-url.test.ts +2 -2
  161. package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +1 -1
  162. package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +8 -8
  163. package/src/rules/common/__tests__/no-identical-paths.test.ts +1 -1
  164. package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +3 -3
  165. package/src/rules/common/__tests__/operation-2xx-response.test.ts +3 -3
  166. package/src/rules/common/__tests__/operation-4xx-response.test.ts +3 -3
  167. package/src/rules/common/__tests__/operation-operationId-unique.test.ts +2 -2
  168. package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +1 -1
  169. package/src/rules/common/__tests__/operation-parameters-unique.test.ts +4 -4
  170. package/src/rules/common/__tests__/operation-security-defined.test.ts +2 -2
  171. package/src/rules/common/__tests__/operation-singular-tag.test.ts +2 -2
  172. package/src/rules/common/__tests__/path-http-verbs-order.test.ts +2 -2
  173. package/src/rules/common/__tests__/path-not-include-query.test.ts +2 -2
  174. package/src/rules/common/__tests__/path-params-defined.test.ts +3 -3
  175. package/src/rules/common/__tests__/paths-kebab-case.test.ts +15 -15
  176. package/src/rules/common/__tests__/scalar-property-missing-example.test.ts +8 -8
  177. package/src/rules/common/__tests__/spec.test.ts +2 -2
  178. package/src/rules/common/__tests__/tag-description.test.ts +2 -2
  179. package/src/rules/common/__tests__/tags-alphabetical.test.ts +2 -2
  180. package/src/rules/common/assertions/__tests__/asserts.test.ts +513 -130
  181. package/src/rules/common/assertions/asserts.ts +4 -4
  182. package/src/rules/common/assertions/index.ts +7 -7
  183. package/src/rules/common/info-license-url.ts +4 -9
  184. package/src/rules/common/info-license.ts +15 -0
  185. package/src/rules/common/no-ambiguous-paths.ts +1 -1
  186. package/src/rules/common/no-enum-type-mismatch.ts +12 -9
  187. package/src/rules/common/no-invalid-parameter-examples.ts +4 -4
  188. package/src/rules/common/no-invalid-schema-examples.ts +4 -4
  189. package/src/rules/common/operation-operationId.ts +1 -1
  190. package/src/rules/common/operation-parameters-unique.ts +2 -2
  191. package/src/rules/common/operation-security-defined.ts +1 -1
  192. package/src/rules/common/path-not-include-query.ts +1 -1
  193. package/src/rules/common/path-params-defined.ts +1 -1
  194. package/src/rules/common/paths-kebab-case.ts +4 -1
  195. package/src/rules/common/scalar-property-missing-example.ts +1 -1
  196. package/src/rules/common/spec.ts +12 -9
  197. package/src/rules/no-unresolved-refs.ts +1 -1
  198. package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +3 -3
  199. package/src/rules/oas2/__tests__/spec/info.test.ts +12 -12
  200. package/src/rules/oas2/__tests__/spec/operation.test.ts +4 -4
  201. package/src/rules/oas2/__tests__/spec/paths.test.ts +10 -10
  202. package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +6 -2
  203. package/src/rules/oas2/__tests__/spec/utils.ts +6 -6
  204. package/src/rules/oas2/index.ts +3 -3
  205. package/src/rules/oas2/remove-unused-components.ts +14 -9
  206. package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +3 -3
  207. package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +16 -16
  208. package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +2 -2
  209. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +13 -13
  210. package/src/rules/oas3/__tests__/no-server-example.com.test.ts +2 -2
  211. package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +3 -3
  212. package/src/rules/oas3/__tests__/no-unused-components.test.ts +1 -1
  213. package/src/rules/oas3/__tests__/spec/callbacks.test.ts +1 -1
  214. package/src/rules/oas3/__tests__/spec/info.test.ts +12 -12
  215. package/src/rules/oas3/__tests__/spec/operation.test.ts +8 -8
  216. package/src/rules/oas3/__tests__/spec/paths.test.ts +10 -10
  217. package/src/rules/oas3/__tests__/spec/referenceableScalars.test.ts +12 -12
  218. package/src/rules/oas3/__tests__/spec/servers.test.ts +15 -15
  219. package/src/rules/oas3/__tests__/spec/spec.test.ts +6 -6
  220. package/src/rules/oas3/__tests__/spec/utils.ts +6 -6
  221. package/src/rules/oas3/index.ts +5 -5
  222. package/src/rules/oas3/no-empty-servers.ts +1 -1
  223. package/src/rules/oas3/no-invalid-media-type-examples.ts +14 -6
  224. package/src/rules/oas3/{no-servers-empty-enum.ts → no-server-variables-empty-enum.ts} +10 -11
  225. package/src/rules/oas3/no-unused-components.ts +1 -1
  226. package/src/rules/oas3/remove-unused-components.ts +21 -10
  227. package/src/rules/other/stats.ts +46 -17
  228. package/src/rules/utils.ts +20 -4
  229. package/src/types/index.ts +5 -5
  230. package/src/types/redocly-yaml.ts +9 -8
  231. package/src/typings/common.ts +9 -1
  232. package/src/typings/openapi.ts +1 -1
  233. package/src/utils.ts +26 -3
  234. package/src/visitors.ts +9 -9
  235. package/src/walk.ts +15 -11
  236. package/tsconfig.tsbuildinfo +1 -1
  237. package/lib/rules/common/license-url.d.ts +0 -2
  238. package/lib/rules/common/license-url.js +0 -12
  239. package/lib/rules/oas3/no-servers-empty-enum.d.ts +0 -2
  240. package/src/rules/common/license-url.ts +0 -10
@@ -4,7 +4,11 @@ import * as path from 'path';
4
4
 
5
5
  import { lintDocument } from '../lint';
6
6
 
7
- import { parseYamlToDocument, replaceSourceWithRef, makeConfigForRuleset } from '../../__tests__/utils';
7
+ import {
8
+ parseYamlToDocument,
9
+ replaceSourceWithRef,
10
+ makeConfigForRuleset,
11
+ } from '../../__tests__/utils';
8
12
  import { BaseResolver, Document } from '../resolve';
9
13
  import { listOf } from '../types';
10
14
  import { Oas3RuleSet } from '../oas-types';
@@ -43,7 +47,7 @@ describe('walk order', () => {
43
47
  contact: {}
44
48
  license: {}
45
49
  `,
46
- '',
50
+ ''
47
51
  );
48
52
 
49
53
  await lintDocument({
@@ -70,14 +74,10 @@ describe('walk order', () => {
70
74
  leave: jest.fn((op) => calls.push(`leave operation: ${op.operationId}`)),
71
75
  Parameter: {
72
76
  enter: jest.fn((param, _ctx, parents) =>
73
- calls.push(
74
- `enter operation ${parents.Operation.operationId} > param ${param.name}`,
75
- ),
77
+ calls.push(`enter operation ${parents.Operation.operationId} > param ${param.name}`)
76
78
  ),
77
79
  leave: jest.fn((param, _ctx, parents) =>
78
- calls.push(
79
- `leave operation ${parents.Operation.operationId} > param ${param.name}`,
80
- ),
80
+ calls.push(`leave operation ${parents.Operation.operationId} > param ${param.name}`)
81
81
  ),
82
82
  },
83
83
  },
@@ -110,7 +110,7 @@ describe('walk order', () => {
110
110
  - name: post_a
111
111
 
112
112
  `,
113
- '',
113
+ ''
114
114
  );
115
115
 
116
116
  await lintDocument({
@@ -154,14 +154,10 @@ describe('walk order', () => {
154
154
  leave: jest.fn((op) => calls.push(`leave operation: ${op.operationId}`)),
155
155
  Parameter: {
156
156
  enter: jest.fn((param, _ctx, parents) =>
157
- calls.push(
158
- `enter operation ${parents.Operation.operationId} > param ${param.name}`,
159
- ),
157
+ calls.push(`enter operation ${parents.Operation.operationId} > param ${param.name}`)
160
158
  ),
161
159
  leave: jest.fn((param, _ctx, parents) =>
162
- calls.push(
163
- `leave operation ${parents.Operation.operationId} > param ${param.name}`,
164
- ),
160
+ calls.push(`leave operation ${parents.Operation.operationId} > param ${param.name}`)
165
161
  ),
166
162
  },
167
163
  },
@@ -194,7 +190,7 @@ describe('walk order', () => {
194
190
  - name: post_a
195
191
 
196
192
  `,
197
- '',
193
+ ''
198
194
  );
199
195
 
200
196
  await lintDocument({
@@ -238,14 +234,10 @@ describe('walk order', () => {
238
234
  leave: jest.fn((op) => calls.push(`leave operation: ${op.operationId}`)),
239
235
  Parameter: {
240
236
  enter: jest.fn((param, _ctx, parents) =>
241
- calls.push(
242
- `enter operation ${parents.Operation.operationId} > param ${param.name}`,
243
- ),
237
+ calls.push(`enter operation ${parents.Operation.operationId} > param ${param.name}`)
244
238
  ),
245
239
  leave: jest.fn((param, _ctx, parents) =>
246
- calls.push(
247
- `leave operation ${parents.Operation.operationId} > param ${param.name}`,
248
- ),
240
+ calls.push(`leave operation ${parents.Operation.operationId} > param ${param.name}`)
249
241
  ),
250
242
  },
251
243
  },
@@ -279,7 +271,7 @@ describe('walk order', () => {
279
271
  shared_a:
280
272
  name: shared-a
281
273
  `,
282
- '',
274
+ ''
283
275
  );
284
276
 
285
277
  await lintDocument({
@@ -317,7 +309,7 @@ describe('walk order', () => {
317
309
  PathItem: {
318
310
  Parameter: {
319
311
  enter: jest.fn((param, _ctx, parents) =>
320
- calls.push(`enter path ${parents.PathItem.id} > param ${param.name}`),
312
+ calls.push(`enter path ${parents.PathItem.id} > param ${param.name}`)
321
313
  ),
322
314
  },
323
315
  },
@@ -351,7 +343,7 @@ describe('walk order', () => {
351
343
  shared_a:
352
344
  name: shared-a
353
345
  `,
354
- '',
346
+ ''
355
347
  );
356
348
 
357
349
  await lintDocument({
@@ -379,15 +371,15 @@ describe('walk order', () => {
379
371
  PathItem: {
380
372
  Parameter: {
381
373
  enter: jest.fn((param, _ctx, parents) =>
382
- calls.push(`enter path ${parents.PathItem.id} > param ${param.name}`),
374
+ calls.push(`enter path ${parents.PathItem.id} > param ${param.name}`)
383
375
  ),
384
376
  },
385
377
  Operation: {
386
378
  Parameter: {
387
379
  enter: jest.fn((param, _ctx, parents) =>
388
380
  calls.push(
389
- `enter operation ${parents.Operation.operationId} > param ${param.name}`,
390
- ),
381
+ `enter operation ${parents.Operation.operationId} > param ${param.name}`
382
+ )
391
383
  ),
392
384
  },
393
385
  },
@@ -423,7 +415,7 @@ describe('walk order', () => {
423
415
  shared_b:
424
416
  name: shared-b
425
417
  `,
426
- '',
418
+ ''
427
419
  );
428
420
 
429
421
  await lintDocument({
@@ -452,10 +444,10 @@ describe('walk order', () => {
452
444
  PathItem: {
453
445
  Parameter: {
454
446
  enter: jest.fn((param, _ctx, parents) =>
455
- calls.push(`enter path ${parents.PathItem.id} > param ${param.name}`),
447
+ calls.push(`enter path ${parents.PathItem.id} > param ${param.name}`)
456
448
  ),
457
449
  leave: jest.fn((param, _ctx, parents) =>
458
- calls.push(`leave path ${parents.PathItem.id} > param ${param.name}`),
450
+ calls.push(`leave path ${parents.PathItem.id} > param ${param.name}`)
459
451
  ),
460
452
  },
461
453
  Operation(op, _ctx, parents) {
@@ -490,7 +482,7 @@ describe('walk order', () => {
490
482
  shared_a:
491
483
  name: shared-a
492
484
  `,
493
- '',
485
+ ''
494
486
  );
495
487
 
496
488
  await lintDocument({
@@ -544,7 +536,7 @@ describe('walk order', () => {
544
536
  - $ref: "#/components/parameters/shared_a"
545
537
  - id: 'nested'
546
538
  `,
547
- '',
539
+ ''
548
540
  );
549
541
 
550
542
  await lintDocument({
@@ -569,7 +561,7 @@ describe('walk order', () => {
569
561
  return {
570
562
  Parameter: {
571
563
  Schema: jest.fn((schema: any, _ctx, parents) =>
572
- calls.push(`enter param ${parents.Parameter.name} > schema ${schema.id}`),
564
+ calls.push(`enter param ${parents.Parameter.name} > schema ${schema.id}`)
573
565
  ),
574
566
  },
575
567
  };
@@ -600,7 +592,7 @@ describe('walk order', () => {
600
592
  - $ref: "#/components/parameters/shared_a"
601
593
  - id: 'nested'
602
594
  `,
603
- '',
595
+ ''
604
596
  );
605
597
 
606
598
  await lintDocument({
@@ -642,7 +634,7 @@ describe('walk order', () => {
642
634
  put:
643
635
  operationId: put
644
636
  `,
645
- '',
637
+ ''
646
638
  );
647
639
 
648
640
  await lintDocument({
@@ -668,7 +660,7 @@ describe('walk order', () => {
668
660
  Operation: {
669
661
  skip: (op) => op.operationId === 'put',
670
662
  Parameter: jest.fn((param, _ctx, parents) =>
671
- calls.push(`enter operation ${parents.Operation.operationId} > param ${param.name}`),
663
+ calls.push(`enter operation ${parents.Operation.operationId} > param ${param.name}`)
672
664
  ),
673
665
  },
674
666
  };
@@ -697,7 +689,7 @@ describe('walk order', () => {
697
689
  shared_a:
698
690
  name: shared-a
699
691
  `,
700
- '',
692
+ ''
701
693
  );
702
694
 
703
695
  await lintDocument({
@@ -724,10 +716,10 @@ describe('walk order', () => {
724
716
  PathItem: {
725
717
  Parameter: {
726
718
  enter: jest.fn((param, _ctx, parents) =>
727
- calls.push(`enter path ${parents.PathItem.id} > param ${param.name}`),
719
+ calls.push(`enter path ${parents.PathItem.id} > param ${param.name}`)
728
720
  ),
729
721
  leave: jest.fn((param, _ctx, parents) =>
730
- calls.push(`leave path ${parents.PathItem.id} > param ${param.name}`),
722
+ calls.push(`leave path ${parents.PathItem.id} > param ${param.name}`)
731
723
  ),
732
724
  },
733
725
  Operation: {
@@ -735,13 +727,13 @@ describe('walk order', () => {
735
727
  Parameter: {
736
728
  enter: jest.fn((param, _ctx, parents) =>
737
729
  calls.push(
738
- `enter operation ${parents.Operation.operationId} > param ${param.name}`,
739
- ),
730
+ `enter operation ${parents.Operation.operationId} > param ${param.name}`
731
+ )
740
732
  ),
741
733
  leave: jest.fn((param, _ctx, parents) =>
742
734
  calls.push(
743
- `leave operation ${parents.Operation.operationId} > param ${param.name}`,
744
- ),
735
+ `leave operation ${parents.Operation.operationId} > param ${param.name}`
736
+ )
745
737
  ),
746
738
  },
747
739
  },
@@ -783,7 +775,7 @@ describe('walk order', () => {
783
775
  shared_b:
784
776
  name: shared-b
785
777
  `,
786
- '',
778
+ ''
787
779
  );
788
780
 
789
781
  await lintDocument({
@@ -817,10 +809,10 @@ describe('walk order', () => {
817
809
  Schema: {
818
810
  Schema: {
819
811
  enter: jest.fn((schema: any, _ctx, parents) =>
820
- calls.push(`enter nested schema ${parents.Schema.id} > ${schema.id}`),
812
+ calls.push(`enter nested schema ${parents.Schema.id} > ${schema.id}`)
821
813
  ),
822
814
  leave: jest.fn((schema: any, _ctx, parents) =>
823
- calls.push(`leave nested schema ${parents.Schema.id} > ${schema.id}`),
815
+ calls.push(`leave nested schema ${parents.Schema.id} > ${schema.id}`)
824
816
  ),
825
817
  },
826
818
  },
@@ -862,7 +854,7 @@ describe('walk order', () => {
862
854
  a:
863
855
  id: inline-nested-nested
864
856
  `,
865
- 'foobar.yaml',
857
+ 'foobar.yaml'
866
858
  );
867
859
 
868
860
  await lintDocument({
@@ -934,7 +926,7 @@ describe('walk order', () => {
934
926
  schema:
935
927
  $ref: '#/components/parameters/shared_b'
936
928
  `,
937
- 'foobar.yaml',
929
+ 'foobar.yaml'
938
930
  );
939
931
 
940
932
  await lintDocument({
@@ -978,7 +970,7 @@ describe('walk order', () => {
978
970
  b:
979
971
  type: number
980
972
  `,
981
- 'foobar.yaml',
973
+ 'foobar.yaml'
982
974
  );
983
975
 
984
976
  await lintDocument({
@@ -1043,7 +1035,7 @@ describe('walk order', () => {
1043
1035
  a:
1044
1036
  type: object
1045
1037
  `,
1046
- '',
1038
+ ''
1047
1039
  );
1048
1040
 
1049
1041
  await lintDocument({
@@ -1131,7 +1123,7 @@ describe('context.report', () => {
1131
1123
  shared_a:
1132
1124
  name: shared_a
1133
1125
  `,
1134
- 'foobar.yaml',
1126
+ 'foobar.yaml'
1135
1127
  );
1136
1128
 
1137
1129
  const results = await lintDocument({
@@ -1207,7 +1199,7 @@ describe('context.report', () => {
1207
1199
  const externalRefResolver = new BaseResolver();
1208
1200
  const document = (await externalRefResolver.resolveDocument(
1209
1201
  null,
1210
- `${cwd}/openapi-with-external-refs.yaml`,
1202
+ `${cwd}/openapi-with-external-refs.yaml`
1211
1203
  )) as Document;
1212
1204
 
1213
1205
  if (document === null) {
@@ -1319,7 +1311,7 @@ describe('context.resolve', () => {
1319
1311
  a:
1320
1312
  $ref: '#/components/schemas/b'
1321
1313
  `,
1322
- 'foobar.yaml',
1314
+ 'foobar.yaml'
1323
1315
  );
1324
1316
 
1325
1317
  await lintDocument({
@@ -1368,7 +1360,7 @@ describe('type extensions', () => {
1368
1360
  parameters:
1369
1361
  - name: a
1370
1362
  `,
1371
- 'foobar.yaml',
1363
+ 'foobar.yaml'
1372
1364
  );
1373
1365
 
1374
1366
  await lintDocument({
@@ -1462,7 +1454,7 @@ describe('ignoreNextRules', () => {
1462
1454
  put:
1463
1455
  operationId: put
1464
1456
  `,
1465
- '',
1457
+ ''
1466
1458
  );
1467
1459
 
1468
1460
  await lintDocument({
@@ -9,7 +9,7 @@ export const count = 10;
9
9
  const rebillyDefinitionRef = pathResolve(pathJoin(__dirname, 'rebilly.yaml'));
10
10
  const rebillyDocument = parseYamlToDocument(
11
11
  readFileSync(rebillyDefinitionRef, 'utf-8'),
12
- rebillyDefinitionRef,
12
+ rebillyDefinitionRef
13
13
  );
14
14
 
15
15
  const ruleset: any = {};
@@ -9,7 +9,7 @@ export const count = 10;
9
9
  const rebillyDefinitionRef = pathResolve(pathJoin(__dirname, 'rebilly.yaml'));
10
10
  const rebillyDocument = parseYamlToDocument(
11
11
  readFileSync(rebillyDefinitionRef, 'utf-8'),
12
- rebillyDefinitionRef,
12
+ rebillyDefinitionRef
13
13
  );
14
14
  const visitor = {
15
15
  test: () => {
@@ -8,7 +8,7 @@ export const count = 10;
8
8
  const rebillyDefinitionRef = pathResolve(pathJoin(__dirname, 'rebilly.yaml'));
9
9
  const rebillyDocument = parseYamlToDocument(
10
10
  readFileSync(rebillyDefinitionRef, 'utf-8'),
11
- rebillyDefinitionRef,
11
+ rebillyDefinitionRef
12
12
  );
13
13
  const config = makeConfigForRuleset({});
14
14
  export function measureAsync() {
@@ -9,13 +9,12 @@ export const count = 10;
9
9
  const rebillyDefinitionRef = pathResolve(pathJoin(__dirname, 'rebilly.yaml'));
10
10
  const rebillyDocument = parseYamlToDocument(
11
11
  readFileSync(rebillyDefinitionRef, 'utf-8'),
12
- rebillyDefinitionRef,
12
+ rebillyDefinitionRef
13
13
  );
14
14
 
15
15
  const config = makeConfigForRuleset({
16
16
  test: () => {
17
17
  return {
18
- // @ts-ignore
19
18
  Schema(schema, ctx) {
20
19
  if (schema.type === 'number') {
21
20
  ctx.report({
@@ -8,7 +8,7 @@ export const count = 10;
8
8
  const rebillyDefinitionRef = pathResolve(pathJoin(__dirname, 'rebilly.yaml'));
9
9
  const rebillyDocument = parseYamlToDocument(
10
10
  readFileSync(rebillyDefinitionRef, 'utf-8'),
11
- rebillyDefinitionRef,
11
+ rebillyDefinitionRef
12
12
  );
13
13
 
14
14
  const config = makeConfigForRuleset({
@@ -1,7 +1,7 @@
1
1
  import { readFileSync } from 'fs';
2
2
  import { join as pathJoin, resolve as pathResolve } from 'path';
3
3
  import { lintDocument } from '../../lint';
4
- import { LintConfig, defaultPlugin, resolvePreset } from '../../config';
4
+ import { StyleguideConfig, defaultPlugin, resolvePreset } from '../../config';
5
5
  import { BaseResolver } from '../../resolve';
6
6
  import { parseYamlToDocument } from '../utils';
7
7
 
@@ -10,13 +10,13 @@ export const count = 10;
10
10
  const rebillyDefinitionRef = pathResolve(pathJoin(__dirname, 'rebilly.yaml'));
11
11
  const rebillyDocument = parseYamlToDocument(
12
12
  readFileSync(rebillyDefinitionRef, 'utf-8'),
13
- rebillyDefinitionRef,
13
+ rebillyDefinitionRef
14
14
  );
15
15
 
16
16
  export function measureAsync() {
17
17
  return lintDocument({
18
18
  externalRefResolver: new BaseResolver(),
19
19
  document: rebillyDocument,
20
- config: new LintConfig(resolvePreset('recommended', [defaultPlugin])),
20
+ config: new StyleguideConfig(resolvePreset('recommended', [defaultPlugin])),
21
21
  });
22
22
  }
@@ -10,7 +10,7 @@ export const count = 10;
10
10
  const rebillyDefinitionRef = path.resolve(path.join(__dirname, 'rebilly.yaml'));
11
11
  const rebillyDocument = parseYamlToDocument(
12
12
  readFileSync(rebillyDefinitionRef, 'utf-8'),
13
- rebillyDefinitionRef,
13
+ rebillyDefinitionRef
14
14
  );
15
15
  const externalRefResolver = new BaseResolver();
16
16
 
@@ -31,7 +31,7 @@ function prepareRevision(revision) {
31
31
  const hash = exec(`git rev-parse "${revision}"`);
32
32
  const dir = path.join(os.tmpdir(), 'redocly-cli-benchmark', hash);
33
33
  if (fs.existsSync(dir)) {
34
- fs.rmdirSync(dir, { recursive: true});
34
+ fs.rmdirSync(dir, { recursive: true });
35
35
  }
36
36
  fs.mkdirSync(dir, { recursive: true });
37
37
 
@@ -48,7 +48,10 @@ function tscBuild(dir) {
48
48
  process.chdir(dir);
49
49
  execSync('npm run compile', { stdio: 'inherit' });
50
50
  exec(
51
- `cp ${path.join(dir, 'packages/core/src/benchmark/benches/*.yaml')} ${path.join(dir, 'packages/core/lib/benchmark/benches/')}`,
51
+ `cp ${path.join(dir, 'packages/core/src/benchmark/benches/*.yaml')} ${path.join(
52
+ dir,
53
+ 'packages/core/lib/benchmark/benches/'
54
+ )}`
52
55
  );
53
56
  process.chdir(oldCwd);
54
57
  return path.join(dir, 'packages/core/lib/benchmark/benches');
@@ -70,7 +73,8 @@ async function collectSamples(modulePath) {
70
73
 
71
74
  // T-Distribution two-tailed critical values for 95% confidence.
72
75
  // See http://www.itl.nist.gov/div898/handbook/eda/section3/eda3672.htm.
73
- const tTable = /* prettier-ignore */ {
76
+ const tTable =
77
+ /* prettier-ignore */ {
74
78
  '1': 12.706, '2': 4.303, '3': 3.182, '4': 2.776, '5': 2.571, '6': 2.447,
75
79
  '7': 2.365, '8': 2.306, '9': 2.262, '10': 2.228, '11': 2.201, '12': 2.179,
76
80
  '13': 2.16, '14': 2.145, '15': 2.131, '16': 2.12, '17': 2.11, '18': 2.101,
@@ -150,7 +154,7 @@ function beautifyBenchmark(results) {
150
154
  grey(' x ') +
151
155
  memPerOpStr() +
152
156
  '/op' +
153
- grey(' (' + numSamples + ' runs sampled)'),
157
+ grey(' (' + numSamples + ' runs sampled)')
154
158
  );
155
159
 
156
160
  function nameStr() {
@@ -255,7 +259,7 @@ function matchBenchmarks(patterns) {
255
259
  let benchmarks = findFiles(LOCAL_DIR('../lib/benchmark/benches'), '*.bench.js');
256
260
  if (patterns.length > 0) {
257
261
  benchmarks = benchmarks.filter((benchmark) =>
258
- patterns.some((pattern) => path.join('../lib/benchmark/benches', benchmark).includes(pattern)),
262
+ patterns.some((pattern) => path.join('../lib/benchmark/benches', benchmark).includes(pattern))
259
263
  );
260
264
  }
261
265
 
@@ -1,9 +1,9 @@
1
1
  import { parseYaml } from '../js-yaml';
2
2
  import { Document, Source } from '../resolve';
3
3
  import { Oas3RuleSet } from '../oas-types';
4
- import { LintConfig, mergeExtends, resolvePlugins } from '../config';
4
+ import { StyleguideConfig, mergeExtends, resolvePlugins } from '../config';
5
5
 
6
- import type { RuleConfig, Plugin, ResolvedLintConfig } from '../config/types';
6
+ import type { RuleConfig, Plugin, ResolvedStyleguideConfig } from '../config/types';
7
7
 
8
8
  export function parseYamlToDocument(body: string, absoluteRef: string = ''): Document {
9
9
  return {
@@ -25,12 +25,12 @@ export function makeConfigForRuleset(rules: Oas3RuleSet, plugin?: Partial<Plugin
25
25
  id: ruleId,
26
26
  rules: { oas3: rules },
27
27
  },
28
- ]) as ResolvedLintConfig,
28
+ ]) as ResolvedStyleguideConfig,
29
29
  ];
30
30
  if (rules) {
31
31
  extendConfigs.push({ rules });
32
32
  }
33
- const lint = mergeExtends(extendConfigs);
33
+ const styleguide = mergeExtends(extendConfigs);
34
34
 
35
- return new LintConfig(lint);
35
+ return new StyleguideConfig(styleguide);
36
36
  }
package/src/bundle.ts CHANGED
@@ -7,16 +7,16 @@ import { Oas3_1Types } from './types/oas3_1';
7
7
  import { NormalizedNodeType, normalizeTypes, NodeType } from './types';
8
8
  import { WalkContext, walkDocument, UserContext, ResolveResult } from './walk';
9
9
  import { detectOpenAPI, openAPIMajor, OasMajorVersion } from './oas-types';
10
- import {isAbsoluteUrl, isRef, Location, refBaseName} from './ref-utils';
10
+ import { isAbsoluteUrl, isRef, Location, refBaseName } from './ref-utils';
11
11
  import { initRules } from './config/rules';
12
12
  import { reportUnresolvedRef } from './rules/no-unresolved-refs';
13
- import { isPlainObject } from './utils';
13
+ import { isPlainObject, isTruthy } from './utils';
14
14
  import { OasRef } from './typings/openapi';
15
15
  import { isRedoclyRegistryURL } from './redocly';
16
16
  import { RemoveUnusedComponents as RemoveUnusedComponentsOas2 } from './rules/oas2/remove-unused-components';
17
17
  import { RemoveUnusedComponents as RemoveUnusedComponentsOas3 } from './rules/oas3/remove-unused-components';
18
18
 
19
- import type { Config, LintConfig } from './config';
19
+ import type { Config, StyleguideConfig } from './config';
20
20
 
21
21
  export type Oas3RuleSet = Record<string, Oas3Rule>;
22
22
 
@@ -57,7 +57,7 @@ export async function bundle(opts: {
57
57
  return bundleDocument({
58
58
  document,
59
59
  ...opts,
60
- config: opts.config.lint,
60
+ config: opts.config.styleguide,
61
61
  externalRefResolver,
62
62
  });
63
63
  }
@@ -66,7 +66,7 @@ type BundleContext = WalkContext;
66
66
 
67
67
  export async function bundleDocument(opts: {
68
68
  document: Document;
69
- config: LintConfig;
69
+ config: StyleguideConfig;
70
70
  customTypes?: Record<string, NodeType>;
71
71
  externalRefResolver: BaseResolver;
72
72
  dereference?: boolean;
@@ -94,9 +94,9 @@ export async function bundleDocument(opts: {
94
94
  ? Oas3_1Types
95
95
  : Oas3Types
96
96
  : Oas2Types,
97
- oasVersion,
97
+ oasVersion
98
98
  ),
99
- config,
99
+ config
100
100
  );
101
101
 
102
102
  const preprocessors = initRules(rules as any, config, 'preprocessors', oasVersion);
@@ -113,10 +113,11 @@ export async function bundleDocument(opts: {
113
113
  decorators.push({
114
114
  severity: 'error',
115
115
  ruleId: 'remove-unused-components',
116
- visitor: oasMajorVersion === OasMajorVersion.Version2
117
- ? RemoveUnusedComponentsOas2({})
118
- : RemoveUnusedComponentsOas3({})
119
- })
116
+ visitor:
117
+ oasMajorVersion === OasMajorVersion.Version2
118
+ ? RemoveUnusedComponentsOas2({})
119
+ : RemoveUnusedComponentsOas3({}),
120
+ });
120
121
  }
121
122
 
122
123
  const resolvedRefMap = await resolveDocument({
@@ -137,12 +138,12 @@ export async function bundleDocument(opts: {
137
138
  skipRedoclyRegistryRefs,
138
139
  document,
139
140
  resolvedRefMap,
140
- keepUrlRefs,
141
+ keepUrlRefs
141
142
  ),
142
143
  },
143
144
  ...decorators,
144
145
  ] as any,
145
- types,
146
+ types
146
147
  );
147
148
 
148
149
  walkDocument({
@@ -210,7 +211,7 @@ function makeBundleVisitor(
210
211
  skipRedoclyRegistryRefs: boolean,
211
212
  rootDocument: Document,
212
213
  resolvedRefMap: ResolvedRefMap,
213
- keepUrlRefs: boolean,
214
+ keepUrlRefs: boolean
214
215
  ) {
215
216
  let components: Record<string, Record<string, any>>;
216
217
 
@@ -287,7 +288,7 @@ function makeBundleVisitor(
287
288
  }
288
289
 
289
290
  function resolveBundledComponent(node: OasRef, resolved: ResolveResult<any>, ctx: UserContext) {
290
- const newRefId = makeRefId(ctx.location.source.absoluteRef, node.$ref)
291
+ const newRefId = makeRefId(ctx.location.source.absoluteRef, node.$ref);
291
292
  resolvedRefMap.set(newRefId, {
292
293
  document: rootDocument,
293
294
  isRemote: false,
@@ -301,16 +302,19 @@ function makeBundleVisitor(
301
302
  if (!isPlainObject(resolved.node)) {
302
303
  ctx.parent[ctx.key] = resolved.node;
303
304
  } else {
305
+ // TODO: why $ref isn't optional in OasRef?
306
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
304
307
  // @ts-ignore
305
308
  delete ref.$ref;
306
- Object.assign(ref, resolved.node);
309
+ const obj = Object.assign({}, resolved.node, ref);
310
+ Object.assign(ref, obj); // assign ref itself again so ref fields take precedence
307
311
  }
308
312
  }
309
313
 
310
314
  function saveComponent(
311
315
  componentType: string,
312
316
  target: { node: any; location: Location },
313
- ctx: UserContext,
317
+ ctx: UserContext
314
318
  ) {
315
319
  components[componentType] = components[componentType] || {};
316
320
  const name = getComponentName(target, componentType, ctx);
@@ -325,7 +329,7 @@ function makeBundleVisitor(
325
329
  function isEqualOrEqualRef(
326
330
  node: any,
327
331
  target: { node: any; location: Location },
328
- ctx: UserContext,
332
+ ctx: UserContext
329
333
  ) {
330
334
  if (
331
335
  isRef(node) &&
@@ -340,14 +344,14 @@ function makeBundleVisitor(
340
344
  function getComponentName(
341
345
  target: { node: any; location: Location },
342
346
  componentType: string,
343
- ctx: UserContext,
347
+ ctx: UserContext
344
348
  ) {
345
349
  const [fileRef, pointer] = [target.location.source.absoluteRef, target.location.pointer];
346
350
  const componentsGroup = components[componentType];
347
351
 
348
352
  let name = '';
349
353
 
350
- const refParts = pointer.slice(2).split('/').filter(Boolean); // slice(2) removes "#/"
354
+ const refParts = pointer.slice(2).split('/').filter(isTruthy); // slice(2) removes "#/"
351
355
  while (refParts.length > 0) {
352
356
  name = refParts.pop() + (name ? `-${name}` : '');
353
357
  if (