@redocly/openapi-core 1.0.0-beta.98 → 1.0.0-rc.1

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 (380) hide show
  1. package/README.md +6 -6
  2. package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +0 -1
  3. package/lib/benchmark/benches/recommended-oas3.bench.js +1 -1
  4. package/lib/benchmark/benches/resolve-with-no-external.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 +12 -15
  8. package/lib/bundle.js +38 -15
  9. package/lib/config/all.d.ts +2 -2
  10. package/lib/config/all.js +17 -6
  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 +121 -66
  15. package/lib/config/config.d.ts +12 -18
  16. package/lib/config/config.js +42 -26
  17. package/lib/config/load.d.ts +16 -3
  18. package/lib/config/load.js +36 -14
  19. package/lib/config/minimal.d.ts +2 -2
  20. package/lib/config/minimal.js +10 -6
  21. package/lib/config/recommended.d.ts +2 -2
  22. package/lib/config/recommended.js +10 -6
  23. package/lib/config/rules.d.ts +7 -4
  24. package/lib/config/rules.js +5 -4
  25. package/lib/config/types.d.ts +72 -23
  26. package/lib/config/types.js +13 -0
  27. package/lib/config/utils.d.ts +6 -5
  28. package/lib/config/utils.js +110 -32
  29. package/lib/decorators/common/filters/filter-helper.d.ts +3 -0
  30. package/lib/decorators/common/filters/filter-helper.js +67 -0
  31. package/lib/decorators/common/filters/filter-in.d.ts +2 -0
  32. package/lib/decorators/common/filters/filter-in.js +17 -0
  33. package/lib/decorators/common/filters/filter-out.d.ts +2 -0
  34. package/lib/decorators/common/filters/filter-out.js +17 -0
  35. package/lib/decorators/common/info-override.d.ts +2 -0
  36. package/lib/decorators/common/info-override.js +28 -0
  37. package/lib/decorators/common/media-type-examples-override.d.ts +2 -0
  38. package/lib/decorators/common/media-type-examples-override.js +53 -0
  39. package/lib/decorators/common/registry-dependencies.js +2 -2
  40. package/lib/decorators/common/remove-x-internal.js +2 -2
  41. package/lib/decorators/oas2/index.d.ts +3 -0
  42. package/lib/decorators/oas2/index.js +7 -1
  43. package/lib/decorators/oas3/index.d.ts +4 -0
  44. package/lib/decorators/oas3/index.js +9 -1
  45. package/lib/env.d.ts +3 -0
  46. package/lib/env.js +8 -0
  47. package/lib/format/codeframes.js +16 -10
  48. package/lib/format/format.d.ts +1 -1
  49. package/lib/format/format.js +64 -32
  50. package/lib/index.d.ts +6 -6
  51. package/lib/index.js +7 -2
  52. package/lib/js-yaml/index.js +2 -6
  53. package/lib/lint.d.ts +4 -2
  54. package/lib/lint.js +36 -11
  55. package/lib/logger.d.ts +10 -0
  56. package/lib/logger.js +31 -0
  57. package/lib/output.d.ts +3 -0
  58. package/lib/output.js +9 -0
  59. package/lib/redocly/index.js +10 -9
  60. package/lib/redocly/registry-api-types.d.ts +28 -28
  61. package/lib/redocly/registry-api.d.ts +3 -3
  62. package/lib/redocly/registry-api.js +10 -2
  63. package/lib/ref-utils.d.ts +1 -0
  64. package/lib/ref-utils.js +8 -2
  65. package/lib/resolve.d.ts +1 -1
  66. package/lib/resolve.js +33 -3
  67. package/lib/rules/ajv.d.ts +2 -2
  68. package/lib/rules/ajv.js +12 -12
  69. package/lib/rules/common/assertions/asserts.d.ts +29 -4
  70. package/lib/rules/common/assertions/asserts.js +227 -97
  71. package/lib/rules/common/assertions/index.d.ts +27 -2
  72. package/lib/rules/common/assertions/index.js +9 -37
  73. package/lib/rules/common/assertions/utils.d.ts +16 -8
  74. package/lib/rules/common/assertions/utils.js +160 -76
  75. package/lib/rules/common/info-license-url.d.ts +1 -1
  76. package/lib/rules/common/info-license-url.js +5 -10
  77. package/lib/rules/common/info-license.d.ts +2 -0
  78. package/lib/rules/common/info-license.js +17 -0
  79. package/lib/rules/common/no-ambiguous-paths.js +1 -1
  80. package/lib/rules/common/no-enum-type-mismatch.js +1 -3
  81. package/lib/rules/common/no-identical-paths.js +4 -4
  82. package/lib/rules/common/no-invalid-parameter-examples.js +3 -3
  83. package/lib/rules/common/no-invalid-schema-examples.js +3 -3
  84. package/lib/rules/common/operation-2xx-response.js +15 -9
  85. package/lib/rules/common/operation-4xx-response.js +15 -9
  86. package/lib/rules/common/operation-operationId.js +2 -2
  87. package/lib/rules/common/operation-tag-defined.js +1 -1
  88. package/lib/rules/common/path-not-include-query.js +2 -2
  89. package/lib/rules/common/path-params-defined.js +7 -2
  90. package/lib/rules/common/paths-kebab-case.js +4 -1
  91. package/lib/rules/common/required-string-property-missing-min-length.d.ts +2 -0
  92. package/lib/rules/common/required-string-property-missing-min-length.js +37 -0
  93. package/lib/rules/common/response-contains-header.d.ts +2 -0
  94. package/lib/rules/common/response-contains-header.js +29 -0
  95. package/lib/rules/common/scalar-property-missing-example.d.ts +2 -0
  96. package/lib/rules/common/scalar-property-missing-example.js +42 -0
  97. package/lib/rules/common/security-defined.d.ts +2 -0
  98. package/lib/rules/common/{operation-security-defined.js → security-defined.js} +25 -6
  99. package/lib/rules/common/spec-strict-refs.d.ts +2 -0
  100. package/lib/rules/common/spec-strict-refs.js +30 -0
  101. package/lib/rules/common/spec.js +41 -18
  102. package/lib/rules/common/tags-alphabetical.js +1 -1
  103. package/lib/rules/oas2/index.d.ts +6 -2
  104. package/lib/rules/oas2/index.js +16 -8
  105. package/lib/rules/oas2/remove-unused-components.js +6 -6
  106. package/lib/rules/oas2/request-mime-type.d.ts +1 -1
  107. package/lib/rules/oas2/request-mime-type.js +1 -1
  108. package/lib/rules/oas2/response-contains-property.d.ts +2 -0
  109. package/lib/rules/oas2/response-contains-property.js +38 -0
  110. package/lib/rules/oas2/response-mime-type.d.ts +1 -1
  111. package/lib/rules/oas2/response-mime-type.js +1 -1
  112. package/lib/rules/oas3/component-name-unique.d.ts +2 -0
  113. package/lib/rules/oas3/component-name-unique.js +124 -0
  114. package/lib/rules/oas3/index.js +24 -10
  115. package/lib/rules/oas3/no-empty-servers.js +2 -2
  116. package/lib/rules/oas3/no-invalid-media-type-examples.js +2 -2
  117. package/lib/rules/oas3/no-server-variables-empty-enum.d.ts +2 -0
  118. package/lib/rules/oas3/{no-servers-empty-enum.js → no-server-variables-empty-enum.js} +5 -5
  119. package/lib/rules/oas3/no-unused-components.js +2 -2
  120. package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.d.ts +5 -0
  121. package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.js +36 -0
  122. package/lib/rules/oas3/remove-unused-components.js +6 -6
  123. package/lib/rules/oas3/request-mime-type.d.ts +1 -1
  124. package/lib/rules/oas3/request-mime-type.js +1 -1
  125. package/lib/rules/oas3/response-contains-property.d.ts +2 -0
  126. package/lib/rules/oas3/response-contains-property.js +40 -0
  127. package/lib/rules/oas3/response-mime-type.d.ts +1 -1
  128. package/lib/rules/oas3/response-mime-type.js +1 -1
  129. package/lib/rules/oas3/spec-components-invalid-map-name.d.ts +2 -0
  130. package/lib/rules/oas3/spec-components-invalid-map-name.js +62 -0
  131. package/lib/rules/other/stats.d.ts +2 -2
  132. package/lib/rules/other/stats.js +45 -16
  133. package/lib/rules/utils.d.ts +5 -2
  134. package/lib/rules/utils.js +54 -6
  135. package/lib/types/config-external-schemas.d.ts +2193 -0
  136. package/lib/types/config-external-schemas.js +805 -0
  137. package/lib/types/index.d.ts +3 -2
  138. package/lib/types/index.js +9 -1
  139. package/lib/types/oas2.js +91 -15
  140. package/lib/types/oas3.js +139 -49
  141. package/lib/types/oas3_1.js +32 -26
  142. package/lib/types/redocly-yaml.js +414 -58
  143. package/lib/typings/openapi.d.ts +3 -2
  144. package/lib/utils.d.ts +15 -3
  145. package/lib/utils.js +73 -7
  146. package/lib/visitors.d.ts +20 -16
  147. package/lib/visitors.js +28 -3
  148. package/lib/walk.d.ts +11 -19
  149. package/lib/walk.js +74 -53
  150. package/package.json +5 -6
  151. package/__tests__/__snapshots__/bundle.test.ts.snap +0 -229
  152. package/__tests__/bundle.test.ts +0 -132
  153. package/__tests__/codeframes.test.ts +0 -531
  154. package/__tests__/fixtures/extension.js +0 -24
  155. package/__tests__/fixtures/refs/definitions.yaml +0 -3
  156. package/__tests__/fixtures/refs/examples.yaml +0 -8
  157. package/__tests__/fixtures/refs/external-request-body.yaml +0 -13
  158. package/__tests__/fixtures/refs/externalref.yaml +0 -35
  159. package/__tests__/fixtures/refs/hosted.yaml +0 -35
  160. package/__tests__/fixtures/refs/openapi-with-external-refs-conflicting-names.yaml +0 -21
  161. package/__tests__/fixtures/refs/openapi-with-external-refs.yaml +0 -33
  162. package/__tests__/fixtures/refs/param-b.yaml +0 -1
  163. package/__tests__/fixtures/refs/param-c.yaml +0 -1
  164. package/__tests__/fixtures/refs/rename.yaml +0 -1
  165. package/__tests__/fixtures/refs/requestBody.yaml +0 -9
  166. package/__tests__/fixtures/refs/schema-a.yaml +0 -1
  167. package/__tests__/fixtures/refs/simple.yaml +0 -1
  168. package/__tests__/fixtures/refs/vendor.schema.yaml +0 -20
  169. package/__tests__/fixtures/resolve/External.yaml +0 -10
  170. package/__tests__/fixtures/resolve/External2.yaml +0 -4
  171. package/__tests__/fixtures/resolve/description.md +0 -3
  172. package/__tests__/fixtures/resolve/externalInfo.yaml +0 -4
  173. package/__tests__/fixtures/resolve/externalLicense.yaml +0 -1
  174. package/__tests__/fixtures/resolve/openapi-with-back.yaml +0 -13
  175. package/__tests__/fixtures/resolve/openapi-with-md-description.yaml +0 -5
  176. package/__tests__/fixtures/resolve/openapi.yaml +0 -28
  177. package/__tests__/fixtures/resolve/schemas/type-a.yaml +0 -10
  178. package/__tests__/fixtures/resolve/schemas/type-b.yaml +0 -6
  179. package/__tests__/fixtures/resolve/transitive/a.yaml +0 -1
  180. package/__tests__/fixtures/resolve/transitive/components.yaml +0 -5
  181. package/__tests__/fixtures/resolve/transitive/schemas.yaml +0 -3
  182. package/__tests__/lint.test.ts +0 -17
  183. package/__tests__/login.test.ts +0 -17
  184. package/__tests__/normalizeVisitors.test.ts +0 -151
  185. package/__tests__/ref-utils.test.ts +0 -120
  186. package/__tests__/resolve-http.test.ts +0 -77
  187. package/__tests__/resolve.test.ts +0 -405
  188. package/__tests__/utils.ts +0 -86
  189. package/__tests__/walk.test.ts +0 -1485
  190. package/lib/rules/common/info-description.d.ts +0 -2
  191. package/lib/rules/common/info-description.js +0 -12
  192. package/lib/rules/common/license-url.d.ts +0 -2
  193. package/lib/rules/common/license-url.js +0 -12
  194. package/lib/rules/common/operation-security-defined.d.ts +0 -2
  195. package/lib/rules/oas3/no-servers-empty-enum.d.ts +0 -2
  196. package/src/__tests__/js-yaml.test.ts +0 -71
  197. package/src/__tests__/lint.test.ts +0 -182
  198. package/src/__tests__/utils.test.ts +0 -74
  199. package/src/benchmark/benches/lint-with-many-rules.bench.ts +0 -35
  200. package/src/benchmark/benches/lint-with-nested-rule.bench.ts +0 -39
  201. package/src/benchmark/benches/lint-with-no-rules.bench.ts +0 -20
  202. package/src/benchmark/benches/lint-with-top-level-rule-report.bench.ts +0 -36
  203. package/src/benchmark/benches/lint-with-top-level-rule.bench.ts +0 -32
  204. package/src/benchmark/benches/rebilly.yaml +0 -32267
  205. package/src/benchmark/benches/recommended-oas3.bench.ts +0 -22
  206. package/src/benchmark/benches/resolve-with-no-external.bench.ts +0 -23
  207. package/src/benchmark/benchmark.js +0 -307
  208. package/src/benchmark/colors.js +0 -29
  209. package/src/benchmark/fork.js +0 -83
  210. package/src/benchmark/utils.ts +0 -36
  211. package/src/bundle.ts +0 -371
  212. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +0 -157
  213. package/src/config/__tests__/config-resolvers.test.ts +0 -429
  214. package/src/config/__tests__/config.test.ts +0 -244
  215. package/src/config/__tests__/fixtures/plugin-config.yaml +0 -3
  216. package/src/config/__tests__/fixtures/plugin.js +0 -56
  217. package/src/config/__tests__/fixtures/resolve-config/api/nested-config.yaml +0 -12
  218. package/src/config/__tests__/fixtures/resolve-config/api/plugin.js +0 -67
  219. package/src/config/__tests__/fixtures/resolve-config/local-config-with-circular.yaml +0 -8
  220. package/src/config/__tests__/fixtures/resolve-config/local-config-with-file.yaml +0 -19
  221. package/src/config/__tests__/fixtures/resolve-config/local-config.yaml +0 -10
  222. package/src/config/__tests__/fixtures/resolve-config/plugin.js +0 -66
  223. package/src/config/__tests__/fixtures/resolve-remote-configs/nested-remote-config.yaml +0 -4
  224. package/src/config/__tests__/fixtures/resolve-remote-configs/remote-config.yaml +0 -5
  225. package/src/config/__tests__/load.test.ts +0 -83
  226. package/src/config/__tests__/resolve-plugins.test.ts +0 -27
  227. package/src/config/all.ts +0 -65
  228. package/src/config/builtIn.ts +0 -37
  229. package/src/config/config-resolvers.ts +0 -359
  230. package/src/config/config.ts +0 -312
  231. package/src/config/index.ts +0 -7
  232. package/src/config/load.ts +0 -84
  233. package/src/config/minimal.ts +0 -58
  234. package/src/config/recommended.ts +0 -58
  235. package/src/config/rules.ts +0 -46
  236. package/src/config/types.ts +0 -168
  237. package/src/config/utils.ts +0 -208
  238. package/src/decorators/__tests__/remove-x-internal.test.ts +0 -316
  239. package/src/decorators/common/info-description-override.ts +0 -24
  240. package/src/decorators/common/operation-description-override.ts +0 -30
  241. package/src/decorators/common/registry-dependencies.ts +0 -25
  242. package/src/decorators/common/remove-x-internal.ts +0 -59
  243. package/src/decorators/common/tag-description-override.ts +0 -25
  244. package/src/decorators/oas2/index.ts +0 -14
  245. package/src/decorators/oas3/index.ts +0 -14
  246. package/src/format/codeframes.ts +0 -210
  247. package/src/format/format.ts +0 -339
  248. package/src/index.ts +0 -68
  249. package/src/js-yaml/index.ts +0 -18
  250. package/src/lint.ts +0 -125
  251. package/src/oas-types.ts +0 -62
  252. package/src/redocly/__tests__/redocly-client.test.ts +0 -140
  253. package/src/redocly/index.ts +0 -182
  254. package/src/redocly/redocly-client-types.ts +0 -10
  255. package/src/redocly/registry-api-types.ts +0 -32
  256. package/src/redocly/registry-api.ts +0 -134
  257. package/src/ref-utils.ts +0 -79
  258. package/src/resolve.ts +0 -378
  259. package/src/rules/__tests__/fixtures/invalid-yaml.yaml +0 -1
  260. package/src/rules/__tests__/fixtures/ref.yaml +0 -1
  261. package/src/rules/__tests__/no-unresolved-refs.test.ts +0 -168
  262. package/src/rules/ajv.ts +0 -103
  263. package/src/rules/common/__tests__/info-description.test.ts +0 -102
  264. package/src/rules/common/__tests__/info-license.test.ts +0 -62
  265. package/src/rules/common/__tests__/license-url.test.ts +0 -63
  266. package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +0 -96
  267. package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +0 -209
  268. package/src/rules/common/__tests__/no-identical-paths.test.ts +0 -58
  269. package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +0 -85
  270. package/src/rules/common/__tests__/operation-2xx-response.test.ts +0 -91
  271. package/src/rules/common/__tests__/operation-4xx-response.test.ts +0 -107
  272. package/src/rules/common/__tests__/operation-operationId-unique.test.ts +0 -76
  273. package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +0 -45
  274. package/src/rules/common/__tests__/operation-parameters-unique.test.ts +0 -167
  275. package/src/rules/common/__tests__/operation-security-defined.test.ts +0 -69
  276. package/src/rules/common/__tests__/operation-singular-tag.test.ts +0 -72
  277. package/src/rules/common/__tests__/path-http-verbs-order.test.ts +0 -95
  278. package/src/rules/common/__tests__/path-not-include-query.test.ts +0 -64
  279. package/src/rules/common/__tests__/path-params-defined.test.ts +0 -133
  280. package/src/rules/common/__tests__/paths-kebab-case.test.ts +0 -108
  281. package/src/rules/common/__tests__/spec.test.ts +0 -62
  282. package/src/rules/common/__tests__/tag-description.test.ts +0 -65
  283. package/src/rules/common/__tests__/tags-alphabetical.test.ts +0 -64
  284. package/src/rules/common/assertions/__tests__/asserts.test.ts +0 -231
  285. package/src/rules/common/assertions/__tests__/index.test.ts +0 -65
  286. package/src/rules/common/assertions/__tests__/utils.test.ts +0 -89
  287. package/src/rules/common/assertions/asserts.ts +0 -137
  288. package/src/rules/common/assertions/index.ts +0 -75
  289. package/src/rules/common/assertions/utils.ts +0 -167
  290. package/src/rules/common/info-contact.ts +0 -15
  291. package/src/rules/common/info-description.ts +0 -10
  292. package/src/rules/common/info-license-url.ts +0 -15
  293. package/src/rules/common/license-url.ts +0 -10
  294. package/src/rules/common/no-ambiguous-paths.ts +0 -50
  295. package/src/rules/common/no-enum-type-mismatch.ts +0 -49
  296. package/src/rules/common/no-http-verbs-in-paths.ts +0 -36
  297. package/src/rules/common/no-identical-paths.ts +0 -24
  298. package/src/rules/common/no-invalid-parameter-examples.ts +0 -36
  299. package/src/rules/common/no-invalid-schema-examples.ts +0 -27
  300. package/src/rules/common/no-path-trailing-slash.ts +0 -15
  301. package/src/rules/common/operation-2xx-response.ts +0 -16
  302. package/src/rules/common/operation-4xx-response.ts +0 -17
  303. package/src/rules/common/operation-description.ts +0 -13
  304. package/src/rules/common/operation-operationId-unique.ts +0 -21
  305. package/src/rules/common/operation-operationId-url-safe.ts +0 -19
  306. package/src/rules/common/operation-operationId.ts +0 -17
  307. package/src/rules/common/operation-parameters-unique.ts +0 -48
  308. package/src/rules/common/operation-security-defined.ts +0 -45
  309. package/src/rules/common/operation-singular-tag.ts +0 -17
  310. package/src/rules/common/operation-summary.ts +0 -13
  311. package/src/rules/common/operation-tag-defined.ts +0 -26
  312. package/src/rules/common/parameter-description.ts +0 -22
  313. package/src/rules/common/path-declaration-must-exist.ts +0 -15
  314. package/src/rules/common/path-excludes-patterns.ts +0 -23
  315. package/src/rules/common/path-http-verbs-order.ts +0 -30
  316. package/src/rules/common/path-not-include-query.ts +0 -17
  317. package/src/rules/common/path-params-defined.ts +0 -58
  318. package/src/rules/common/path-segment-plural.ts +0 -31
  319. package/src/rules/common/paths-kebab-case.ts +0 -16
  320. package/src/rules/common/spec.ts +0 -143
  321. package/src/rules/common/tag-description.ts +0 -10
  322. package/src/rules/common/tags-alphabetical.ts +0 -20
  323. package/src/rules/no-unresolved-refs.ts +0 -51
  324. package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +0 -110
  325. package/src/rules/oas2/__tests__/spec/fixtures/description.md +0 -1
  326. package/src/rules/oas2/__tests__/spec/info.test.ts +0 -355
  327. package/src/rules/oas2/__tests__/spec/operation.test.ts +0 -123
  328. package/src/rules/oas2/__tests__/spec/paths.test.ts +0 -245
  329. package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +0 -31
  330. package/src/rules/oas2/__tests__/spec/utils.ts +0 -32
  331. package/src/rules/oas2/boolean-parameter-prefixes.ts +0 -26
  332. package/src/rules/oas2/index.ts +0 -83
  333. package/src/rules/oas2/remove-unused-components.ts +0 -76
  334. package/src/rules/oas2/request-mime-type.ts +0 -17
  335. package/src/rules/oas2/response-mime-type.ts +0 -17
  336. package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +0 -111
  337. package/src/rules/oas3/__tests__/fixtures/common.yaml +0 -11
  338. package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +0 -205
  339. package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +0 -65
  340. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +0 -392
  341. package/src/rules/oas3/__tests__/no-server-example.com.test.ts +0 -60
  342. package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +0 -79
  343. package/src/rules/oas3/__tests__/no-unused-components.test.ts +0 -131
  344. package/src/rules/oas3/__tests__/spec/callbacks.test.ts +0 -41
  345. package/src/rules/oas3/__tests__/spec/fixtures/description.md +0 -1
  346. package/src/rules/oas3/__tests__/spec/info.test.ts +0 -391
  347. package/src/rules/oas3/__tests__/spec/operation.test.ts +0 -253
  348. package/src/rules/oas3/__tests__/spec/paths.test.ts +0 -284
  349. package/src/rules/oas3/__tests__/spec/referenceableScalars.test.ts +0 -77
  350. package/src/rules/oas3/__tests__/spec/servers.test.ts +0 -499
  351. package/src/rules/oas3/__tests__/spec/spec.test.ts +0 -288
  352. package/src/rules/oas3/__tests__/spec/utils.ts +0 -32
  353. package/src/rules/oas3/boolean-parameter-prefixes.ts +0 -28
  354. package/src/rules/oas3/index.ts +0 -99
  355. package/src/rules/oas3/no-empty-servers.ts +0 -22
  356. package/src/rules/oas3/no-example-value-and-externalValue.ts +0 -14
  357. package/src/rules/oas3/no-invalid-media-type-examples.ts +0 -41
  358. package/src/rules/oas3/no-server-example.com.ts +0 -14
  359. package/src/rules/oas3/no-server-trailing-slash.ts +0 -15
  360. package/src/rules/oas3/no-servers-empty-enum.ts +0 -67
  361. package/src/rules/oas3/no-undefined-server-variable.ts +0 -30
  362. package/src/rules/oas3/no-unused-components.ts +0 -75
  363. package/src/rules/oas3/remove-unused-components.ts +0 -84
  364. package/src/rules/oas3/request-mime-type.ts +0 -31
  365. package/src/rules/oas3/response-mime-type.ts +0 -31
  366. package/src/rules/other/stats.ts +0 -44
  367. package/src/rules/utils.ts +0 -123
  368. package/src/types/index.ts +0 -138
  369. package/src/types/oas2.ts +0 -397
  370. package/src/types/oas3.ts +0 -506
  371. package/src/types/oas3_1.ts +0 -251
  372. package/src/types/redocly-yaml.ts +0 -637
  373. package/src/typings/common.ts +0 -9
  374. package/src/typings/openapi.ts +0 -297
  375. package/src/typings/swagger.ts +0 -236
  376. package/src/utils.ts +0 -190
  377. package/src/visitors.ts +0 -448
  378. package/src/walk.ts +0 -416
  379. package/tsconfig.json +0 -8
  380. package/tsconfig.tsbuildinfo +0 -1
@@ -2,20 +2,22 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.formatProblems = exports.getTotals = void 0;
4
4
  const path = require("path");
5
- const colorette_1 = require("colorette");
5
+ const logger_1 = require("../logger");
6
+ const output_1 = require("../output");
6
7
  const coreVersion = require('../../package.json').version;
7
8
  const codeframes_1 = require("./codeframes");
8
- const config_1 = require("../config");
9
+ const env_1 = require("../env");
10
+ const ref_utils_1 = require("../ref-utils");
9
11
  const ERROR_MESSAGE = {
10
12
  INVALID_SEVERITY_LEVEL: 'Invalid severity level; accepted values: error or warn',
11
13
  };
12
14
  const BG_COLORS = {
13
- warn: (str) => colorette_1.bgYellow(colorette_1.black(str)),
14
- error: colorette_1.bgRed,
15
+ warn: (str) => logger_1.colorize.bgYellow(logger_1.colorize.black(str)),
16
+ error: logger_1.colorize.bgRed,
15
17
  };
16
18
  const COLORS = {
17
- warn: colorette_1.yellow,
18
- error: colorette_1.red,
19
+ warn: logger_1.colorize.yellow,
20
+ error: logger_1.colorize.red,
19
21
  };
20
22
  const SEVERITY_NAMES = {
21
23
  warn: 'Warning',
@@ -51,8 +53,8 @@ function getTotals(problems) {
51
53
  }
52
54
  exports.getTotals = getTotals;
53
55
  function formatProblems(problems, opts) {
54
- const { maxProblems = 100, cwd = process.cwd(), format = 'codeframe', color = colorette_1.options.enabled, totals = getTotals(problems), version = coreVersion, } = opts;
55
- colorette_1.options.enabled = color; // force colors if specified
56
+ const { maxProblems = 100, cwd = process.cwd(), format = 'codeframe', color = logger_1.colorOptions.enabled, totals = getTotals(problems), version = coreVersion, } = opts;
57
+ logger_1.colorOptions.enabled = color; // force colors if specified
56
58
  const totalProblems = problems.length;
57
59
  problems = problems.filter((m) => !m.ignored);
58
60
  const ignoredProblems = totalProblems - problems.length;
@@ -68,39 +70,42 @@ function formatProblems(problems, opts) {
68
70
  case 'codeframe':
69
71
  for (let i = 0; i < problems.length; i++) {
70
72
  const problem = problems[i];
71
- process.stderr.write(`${formatCodeframe(problem, i)}\n`);
73
+ logger_1.logger.info(`${formatCodeframe(problem, i)}\n`);
72
74
  }
73
75
  break;
74
76
  case 'stylish': {
75
77
  const groupedByFile = groupByFiles(problems);
76
78
  for (const [file, { ruleIdPad, locationPad: positionPad, fileProblems }] of Object.entries(groupedByFile)) {
77
- process.stderr.write(`${colorette_1.blue(path.relative(cwd, file))}:\n`);
79
+ logger_1.logger.info(`${logger_1.colorize.blue(ref_utils_1.isAbsoluteUrl(file) ? file : path.relative(cwd, file))}:\n`);
78
80
  for (let i = 0; i < fileProblems.length; i++) {
79
81
  const problem = fileProblems[i];
80
- process.stderr.write(`${formatStylish(problem, positionPad, ruleIdPad)}\n`);
82
+ logger_1.logger.info(`${formatStylish(problem, positionPad, ruleIdPad)}\n`);
81
83
  }
82
- process.stderr.write('\n');
84
+ logger_1.logger.info('\n');
83
85
  }
84
86
  break;
85
87
  }
86
88
  case 'checkstyle': {
87
89
  const groupedByFile = groupByFiles(problems);
88
- process.stdout.write('<?xml version="1.0" encoding="UTF-8"?>\n');
89
- process.stdout.write('<checkstyle version="4.3">\n');
90
+ output_1.output.write('<?xml version="1.0" encoding="UTF-8"?>\n');
91
+ output_1.output.write('<checkstyle version="4.3">\n');
90
92
  for (const [file, { fileProblems }] of Object.entries(groupedByFile)) {
91
- process.stdout.write(`<file name="${xmlEscape(path.relative(cwd, file))}">\n`);
93
+ output_1.output.write(`<file name="${xmlEscape(ref_utils_1.isAbsoluteUrl(file) ? file : path.relative(cwd, file))}">\n`);
92
94
  fileProblems.forEach(formatCheckstyle);
93
- process.stdout.write(`</file>\n`);
95
+ output_1.output.write(`</file>\n`);
94
96
  }
95
- process.stdout.write(`</checkstyle>\n`);
97
+ output_1.output.write(`</checkstyle>\n`);
96
98
  break;
97
99
  }
98
100
  case 'codeclimate':
99
101
  outputForCodeClimate();
100
102
  break;
103
+ case 'summary':
104
+ formatSummary(problems);
105
+ break;
101
106
  }
102
107
  if (totalProblems - ignoredProblems > maxProblems) {
103
- process.stderr.write(`< ... ${totalProblems - maxProblems} more problems hidden > ${colorette_1.gray('increase with `--max-problems N`')}\n`);
108
+ logger_1.logger.info(`< ... ${totalProblems - maxProblems} more problems hidden > ${logger_1.colorize.gray('increase with `--max-problems N`')}\n`);
104
109
  }
105
110
  function outputForCodeClimate() {
106
111
  const issues = problems.map((p) => {
@@ -109,7 +114,9 @@ function formatProblems(problems, opts) {
109
114
  return {
110
115
  description: p.message,
111
116
  location: {
112
- path: path.relative(cwd, location.source.absoluteRef),
117
+ path: ref_utils_1.isAbsoluteUrl(location.source.absoluteRef)
118
+ ? location.source.absoluteRef
119
+ : path.relative(cwd, location.source.absoluteRef),
113
120
  lines: {
114
121
  begin: lineCol.start.line,
115
122
  },
@@ -118,21 +125,25 @@ function formatProblems(problems, opts) {
118
125
  fingerprint: `${p.ruleId}${p.location.length > 0 ? '-' + p.location[0].pointer : ''}`,
119
126
  };
120
127
  });
121
- process.stdout.write(JSON.stringify(issues, null, 2));
128
+ output_1.output.write(JSON.stringify(issues, null, 2));
122
129
  }
123
130
  function outputJSON() {
124
131
  const resultObject = {
125
132
  totals,
126
133
  version,
127
134
  problems: problems.map((p) => {
128
- var _a;
129
- let problem = Object.assign(Object.assign({}, p), { location: p.location.map((location) => (Object.assign(Object.assign({}, location), { source: {
130
- ref: path.relative(cwd, location.source.absoluteRef),
135
+ var _a, _b, _c;
136
+ const problem = Object.assign(Object.assign({}, p), { location: p.location.map((location) => (Object.assign(Object.assign({}, location), { source: {
137
+ ref: ref_utils_1.isAbsoluteUrl(location.source.absoluteRef)
138
+ ? location.source.absoluteRef
139
+ : path.relative(cwd, location.source.absoluteRef),
131
140
  } }))), from: p.from
132
141
  ? Object.assign(Object.assign({}, p.from), { source: {
133
- ref: path.relative(cwd, ((_a = p.from) === null || _a === void 0 ? void 0 : _a.source.absoluteRef) || cwd),
142
+ ref: ref_utils_1.isAbsoluteUrl((_a = p.from) === null || _a === void 0 ? void 0 : _a.source.absoluteRef)
143
+ ? (_b = p.from) === null || _b === void 0 ? void 0 : _b.source.absoluteRef
144
+ : path.relative(cwd, ((_c = p.from) === null || _c === void 0 ? void 0 : _c.source.absoluteRef) || cwd),
134
145
  } }) : undefined });
135
- if (config_1.env.FORMAT_JSON_WITH_CODEFRAMES) {
146
+ if (env_1.env.FORMAT_JSON_WITH_CODEFRAMES) {
136
147
  const location = p.location[0]; // TODO: support multiple locations
137
148
  const loc = codeframes_1.getLineColLocation(location);
138
149
  problem.codeframe = codeframes_1.getCodeframe(loc, color);
@@ -140,7 +151,7 @@ function formatProblems(problems, opts) {
140
151
  return problem;
141
152
  }),
142
153
  };
143
- process.stdout.write(JSON.stringify(resultObject, null, 2));
154
+ output_1.output.write(JSON.stringify(resultObject, null, 2));
144
155
  }
145
156
  function getBgColor(problem) {
146
157
  const { severity } = problem;
@@ -152,9 +163,11 @@ function formatProblems(problems, opts) {
152
163
  function formatCodeframe(problem, idx) {
153
164
  const bgColor = getBgColor(problem);
154
165
  const location = problem.location[0]; // TODO: support multiple locations
155
- const relativePath = path.relative(cwd, location.source.absoluteRef);
166
+ const relativePath = ref_utils_1.isAbsoluteUrl(location.source.absoluteRef)
167
+ ? location.source.absoluteRef
168
+ : path.relative(cwd, location.source.absoluteRef);
156
169
  const loc = codeframes_1.getLineColLocation(location);
157
- const atPointer = location.pointer ? colorette_1.gray(`at ${location.pointer}`) : '';
170
+ const atPointer = location.pointer ? logger_1.colorize.gray(`at ${location.pointer}`) : '';
158
171
  const fileWithLoc = `${relativePath}:${loc.start.line}:${loc.start.col}`;
159
172
  return (`[${idx + 1}] ${bgColor(fileWithLoc)} ${atPointer}\n\n` +
160
173
  `${problem.message}\n\n` +
@@ -162,12 +175,12 @@ function formatProblems(problems, opts) {
162
175
  codeframes_1.getCodeframe(loc, color) +
163
176
  '\n\n' +
164
177
  formatFrom(cwd, problem.from) +
165
- `${SEVERITY_NAMES[problem.severity]} was generated by the ${colorette_1.blue(problem.ruleId)} rule.\n\n`);
178
+ `${SEVERITY_NAMES[problem.severity]} was generated by the ${logger_1.colorize.blue(problem.ruleId)} rule.\n\n`);
166
179
  }
167
180
  function formatStylish(problem, locationPad, ruleIdPad) {
168
181
  const color = COLORS[problem.severity];
169
182
  if (!SEVERITY_NAMES[problem.severity]) {
170
- return 'Error not found severity. Please check your config file. Allowed values: \`warn,error,off\`';
183
+ return 'Error not found severity. Please check your config file. Allowed values: `warn,error,off`';
171
184
  }
172
185
  const severityName = color(SEVERITY_NAMES[problem.severity].toLowerCase().padEnd(7));
173
186
  const { start } = problem.location[0];
@@ -178,17 +191,35 @@ function formatProblems(problems, opts) {
178
191
  const severity = problem.severity == 'warn' ? 'warning' : 'error';
179
192
  const message = xmlEscape(problem.message);
180
193
  const source = xmlEscape(problem.ruleId);
181
- process.stdout.write(`<error line="${line}" column="${col}" severity="${severity}" message="${message}" source="${source}" />\n`);
194
+ output_1.output.write(`<error line="${line}" column="${col}" severity="${severity}" message="${message}" source="${source}" />\n`);
182
195
  }
183
196
  }
184
197
  exports.formatProblems = formatProblems;
198
+ function formatSummary(problems) {
199
+ const counts = {};
200
+ for (const problem of problems) {
201
+ counts[problem.ruleId] = counts[problem.ruleId] || { count: 0, severity: problem.severity };
202
+ counts[problem.ruleId].count++;
203
+ }
204
+ const sorted = Object.entries(counts).sort(([, a], [, b]) => {
205
+ const severityDiff = severityToNumber(a.severity) - severityToNumber(b.severity);
206
+ return severityDiff || b.count - a.count;
207
+ });
208
+ for (const [ruleId, info] of sorted) {
209
+ const color = COLORS[info.severity];
210
+ const severityName = color(SEVERITY_NAMES[info.severity].toLowerCase().padEnd(7));
211
+ logger_1.logger.info(`${severityName} ${ruleId}: ${info.count}\n`);
212
+ }
213
+ logger_1.logger.info('\n');
214
+ }
185
215
  function formatFrom(cwd, location) {
186
216
  if (!location)
187
217
  return '';
188
218
  const relativePath = path.relative(cwd, location.source.absoluteRef);
189
219
  const loc = codeframes_1.getLineColLocation(location);
190
220
  const fileWithLoc = `${relativePath}:${loc.start.line}:${loc.start.col}`;
191
- return `referenced from ${colorette_1.blue(fileWithLoc)}\n\n`;
221
+ const atPointer = location.pointer ? logger_1.colorize.gray(`at ${location.pointer}`) : '';
222
+ return `referenced from ${logger_1.colorize.blue(fileWithLoc)} ${atPointer} \n\n`;
192
223
  }
193
224
  function formatDidYouMean(problem) {
194
225
  if (problem.suggest.length === 0)
@@ -217,6 +248,7 @@ const groupByFiles = (problems) => {
217
248
  return fileGroups;
218
249
  };
219
250
  function xmlEscape(s) {
251
+ // eslint-disable-next-line no-control-regex
220
252
  return s.replace(/[<>&"'\x00-\x1F\x7F\u0080-\uFFFF]/gu, (char) => {
221
253
  switch (char) {
222
254
  case '<':
package/lib/index.d.ts CHANGED
@@ -1,18 +1,18 @@
1
- export { BundleOutputFormat, readFileFromUrl, slash } from './utils';
1
+ export { BundleOutputFormat, readFileFromUrl, slash, doesYamlFileExist, isTruthy } from './utils';
2
2
  export { Oas3_1Types } from './types/oas3_1';
3
3
  export { Oas3Types } from './types/oas3';
4
4
  export { Oas2Types } from './types/oas2';
5
5
  export { ConfigTypes } from './types/redocly-yaml';
6
- export { Oas3Definition, Oas3_1Definition, Oas3Components, Oas3PathItem, Oas3Paths, Oas3ComponentName, Oas3Schema, Oas3_1Schema, Oas3Tag, Oas3_1Webhooks, Referenced, } from './typings/openapi';
7
- export { Oas2Definition } from './typings/swagger';
8
- export { StatsAccumulator, StatsName } from './typings/common';
6
+ export type { Oas3Definition, Oas3_1Definition, Oas3Components, Oas3PathItem, Oas3Paths, Oas3ComponentName, Oas3Schema, Oas3_1Schema, Oas3Tag, Oas3_1Webhooks, Referenced, OasRef, } from './typings/openapi';
7
+ export type { Oas2Definition } from './typings/swagger';
8
+ export type { StatsAccumulator, StatsName } from './typings/common';
9
9
  export { normalizeTypes } from './types';
10
10
  export { Stats } from './rules/other/stats';
11
- export { Config, LintConfig, RawConfig, IGNORE_FILE, Region, getMergedConfig, transformConfig, loadConfig, getConfig, findConfig, CONFIG_FILE_NAMES, } from './config';
11
+ export { Config, StyleguideConfig, RawConfig, IGNORE_FILE, Region, getMergedConfig, transformConfig, loadConfig, getConfig, findConfig, CONFIG_FILE_NAMES, RuleSeverity, createConfig, ResolvedApi, } from './config';
12
12
  export { RedoclyClient, isRedoclyRegistryURL } from './redocly';
13
13
  export { Source, BaseResolver, Document, resolveDocument, ResolveError, YamlParseError, makeDocumentFromString, } from './resolve';
14
14
  export { parseYaml, stringifyYaml } from './js-yaml';
15
- export { unescapePointer, isRef } from './ref-utils';
15
+ export { unescapePointer, isRef, isAbsoluteUrl } from './ref-utils';
16
16
  export { detectOpenAPI, OasMajorVersion, openAPIMajor, OasVersion } from './oas-types';
17
17
  export { normalizeVisitors } from './visitors';
18
18
  export { WalkContext, walkDocument, NormalizedProblem, ProblemSeverity, LineColLocationObject, LocationObject, Loc, } from './walk';
package/lib/index.js CHANGED
@@ -1,9 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mapTypeToComponent = exports.bundleDocument = exports.bundle = exports.lintConfig = exports.lintFromString = exports.lintDocument = exports.validate = exports.lint = exports.getTotals = exports.formatProblems = exports.getLineColLocation = exports.getAstNodeByPointer = exports.walkDocument = exports.normalizeVisitors = exports.OasVersion = exports.openAPIMajor = exports.OasMajorVersion = exports.detectOpenAPI = exports.isRef = exports.unescapePointer = exports.stringifyYaml = exports.parseYaml = exports.makeDocumentFromString = exports.YamlParseError = exports.ResolveError = exports.resolveDocument = exports.BaseResolver = exports.Source = exports.isRedoclyRegistryURL = exports.RedoclyClient = exports.CONFIG_FILE_NAMES = exports.findConfig = exports.getConfig = exports.loadConfig = exports.transformConfig = exports.getMergedConfig = exports.IGNORE_FILE = exports.LintConfig = exports.Config = exports.Stats = exports.normalizeTypes = exports.ConfigTypes = exports.Oas2Types = exports.Oas3Types = exports.Oas3_1Types = exports.slash = exports.readFileFromUrl = void 0;
3
+ exports.bundleDocument = exports.bundle = exports.lintConfig = exports.lintFromString = exports.lintDocument = exports.validate = exports.lint = exports.getTotals = exports.formatProblems = exports.getLineColLocation = exports.getAstNodeByPointer = exports.walkDocument = exports.normalizeVisitors = exports.OasVersion = exports.openAPIMajor = exports.OasMajorVersion = exports.detectOpenAPI = exports.isAbsoluteUrl = exports.isRef = exports.unescapePointer = exports.stringifyYaml = exports.parseYaml = exports.makeDocumentFromString = exports.YamlParseError = exports.ResolveError = exports.resolveDocument = exports.BaseResolver = exports.Source = exports.isRedoclyRegistryURL = exports.RedoclyClient = exports.createConfig = exports.CONFIG_FILE_NAMES = exports.findConfig = exports.getConfig = exports.loadConfig = exports.transformConfig = exports.getMergedConfig = exports.IGNORE_FILE = exports.StyleguideConfig = exports.Config = exports.Stats = exports.normalizeTypes = exports.ConfigTypes = exports.Oas2Types = exports.Oas3Types = exports.Oas3_1Types = exports.isTruthy = exports.doesYamlFileExist = exports.slash = exports.readFileFromUrl = void 0;
4
+ exports.mapTypeToComponent = void 0;
4
5
  var utils_1 = require("./utils");
5
6
  Object.defineProperty(exports, "readFileFromUrl", { enumerable: true, get: function () { return utils_1.readFileFromUrl; } });
6
7
  Object.defineProperty(exports, "slash", { enumerable: true, get: function () { return utils_1.slash; } });
8
+ Object.defineProperty(exports, "doesYamlFileExist", { enumerable: true, get: function () { return utils_1.doesYamlFileExist; } });
9
+ Object.defineProperty(exports, "isTruthy", { enumerable: true, get: function () { return utils_1.isTruthy; } });
7
10
  var oas3_1_1 = require("./types/oas3_1");
8
11
  Object.defineProperty(exports, "Oas3_1Types", { enumerable: true, get: function () { return oas3_1_1.Oas3_1Types; } });
9
12
  var oas3_1 = require("./types/oas3");
@@ -18,7 +21,7 @@ var stats_1 = require("./rules/other/stats");
18
21
  Object.defineProperty(exports, "Stats", { enumerable: true, get: function () { return stats_1.Stats; } });
19
22
  var config_1 = require("./config");
20
23
  Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return config_1.Config; } });
21
- Object.defineProperty(exports, "LintConfig", { enumerable: true, get: function () { return config_1.LintConfig; } });
24
+ Object.defineProperty(exports, "StyleguideConfig", { enumerable: true, get: function () { return config_1.StyleguideConfig; } });
22
25
  Object.defineProperty(exports, "IGNORE_FILE", { enumerable: true, get: function () { return config_1.IGNORE_FILE; } });
23
26
  Object.defineProperty(exports, "getMergedConfig", { enumerable: true, get: function () { return config_1.getMergedConfig; } });
24
27
  Object.defineProperty(exports, "transformConfig", { enumerable: true, get: function () { return config_1.transformConfig; } });
@@ -26,6 +29,7 @@ Object.defineProperty(exports, "loadConfig", { enumerable: true, get: function (
26
29
  Object.defineProperty(exports, "getConfig", { enumerable: true, get: function () { return config_1.getConfig; } });
27
30
  Object.defineProperty(exports, "findConfig", { enumerable: true, get: function () { return config_1.findConfig; } });
28
31
  Object.defineProperty(exports, "CONFIG_FILE_NAMES", { enumerable: true, get: function () { return config_1.CONFIG_FILE_NAMES; } });
32
+ Object.defineProperty(exports, "createConfig", { enumerable: true, get: function () { return config_1.createConfig; } });
29
33
  var redocly_1 = require("./redocly");
30
34
  Object.defineProperty(exports, "RedoclyClient", { enumerable: true, get: function () { return redocly_1.RedoclyClient; } });
31
35
  Object.defineProperty(exports, "isRedoclyRegistryURL", { enumerable: true, get: function () { return redocly_1.isRedoclyRegistryURL; } });
@@ -42,6 +46,7 @@ Object.defineProperty(exports, "stringifyYaml", { enumerable: true, get: functio
42
46
  var ref_utils_1 = require("./ref-utils");
43
47
  Object.defineProperty(exports, "unescapePointer", { enumerable: true, get: function () { return ref_utils_1.unescapePointer; } });
44
48
  Object.defineProperty(exports, "isRef", { enumerable: true, get: function () { return ref_utils_1.isRef; } });
49
+ Object.defineProperty(exports, "isAbsoluteUrl", { enumerable: true, get: function () { return ref_utils_1.isAbsoluteUrl; } });
45
50
  var oas_types_1 = require("./oas-types");
46
51
  Object.defineProperty(exports, "detectOpenAPI", { enumerable: true, get: function () { return oas_types_1.detectOpenAPI; } });
47
52
  Object.defineProperty(exports, "OasMajorVersion", { enumerable: true, get: function () { return oas_types_1.OasMajorVersion; } });
@@ -2,16 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.stringifyYaml = exports.parseYaml = void 0;
4
4
  // TODO: add a type for "types" https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/js-yaml/index.d.ts
5
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
5
6
  // @ts-ignore
6
7
  const js_yaml_1 = require("js-yaml");
7
8
  const DEFAULT_SCHEMA_WITHOUT_TIMESTAMP = js_yaml_1.JSON_SCHEMA.extend({
8
9
  implicit: [js_yaml_1.types.merge],
9
- explicit: [
10
- js_yaml_1.types.binary,
11
- js_yaml_1.types.omap,
12
- js_yaml_1.types.pairs,
13
- js_yaml_1.types.set,
14
- ],
10
+ explicit: [js_yaml_1.types.binary, js_yaml_1.types.omap, js_yaml_1.types.pairs, js_yaml_1.types.set],
15
11
  });
16
12
  const parseYaml = (str, opts) => js_yaml_1.load(str, Object.assign({ schema: DEFAULT_SCHEMA_WITHOUT_TIMESTAMP }, opts));
17
13
  exports.parseYaml = parseYaml;
package/lib/lint.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { BaseResolver, Document } from './resolve';
2
2
  import { NodeType } from './types';
3
- import { LintConfig, Config } from './config';
3
+ import { ProblemSeverity } from './walk';
4
+ import { StyleguideConfig, Config } from './config';
4
5
  export declare function lint(opts: {
5
6
  ref: string;
6
7
  config: Config;
@@ -14,10 +15,11 @@ export declare function lintFromString(opts: {
14
15
  }): Promise<import("./walk").NormalizedProblem[]>;
15
16
  export declare function lintDocument(opts: {
16
17
  document: Document;
17
- config: LintConfig;
18
+ config: StyleguideConfig;
18
19
  customTypes?: Record<string, NodeType>;
19
20
  externalRefResolver: BaseResolver;
20
21
  }): Promise<import("./walk").NormalizedProblem[]>;
21
22
  export declare function lintConfig(opts: {
22
23
  document: Document;
24
+ severity?: ProblemSeverity;
23
25
  }): Promise<import("./walk").NormalizedProblem[]>;
package/lib/lint.js CHANGED
@@ -26,7 +26,7 @@ function lint(opts) {
26
26
  return __awaiter(this, void 0, void 0, function* () {
27
27
  const { ref, externalRefResolver = new resolve_1.BaseResolver(opts.config.resolve) } = opts;
28
28
  const document = (yield externalRefResolver.resolveDocument(null, ref, true));
29
- return lintDocument(Object.assign(Object.assign({ document }, opts), { externalRefResolver, config: opts.config.lint }));
29
+ return lintDocument(Object.assign(Object.assign({ document }, opts), { externalRefResolver, config: opts.config.styleguide }));
30
30
  });
31
31
  }
32
32
  exports.lint = lint;
@@ -34,7 +34,7 @@ function lintFromString(opts) {
34
34
  return __awaiter(this, void 0, void 0, function* () {
35
35
  const { source, absoluteRef, externalRefResolver = new resolve_1.BaseResolver(opts.config.resolve) } = opts;
36
36
  const document = resolve_1.makeDocumentFromString(source, absoluteRef || '/');
37
- return lintDocument(Object.assign(Object.assign({ document }, opts), { externalRefResolver, config: opts.config.lint }));
37
+ return lintDocument(Object.assign(Object.assign({ document }, opts), { externalRefResolver, config: opts.config.styleguide }));
38
38
  });
39
39
  }
40
40
  exports.lintFromString = lintFromString;
@@ -45,7 +45,11 @@ function lintDocument(opts) {
45
45
  const oasVersion = oas_types_1.detectOpenAPI(document.parsed);
46
46
  const oasMajorVersion = oas_types_1.openAPIMajor(oasVersion);
47
47
  const rules = config.getRulesForOasVersion(oasMajorVersion);
48
- const types = types_1.normalizeTypes(config.extendTypes((customTypes !== null && customTypes !== void 0 ? customTypes : oasMajorVersion === oas_types_1.OasMajorVersion.Version3) ? (oasVersion === oas_types_1.OasVersion.Version3_1 ? oas3_1_1.Oas3_1Types : oas3_1.Oas3Types) : oas2_1.Oas2Types, oasVersion), config);
48
+ const types = types_1.normalizeTypes(config.extendTypes((customTypes !== null && customTypes !== void 0 ? customTypes : oasMajorVersion === oas_types_1.OasMajorVersion.Version3)
49
+ ? oasVersion === oas_types_1.OasVersion.Version3_1
50
+ ? oas3_1_1.Oas3_1Types
51
+ : oas3_1.Oas3Types
52
+ : oas2_1.Oas2Types, oasVersion), config);
49
53
  const ctx = {
50
54
  problems: [],
51
55
  oasVersion: oasVersion,
@@ -53,15 +57,30 @@ function lintDocument(opts) {
53
57
  };
54
58
  const preprocessors = config_1.initRules(rules, config, 'preprocessors', oasVersion);
55
59
  const regularRules = config_1.initRules(rules, config, 'rules', oasVersion);
56
- const normalizedVisitors = visitors_1.normalizeVisitors([...preprocessors, ...regularRules], types);
57
- const resolvedRefMap = yield resolve_1.resolveDocument({
60
+ let resolvedRefMap = yield resolve_1.resolveDocument({
58
61
  rootDocument: document,
59
- rootType: types.DefinitionRoot,
60
- externalRefResolver
62
+ rootType: types.Root,
63
+ externalRefResolver,
61
64
  });
65
+ if (preprocessors.length > 0) {
66
+ // Make additional pass to resolve refs defined in preprocessors.
67
+ walk_1.walkDocument({
68
+ document,
69
+ rootType: types.Root,
70
+ normalizedVisitors: visitors_1.normalizeVisitors(preprocessors, types),
71
+ resolvedRefMap,
72
+ ctx,
73
+ });
74
+ resolvedRefMap = yield resolve_1.resolveDocument({
75
+ rootDocument: document,
76
+ rootType: types.Root,
77
+ externalRefResolver,
78
+ });
79
+ }
80
+ const normalizedVisitors = visitors_1.normalizeVisitors(regularRules, types);
62
81
  walk_1.walkDocument({
63
82
  document,
64
- rootType: types.DefinitionRoot,
83
+ rootType: types.Root,
65
84
  normalizedVisitors,
66
85
  resolvedRefMap,
67
86
  ctx,
@@ -72,19 +91,25 @@ function lintDocument(opts) {
72
91
  exports.lintDocument = lintDocument;
73
92
  function lintConfig(opts) {
74
93
  return __awaiter(this, void 0, void 0, function* () {
75
- const { document } = opts;
94
+ const { document, severity } = opts;
76
95
  const ctx = {
77
96
  problems: [],
78
97
  oasVersion: oas_types_1.OasVersion.Version3_0,
79
98
  visitorsData: {},
80
99
  };
81
100
  const plugins = config_1.resolvePlugins([config_1.defaultPlugin]);
82
- const config = new config_1.LintConfig({
101
+ const config = new config_1.StyleguideConfig({
83
102
  plugins,
84
103
  rules: { spec: 'error' },
85
104
  });
86
105
  const types = types_1.normalizeTypes(redocly_yaml_1.ConfigTypes, config);
87
- const rules = [{ severity: 'error', ruleId: 'spec', visitor: spec_1.OasSpec({ severity: 'error' }) }];
106
+ const rules = [
107
+ {
108
+ severity: severity || 'error',
109
+ ruleId: 'configuration spec',
110
+ visitor: spec_1.OasSpec({ severity: 'error' }),
111
+ },
112
+ ];
88
113
  const normalizedVisitors = visitors_1.normalizeVisitors(rules, types);
89
114
  walk_1.walkDocument({
90
115
  document,
@@ -0,0 +1,10 @@
1
+ import * as colorette from 'colorette';
2
+ export { options as colorOptions } from 'colorette';
3
+ export declare const colorize: typeof colorette;
4
+ declare class Logger {
5
+ protected stderr(str: string): boolean;
6
+ info(str: string): boolean | void;
7
+ warn(str: string): boolean | void;
8
+ error(str: string): boolean | void;
9
+ }
10
+ export declare const logger: Logger;
package/lib/logger.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.logger = exports.colorize = exports.colorOptions = void 0;
4
+ const colorette = require("colorette");
5
+ var colorette_1 = require("colorette");
6
+ Object.defineProperty(exports, "colorOptions", { enumerable: true, get: function () { return colorette_1.options; } });
7
+ const env_1 = require("./env");
8
+ const utils_1 = require("./utils");
9
+ exports.colorize = new Proxy(colorette, {
10
+ get(target, prop) {
11
+ if (env_1.isBrowser) {
12
+ return utils_1.identity;
13
+ }
14
+ return target[prop];
15
+ },
16
+ });
17
+ class Logger {
18
+ stderr(str) {
19
+ return process.stderr.write(str);
20
+ }
21
+ info(str) {
22
+ return env_1.isBrowser ? console.log(str) : this.stderr(str);
23
+ }
24
+ warn(str) {
25
+ return env_1.isBrowser ? console.warn(str) : this.stderr(exports.colorize.yellow(str));
26
+ }
27
+ error(str) {
28
+ return env_1.isBrowser ? console.error(str) : this.stderr(exports.colorize.red(str));
29
+ }
30
+ }
31
+ exports.logger = new Logger();
@@ -0,0 +1,3 @@
1
+ export declare const output: {
2
+ write(str: string): boolean | undefined;
3
+ };
package/lib/output.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.output = void 0;
4
+ const env_1 = require("./env");
5
+ exports.output = {
6
+ write(str) {
7
+ return env_1.isBrowser ? undefined : process.stdout.write(str);
8
+ },
9
+ };
@@ -13,26 +13,27 @@ exports.isRedoclyRegistryURL = exports.RedoclyClient = void 0;
13
13
  const fs_1 = require("fs");
14
14
  const path_1 = require("path");
15
15
  const os_1 = require("os");
16
- const colorette_1 = require("colorette");
17
16
  const registry_api_1 = require("./registry-api");
18
17
  const config_1 = require("../config/config");
18
+ const env_1 = require("../env");
19
19
  const utils_1 = require("../utils");
20
+ const logger_1 = require("../logger");
20
21
  const TOKEN_FILENAME = '.redocly-config.json';
21
22
  class RedoclyClient {
22
23
  constructor(region) {
23
24
  this.accessTokens = {};
24
25
  this.region = this.loadRegion(region);
25
26
  this.loadTokens();
26
- this.domain = region ? config_1.DOMAINS[region] : config_1.env.REDOCLY_DOMAIN || config_1.DOMAINS[config_1.DEFAULT_REGION];
27
- config_1.env.REDOCLY_DOMAIN = this.domain; // isRedoclyRegistryURL depends on the value to be set
27
+ this.domain = region ? config_1.DOMAINS[region] : env_1.env.REDOCLY_DOMAIN || config_1.DOMAINS[config_1.DEFAULT_REGION];
28
+ env_1.env.REDOCLY_DOMAIN = this.domain; // isRedoclyRegistryURL depends on the value to be set
28
29
  this.registryApi = new registry_api_1.RegistryApi(this.accessTokens, this.region);
29
30
  }
30
31
  loadRegion(region) {
31
32
  if (region && !config_1.DOMAINS[region]) {
32
- throw new Error(`Invalid argument: region in config file.\nGiven: ${colorette_1.green(region)}, choices: "us", "eu".`);
33
+ throw new Error(`Invalid argument: region in config file.\nGiven: ${logger_1.colorize.green(region)}, choices: "us", "eu".`);
33
34
  }
34
- if (config_1.env.REDOCLY_DOMAIN) {
35
- return (config_1.AVAILABLE_REGIONS.find((region) => config_1.DOMAINS[region] === config_1.env.REDOCLY_DOMAIN) || config_1.DEFAULT_REGION);
35
+ if (env_1.env.REDOCLY_DOMAIN) {
36
+ return (config_1.AVAILABLE_REGIONS.find((region) => config_1.DOMAINS[region] === env_1.env.REDOCLY_DOMAIN) || config_1.DEFAULT_REGION);
36
37
  }
37
38
  return region || config_1.DEFAULT_REGION;
38
39
  }
@@ -64,8 +65,8 @@ class RedoclyClient {
64
65
  [this.region]: credentials.token,
65
66
  })));
66
67
  }
67
- if (config_1.env.REDOCLY_AUTHORIZATION) {
68
- this.setAccessTokens(Object.assign(Object.assign({}, this.accessTokens), { [this.region]: config_1.env.REDOCLY_AUTHORIZATION }));
68
+ if (env_1.env.REDOCLY_AUTHORIZATION) {
69
+ this.setAccessTokens(Object.assign(Object.assign({}, this.accessTokens), { [this.region]: env_1.env.REDOCLY_AUTHORIZATION }));
69
70
  }
70
71
  }
71
72
  getAllTokens() {
@@ -142,7 +143,7 @@ class RedoclyClient {
142
143
  }
143
144
  exports.RedoclyClient = RedoclyClient;
144
145
  function isRedoclyRegistryURL(link) {
145
- const domain = config_1.env.REDOCLY_DOMAIN || config_1.DOMAINS[config_1.DEFAULT_REGION];
146
+ const domain = env_1.env.REDOCLY_DOMAIN || config_1.DOMAINS[config_1.DEFAULT_REGION];
146
147
  const legacyDomain = domain === 'redocly.com' ? 'redoc.ly' : domain;
147
148
  if (!link.startsWith(`https://api.${domain}/registry/`) &&
148
149
  !link.startsWith(`https://api.${legacyDomain}/registry/`)) {
@@ -1,29 +1,29 @@
1
- export declare namespace RegistryApiTypes {
2
- interface VersionParams {
3
- organizationId: string;
4
- name: string;
5
- version: string;
6
- }
7
- export interface PrepareFileuploadParams extends VersionParams {
8
- filesHash: string;
9
- filename: string;
10
- isUpsert?: boolean;
11
- }
12
- export interface PushApiParams extends VersionParams {
13
- rootFilePath: string;
14
- filePaths: string[];
15
- branch?: string;
16
- isUpsert?: boolean;
17
- isPublic?: boolean;
18
- }
19
- export interface PrepareFileuploadOKResponse {
20
- filePath: string;
21
- signedUploadUrl: string;
22
- }
23
- export interface NotFoundProblemResponse {
24
- status: 404;
25
- title: 'Not Found';
26
- code: 'ORGANIZATION_NOT_FOUND' | 'API_VERSION_NOT_FOUND';
27
- }
28
- export {};
1
+ interface VersionParams {
2
+ organizationId: string;
3
+ name: string;
4
+ version: string;
29
5
  }
6
+ export interface PrepareFileuploadParams extends VersionParams {
7
+ filesHash: string;
8
+ filename: string;
9
+ isUpsert?: boolean;
10
+ }
11
+ export interface PushApiParams extends VersionParams {
12
+ rootFilePath: string;
13
+ filePaths: string[];
14
+ branch?: string;
15
+ isUpsert?: boolean;
16
+ isPublic?: boolean;
17
+ batchId?: string;
18
+ batchSize?: number;
19
+ }
20
+ export interface PrepareFileuploadOKResponse {
21
+ filePath: string;
22
+ signedUploadUrl: string;
23
+ }
24
+ export interface NotFoundProblemResponse {
25
+ status: 404;
26
+ title: 'Not Found';
27
+ code: 'ORGANIZATION_NOT_FOUND' | 'API_VERSION_NOT_FOUND';
28
+ }
29
+ export {};
@@ -1,4 +1,4 @@
1
- import { RegistryApiTypes } from './registry-api-types';
1
+ import type { PrepareFileuploadOKResponse, PrepareFileuploadParams, PushApiParams } from './registry-api-types';
2
2
  import type { AccessTokens, Region } from '../config/types';
3
3
  export declare class RegistryApi {
4
4
  private accessTokens;
@@ -12,6 +12,6 @@ export declare class RegistryApi {
12
12
  viewerId: string;
13
13
  organizations: string[];
14
14
  }>;
15
- prepareFileUpload({ organizationId, name, version, filesHash, filename, isUpsert, }: RegistryApiTypes.PrepareFileuploadParams): Promise<RegistryApiTypes.PrepareFileuploadOKResponse>;
16
- pushApi({ organizationId, name, version, rootFilePath, filePaths, branch, isUpsert, isPublic, }: RegistryApiTypes.PushApiParams): Promise<void>;
15
+ prepareFileUpload({ organizationId, name, version, filesHash, filename, isUpsert, }: PrepareFileuploadParams): Promise<PrepareFileuploadOKResponse>;
16
+ pushApi({ organizationId, name, version, rootFilePath, filePaths, branch, isUpsert, isPublic, batchId, batchSize, }: PushApiParams): Promise<void>;
17
17
  }