@redocly/openapi-core 1.18.1 → 1.20.0

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 (411) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/__tests__/utils.ts +14 -7
  3. package/lib/benchmark/benches/lint-with-many-rules.bench.d.ts +1 -0
  4. package/lib/benchmark/benches/lint-with-many-rules.bench.js +7 -3
  5. package/lib/benchmark/benches/lint-with-nested-rule.bench.d.ts +1 -0
  6. package/lib/benchmark/benches/lint-with-nested-rule.bench.js +7 -3
  7. package/lib/benchmark/benches/lint-with-no-rules.bench.d.ts +1 -0
  8. package/lib/benchmark/benches/lint-with-no-rules.bench.js +7 -3
  9. package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.d.ts +1 -0
  10. package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +19 -15
  11. package/lib/benchmark/benches/lint-with-top-level-rule.bench.d.ts +1 -0
  12. package/lib/benchmark/benches/lint-with-top-level-rule.bench.js +18 -14
  13. package/lib/benchmark/benches/recommended-oas3.bench.js +2 -2
  14. package/lib/benchmark/benches/resolve-with-no-external.bench.js +2 -2
  15. package/lib/benchmark/utils.d.ts +3 -3
  16. package/lib/benchmark/utils.js +10 -7
  17. package/lib/bundle.d.ts +2 -2
  18. package/lib/bundle.js +127 -120
  19. package/lib/config/all.js +13 -1
  20. package/lib/config/builtIn.js +18 -17
  21. package/lib/config/config-resolvers.d.ts +1 -1
  22. package/lib/config/config-resolvers.js +241 -158
  23. package/lib/config/config.d.ts +4 -3
  24. package/lib/config/config.js +53 -34
  25. package/lib/config/load.d.ts +1 -1
  26. package/lib/config/load.js +105 -117
  27. package/lib/config/minimal.js +13 -0
  28. package/lib/config/recommended-strict.js +14 -1
  29. package/lib/config/recommended.js +14 -1
  30. package/lib/config/rules.d.ts +3 -3
  31. package/lib/config/rules.js +1 -2
  32. package/lib/config/types.d.ts +17 -4
  33. package/lib/config/utils.d.ts +3 -1
  34. package/lib/config/utils.js +78 -49
  35. package/lib/decorators/async3/index.d.ts +1 -0
  36. package/lib/decorators/async3/index.js +4 -0
  37. package/lib/decorators/common/filters/filter-helper.d.ts +1 -1
  38. package/lib/decorators/common/filters/filter-helper.js +2 -3
  39. package/lib/decorators/common/filters/filter-in.d.ts +1 -1
  40. package/lib/decorators/common/filters/filter-in.js +1 -1
  41. package/lib/decorators/common/filters/filter-out.d.ts +1 -1
  42. package/lib/decorators/common/filters/filter-out.js +1 -1
  43. package/lib/decorators/common/info-description-override.d.ts +1 -1
  44. package/lib/decorators/common/info-override.d.ts +1 -1
  45. package/lib/decorators/common/info-override.js +1 -12
  46. package/lib/decorators/common/media-type-examples-override.d.ts +1 -1
  47. package/lib/decorators/common/media-type-examples-override.js +8 -2
  48. package/lib/decorators/common/operation-description-override.d.ts +1 -1
  49. package/lib/decorators/common/registry-dependencies.d.ts +1 -1
  50. package/lib/decorators/common/remove-x-internal.d.ts +1 -1
  51. package/lib/decorators/common/remove-x-internal.js +4 -5
  52. package/lib/decorators/common/tag-description-override.d.ts +1 -1
  53. package/lib/decorators/oas2/index.d.ts +1 -1
  54. package/lib/decorators/oas2/remove-unused-components.js +1 -2
  55. package/lib/decorators/oas3/index.d.ts +1 -1
  56. package/lib/decorators/oas3/remove-unused-components.js +1 -2
  57. package/lib/env.d.ts +0 -1
  58. package/lib/env.js +1 -1
  59. package/lib/format/codeframes.d.ts +1 -1
  60. package/lib/format/codeframes.js +10 -8
  61. package/lib/format/format.d.ts +1 -1
  62. package/lib/format/format.js +24 -16
  63. package/lib/index.d.ts +2 -1
  64. package/lib/index.js +6 -4
  65. package/lib/js-yaml/index.d.ts +1 -1
  66. package/lib/js-yaml/index.js +1 -1
  67. package/lib/lint.d.ts +3 -1
  68. package/lib/lint.js +92 -99
  69. package/lib/logger.js +2 -2
  70. package/lib/oas-types.d.ts +9 -5
  71. package/lib/oas-types.js +22 -12
  72. package/lib/redocly/domains.d.ts +1 -1
  73. package/lib/redocly/domains.js +6 -6
  74. package/lib/redocly/index.d.ts +1 -1
  75. package/lib/redocly/index.js +60 -73
  76. package/lib/redocly/registry-api.js +64 -82
  77. package/lib/ref-utils.d.ts +2 -2
  78. package/lib/ref-utils.js +14 -13
  79. package/lib/resolve.d.ts +2 -2
  80. package/lib/resolve.js +186 -205
  81. package/lib/rules/ajv.d.ts +1 -1
  82. package/lib/rules/ajv.js +10 -8
  83. package/lib/rules/arazzo/index.js +2 -0
  84. package/lib/rules/async2/channels-kebab-case.d.ts +1 -1
  85. package/lib/rules/async2/index.js +2 -0
  86. package/lib/rules/async2/no-channel-trailing-slash.d.ts +1 -1
  87. package/lib/rules/async3/channels-kebab-case.d.ts +2 -0
  88. package/lib/rules/async3/channels-kebab-case.js +19 -0
  89. package/lib/rules/async3/index.d.ts +3 -0
  90. package/lib/rules/async3/index.js +24 -0
  91. package/lib/rules/async3/no-channel-trailing-slash.d.ts +2 -0
  92. package/lib/rules/async3/no-channel-trailing-slash.js +16 -0
  93. package/lib/rules/common/assertions/asserts.d.ts +2 -2
  94. package/lib/rules/common/assertions/asserts.js +5 -5
  95. package/lib/rules/common/assertions/index.d.ts +4 -4
  96. package/lib/rules/common/assertions/utils.d.ts +1 -1
  97. package/lib/rules/common/assertions/utils.js +43 -28
  98. package/lib/rules/common/info-contact.d.ts +1 -1
  99. package/lib/rules/common/info-license-strict.d.ts +2 -0
  100. package/lib/rules/common/info-license-strict.js +26 -0
  101. package/lib/rules/common/info-license-url.d.ts +1 -1
  102. package/lib/rules/common/info-license.d.ts +1 -1
  103. package/lib/rules/common/no-ambiguous-paths.d.ts +1 -1
  104. package/lib/rules/common/no-enum-type-mismatch.d.ts +1 -1
  105. package/lib/rules/common/no-http-verbs-in-paths.d.ts +1 -1
  106. package/lib/rules/common/no-identical-paths.d.ts +1 -1
  107. package/lib/rules/common/no-invalid-parameter-examples.js +1 -2
  108. package/lib/rules/common/no-invalid-schema-examples.js +1 -2
  109. package/lib/rules/common/no-path-trailing-slash.d.ts +1 -1
  110. package/lib/rules/common/no-required-schema-properties-undefined.d.ts +1 -1
  111. package/lib/rules/common/no-required-schema-properties-undefined.js +1 -2
  112. package/lib/rules/common/operation-2xx-response.d.ts +1 -1
  113. package/lib/rules/common/operation-4xx-response.d.ts +1 -1
  114. package/lib/rules/common/operation-description.d.ts +1 -1
  115. package/lib/rules/common/operation-operationId-unique.d.ts +1 -1
  116. package/lib/rules/common/operation-operationId-url-safe.d.ts +1 -1
  117. package/lib/rules/common/operation-operationId-url-safe.js +1 -0
  118. package/lib/rules/common/operation-operationId.d.ts +1 -1
  119. package/lib/rules/common/operation-parameters-unique.d.ts +1 -1
  120. package/lib/rules/common/operation-singular-tag.d.ts +1 -1
  121. package/lib/rules/common/operation-summary.d.ts +1 -1
  122. package/lib/rules/common/operation-tag-defined.d.ts +1 -1
  123. package/lib/rules/common/operation-tag-defined.js +1 -2
  124. package/lib/rules/common/parameter-description.d.ts +1 -1
  125. package/lib/rules/common/path-declaration-must-exist.d.ts +1 -1
  126. package/lib/rules/common/path-excludes-patterns.d.ts +1 -1
  127. package/lib/rules/common/path-http-verbs-order.d.ts +1 -1
  128. package/lib/rules/common/path-http-verbs-order.js +1 -1
  129. package/lib/rules/common/path-not-include-query.d.ts +1 -1
  130. package/lib/rules/common/path-params-defined.d.ts +1 -1
  131. package/lib/rules/common/path-segment-plural.d.ts +1 -1
  132. package/lib/rules/common/paths-kebab-case.d.ts +1 -1
  133. package/lib/rules/common/required-string-property-missing-min-length.d.ts +1 -1
  134. package/lib/rules/common/required-string-property-missing-min-length.js +2 -2
  135. package/lib/rules/common/response-contains-header.d.ts +1 -1
  136. package/lib/rules/common/response-contains-header.js +2 -2
  137. package/lib/rules/common/security-defined.d.ts +1 -1
  138. package/lib/rules/common/security-defined.js +3 -7
  139. package/lib/rules/common/spec-strict-refs.d.ts +1 -1
  140. package/lib/rules/common/spec.d.ts +2 -2
  141. package/lib/rules/common/spec.js +6 -7
  142. package/lib/rules/common/tag-description.d.ts +1 -1
  143. package/lib/rules/common/tags-alphabetical.d.ts +1 -1
  144. package/lib/rules/no-unresolved-refs.d.ts +3 -3
  145. package/lib/rules/no-unresolved-refs.js +3 -4
  146. package/lib/rules/oas2/boolean-parameter-prefixes.d.ts +1 -1
  147. package/lib/rules/oas2/index.d.ts +1 -1
  148. package/lib/rules/oas2/index.js +2 -0
  149. package/lib/rules/oas2/response-contains-property.d.ts +1 -1
  150. package/lib/rules/oas2/response-contains-property.js +1 -2
  151. package/lib/rules/oas3/array-parameter-serialization.d.ts +1 -1
  152. package/lib/rules/oas3/array-parameter-serialization.js +1 -2
  153. package/lib/rules/oas3/boolean-parameter-prefixes.d.ts +1 -1
  154. package/lib/rules/oas3/component-name-unique.d.ts +1 -1
  155. package/lib/rules/oas3/component-name-unique.js +2 -4
  156. package/lib/rules/oas3/index.d.ts +1 -1
  157. package/lib/rules/oas3/index.js +2 -0
  158. package/lib/rules/oas3/no-empty-servers.d.ts +1 -1
  159. package/lib/rules/oas3/no-example-value-and-externalValue.d.ts +1 -1
  160. package/lib/rules/oas3/no-invalid-media-type-examples.d.ts +1 -1
  161. package/lib/rules/oas3/no-invalid-media-type-examples.js +1 -2
  162. package/lib/rules/oas3/no-server-example.com.d.ts +1 -1
  163. package/lib/rules/oas3/no-server-example.com.js +1 -0
  164. package/lib/rules/oas3/no-server-trailing-slash.d.ts +1 -1
  165. package/lib/rules/oas3/no-server-variables-empty-enum.d.ts +1 -1
  166. package/lib/rules/oas3/no-server-variables-empty-enum.js +1 -2
  167. package/lib/rules/oas3/no-undefined-server-variable.d.ts +1 -1
  168. package/lib/rules/oas3/no-undefined-server-variable.js +2 -3
  169. package/lib/rules/oas3/no-unused-components.d.ts +1 -1
  170. package/lib/rules/oas3/no-unused-components.js +1 -2
  171. package/lib/rules/oas3/response-contains-property.d.ts +1 -1
  172. package/lib/rules/oas3/response-contains-property.js +1 -2
  173. package/lib/rules/oas3/spec-components-invalid-map-name.d.ts +1 -1
  174. package/lib/rules/other/stats.d.ts +3 -3
  175. package/lib/rules/other/stats.js +5 -3
  176. package/lib/rules/spot/parameters-no-body-inside-in.d.ts +2 -0
  177. package/lib/rules/spot/parameters-no-body-inside-in.js +18 -0
  178. package/lib/rules/utils.d.ts +4 -2
  179. package/lib/rules/utils.js +41 -13
  180. package/lib/types/arazzo.d.ts +1 -2275
  181. package/lib/types/arazzo.js +246 -309
  182. package/lib/types/asyncapi2.d.ts +17 -0
  183. package/lib/types/{asyncapi.js → asyncapi2.js} +59 -53
  184. package/lib/types/asyncapi3.d.ts +2 -0
  185. package/lib/types/asyncapi3.js +347 -0
  186. package/lib/types/index.js +19 -10
  187. package/lib/types/json-schema-adapter.d.ts +1 -1
  188. package/lib/types/json-schema-adapter.js +4 -18
  189. package/lib/types/oas2.js +6 -6
  190. package/lib/types/oas3.d.ts +4 -0
  191. package/lib/types/oas3.js +19 -19
  192. package/lib/types/oas3_1.d.ts +3 -0
  193. package/lib/types/oas3_1.js +20 -14
  194. package/lib/types/redocly-yaml.d.ts +8 -6
  195. package/lib/types/redocly-yaml.js +135 -36
  196. package/lib/typings/arazzo.d.ts +145 -27
  197. package/lib/typings/asyncapi3.d.ts +53 -0
  198. package/lib/typings/asyncapi3.js +2 -0
  199. package/lib/typings/common.d.ts +1 -1
  200. package/lib/typings/swagger.d.ts +2 -2
  201. package/lib/utils.d.ts +4 -3
  202. package/lib/utils.js +55 -72
  203. package/lib/visitors.d.ts +29 -1
  204. package/lib/visitors.js +21 -8
  205. package/lib/walk.d.ts +3 -3
  206. package/lib/walk.js +30 -23
  207. package/package.json +3 -3
  208. package/src/__tests__/bundle.test.ts +144 -2
  209. package/src/__tests__/lint.test.ts +29 -21
  210. package/src/__tests__/walk.test.ts +25 -25
  211. package/src/benchmark/benches/lint-with-many-rules.bench.ts +7 -1
  212. package/src/benchmark/benches/lint-with-nested-rule.bench.ts +7 -1
  213. package/src/benchmark/benches/lint-with-no-rules.bench.ts +8 -1
  214. package/src/benchmark/benches/lint-with-top-level-rule-report.bench.ts +18 -13
  215. package/src/benchmark/benches/lint-with-top-level-rule.bench.ts +17 -11
  216. package/src/benchmark/fork.js +4 -0
  217. package/src/benchmark/utils.ts +6 -5
  218. package/src/bundle.ts +19 -4
  219. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +32 -2
  220. package/src/config/__tests__/__snapshots__/config.test.ts.snap +24 -0
  221. package/src/config/__tests__/config-resolvers.test.ts +82 -0
  222. package/src/config/__tests__/config.test.ts +11 -0
  223. package/src/config/__tests__/fixtures/resolve-config/local-config-with-commonjs-export-function.yaml +2 -0
  224. package/src/config/__tests__/fixtures/resolve-config/local-config-with-esm.yaml +2 -0
  225. package/src/config/__tests__/fixtures/resolve-config/plugin-esm.mjs +10 -0
  226. package/src/config/__tests__/fixtures/resolve-config/plugin-with-export-function.cjs +10 -0
  227. package/src/config/__tests__/resolve-plugins.test.ts +4 -1
  228. package/src/config/all.ts +13 -1
  229. package/src/config/builtIn.ts +9 -8
  230. package/src/config/config-resolvers.ts +92 -21
  231. package/src/config/config.ts +31 -13
  232. package/src/config/load.ts +2 -2
  233. package/src/config/minimal.ts +13 -0
  234. package/src/config/recommended-strict.ts +14 -1
  235. package/src/config/recommended.ts +14 -1
  236. package/src/config/rules.ts +12 -4
  237. package/src/config/types.ts +34 -5
  238. package/src/config/utils.ts +28 -2
  239. package/src/decorators/__tests__/filter-in.test.ts +29 -26
  240. package/src/decorators/__tests__/filter-out.test.ts +32 -23
  241. package/src/decorators/__tests__/media-type-examples-override.test.ts +45 -45
  242. package/src/decorators/__tests__/remove-x-internal.test.ts +8 -5
  243. package/src/decorators/async3/index.ts +1 -0
  244. package/src/decorators/common/filters/filter-helper.ts +2 -1
  245. package/src/decorators/common/filters/filter-in.ts +2 -1
  246. package/src/decorators/common/filters/filter-out.ts +2 -1
  247. package/src/decorators/common/info-description-override.ts +3 -2
  248. package/src/decorators/common/info-override.ts +1 -1
  249. package/src/decorators/common/media-type-examples-override.ts +4 -3
  250. package/src/decorators/common/operation-description-override.ts +5 -4
  251. package/src/decorators/common/registry-dependencies.ts +2 -2
  252. package/src/decorators/common/remove-x-internal.ts +5 -4
  253. package/src/decorators/common/tag-description-override.ts +3 -2
  254. package/src/decorators/oas2/__tests__/remove-unused-components.test.ts +3 -3
  255. package/src/decorators/oas2/index.ts +2 -1
  256. package/src/decorators/oas2/remove-unused-components.ts +1 -1
  257. package/src/decorators/oas3/__tests__/remove-unused-components.test.ts +4 -4
  258. package/src/decorators/oas3/index.ts +2 -1
  259. package/src/decorators/oas3/remove-unused-components.ts +1 -1
  260. package/src/format/codeframes.ts +2 -1
  261. package/src/format/format.ts +9 -4
  262. package/src/index.ts +2 -1
  263. package/src/js-yaml/index.ts +3 -1
  264. package/src/lint.ts +28 -4
  265. package/src/logger.ts +2 -2
  266. package/src/oas-types.ts +41 -22
  267. package/src/redocly/domains.ts +1 -1
  268. package/src/redocly/index.ts +3 -3
  269. package/src/redocly/registry-api.ts +5 -3
  270. package/src/ref-utils.ts +4 -2
  271. package/src/resolve.ts +6 -4
  272. package/src/rules/__tests__/no-unresolved-refs.test.ts +21 -7
  273. package/src/rules/ajv.ts +2 -1
  274. package/src/rules/arazzo/__tests__/parameters-no-body-inside-in.test.ts +76 -0
  275. package/src/rules/arazzo/index.ts +6 -3
  276. package/src/rules/async2/__tests__/channels-kebab-case.test.ts +9 -5
  277. package/src/rules/async2/__tests__/no-channel-trailing-slash.test.ts +3 -3
  278. package/src/rules/async2/channels-kebab-case.ts +2 -2
  279. package/src/rules/async2/index.ts +9 -6
  280. package/src/rules/async2/no-channel-trailing-slash.ts +2 -2
  281. package/src/rules/async3/__tests__/channels-kebab-case.test.ts +145 -0
  282. package/src/rules/async3/__tests__/no-channel-trailing-slash.test.ts +96 -0
  283. package/src/rules/async3/channels-kebab-case.ts +19 -0
  284. package/src/rules/async3/index.ts +26 -0
  285. package/src/rules/async3/no-channel-trailing-slash.ts +16 -0
  286. package/src/rules/common/__tests__/info-license-strict.test.ts +141 -0
  287. package/src/rules/common/__tests__/info-license.test.ts +2 -2
  288. package/src/rules/common/__tests__/license-url.test.ts +2 -2
  289. package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +1 -1
  290. package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +5 -5
  291. package/src/rules/common/__tests__/no-identical-paths.test.ts +1 -1
  292. package/src/rules/common/__tests__/no-invalid-parameter-examples.test.ts +1 -1
  293. package/src/rules/common/__tests__/no-invalid-schema-examples.test.ts +1 -1
  294. package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +4 -4
  295. package/src/rules/common/__tests__/no-required-schema-properties-undefined.test.ts +11 -11
  296. package/src/rules/common/__tests__/operation-2xx-response.test.ts +8 -6
  297. package/src/rules/common/__tests__/operation-4xx-response.test.ts +9 -7
  298. package/src/rules/common/__tests__/operation-operationId-unique.test.ts +2 -2
  299. package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +1 -1
  300. package/src/rules/common/__tests__/operation-parameters-unique.test.ts +4 -4
  301. package/src/rules/common/__tests__/operation-singular-tag.test.ts +2 -2
  302. package/src/rules/common/__tests__/path-http-verbs-order.test.ts +2 -2
  303. package/src/rules/common/__tests__/path-not-include-query.test.ts +2 -2
  304. package/src/rules/common/__tests__/path-params-defined.test.ts +5 -5
  305. package/src/rules/common/__tests__/paths-kebab-case.test.ts +6 -4
  306. package/src/rules/common/__tests__/scalar-property-missing-example.test.ts +8 -8
  307. package/src/rules/common/__tests__/security-defined.test.ts +14 -8
  308. package/src/rules/common/__tests__/spec-strict-refs.test.ts +1 -1
  309. package/src/rules/common/__tests__/spec.test.ts +10 -10
  310. package/src/rules/common/__tests__/tag-description.test.ts +2 -2
  311. package/src/rules/common/__tests__/tags-alphabetical.test.ts +6 -4
  312. package/src/rules/common/assertions/asserts.ts +5 -9
  313. package/src/rules/common/assertions/index.ts +12 -4
  314. package/src/rules/common/assertions/utils.ts +4 -2
  315. package/src/rules/common/info-contact.ts +2 -1
  316. package/src/rules/common/info-license-strict.ts +24 -0
  317. package/src/rules/common/info-license-url.ts +2 -1
  318. package/src/rules/common/info-license.ts +2 -1
  319. package/src/rules/common/no-ambiguous-paths.ts +4 -4
  320. package/src/rules/common/no-enum-type-mismatch.ts +5 -4
  321. package/src/rules/common/no-http-verbs-in-paths.ts +5 -4
  322. package/src/rules/common/no-identical-paths.ts +4 -4
  323. package/src/rules/common/no-invalid-parameter-examples.ts +3 -2
  324. package/src/rules/common/no-path-trailing-slash.ts +2 -2
  325. package/src/rules/common/no-required-schema-properties-undefined.ts +5 -4
  326. package/src/rules/common/operation-2xx-response.ts +3 -2
  327. package/src/rules/common/operation-4xx-response.ts +3 -2
  328. package/src/rules/common/operation-description.ts +5 -4
  329. package/src/rules/common/operation-operationId-unique.ts +4 -4
  330. package/src/rules/common/operation-operationId-url-safe.ts +5 -4
  331. package/src/rules/common/operation-operationId.ts +5 -4
  332. package/src/rules/common/operation-parameters-unique.ts +4 -4
  333. package/src/rules/common/operation-singular-tag.ts +4 -4
  334. package/src/rules/common/operation-summary.ts +5 -4
  335. package/src/rules/common/operation-tag-defined.ts +4 -4
  336. package/src/rules/common/parameter-description.ts +4 -4
  337. package/src/rules/common/path-declaration-must-exist.ts +2 -2
  338. package/src/rules/common/path-excludes-patterns.ts +4 -4
  339. package/src/rules/common/path-http-verbs-order.ts +4 -4
  340. package/src/rules/common/path-not-include-query.ts +2 -2
  341. package/src/rules/common/path-params-defined.ts +4 -4
  342. package/src/rules/common/path-segment-plural.ts +3 -2
  343. package/src/rules/common/paths-kebab-case.ts +2 -2
  344. package/src/rules/common/required-string-property-missing-min-length.ts +4 -4
  345. package/src/rules/common/response-contains-header.ts +5 -4
  346. package/src/rules/common/scalar-property-missing-example.ts +2 -1
  347. package/src/rules/common/security-defined.ts +5 -5
  348. package/src/rules/common/spec-strict-refs.ts +2 -1
  349. package/src/rules/common/spec.ts +4 -3
  350. package/src/rules/common/tag-description.ts +2 -1
  351. package/src/rules/common/tags-alphabetical.ts +4 -4
  352. package/src/rules/no-unresolved-refs.ts +4 -3
  353. package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +7 -5
  354. package/src/rules/oas2/__tests__/response-contains-header.test.ts +14 -8
  355. package/src/rules/oas2/__tests__/response-contains-property.test.ts +14 -8
  356. package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +3 -1
  357. package/src/rules/oas2/boolean-parameter-prefixes.ts +1 -1
  358. package/src/rules/oas2/index.ts +8 -6
  359. package/src/rules/oas2/request-mime-type.ts +2 -1
  360. package/src/rules/oas2/response-contains-property.ts +3 -2
  361. package/src/rules/oas2/response-mime-type.ts +2 -1
  362. package/src/rules/oas3/__tests__/array-parameter-serialization.test.ts +18 -6
  363. package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +7 -5
  364. package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +6 -6
  365. package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +2 -2
  366. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +34 -24
  367. package/src/rules/oas3/__tests__/no-server-example.com.test.ts +3 -3
  368. package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +3 -3
  369. package/src/rules/oas3/__tests__/no-unused-components.test.ts +1 -1
  370. package/src/rules/oas3/__tests__/operation-4xx-problem-details-rfc7807.test.ts +3 -3
  371. package/src/rules/oas3/__tests__/response-contains-header.test.ts +34 -22
  372. package/src/rules/oas3/__tests__/response-contains-property.test.ts +34 -20
  373. package/src/rules/oas3/__tests__/spec/spec.test.ts +12 -3
  374. package/src/rules/oas3/__tests__/spec-components-invalid-map-name.test.ts +9 -3
  375. package/src/rules/oas3/__tests__/utils/lint-document-for-test.ts +1 -1
  376. package/src/rules/oas3/array-parameter-serialization.ts +3 -2
  377. package/src/rules/oas3/boolean-parameter-prefixes.ts +1 -1
  378. package/src/rules/oas3/component-name-unique.ts +3 -3
  379. package/src/rules/oas3/index.ts +42 -38
  380. package/src/rules/oas3/no-empty-servers.ts +1 -1
  381. package/src/rules/oas3/no-example-value-and-externalValue.ts +1 -1
  382. package/src/rules/oas3/no-invalid-media-type-examples.ts +6 -4
  383. package/src/rules/oas3/no-server-example.com.ts +2 -1
  384. package/src/rules/oas3/no-server-trailing-slash.ts +1 -1
  385. package/src/rules/oas3/no-server-variables-empty-enum.ts +2 -2
  386. package/src/rules/oas3/no-undefined-server-variable.ts +1 -1
  387. package/src/rules/oas3/no-unused-components.ts +2 -2
  388. package/src/rules/oas3/operation-4xx-problem-details-rfc7807.ts +2 -1
  389. package/src/rules/oas3/request-mime-type.ts +2 -1
  390. package/src/rules/oas3/response-contains-property.ts +3 -2
  391. package/src/rules/oas3/response-mime-type.ts +2 -1
  392. package/src/rules/oas3/spec-components-invalid-map-name.ts +3 -3
  393. package/src/rules/other/stats.ts +8 -6
  394. package/src/rules/spot/parameters-no-body-inside-in.ts +17 -0
  395. package/src/rules/utils.ts +41 -4
  396. package/src/types/arazzo.ts +257 -334
  397. package/src/types/{asyncapi.ts → asyncapi2.ts} +41 -35
  398. package/src/types/asyncapi3.ts +383 -0
  399. package/src/types/json-schema-adapter.ts +2 -2
  400. package/src/types/oas3.ts +4 -4
  401. package/src/types/oas3_1.ts +5 -4
  402. package/src/types/redocly-yaml.ts +21 -4
  403. package/src/typings/arazzo.ts +169 -41
  404. package/src/typings/asyncapi3.ts +61 -0
  405. package/src/typings/common.ts +1 -0
  406. package/src/typings/swagger.ts +2 -2
  407. package/src/utils.ts +5 -3
  408. package/src/visitors.ts +58 -1
  409. package/src/walk.ts +3 -3
  410. package/tsconfig.tsbuildinfo +1 -1
  411. package/lib/types/asyncapi.d.ts +0 -2
@@ -1,13 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatProblems = exports.getTotals = void 0;
3
+ exports.getTotals = getTotals;
4
+ exports.formatProblems = formatProblems;
4
5
  const path = require("path");
5
6
  const logger_1 = require("../logger");
6
7
  const output_1 = require("../output");
7
- const coreVersion = require('../../package.json').version;
8
8
  const codeframes_1 = require("./codeframes");
9
9
  const env_1 = require("../env");
10
10
  const ref_utils_1 = require("../ref-utils");
11
+ const coreVersion = require('../../package.json').version;
11
12
  const ERROR_MESSAGE = {
12
13
  INVALID_SEVERITY_LEVEL: 'Invalid severity level; accepted values: error or warn',
13
14
  };
@@ -51,7 +52,6 @@ function getTotals(problems) {
51
52
  ignored,
52
53
  };
53
54
  }
54
- exports.getTotals = getTotals;
55
55
  function formatProblems(problems, opts) {
56
56
  const { maxProblems = 100, cwd = env_1.isBrowser ? '' : process.cwd(), format = 'codeframe', color = logger_1.colorOptions.enabled, totals = getTotals(problems), version = coreVersion, } = opts;
57
57
  logger_1.colorOptions.enabled = color; // force colors if specified
@@ -158,17 +158,27 @@ function formatProblems(problems, opts) {
158
158
  totals,
159
159
  version,
160
160
  problems: problems.map((p) => {
161
- var _a, _b, _c;
162
- const problem = Object.assign(Object.assign({}, p), { location: p.location.map((location) => (Object.assign(Object.assign({}, location), { source: {
161
+ const problem = {
162
+ ...p,
163
+ location: p.location.map((location) => ({
164
+ ...location,
165
+ source: {
163
166
  ref: (0, ref_utils_1.isAbsoluteUrl)(location.source.absoluteRef)
164
167
  ? location.source.absoluteRef
165
168
  : path.relative(cwd, location.source.absoluteRef),
166
- } }))), from: p.from
167
- ? Object.assign(Object.assign({}, p.from), { source: {
168
- ref: (0, ref_utils_1.isAbsoluteUrl)((_a = p.from) === null || _a === void 0 ? void 0 : _a.source.absoluteRef)
169
- ? (_b = p.from) === null || _b === void 0 ? void 0 : _b.source.absoluteRef
170
- : path.relative(cwd, ((_c = p.from) === null || _c === void 0 ? void 0 : _c.source.absoluteRef) || cwd),
171
- } }) : undefined });
169
+ },
170
+ })),
171
+ from: p.from
172
+ ? {
173
+ ...p.from,
174
+ source: {
175
+ ref: (0, ref_utils_1.isAbsoluteUrl)(p.from?.source.absoluteRef)
176
+ ? p.from?.source.absoluteRef
177
+ : path.relative(cwd, p.from?.source.absoluteRef || cwd),
178
+ },
179
+ }
180
+ : undefined,
181
+ };
172
182
  if (env_1.env.FORMAT_JSON_WITH_CODEFRAMES) {
173
183
  const location = p.location[0]; // TODO: support multiple locations
174
184
  const loc = (0, codeframes_1.getLineColLocation)(location);
@@ -228,7 +238,6 @@ function formatProblems(problems, opts) {
228
238
  output_1.output.write(`<error line="${line}" column="${col}" severity="${severity}" message="${message}" source="${source}" />\n`);
229
239
  }
230
240
  }
231
- exports.formatProblems = formatProblems;
232
241
  function formatSummary(problems) {
233
242
  const counts = {};
234
243
  for (const problem of problems) {
@@ -274,7 +283,7 @@ const groupByFiles = (problems) => {
274
283
  ruleIdPad: 0,
275
284
  locationPad: 0,
276
285
  };
277
- const mappedProblem = Object.assign(Object.assign({}, problem), { location: problem.location.map(codeframes_1.getLineColLocation) });
286
+ const mappedProblem = { ...problem, location: problem.location.map(codeframes_1.getLineColLocation) };
278
287
  fileGroups[absoluteRef].fileProblems.push(mappedProblem);
279
288
  fileGroups[absoluteRef].ruleIdPad = Math.max(problem.ruleId.length, fileGroups[absoluteRef].ruleIdPad);
280
289
  fileGroups[absoluteRef].locationPad = Math.max(Math.max(...mappedProblem.location.map((loc) => `${loc.start.line}:${loc.start.col}`.length)), fileGroups[absoluteRef].locationPad);
@@ -301,7 +310,6 @@ function xmlEscape(s) {
301
310
  });
302
311
  }
303
312
  function outputForGithubActions(problems, cwd) {
304
- var _a, _b;
305
313
  for (const problem of problems) {
306
314
  for (const location of problem.location.map(codeframes_1.getLineColLocation)) {
307
315
  let command;
@@ -322,8 +330,8 @@ function outputForGithubActions(problems, cwd) {
322
330
  : path.relative(cwd, location.source.absoluteRef),
323
331
  line: location.start.line,
324
332
  col: location.start.col,
325
- endLine: (_a = location.end) === null || _a === void 0 ? void 0 : _a.line,
326
- endColumn: (_b = location.end) === null || _b === void 0 ? void 0 : _b.col,
333
+ endLine: location.end?.line,
334
+ endColumn: location.end?.col,
327
335
  };
328
336
  output_1.output.write(`::${command} ${formatProperties(properties)}::${escapeMessage(message)}\n`);
329
337
  }
package/lib/index.d.ts CHANGED
@@ -3,7 +3,8 @@ export { Oas3_1Types } from './types/oas3_1';
3
3
  export { ArazzoTypes } from './types/arazzo';
4
4
  export { Oas3Types } from './types/oas3';
5
5
  export { Oas2Types } from './types/oas2';
6
- export { AsyncApi2Types } from './types/asyncapi';
6
+ export { AsyncApi2Types } from './types/asyncapi2';
7
+ export { AsyncApi3Types } from './types/asyncapi3';
7
8
  export { ConfigTypes } from './types/redocly-yaml';
8
9
  export type { Oas3Definition, Oas3_1Definition, Oas3Components, Oas3PathItem, Oas3Paths, Oas3ComponentName, Oas3Schema, Oas3_1Schema, Oas3Tag, Oas3_1Webhooks, Referenced, OasRef, } from './typings/openapi';
9
10
  export type { Oas2Definition } from './typings/swagger';
package/lib/index.js CHANGED
@@ -14,8 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.lintDocument = exports.validate = exports.lint = exports.getTotals = exports.formatProblems = exports.getLineColLocation = exports.getAstNodeByPointer = exports.walkDocument = exports.normalizeVisitors = exports.getTypes = exports.detectSpec = exports.SpecVersion = exports.getMajorSpecVersion = exports.SpecMajorVersion = exports.isAbsoluteUrl = exports.isRef = exports.unescapePointer = exports.stringifyYaml = exports.parseYaml = exports.makeDocumentFromString = exports.YamlParseError = exports.ResolveError = exports.resolveDocument = exports.BaseResolver = exports.Source = 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.AsyncApi2Types = exports.Oas2Types = exports.Oas3Types = exports.ArazzoTypes = exports.Oas3_1Types = exports.pause = exports.getProxyAgent = exports.isTruthy = exports.doesYamlFileExist = exports.slash = exports.readFileFromUrl = void 0;
18
- exports.bundleFromString = exports.mapTypeToComponent = exports.bundleDocument = exports.bundle = exports.lintConfig = exports.lintFromString = void 0;
17
+ exports.validate = exports.lint = exports.getTotals = exports.formatProblems = exports.getLineColLocation = exports.getAstNodeByPointer = exports.walkDocument = exports.normalizeVisitors = exports.getTypes = exports.detectSpec = exports.SpecVersion = exports.getMajorSpecVersion = exports.SpecMajorVersion = exports.isAbsoluteUrl = exports.isRef = exports.unescapePointer = exports.stringifyYaml = exports.parseYaml = exports.makeDocumentFromString = exports.YamlParseError = exports.ResolveError = exports.resolveDocument = exports.BaseResolver = exports.Source = 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.AsyncApi3Types = exports.AsyncApi2Types = exports.Oas2Types = exports.Oas3Types = exports.ArazzoTypes = exports.Oas3_1Types = exports.pause = exports.getProxyAgent = exports.isTruthy = exports.doesYamlFileExist = exports.slash = exports.readFileFromUrl = void 0;
18
+ exports.bundleFromString = exports.mapTypeToComponent = exports.bundleDocument = exports.bundle = exports.lintConfig = exports.lintFromString = exports.lintDocument = void 0;
19
19
  var utils_1 = require("./utils");
20
20
  Object.defineProperty(exports, "readFileFromUrl", { enumerable: true, get: function () { return utils_1.readFileFromUrl; } });
21
21
  Object.defineProperty(exports, "slash", { enumerable: true, get: function () { return utils_1.slash; } });
@@ -31,8 +31,10 @@ var oas3_1 = require("./types/oas3");
31
31
  Object.defineProperty(exports, "Oas3Types", { enumerable: true, get: function () { return oas3_1.Oas3Types; } });
32
32
  var oas2_1 = require("./types/oas2");
33
33
  Object.defineProperty(exports, "Oas2Types", { enumerable: true, get: function () { return oas2_1.Oas2Types; } });
34
- var asyncapi_1 = require("./types/asyncapi");
35
- Object.defineProperty(exports, "AsyncApi2Types", { enumerable: true, get: function () { return asyncapi_1.AsyncApi2Types; } });
34
+ var asyncapi2_1 = require("./types/asyncapi2");
35
+ Object.defineProperty(exports, "AsyncApi2Types", { enumerable: true, get: function () { return asyncapi2_1.AsyncApi2Types; } });
36
+ var asyncapi3_1 = require("./types/asyncapi3");
37
+ Object.defineProperty(exports, "AsyncApi3Types", { enumerable: true, get: function () { return asyncapi3_1.AsyncApi3Types; } });
36
38
  var redocly_yaml_1 = require("./types/redocly-yaml");
37
39
  Object.defineProperty(exports, "ConfigTypes", { enumerable: true, get: function () { return redocly_yaml_1.ConfigTypes; } });
38
40
  var types_1 = require("./types");
@@ -1,3 +1,3 @@
1
- import { LoadOptions, DumpOptions } from 'js-yaml';
1
+ import type { LoadOptions, DumpOptions } from 'js-yaml';
2
2
  export declare const parseYaml: (str: string, opts?: LoadOptions) => unknown;
3
3
  export declare const stringifyYaml: (obj: any, opts?: DumpOptions) => string;
@@ -9,7 +9,7 @@ const DEFAULT_SCHEMA_WITHOUT_TIMESTAMP = js_yaml_1.JSON_SCHEMA.extend({
9
9
  implicit: [js_yaml_1.types.merge],
10
10
  explicit: [js_yaml_1.types.binary, js_yaml_1.types.omap, js_yaml_1.types.pairs, js_yaml_1.types.set],
11
11
  });
12
- const parseYaml = (str, opts) => (0, js_yaml_1.load)(str, Object.assign({ schema: DEFAULT_SCHEMA_WITHOUT_TIMESTAMP }, opts));
12
+ const parseYaml = (str, opts) => (0, js_yaml_1.load)(str, { schema: DEFAULT_SCHEMA_WITHOUT_TIMESTAMP, ...opts });
13
13
  exports.parseYaml = parseYaml;
14
14
  const stringifyYaml = (obj, opts) => (0, js_yaml_1.dump)(obj, opts);
15
15
  exports.stringifyYaml = stringifyYaml;
package/lib/lint.d.ts CHANGED
@@ -1,12 +1,14 @@
1
1
  import { BaseResolver } from './resolve';
2
- import { StyleguideConfig, Config } from './config';
2
+ import type { StyleguideConfig, Config } from './config';
3
3
  import type { Document, ResolvedRefMap } from './resolve';
4
4
  import type { ProblemSeverity } from './walk';
5
5
  import type { NodeType } from './types';
6
+ import type { CollectFn } from './utils';
6
7
  export declare function lint(opts: {
7
8
  ref: string;
8
9
  config: Config;
9
10
  externalRefResolver?: BaseResolver;
11
+ collectSpecData?: CollectFn;
10
12
  }): Promise<import("./walk").NormalizedProblem[]>;
11
13
  export declare function lintFromString(opts: {
12
14
  source: string;
package/lib/lint.js CHANGED
@@ -1,125 +1,118 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.lintConfig = exports.lintDocument = exports.lintFromString = exports.lint = void 0;
3
+ exports.lint = lint;
4
+ exports.lintFromString = lintFromString;
5
+ exports.lintDocument = lintDocument;
6
+ exports.lintConfig = lintConfig;
7
+ const config_1 = require("@redocly/config");
13
8
  const resolve_1 = require("./resolve");
14
9
  const visitors_1 = require("./visitors");
15
10
  const walk_1 = require("./walk");
16
- const config_1 = require("./config");
11
+ const config_2 = require("./config");
17
12
  const types_1 = require("./types");
18
13
  const ajv_1 = require("./rules/ajv");
19
14
  const oas_types_1 = require("./oas-types");
20
15
  const redocly_yaml_1 = require("./types/redocly-yaml");
21
16
  const spec_1 = require("./rules/common/spec");
22
17
  const no_unresolved_refs_1 = require("./rules/no-unresolved-refs");
23
- const config_2 = require("@redocly/config");
24
- function lint(opts) {
25
- return __awaiter(this, void 0, void 0, function* () {
26
- const { ref, externalRefResolver = new resolve_1.BaseResolver(opts.config.resolve) } = opts;
27
- const document = (yield externalRefResolver.resolveDocument(null, ref, true));
28
- return lintDocument(Object.assign(Object.assign({ document }, opts), { externalRefResolver, config: opts.config.styleguide }));
18
+ async function lint(opts) {
19
+ const { ref, externalRefResolver = new resolve_1.BaseResolver(opts.config.resolve) } = opts;
20
+ const document = (await externalRefResolver.resolveDocument(null, ref, true));
21
+ opts.collectSpecData?.(document.parsed);
22
+ return lintDocument({
23
+ document,
24
+ ...opts,
25
+ externalRefResolver,
26
+ config: opts.config.styleguide,
29
27
  });
30
28
  }
31
- exports.lint = lint;
32
- function lintFromString(opts) {
33
- return __awaiter(this, void 0, void 0, function* () {
34
- const { source, absoluteRef, externalRefResolver = new resolve_1.BaseResolver(opts.config.resolve) } = opts;
35
- const document = (0, resolve_1.makeDocumentFromString)(source, absoluteRef || '/');
36
- return lintDocument(Object.assign(Object.assign({ document }, opts), { externalRefResolver, config: opts.config.styleguide }));
29
+ async function lintFromString(opts) {
30
+ const { source, absoluteRef, externalRefResolver = new resolve_1.BaseResolver(opts.config.resolve) } = opts;
31
+ const document = (0, resolve_1.makeDocumentFromString)(source, absoluteRef || '/');
32
+ return lintDocument({
33
+ document,
34
+ ...opts,
35
+ externalRefResolver,
36
+ config: opts.config.styleguide,
37
37
  });
38
38
  }
39
- exports.lintFromString = lintFromString;
40
- function lintDocument(opts) {
41
- return __awaiter(this, void 0, void 0, function* () {
42
- (0, ajv_1.releaseAjvInstance)(); // FIXME: preprocessors can modify nodes which are then cached to ajv-instance by absolute path
43
- const { document, customTypes, externalRefResolver, config } = opts;
44
- const specVersion = (0, oas_types_1.detectSpec)(document.parsed);
45
- const specMajorVersion = (0, oas_types_1.getMajorSpecVersion)(specVersion);
46
- const rules = config.getRulesForOasVersion(specMajorVersion);
47
- const types = (0, types_1.normalizeTypes)(config.extendTypes(customTypes !== null && customTypes !== void 0 ? customTypes : (0, oas_types_1.getTypes)(specVersion), specVersion), config);
48
- const ctx = {
49
- problems: [],
50
- oasVersion: specVersion,
51
- visitorsData: {},
52
- };
53
- const preprocessors = (0, config_1.initRules)(rules, config, 'preprocessors', specVersion);
54
- const regularRules = (0, config_1.initRules)(rules, config, 'rules', specVersion);
55
- let resolvedRefMap = yield (0, resolve_1.resolveDocument)({
56
- rootDocument: document,
57
- rootType: types.Root,
58
- externalRefResolver,
59
- });
60
- if (preprocessors.length > 0) {
61
- // Make additional pass to resolve refs defined in preprocessors.
62
- (0, walk_1.walkDocument)({
63
- document,
64
- rootType: types.Root,
65
- normalizedVisitors: (0, visitors_1.normalizeVisitors)(preprocessors, types),
66
- resolvedRefMap,
67
- ctx,
68
- });
69
- resolvedRefMap = yield (0, resolve_1.resolveDocument)({
70
- rootDocument: document,
71
- rootType: types.Root,
72
- externalRefResolver,
73
- });
74
- }
75
- const normalizedVisitors = (0, visitors_1.normalizeVisitors)(regularRules, types);
39
+ async function lintDocument(opts) {
40
+ (0, ajv_1.releaseAjvInstance)(); // FIXME: preprocessors can modify nodes which are then cached to ajv-instance by absolute path
41
+ const { document, customTypes, externalRefResolver, config } = opts;
42
+ const specVersion = (0, oas_types_1.detectSpec)(document.parsed);
43
+ const specMajorVersion = (0, oas_types_1.getMajorSpecVersion)(specVersion);
44
+ const rules = config.getRulesForOasVersion(specMajorVersion);
45
+ const types = (0, types_1.normalizeTypes)(config.extendTypes(customTypes ?? (0, oas_types_1.getTypes)(specVersion), specVersion), config);
46
+ const ctx = {
47
+ problems: [],
48
+ oasVersion: specVersion,
49
+ visitorsData: {},
50
+ };
51
+ const preprocessors = (0, config_2.initRules)(rules, config, 'preprocessors', specVersion);
52
+ const regularRules = (0, config_2.initRules)(rules, config, 'rules', specVersion);
53
+ let resolvedRefMap = await (0, resolve_1.resolveDocument)({
54
+ rootDocument: document,
55
+ rootType: types.Root,
56
+ externalRefResolver,
57
+ });
58
+ if (preprocessors.length > 0) {
59
+ // Make additional pass to resolve refs defined in preprocessors.
76
60
  (0, walk_1.walkDocument)({
77
61
  document,
78
62
  rootType: types.Root,
79
- normalizedVisitors,
63
+ normalizedVisitors: (0, visitors_1.normalizeVisitors)(preprocessors, types),
80
64
  resolvedRefMap,
81
65
  ctx,
82
66
  });
83
- return ctx.problems.map((problem) => config.addProblemToIgnore(problem));
67
+ resolvedRefMap = await (0, resolve_1.resolveDocument)({
68
+ rootDocument: document,
69
+ rootType: types.Root,
70
+ externalRefResolver,
71
+ });
72
+ }
73
+ const normalizedVisitors = (0, visitors_1.normalizeVisitors)(regularRules, types);
74
+ (0, walk_1.walkDocument)({
75
+ document,
76
+ rootType: types.Root,
77
+ normalizedVisitors,
78
+ resolvedRefMap,
79
+ ctx,
84
80
  });
81
+ return ctx.problems.map((problem) => config.addProblemToIgnore(problem));
85
82
  }
86
- exports.lintDocument = lintDocument;
87
- function lintConfig(opts) {
88
- return __awaiter(this, void 0, void 0, function* () {
89
- const { document, severity, externalRefResolver = new resolve_1.BaseResolver(), config } = opts;
90
- const ctx = {
91
- problems: [],
92
- oasVersion: oas_types_1.SpecVersion.OAS3_0,
93
- visitorsData: {},
94
- };
95
- const types = (0, types_1.normalizeTypes)(opts.externalConfigTypes || (0, redocly_yaml_1.createConfigTypes)(config_2.rootRedoclyConfigSchema, config), { doNotResolveExamples: config.styleguide.doNotResolveExamples });
96
- const rules = [
97
- {
98
- severity: severity || 'error',
99
- ruleId: 'configuration spec',
100
- visitor: (0, spec_1.Spec)({ severity: 'error' }),
101
- },
102
- {
103
- severity: severity || 'error',
104
- ruleId: 'configuration no-unresolved-refs',
105
- visitor: (0, no_unresolved_refs_1.NoUnresolvedRefs)({ severity: 'error' }),
106
- },
107
- ];
108
- const normalizedVisitors = (0, visitors_1.normalizeVisitors)(rules, types);
109
- const resolvedRefMap = opts.resolvedRefMap ||
110
- (yield (0, resolve_1.resolveDocument)({
111
- rootDocument: document,
112
- rootType: types.ConfigRoot,
113
- externalRefResolver,
114
- }));
115
- (0, walk_1.walkDocument)({
116
- document,
83
+ async function lintConfig(opts) {
84
+ const { document, severity, externalRefResolver = new resolve_1.BaseResolver(), config } = opts;
85
+ const ctx = {
86
+ problems: [],
87
+ oasVersion: oas_types_1.SpecVersion.OAS3_0,
88
+ visitorsData: {},
89
+ };
90
+ const types = (0, types_1.normalizeTypes)(opts.externalConfigTypes || (0, redocly_yaml_1.createConfigTypes)(config_1.rootRedoclyConfigSchema, config), { doNotResolveExamples: config.styleguide.doNotResolveExamples });
91
+ const rules = [
92
+ {
93
+ severity: severity || 'error',
94
+ ruleId: 'configuration spec',
95
+ visitor: (0, spec_1.Spec)({ severity: 'error' }),
96
+ },
97
+ {
98
+ severity: severity || 'error',
99
+ ruleId: 'configuration no-unresolved-refs',
100
+ visitor: (0, no_unresolved_refs_1.NoUnresolvedRefs)({ severity: 'error' }),
101
+ },
102
+ ];
103
+ const normalizedVisitors = (0, visitors_1.normalizeVisitors)(rules, types);
104
+ const resolvedRefMap = opts.resolvedRefMap ||
105
+ (await (0, resolve_1.resolveDocument)({
106
+ rootDocument: document,
117
107
  rootType: types.ConfigRoot,
118
- normalizedVisitors,
119
- resolvedRefMap,
120
- ctx,
121
- });
122
- return ctx.problems;
108
+ externalRefResolver,
109
+ }));
110
+ (0, walk_1.walkDocument)({
111
+ document,
112
+ rootType: types.ConfigRoot,
113
+ normalizedVisitors,
114
+ resolvedRefMap,
115
+ ctx,
123
116
  });
117
+ return ctx.problems;
124
118
  }
125
- exports.lintConfig = lintConfig;
package/lib/logger.js CHANGED
@@ -2,10 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.logger = exports.colorize = exports.colorOptions = void 0;
4
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
5
  const env_1 = require("./env");
8
6
  const utils_1 = require("./utils");
7
+ var colorette_1 = require("colorette");
8
+ Object.defineProperty(exports, "colorOptions", { enumerable: true, get: function () { return colorette_1.options; } });
9
9
  exports.colorize = new Proxy(colorette, {
10
10
  get(target, prop) {
11
11
  if (env_1.isBrowser) {
@@ -1,32 +1,36 @@
1
- import { Oas3Rule, Oas3Preprocessor, Oas2Rule, Oas2Preprocessor, Async2Preprocessor, Async2Rule, ArazzoPreprocessor, ArazzoRule } from './visitors';
2
- import { BuiltInAsync2RuleId, BuiltInCommonOASRuleId, BuiltInArazzoRuleId, BuiltInOAS2RuleId, BuiltInOAS3RuleId } from './types/redocly-yaml';
3
- export type RuleSet<T> = Record<string, T>;
1
+ import type { BuiltInAsync2RuleId, BuiltInAsync3RuleId, BuiltInCommonOASRuleId, BuiltInArazzoRuleId, BuiltInOAS2RuleId, BuiltInOAS3RuleId } from './types/redocly-yaml';
2
+ import type { Oas3Rule, Oas3Preprocessor, Oas2Rule, Oas2Preprocessor, Async2Preprocessor, Async2Rule, Async3Preprocessor, Async3Rule, ArazzoPreprocessor, ArazzoRule } from './visitors';
4
3
  export declare enum SpecVersion {
5
4
  OAS2 = "oas2",
6
5
  OAS3_0 = "oas3_0",
7
6
  OAS3_1 = "oas3_1",
8
7
  Async2 = "async2",
8
+ Async3 = "async3",
9
9
  Arazzo = "arazzo"
10
10
  }
11
11
  export declare enum SpecMajorVersion {
12
12
  OAS2 = "oas2",
13
13
  OAS3 = "oas3",
14
14
  Async2 = "async2",
15
+ Async3 = "async3",
15
16
  Arazzo = "arazzo"
16
17
  }
17
18
  export type RuleMap<Key extends string, RuleConfig, T> = Record<T extends 'built-in' ? Key : string, RuleConfig>;
18
19
  export type Oas3RuleSet<T = undefined> = RuleMap<BuiltInCommonOASRuleId | BuiltInOAS3RuleId | 'assertions', Oas3Rule, T>;
19
20
  export type Oas2RuleSet<T = undefined> = RuleMap<BuiltInCommonOASRuleId | BuiltInOAS2RuleId | 'assertions', Oas2Rule, T>;
20
21
  export type Async2RuleSet<T = undefined> = RuleMap<BuiltInAsync2RuleId | 'assertions', Async2Rule, T>;
22
+ export type Async3RuleSet<T = undefined> = RuleMap<BuiltInAsync3RuleId | 'assertions', Async3Rule, T>;
21
23
  export type ArazzoRuleSet<T = undefined> = RuleMap<BuiltInArazzoRuleId | 'assertions', ArazzoRule, T>;
22
24
  export type Oas3PreprocessorsSet = Record<string, Oas3Preprocessor>;
23
25
  export type Oas2PreprocessorsSet = Record<string, Oas2Preprocessor>;
24
26
  export type Async2PreprocessorsSet = Record<string, Async2Preprocessor>;
27
+ export type Async3PreprocessorsSet = Record<string, Async3Preprocessor>;
25
28
  export type ArazzoPreprocessorsSet = Record<string, ArazzoPreprocessor>;
26
29
  export type Oas3DecoratorsSet = Record<string, Oas3Preprocessor>;
27
30
  export type Oas2DecoratorsSet = Record<string, Oas2Preprocessor>;
28
31
  export type Async2DecoratorsSet = Record<string, Async2Preprocessor>;
32
+ export type Async3DecoratorsSet = Record<string, Async3Preprocessor>;
29
33
  export type ArazzoDecoratorsSet = Record<string, ArazzoPreprocessor>;
30
- export declare function detectSpec(root: any): SpecVersion;
34
+ export declare function detectSpec(root: unknown): SpecVersion;
31
35
  export declare function getMajorSpecVersion(version: SpecVersion): SpecMajorVersion;
32
- export declare function getTypes(spec: SpecVersion): Record<string, import("./types").NodeType> | Record<"Root" | "Tag" | "ExternalDocs" | "SecurityRequirement" | "Info" | "Contact" | "License" | "Paths" | "PathItem" | "Parameter" | "Operation" | "Example" | "Header" | "Responses" | "Response" | "Schema" | "Xml" | "SchemaProperties" | "NamedSchemas" | "NamedResponses" | "NamedParameters" | "NamedSecuritySchemes" | "SecurityScheme" | "Examples" | "ExamplesMap" | "TagList" | "SecurityRequirementList" | "ParameterList" | "ParameterItems" | "TagGroup" | "TagGroups" | "EnumDescriptions" | "Logo" | "XCodeSample" | "XCodeSampleList" | "XServer" | "XServerList", import("./types").NodeType> | Record<"Root" | "Tag" | "ExternalDocs" | "Server" | "ServerVariable" | "SecurityRequirement" | "Info" | "Contact" | "License" | "Paths" | "PathItem" | "Callback" | "CallbacksMap" | "Parameter" | "Operation" | "RequestBody" | "MediaTypesMap" | "MediaType" | "Example" | "Encoding" | "Header" | "Responses" | "Response" | "Link" | "Schema" | "Xml" | "SchemaProperties" | "DiscriminatorMapping" | "Discriminator" | "Components" | "NamedSchemas" | "NamedResponses" | "NamedParameters" | "NamedExamples" | "NamedRequestBodies" | "NamedHeaders" | "NamedSecuritySchemes" | "NamedLinks" | "NamedCallbacks" | "ImplicitFlow" | "PasswordFlow" | "ClientCredentials" | "AuthorizationCode" | "OAuth2Flows" | "SecurityScheme" | "ServerVariablesMap" | "ExamplesMap" | "EncodingMap" | "HeadersMap" | "LinksMap" | "TagList" | "SecurityRequirementList" | "ParameterList" | "TagGroup" | "TagGroups" | "EnumDescriptions" | "Logo" | "XCodeSample" | "XCodeSampleList" | "ServerList" | "XUsePkce" | "WebhooksMap", import("./types").NodeType> | Record<"Root" | "Info" | "License" | "Operation" | "Schema" | "SchemaProperties" | "Components" | "SecurityScheme" | "NamedPathItems" | "DependentRequired", import("./types").NodeType>;
36
+ export declare function getTypes(spec: SpecVersion): Record<string, import("./types").NodeType> | Record<"Root" | "Tag" | "TagList" | "ExternalDocs" | "SecurityRequirement" | "SecurityRequirementList" | "Info" | "Contact" | "License" | "Paths" | "PathItem" | "Parameter" | "ParameterList" | "ParameterItems" | "Operation" | "Example" | "ExamplesMap" | "Examples" | "Header" | "Responses" | "Response" | "Schema" | "Xml" | "SchemaProperties" | "NamedSchemas" | "NamedResponses" | "NamedParameters" | "NamedSecuritySchemes" | "SecurityScheme" | "TagGroup" | "TagGroups" | "EnumDescriptions" | "Logo" | "XCodeSample" | "XCodeSampleList" | "XServer" | "XServerList", import("./types").NodeType> | Record<"Root" | "Tag" | "TagList" | "ExternalDocs" | "SecurityRequirement" | "SecurityRequirementList" | "Info" | "Contact" | "License" | "Paths" | "PathItem" | "Parameter" | "ParameterList" | "Operation" | "Example" | "ExamplesMap" | "Header" | "Responses" | "Response" | "Schema" | "Xml" | "SchemaProperties" | "NamedSchemas" | "NamedResponses" | "NamedParameters" | "NamedSecuritySchemes" | "SecurityScheme" | "TagGroup" | "TagGroups" | "EnumDescriptions" | "Logo" | "XCodeSample" | "XCodeSampleList" | "Server" | "ServerList" | "ServerVariable" | "ServerVariablesMap" | "Callback" | "CallbacksMap" | "RequestBody" | "MediaTypesMap" | "MediaType" | "Encoding" | "EncodingMap" | "HeadersMap" | "Link" | "LinksMap" | "DiscriminatorMapping" | "Discriminator" | "Components" | "NamedExamples" | "NamedRequestBodies" | "NamedHeaders" | "NamedLinks" | "NamedCallbacks" | "ImplicitFlow" | "PasswordFlow" | "ClientCredentials" | "AuthorizationCode" | "OAuth2Flows" | "XUsePkce" | "WebhooksMap", import("./types").NodeType> | Record<"Root" | "Info" | "License" | "Operation" | "Schema" | "SchemaProperties" | "SecurityScheme" | "Components" | "PatternProperties" | "NamedPathItems" | "DependentRequired", import("./types").NodeType>;
package/lib/oas-types.js CHANGED
@@ -1,17 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTypes = exports.getMajorSpecVersion = exports.detectSpec = exports.SpecMajorVersion = exports.SpecVersion = void 0;
3
+ exports.SpecMajorVersion = exports.SpecVersion = void 0;
4
+ exports.detectSpec = detectSpec;
5
+ exports.getMajorSpecVersion = getMajorSpecVersion;
6
+ exports.getTypes = getTypes;
4
7
  const oas2_1 = require("./types/oas2");
5
8
  const oas3_1 = require("./types/oas3");
6
9
  const oas3_1_1 = require("./types/oas3_1");
7
- const asyncapi_1 = require("./types/asyncapi");
10
+ const asyncapi2_1 = require("./types/asyncapi2");
11
+ const asyncapi3_1 = require("./types/asyncapi3");
8
12
  const arazzo_1 = require("./types/arazzo");
13
+ const utils_1 = require("./utils");
9
14
  var SpecVersion;
10
15
  (function (SpecVersion) {
11
16
  SpecVersion["OAS2"] = "oas2";
12
17
  SpecVersion["OAS3_0"] = "oas3_0";
13
18
  SpecVersion["OAS3_1"] = "oas3_1";
14
19
  SpecVersion["Async2"] = "async2";
20
+ SpecVersion["Async3"] = "async3";
15
21
  SpecVersion["Arazzo"] = "arazzo";
16
22
  })(SpecVersion || (exports.SpecVersion = SpecVersion = {}));
17
23
  var SpecMajorVersion;
@@ -19,47 +25,50 @@ var SpecMajorVersion;
19
25
  SpecMajorVersion["OAS2"] = "oas2";
20
26
  SpecMajorVersion["OAS3"] = "oas3";
21
27
  SpecMajorVersion["Async2"] = "async2";
28
+ SpecMajorVersion["Async3"] = "async3";
22
29
  SpecMajorVersion["Arazzo"] = "arazzo";
23
30
  })(SpecMajorVersion || (exports.SpecMajorVersion = SpecMajorVersion = {}));
24
31
  const typesMap = {
25
32
  [SpecVersion.OAS2]: oas2_1.Oas2Types,
26
33
  [SpecVersion.OAS3_0]: oas3_1.Oas3Types,
27
34
  [SpecVersion.OAS3_1]: oas3_1_1.Oas3_1Types,
28
- [SpecVersion.Async2]: asyncapi_1.AsyncApi2Types,
35
+ [SpecVersion.Async2]: asyncapi2_1.AsyncApi2Types,
36
+ [SpecVersion.Async3]: asyncapi3_1.AsyncApi3Types,
29
37
  [SpecVersion.Arazzo]: arazzo_1.ArazzoTypes,
30
38
  };
31
39
  function detectSpec(root) {
32
- if (typeof root !== 'object') {
40
+ if (!(0, utils_1.isPlainObject)(root)) {
33
41
  throw new Error(`Document must be JSON object, got ${typeof root}`);
34
42
  }
35
43
  if (root.openapi && typeof root.openapi !== 'string') {
36
44
  throw new Error(`Invalid OpenAPI version: should be a string but got "${typeof root.openapi}"`);
37
45
  }
38
- if (root.openapi && root.openapi.startsWith('3.0')) {
46
+ if (typeof root.openapi === 'string' && root.openapi.startsWith('3.0')) {
39
47
  return SpecVersion.OAS3_0;
40
48
  }
41
- if (root.openapi && root.openapi.startsWith('3.1')) {
49
+ if (typeof root.openapi === 'string' && root.openapi.startsWith('3.1')) {
42
50
  return SpecVersion.OAS3_1;
43
51
  }
44
52
  if (root.swagger && root.swagger === '2.0') {
45
53
  return SpecVersion.OAS2;
46
54
  }
47
- // if not detected yet
48
55
  if (root.openapi || root.swagger) {
49
56
  throw new Error(`Unsupported OpenAPI version: ${root.openapi || root.swagger}`);
50
57
  }
51
- if (root.asyncapi && root.asyncapi.startsWith('2.')) {
58
+ if (typeof root.asyncapi === 'string' && root.asyncapi.startsWith('2.')) {
52
59
  return SpecVersion.Async2;
53
60
  }
61
+ if (typeof root.asyncapi === 'string' && root.asyncapi.startsWith('3.')) {
62
+ return SpecVersion.Async3;
63
+ }
54
64
  if (root.asyncapi) {
55
65
  throw new Error(`Unsupported AsyncAPI version: ${root.asyncapi}`);
56
66
  }
57
- if (root.arazzo && root.arazzo.startsWith('1.')) {
67
+ if (typeof root.arazzo === 'string' && root.arazzo.startsWith('1.')) {
58
68
  return SpecVersion.Arazzo;
59
69
  }
60
70
  throw new Error(`Unsupported specification`);
61
71
  }
62
- exports.detectSpec = detectSpec;
63
72
  function getMajorSpecVersion(version) {
64
73
  if (version === SpecVersion.OAS2) {
65
74
  return SpecMajorVersion.OAS2;
@@ -67,6 +76,9 @@ function getMajorSpecVersion(version) {
67
76
  else if (version === SpecVersion.Async2) {
68
77
  return SpecMajorVersion.Async2;
69
78
  }
79
+ else if (version === SpecVersion.Async3) {
80
+ return SpecMajorVersion.Async3;
81
+ }
70
82
  else if (version === SpecVersion.Arazzo) {
71
83
  return SpecMajorVersion.Arazzo;
72
84
  }
@@ -74,8 +86,6 @@ function getMajorSpecVersion(version) {
74
86
  return SpecMajorVersion.OAS3;
75
87
  }
76
88
  }
77
- exports.getMajorSpecVersion = getMajorSpecVersion;
78
89
  function getTypes(spec) {
79
90
  return typesMap[spec];
80
91
  }
81
- exports.getTypes = getTypes;
@@ -1,4 +1,4 @@
1
- import { Region } from '../config/types';
1
+ import type { Region } from '../config/types';
2
2
  export declare const DEFAULT_REGION = "us";
3
3
  export declare const DOMAINS: {
4
4
  us: string;
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isRedoclyRegistryURL = exports.getRedoclyDomain = exports.setRedoclyDomain = exports.getDomains = exports.AVAILABLE_REGIONS = exports.DOMAINS = exports.DEFAULT_REGION = void 0;
3
+ exports.AVAILABLE_REGIONS = exports.DOMAINS = exports.DEFAULT_REGION = void 0;
4
+ exports.getDomains = getDomains;
5
+ exports.setRedoclyDomain = setRedoclyDomain;
6
+ exports.getRedoclyDomain = getRedoclyDomain;
7
+ exports.isRedoclyRegistryURL = isRedoclyRegistryURL;
4
8
  let redoclyDomain = 'redocly.com';
5
9
  exports.DEFAULT_REGION = 'us';
6
10
  exports.DOMAINS = getDomains();
@@ -12,7 +16,7 @@ function getDomains() {
12
16
  };
13
17
  // FIXME: temporary fix for our lab environments
14
18
  const domain = redoclyDomain;
15
- if (domain === null || domain === void 0 ? void 0 : domain.endsWith('.redocly.host')) {
19
+ if (domain?.endsWith('.redocly.host')) {
16
20
  domains[domain.split('.')[0]] = domain;
17
21
  }
18
22
  if (domain === 'redoc.online') {
@@ -20,15 +24,12 @@ function getDomains() {
20
24
  }
21
25
  return domains;
22
26
  }
23
- exports.getDomains = getDomains;
24
27
  function setRedoclyDomain(domain) {
25
28
  redoclyDomain = domain;
26
29
  }
27
- exports.setRedoclyDomain = setRedoclyDomain;
28
30
  function getRedoclyDomain() {
29
31
  return redoclyDomain;
30
32
  }
31
- exports.getRedoclyDomain = getRedoclyDomain;
32
33
  function isRedoclyRegistryURL(link) {
33
34
  const domain = getRedoclyDomain() || exports.DOMAINS[exports.DEFAULT_REGION];
34
35
  const legacyDomain = domain === 'redocly.com' ? 'redoc.ly' : domain;
@@ -38,4 +39,3 @@ function isRedoclyRegistryURL(link) {
38
39
  }
39
40
  return true;
40
41
  }
41
- exports.isRedoclyRegistryURL = isRedoclyRegistryURL;
@@ -1,5 +1,5 @@
1
1
  import { RegistryApi } from './registry-api';
2
- import { RegionalToken, RegionalTokenWithValidity } from './redocly-client-types';
2
+ import type { RegionalToken, RegionalTokenWithValidity } from './redocly-client-types';
3
3
  import type { AccessTokens, Region } from '../config/types';
4
4
  export declare const TOKEN_FILENAME = ".redocly-config.json";
5
5
  export declare class RedoclyClient {