@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
package/lib/utils.js CHANGED
@@ -1,15 +1,40 @@
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.dequal = exports.getProxyAgent = exports.pause = exports.nextTick = exports.pickDefined = exports.keysOf = exports.identity = exports.isTruthy = exports.showErrorForDeprecatedField = exports.showWarningForDeprecatedField = exports.doesYamlFileExist = exports.isCustomRuleId = exports.getMatchingStatusCodeRange = exports.assignExisting = exports.isNotString = exports.isString = exports.isNotEmptyObject = exports.slash = exports.isPathParameter = exports.yamlAndJsonSyncReader = exports.readFileAsStringSync = exports.validateMimeTypeOAS3 = exports.validateMimeType = exports.splitCamelCaseIntoWords = exports.omitObjectProps = exports.pickObjectProps = exports.readFileFromUrl = exports.isEmptyArray = exports.isEmptyObject = exports.isPlainObject = exports.isDefined = exports.loadYaml = exports.popStack = exports.pushStack = exports.stringifyYaml = exports.parseYaml = void 0;
3
+ exports.stringifyYaml = exports.parseYaml = void 0;
4
+ exports.pushStack = pushStack;
5
+ exports.popStack = popStack;
6
+ exports.loadYaml = loadYaml;
7
+ exports.isDefined = isDefined;
8
+ exports.isPlainObject = isPlainObject;
9
+ exports.isEmptyObject = isEmptyObject;
10
+ exports.isEmptyArray = isEmptyArray;
11
+ exports.readFileFromUrl = readFileFromUrl;
12
+ exports.pickObjectProps = pickObjectProps;
13
+ exports.omitObjectProps = omitObjectProps;
14
+ exports.splitCamelCaseIntoWords = splitCamelCaseIntoWords;
15
+ exports.validateMimeType = validateMimeType;
16
+ exports.validateMimeTypeOAS3 = validateMimeTypeOAS3;
17
+ exports.readFileAsStringSync = readFileAsStringSync;
18
+ exports.yamlAndJsonSyncReader = yamlAndJsonSyncReader;
19
+ exports.isPathParameter = isPathParameter;
20
+ exports.slash = slash;
21
+ exports.isNotEmptyObject = isNotEmptyObject;
22
+ exports.isString = isString;
23
+ exports.isNotString = isNotString;
24
+ exports.assignExisting = assignExisting;
25
+ exports.getMatchingStatusCodeRange = getMatchingStatusCodeRange;
26
+ exports.isCustomRuleId = isCustomRuleId;
27
+ exports.doesYamlFileExist = doesYamlFileExist;
28
+ exports.showWarningForDeprecatedField = showWarningForDeprecatedField;
29
+ exports.showErrorForDeprecatedField = showErrorForDeprecatedField;
30
+ exports.isTruthy = isTruthy;
31
+ exports.identity = identity;
32
+ exports.keysOf = keysOf;
33
+ exports.pickDefined = pickDefined;
34
+ exports.nextTick = nextTick;
35
+ exports.pause = pause;
36
+ exports.getProxyAgent = getProxyAgent;
37
+ exports.dequal = dequal;
13
38
  const fs = require("fs");
14
39
  const path_1 = require("path");
15
40
  const minimatch = require("minimatch");
@@ -24,54 +49,41 @@ Object.defineProperty(exports, "stringifyYaml", { enumerable: true, get: functio
24
49
  function pushStack(head, value) {
25
50
  return { prev: head, value };
26
51
  }
27
- exports.pushStack = pushStack;
28
52
  function popStack(head) {
29
- var _a;
30
- return (_a = head === null || head === void 0 ? void 0 : head.prev) !== null && _a !== void 0 ? _a : null;
53
+ return head?.prev ?? null;
31
54
  }
32
- exports.popStack = popStack;
33
- function loadYaml(filename) {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- const contents = yield fs.promises.readFile(filename, 'utf-8');
36
- return (0, js_yaml_1.parseYaml)(contents);
37
- });
55
+ async function loadYaml(filename) {
56
+ const contents = await fs.promises.readFile(filename, 'utf-8');
57
+ return (0, js_yaml_1.parseYaml)(contents);
38
58
  }
39
- exports.loadYaml = loadYaml;
40
59
  function isDefined(x) {
41
60
  return x !== undefined;
42
61
  }
43
- exports.isDefined = isDefined;
44
62
  function isPlainObject(value) {
45
63
  return value !== null && typeof value === 'object' && !Array.isArray(value);
46
64
  }
47
- exports.isPlainObject = isPlainObject;
48
65
  function isEmptyObject(value) {
49
66
  return isPlainObject(value) && Object.keys(value).length === 0;
50
67
  }
51
- exports.isEmptyObject = isEmptyObject;
52
68
  function isEmptyArray(value) {
53
69
  return Array.isArray(value) && value.length === 0;
54
70
  }
55
- exports.isEmptyArray = isEmptyArray;
56
- function readFileFromUrl(url, config) {
57
- return __awaiter(this, void 0, void 0, function* () {
58
- const headers = {};
59
- for (const header of config.headers) {
60
- if (match(url, header.matches)) {
61
- headers[header.name] =
62
- header.envVariable !== undefined ? env_1.env[header.envVariable] || '' : header.value;
63
- }
64
- }
65
- const req = yield (config.customFetch || node_fetch_1.default)(url, {
66
- headers: headers,
67
- });
68
- if (!req.ok) {
69
- throw new Error(`Failed to load ${url}: ${req.status} ${req.statusText}`);
71
+ async function readFileFromUrl(url, config) {
72
+ const headers = {};
73
+ for (const header of config.headers) {
74
+ if (match(url, header.matches)) {
75
+ headers[header.name] =
76
+ header.envVariable !== undefined ? env_1.env[header.envVariable] || '' : header.value;
70
77
  }
71
- return { body: yield req.text(), mimeType: req.headers.get('content-type') };
78
+ }
79
+ const req = await (config.customFetch || node_fetch_1.default)(url, {
80
+ headers: headers,
72
81
  });
82
+ if (!req.ok) {
83
+ throw new Error(`Failed to load ${url}: ${req.status} ${req.statusText}`);
84
+ }
85
+ return { body: await req.text(), mimeType: req.headers.get('content-type') };
73
86
  }
74
- exports.readFileFromUrl = readFileFromUrl;
75
87
  function match(url, pattern) {
76
88
  if (!pattern.match(/^https?:\/\//)) {
77
89
  // if pattern doesn't specify protocol directly, do not match against it
@@ -82,11 +94,9 @@ function match(url, pattern) {
82
94
  function pickObjectProps(object, keys) {
83
95
  return Object.fromEntries(keys.filter((key) => key in object).map((key) => [key, object[key]]));
84
96
  }
85
- exports.pickObjectProps = pickObjectProps;
86
97
  function omitObjectProps(object, keys) {
87
98
  return Object.fromEntries(Object.entries(object).filter(([key]) => !keys.includes(key)));
88
99
  }
89
- exports.omitObjectProps = omitObjectProps;
90
100
  function splitCamelCaseIntoWords(str) {
91
101
  const camel = str
92
102
  .split(/(?:[-._])|([A-Z][a-z]+)/)
@@ -98,7 +108,6 @@ function splitCamelCaseIntoWords(str) {
98
108
  .map((item) => item.toLocaleLowerCase());
99
109
  return new Set([...camel, ...caps]);
100
110
  }
101
- exports.splitCamelCaseIntoWords = splitCamelCaseIntoWords;
102
111
  function validateMimeType({ type, value }, { report, location }, allowedValues) {
103
112
  const ruleType = type === 'consumes' ? 'request' : 'response';
104
113
  if (!allowedValues)
@@ -114,7 +123,6 @@ function validateMimeType({ type, value }, { report, location }, allowedValues)
114
123
  }
115
124
  }
116
125
  }
117
- exports.validateMimeType = validateMimeType;
118
126
  function validateMimeTypeOAS3({ type, value }, { report, location }, allowedValues) {
119
127
  const ruleType = type === 'consumes' ? 'request' : 'response';
120
128
  if (!allowedValues)
@@ -130,20 +138,16 @@ function validateMimeTypeOAS3({ type, value }, { report, location }, allowedValu
130
138
  }
131
139
  }
132
140
  }
133
- exports.validateMimeTypeOAS3 = validateMimeTypeOAS3;
134
141
  function readFileAsStringSync(filePath) {
135
142
  return fs.readFileSync(filePath, 'utf-8');
136
143
  }
137
- exports.readFileAsStringSync = readFileAsStringSync;
138
144
  function yamlAndJsonSyncReader(filePath) {
139
145
  const content = fs.readFileSync(filePath, 'utf-8');
140
146
  return (0, js_yaml_1.parseYaml)(content);
141
147
  }
142
- exports.yamlAndJsonSyncReader = yamlAndJsonSyncReader;
143
148
  function isPathParameter(pathSegment) {
144
149
  return pathSegment.startsWith('{') && pathSegment.endsWith('}');
145
150
  }
146
- exports.isPathParameter = isPathParameter;
147
151
  /**
148
152
  * Convert Windows backslash paths to slash paths: foo\\bar ➔ foo/bar
149
153
  */
@@ -154,20 +158,16 @@ function slash(path) {
154
158
  }
155
159
  return path.replace(/\\/g, '/');
156
160
  }
157
- exports.slash = slash;
158
161
  function isNotEmptyObject(obj) {
159
162
  return !!obj && Object.keys(obj).length > 0;
160
163
  }
161
- exports.isNotEmptyObject = isNotEmptyObject;
162
164
  // TODO: use it everywhere
163
165
  function isString(value) {
164
166
  return typeof value === 'string';
165
167
  }
166
- exports.isString = isString;
167
168
  function isNotString(value) {
168
169
  return !isString(value);
169
170
  }
170
- exports.isNotString = isNotString;
171
171
  function assignExisting(target, obj) {
172
172
  for (const k of Object.keys(obj)) {
173
173
  if (target.hasOwnProperty(k)) {
@@ -175,46 +175,36 @@ function assignExisting(target, obj) {
175
175
  }
176
176
  }
177
177
  }
178
- exports.assignExisting = assignExisting;
179
178
  function getMatchingStatusCodeRange(code) {
180
179
  return `${code}`.replace(/^(\d)\d\d$/, (_, firstDigit) => `${firstDigit}XX`);
181
180
  }
182
- exports.getMatchingStatusCodeRange = getMatchingStatusCodeRange;
183
181
  function isCustomRuleId(id) {
184
182
  return id.includes('/');
185
183
  }
186
- exports.isCustomRuleId = isCustomRuleId;
187
184
  function doesYamlFileExist(filePath) {
188
- var _a;
189
185
  return (((0, path_1.extname)(filePath) === '.yaml' || (0, path_1.extname)(filePath) === '.yml') &&
190
- ((_a = fs === null || fs === void 0 ? void 0 : fs.hasOwnProperty) === null || _a === void 0 ? void 0 : _a.call(fs, 'existsSync')) &&
186
+ fs?.hasOwnProperty?.('existsSync') &&
191
187
  fs.existsSync(filePath));
192
188
  }
193
- exports.doesYamlFileExist = doesYamlFileExist;
194
189
  function showWarningForDeprecatedField(deprecatedField, updatedField, updatedObject) {
195
190
  logger_1.logger.warn(`The '${logger_1.colorize.red(deprecatedField)}' field is deprecated. ${updatedField
196
191
  ? `Use ${logger_1.colorize.green(getUpdatedFieldName(updatedField, updatedObject))} instead. `
197
192
  : ''}Read more about this change: https://redocly.com/docs/api-registry/guides/migration-guide-config-file/#changed-properties\n`);
198
193
  }
199
- exports.showWarningForDeprecatedField = showWarningForDeprecatedField;
200
194
  function showErrorForDeprecatedField(deprecatedField, updatedField, updatedObject) {
201
195
  throw new Error(`Do not use '${deprecatedField}' field. ${updatedField ? `Use '${getUpdatedFieldName(updatedField, updatedObject)}' instead. ` : ''}\n`);
202
196
  }
203
- exports.showErrorForDeprecatedField = showErrorForDeprecatedField;
204
197
  function isTruthy(value) {
205
198
  return !!value;
206
199
  }
207
- exports.isTruthy = isTruthy;
208
200
  function identity(value) {
209
201
  return value;
210
202
  }
211
- exports.identity = identity;
212
203
  function keysOf(obj) {
213
204
  if (!obj)
214
205
  return [];
215
206
  return Object.keys(obj);
216
207
  }
217
- exports.keysOf = keysOf;
218
208
  function pickDefined(obj) {
219
209
  if (!obj)
220
210
  return undefined;
@@ -226,19 +216,14 @@ function pickDefined(obj) {
226
216
  }
227
217
  return res;
228
218
  }
229
- exports.pickDefined = pickDefined;
230
219
  function nextTick() {
231
220
  return new Promise((resolve) => {
232
221
  setTimeout(resolve);
233
222
  });
234
223
  }
235
- exports.nextTick = nextTick;
236
- function pause(ms) {
237
- return __awaiter(this, void 0, void 0, function* () {
238
- return new Promise((resolve) => setTimeout(resolve, ms));
239
- });
224
+ async function pause(ms) {
225
+ return new Promise((resolve) => setTimeout(resolve, ms));
240
226
  }
241
- exports.pause = pause;
242
227
  function getUpdatedFieldName(updatedField, updatedObject) {
243
228
  return `${typeof updatedObject !== 'undefined' ? `${updatedObject}.` : ''}${updatedField}`;
244
229
  }
@@ -246,7 +231,6 @@ function getProxyAgent() {
246
231
  const proxy = process.env.HTTPS_PROXY || process.env.HTTP_PROXY;
247
232
  return proxy ? new https_proxy_agent_1.HttpsProxyAgent(proxy) : undefined;
248
233
  }
249
- exports.getProxyAgent = getProxyAgent;
250
234
  /**
251
235
  * Checks if two objects are deeply equal.
252
236
  * Borrowed the source code from https://github.com/lukeed/dequal.
@@ -282,4 +266,3 @@ function dequal(foo, bar) {
282
266
  }
283
267
  return foo !== foo && bar !== bar;
284
268
  }
285
- exports.dequal = dequal;
package/lib/visitors.d.ts CHANGED
@@ -5,7 +5,8 @@ import type { Location } from './ref-utils';
5
5
  import type { Oas3Definition, Oas3ExternalDocs, Oas3Info, Oas3Contact, Oas3Components, Oas3License, Oas3Schema, Oas3Header, Oas3Parameter, Oas3Operation, Oas3PathItem, Oas3ServerVariable, Oas3Server, Oas3MediaType, Oas3Response, Oas3Example, Oas3RequestBody, Oas3Tag, OasRef, Oas3SecurityScheme, Oas3SecurityRequirement, Oas3Encoding, Oas3Link, Oas3Xml, Oas3Discriminator, Oas3Callback } from './typings/openapi';
6
6
  import type { Oas2Definition, Oas2Tag, Oas2ExternalDocs, Oas2SecurityRequirement, Oas2Info, Oas2Contact, Oas2License, Oas2PathItem, Oas2Operation, Oas2Header, Oas2Response, Oas2Schema, Oas2Xml, Oas2Parameter, Oas2SecurityScheme } from './typings/swagger';
7
7
  import type { Async2Definition } from './typings/asyncapi';
8
- import type { ArazzoDefinition } from './typings/arazzo';
8
+ import type { Async3Definition } from './typings/asyncapi3';
9
+ import type { ArazzoDefinition, ArazzoSourceDescription, CriteriaObject, ExpectSchema, ExtendedOperation, InfoObject, NoneSourceDescription, OnFailureObject, OnSuccessObject, OpenAPISourceDescription, Parameter, Replacement, RequestBody, SourceDescription, Step, Workflow } from './typings/arazzo';
9
10
  export type SkipFunctionContext = Pick<UserContext, 'location' | 'rawNode' | 'resolve' | 'rawLocation'>;
10
11
  export type VisitFunction<T> = (node: T, ctx: UserContext & {
11
12
  ignoreNextVisitorsOnNode: () => void;
@@ -140,8 +141,28 @@ type Oas2FlatVisitor = {
140
141
  type Async2FlatVisitor = {
141
142
  Root?: VisitFunctionOrObject<Async2Definition>;
142
143
  };
144
+ type Async3FlatVisitor = {
145
+ Root?: VisitFunctionOrObject<Async3Definition>;
146
+ };
143
147
  type ArazzoFlatVisitor = {
144
148
  Root?: VisitFunctionOrObject<ArazzoDefinition>;
149
+ ParameterObject?: VisitFunctionOrObject<Parameter>;
150
+ InfoObject?: VisitFunctionOrObject<InfoObject>;
151
+ OpenAPISourceDescription?: VisitFunctionOrObject<OpenAPISourceDescription>;
152
+ NoneSourceDescription?: VisitFunctionOrObject<NoneSourceDescription>;
153
+ ArazzoSourceDescription?: VisitFunctionOrObject<ArazzoSourceDescription>;
154
+ SourceDescription?: VisitFunctionOrObject<SourceDescription>;
155
+ ExtendedOperation?: VisitFunctionOrObject<ExtendedOperation>;
156
+ ExpectSchema?: VisitFunctionOrObject<ExpectSchema>;
157
+ Replacement?: VisitFunctionOrObject<Replacement>;
158
+ RequestBody?: VisitFunctionOrObject<RequestBody>;
159
+ CriteriaObject?: VisitFunctionOrObject<CriteriaObject>;
160
+ OnSuccessObject?: VisitFunctionOrObject<OnSuccessObject>;
161
+ OnFailureObject?: VisitFunctionOrObject<OnFailureObject>;
162
+ Step?: VisitFunctionOrObject<Step>;
163
+ Steps?: VisitFunctionOrObject<Step[]>;
164
+ Workflow?: VisitFunctionOrObject<Workflow>;
165
+ Workflows?: VisitFunctionOrObject<Workflow[]>;
145
166
  };
146
167
  type Oas3NestedVisitor = {
147
168
  [T in keyof Oas3FlatVisitor]: Oas3FlatVisitor[T] extends Function ? Oas3FlatVisitor[T] : Oas3FlatVisitor[T] & NestedVisitor<Oas3NestedVisitor>;
@@ -152,12 +173,16 @@ type Oas2NestedVisitor = {
152
173
  type Async2NestedVisitor = {
153
174
  [T in keyof Async2FlatVisitor]: Async2FlatVisitor[T] extends Function ? Async2FlatVisitor[T] : Async2FlatVisitor[T] & NestedVisitor<Async2NestedVisitor>;
154
175
  };
176
+ type Async3NestedVisitor = {
177
+ [T in keyof Async3FlatVisitor]: Async3FlatVisitor[T] extends Function ? Async3FlatVisitor[T] : Async3FlatVisitor[T] & NestedVisitor<Async3NestedVisitor>;
178
+ };
155
179
  type ArazzoNestedVisitor = {
156
180
  [T in keyof ArazzoFlatVisitor]: ArazzoFlatVisitor[T] extends Function ? ArazzoFlatVisitor[T] : ArazzoFlatVisitor[T] & NestedVisitor<ArazzoNestedVisitor>;
157
181
  };
158
182
  export type Oas3Visitor = BaseVisitor & Oas3NestedVisitor & Record<string, VisitFunction<any> | NestedVisitObject<any, Oas3NestedVisitor>>;
159
183
  export type Oas2Visitor = BaseVisitor & Oas2NestedVisitor & Record<string, VisitFunction<any> | NestedVisitObject<any, Oas2NestedVisitor>>;
160
184
  export type Async2Visitor = BaseVisitor & Async2NestedVisitor & Record<string, VisitFunction<any> | NestedVisitObject<any, Async2NestedVisitor>>;
185
+ export type Async3Visitor = BaseVisitor & Async3NestedVisitor & Record<string, VisitFunction<any> | NestedVisitObject<any, Async3NestedVisitor>>;
161
186
  export type ArazzoVisitor = BaseVisitor & ArazzoNestedVisitor & Record<string, VisitFunction<any> | NestedVisitObject<any, ArazzoNestedVisitor>>;
162
187
  export type NestedVisitor<T> = Exclude<T, 'any' | 'ref' | 'Root'>;
163
188
  export type NormalizedOasVisitors<T extends BaseVisitor> = {
@@ -178,14 +203,17 @@ export type NormalizedOasVisitors<T extends BaseVisitor> = {
178
203
  export type Oas3Rule = (options: Record<string, any>) => Oas3Visitor | Oas3Visitor[];
179
204
  export type Oas2Rule = (options: Record<string, any>) => Oas2Visitor | Oas2Visitor[];
180
205
  export type Async2Rule = (options: Record<string, any>) => Async2Visitor | Async2Visitor[];
206
+ export type Async3Rule = (options: Record<string, any>) => Async3Visitor | Async3Visitor[];
181
207
  export type ArazzoRule = (options: Record<string, any>) => ArazzoVisitor | ArazzoVisitor[];
182
208
  export type Oas3Preprocessor = (options: Record<string, any>) => Oas3Visitor;
183
209
  export type Oas2Preprocessor = (options: Record<string, any>) => Oas2Visitor;
184
210
  export type Async2Preprocessor = (options: Record<string, any>) => Async2Visitor;
211
+ export type Async3Preprocessor = (options: Record<string, any>) => Async3Visitor;
185
212
  export type ArazzoPreprocessor = (options: Record<string, any>) => ArazzoVisitor;
186
213
  export type Oas3Decorator = (options: Record<string, any>) => Oas3Visitor;
187
214
  export type Oas2Decorator = (options: Record<string, any>) => Oas2Visitor;
188
215
  export type Async2Decorator = (options: Record<string, any>) => Async2Visitor;
216
+ export type Async3Decorator = (options: Record<string, any>) => Async3Visitor;
189
217
  export type ArazzoDecorator = (options: Record<string, any>) => ArazzoVisitor;
190
218
  export type OasRule = Oas3Rule;
191
219
  export type OasPreprocessor = Oas3Preprocessor;
package/lib/visitors.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeVisitors = void 0;
3
+ exports.normalizeVisitors = normalizeVisitors;
4
4
  const types_1 = require("./types");
5
5
  const legacyTypesMap = {
6
6
  Root: 'DefinitionRoot',
@@ -81,11 +81,16 @@ function normalizeVisitors(visitorsConfig, types) {
81
81
  enter: [],
82
82
  leave: [],
83
83
  };
84
- normalizedVisitors[interType.name].enter.push(Object.assign(Object.assign({}, ruleConf), { visit: () => undefined, depth: 0, context: {
84
+ normalizedVisitors[interType.name].enter.push({
85
+ ...ruleConf,
86
+ visit: () => undefined,
87
+ depth: 0,
88
+ context: {
85
89
  isSkippedLevel: true,
86
90
  seen: new Set(),
87
91
  parent: parentContext,
88
- } }));
92
+ },
93
+ });
89
94
  }
90
95
  }
91
96
  }
@@ -147,17 +152,25 @@ function normalizeVisitors(visitorsConfig, types) {
147
152
  if (visitorEnter && typeof visitorEnter !== 'function') {
148
153
  throw new Error('DEV: should be function');
149
154
  }
150
- normalizedTypeVisitor.enter.push(Object.assign(Object.assign({}, ruleConf), { visit: visitorEnter || (() => undefined), skip: visitorSkip, depth,
151
- context }));
155
+ normalizedTypeVisitor.enter.push({
156
+ ...ruleConf,
157
+ visit: visitorEnter || (() => undefined),
158
+ skip: visitorSkip,
159
+ depth,
160
+ context,
161
+ });
152
162
  }
153
163
  if (visitorLeave) {
154
164
  if (typeof visitorLeave !== 'function') {
155
165
  throw new Error('DEV: should be function');
156
166
  }
157
- normalizedTypeVisitor.leave.push(Object.assign(Object.assign({}, ruleConf), { visit: visitorLeave, depth,
158
- context }));
167
+ normalizedTypeVisitor.leave.push({
168
+ ...ruleConf,
169
+ visit: visitorLeave,
170
+ depth,
171
+ context,
172
+ });
159
173
  }
160
174
  }
161
175
  }
162
176
  }
163
- exports.normalizeVisitors = normalizeVisitors;
package/lib/walk.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { Location } from './ref-utils';
2
- import { ResolveError, YamlParseError, Source } from './resolve';
3
- import { SpecVersion } from './oas-types';
2
+ import { YamlParseError } from './resolve';
3
+ import type { SpecVersion } from './oas-types';
4
+ import type { ResolveError, Source, ResolvedRefMap, Document } from './resolve';
4
5
  import type { Referenced } from './typings/openapi';
5
6
  import type { NormalizedOasVisitors, BaseVisitor } from './visitors';
6
- import type { ResolvedRefMap, Document } from './resolve';
7
7
  import type { NormalizedNodeType } from './types';
8
8
  import type { RuleSeverity } from './config';
9
9
  export type NonUndefined = string | number | boolean | symbol | bigint | object | Record<string, any>;
package/lib/walk.js CHANGED
@@ -1,25 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.walkDocument = void 0;
3
+ exports.walkDocument = walkDocument;
4
4
  const ref_utils_1 = require("./ref-utils");
5
5
  const utils_1 = require("./utils");
6
6
  const resolve_1 = require("./resolve");
7
7
  const types_1 = require("./types");
8
8
  function collectParents(ctx) {
9
- var _a;
10
9
  const parents = {};
11
10
  while (ctx.parent) {
12
- parents[ctx.parent.type.name] = (_a = ctx.parent.activatedOn) === null || _a === void 0 ? void 0 : _a.value.node;
11
+ parents[ctx.parent.type.name] = ctx.parent.activatedOn?.value.node;
13
12
  ctx = ctx.parent;
14
13
  }
15
14
  return parents;
16
15
  }
17
16
  function collectParentsLocations(ctx) {
18
- var _a, _b;
19
17
  const locations = {};
20
18
  while (ctx.parent) {
21
- if ((_a = ctx.parent.activatedOn) === null || _a === void 0 ? void 0 : _a.value.location) {
22
- locations[ctx.parent.type.name] = (_b = ctx.parent.activatedOn) === null || _b === void 0 ? void 0 : _b.value.location;
19
+ if (ctx.parent.activatedOn?.value.location) {
20
+ locations[ctx.parent.type.name] = ctx.parent.activatedOn?.value.location;
23
21
  }
24
22
  ctx = ctx.parent;
25
23
  }
@@ -31,7 +29,6 @@ function walkDocument(opts) {
31
29
  const ignoredNodes = new Set();
32
30
  walkNode(document.parsed, rootType, new ref_utils_1.Location(document.source, '#/'), undefined, '');
33
31
  function walkNode(node, type, location, parent, key) {
34
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
35
32
  const resolve = (ref, from = currentLocation.source.absoluteRef) => {
36
33
  if (!(0, ref_utils_1.isRef)(ref))
37
34
  return { location, node: ref };
@@ -73,17 +70,17 @@ function walkDocument(opts) {
73
70
  oasVersion: ctx.oasVersion,
74
71
  getVisitorData: getVisitorDataFn.bind(undefined, ruleId),
75
72
  }, { node: resolvedNode, location: resolvedLocation, error });
76
- if ((resolvedLocation === null || resolvedLocation === void 0 ? void 0 : resolvedLocation.source.absoluteRef) && ctx.refTypes) {
77
- ctx.refTypes.set(resolvedLocation === null || resolvedLocation === void 0 ? void 0 : resolvedLocation.source.absoluteRef, type);
73
+ if (resolvedLocation?.source.absoluteRef && ctx.refTypes) {
74
+ ctx.refTypes.set(resolvedLocation?.source.absoluteRef, type);
78
75
  }
79
76
  }
80
77
  }
81
78
  if (resolvedNode !== undefined && resolvedLocation && type.name !== 'scalar') {
82
79
  currentLocation = resolvedLocation;
83
- const isNodeSeen = (_b = (_a = seenNodesPerType[type.name]) === null || _a === void 0 ? void 0 : _a.has) === null || _b === void 0 ? void 0 : _b.call(_a, resolvedNode);
80
+ const isNodeSeen = seenNodesPerType[type.name]?.has?.(resolvedNode);
84
81
  let visitedBySome = false;
85
82
  const anyEnterVisitors = normalizedVisitors.any.enter;
86
- const currentEnterVisitors = anyEnterVisitors.concat(((_c = normalizedVisitors[type.name]) === null || _c === void 0 ? void 0 : _c.enter) || []);
83
+ const currentEnterVisitors = anyEnterVisitors.concat(normalizedVisitors[type.name]?.enter || []);
87
84
  const activatedContexts = [];
88
85
  for (const { context, visit, skip, ruleId, severity } of currentEnterVisitors) {
89
86
  if (ignoredNodes.has(`${currentLocation.absolutePointer}${currentLocation.pointer}`))
@@ -101,9 +98,9 @@ function walkDocument(opts) {
101
98
  else {
102
99
  if ((context.parent && // if nested
103
100
  context.parent.activatedOn &&
104
- ((_d = context.activatedOn) === null || _d === void 0 ? void 0 : _d.value.withParentNode) !== context.parent.activatedOn.value.node &&
101
+ context.activatedOn?.value.withParentNode !== context.parent.activatedOn.value.node &&
105
102
  // do not enter if visited by parent children (it works thanks because deeper visitors are sorted before)
106
- ((_e = context.parent.activatedOn.value.nextLevelTypeActivated) === null || _e === void 0 ? void 0 : _e.value) !== type) ||
103
+ context.parent.activatedOn.value.nextLevelTypeActivated?.value !== type) ||
107
104
  (!context.parent && !isNodeSeen) // if top-level visit each node just once
108
105
  ) {
109
106
  activatedContexts.push(context);
@@ -111,14 +108,15 @@ function walkDocument(opts) {
111
108
  node: resolvedNode,
112
109
  location: resolvedLocation,
113
110
  nextLevelTypeActivated: null,
114
- withParentNode: (_g = (_f = context.parent) === null || _f === void 0 ? void 0 : _f.activatedOn) === null || _g === void 0 ? void 0 : _g.value.node,
115
- skipped: (_k = (((_j = (_h = context.parent) === null || _h === void 0 ? void 0 : _h.activatedOn) === null || _j === void 0 ? void 0 : _j.value.skipped) ||
116
- (skip === null || skip === void 0 ? void 0 : skip(resolvedNode, key, {
111
+ withParentNode: context.parent?.activatedOn?.value.node,
112
+ skipped: (context.parent?.activatedOn?.value.skipped ||
113
+ skip?.(resolvedNode, key, {
117
114
  location,
118
115
  rawLocation,
119
116
  resolve,
120
117
  rawNode: node,
121
- })))) !== null && _k !== void 0 ? _k : false,
118
+ })) ??
119
+ false,
122
120
  };
123
121
  context.activatedOn = (0, utils_1.pushStack)(context.activatedOn, activatedOn);
124
122
  let ctx = context.parent;
@@ -180,7 +178,7 @@ function walkDocument(opts) {
180
178
  propName.startsWith(type.extensionsPrefix)) {
181
179
  propType = types_1.SpecExtension;
182
180
  }
183
- if (!(0, types_1.isNamedType)(propType) && (propType === null || propType === void 0 ? void 0 : propType.directResolveAs)) {
181
+ if (!(0, types_1.isNamedType)(propType) && propType?.directResolveAs) {
184
182
  propType = propType.directResolveAs;
185
183
  value = { $ref: value };
186
184
  }
@@ -195,7 +193,7 @@ function walkDocument(opts) {
195
193
  }
196
194
  }
197
195
  const anyLeaveVisitors = normalizedVisitors.any.leave;
198
- const currentLeaveVisitors = (((_l = normalizedVisitors[type.name]) === null || _l === void 0 ? void 0 : _l.leave) || []).concat(anyLeaveVisitors);
196
+ const currentLeaveVisitors = (normalizedVisitors[type.name]?.leave || []).concat(anyLeaveVisitors);
199
197
  for (const context of activatedContexts.reverse()) {
200
198
  if (context.isSkippedLevel) {
201
199
  context.seen.delete(resolvedNode);
@@ -264,11 +262,21 @@ function walkDocument(opts) {
264
262
  ? Array.isArray(opts.location)
265
263
  ? opts.location
266
264
  : [opts.location]
267
- : [Object.assign(Object.assign({}, currentLocation), { reportOnKey: false })];
268
- const location = normalizedLocation.map((l) => (Object.assign(Object.assign(Object.assign({}, currentLocation), { reportOnKey: false }), l)));
265
+ : [{ ...currentLocation, reportOnKey: false }];
266
+ const location = normalizedLocation.map((l) => ({
267
+ ...currentLocation,
268
+ reportOnKey: false,
269
+ ...l,
270
+ }));
269
271
  const ruleSeverity = opts.forceSeverity || severity;
270
272
  if (ruleSeverity !== 'off') {
271
- ctx.problems.push(Object.assign(Object.assign({ ruleId: opts.ruleId || ruleId, severity: ruleSeverity }, opts), { suggest: opts.suggest || [], location }));
273
+ ctx.problems.push({
274
+ ruleId: opts.ruleId || ruleId,
275
+ severity: ruleSeverity,
276
+ ...opts,
277
+ suggest: opts.suggest || [],
278
+ location,
279
+ });
272
280
  }
273
281
  }
274
282
  function getVisitorDataFn(ruleId) {
@@ -277,4 +285,3 @@ function walkDocument(opts) {
277
285
  }
278
286
  }
279
287
  }
280
- exports.walkDocument = walkDocument;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redocly/openapi-core",
3
- "version": "1.18.1",
3
+ "version": "1.20.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "engines": {
@@ -36,7 +36,7 @@
36
36
  ],
37
37
  "dependencies": {
38
38
  "@redocly/ajv": "^8.11.0",
39
- "@redocly/config": "^0.7.0",
39
+ "@redocly/config": "^0.9.0",
40
40
  "colorette": "^1.2.0",
41
41
  "https-proxy-agent": "^7.0.4",
42
42
  "js-levenshtein": "^1.1.6",
@@ -56,6 +56,6 @@
56
56
  "@types/node-fetch": "^2.5.7",
57
57
  "@types/pluralize": "^0.0.29",
58
58
  "json-schema-to-ts": "^3.1.0",
59
- "typescript": "^5.2.2"
59
+ "typescript": "5.5.3"
60
60
  }
61
61
  }