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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (380) hide show
  1. package/README.md +6 -6
  2. package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +0 -1
  3. package/lib/benchmark/benches/recommended-oas3.bench.js +1 -1
  4. package/lib/benchmark/benches/resolve-with-no-external.bench.js +1 -1
  5. package/lib/benchmark/utils.d.ts +2 -2
  6. package/lib/benchmark/utils.js +2 -2
  7. package/lib/bundle.d.ts +12 -15
  8. package/lib/bundle.js +38 -15
  9. package/lib/config/all.d.ts +2 -2
  10. package/lib/config/all.js +17 -6
  11. package/lib/config/builtIn.d.ts +2 -2
  12. package/lib/config/builtIn.js +2 -2
  13. package/lib/config/config-resolvers.d.ts +5 -5
  14. package/lib/config/config-resolvers.js +121 -66
  15. package/lib/config/config.d.ts +12 -18
  16. package/lib/config/config.js +42 -26
  17. package/lib/config/load.d.ts +16 -3
  18. package/lib/config/load.js +36 -14
  19. package/lib/config/minimal.d.ts +2 -2
  20. package/lib/config/minimal.js +10 -6
  21. package/lib/config/recommended.d.ts +2 -2
  22. package/lib/config/recommended.js +10 -6
  23. package/lib/config/rules.d.ts +7 -4
  24. package/lib/config/rules.js +5 -4
  25. package/lib/config/types.d.ts +72 -23
  26. package/lib/config/types.js +13 -0
  27. package/lib/config/utils.d.ts +6 -5
  28. package/lib/config/utils.js +110 -32
  29. package/lib/decorators/common/filters/filter-helper.d.ts +3 -0
  30. package/lib/decorators/common/filters/filter-helper.js +67 -0
  31. package/lib/decorators/common/filters/filter-in.d.ts +2 -0
  32. package/lib/decorators/common/filters/filter-in.js +17 -0
  33. package/lib/decorators/common/filters/filter-out.d.ts +2 -0
  34. package/lib/decorators/common/filters/filter-out.js +17 -0
  35. package/lib/decorators/common/info-override.d.ts +2 -0
  36. package/lib/decorators/common/info-override.js +28 -0
  37. package/lib/decorators/common/media-type-examples-override.d.ts +2 -0
  38. package/lib/decorators/common/media-type-examples-override.js +53 -0
  39. package/lib/decorators/common/registry-dependencies.js +2 -2
  40. package/lib/decorators/common/remove-x-internal.js +2 -2
  41. package/lib/decorators/oas2/index.d.ts +3 -0
  42. package/lib/decorators/oas2/index.js +7 -1
  43. package/lib/decorators/oas3/index.d.ts +4 -0
  44. package/lib/decorators/oas3/index.js +9 -1
  45. package/lib/env.d.ts +3 -0
  46. package/lib/env.js +8 -0
  47. package/lib/format/codeframes.js +16 -10
  48. package/lib/format/format.d.ts +1 -1
  49. package/lib/format/format.js +64 -32
  50. package/lib/index.d.ts +6 -6
  51. package/lib/index.js +7 -2
  52. package/lib/js-yaml/index.js +2 -6
  53. package/lib/lint.d.ts +4 -2
  54. package/lib/lint.js +36 -11
  55. package/lib/logger.d.ts +10 -0
  56. package/lib/logger.js +31 -0
  57. package/lib/output.d.ts +3 -0
  58. package/lib/output.js +9 -0
  59. package/lib/redocly/index.js +10 -9
  60. package/lib/redocly/registry-api-types.d.ts +28 -28
  61. package/lib/redocly/registry-api.d.ts +3 -3
  62. package/lib/redocly/registry-api.js +10 -2
  63. package/lib/ref-utils.d.ts +1 -0
  64. package/lib/ref-utils.js +8 -2
  65. package/lib/resolve.d.ts +1 -1
  66. package/lib/resolve.js +33 -3
  67. package/lib/rules/ajv.d.ts +2 -2
  68. package/lib/rules/ajv.js +12 -12
  69. package/lib/rules/common/assertions/asserts.d.ts +29 -4
  70. package/lib/rules/common/assertions/asserts.js +227 -97
  71. package/lib/rules/common/assertions/index.d.ts +27 -2
  72. package/lib/rules/common/assertions/index.js +9 -37
  73. package/lib/rules/common/assertions/utils.d.ts +16 -8
  74. package/lib/rules/common/assertions/utils.js +160 -76
  75. package/lib/rules/common/info-license-url.d.ts +1 -1
  76. package/lib/rules/common/info-license-url.js +5 -10
  77. package/lib/rules/common/info-license.d.ts +2 -0
  78. package/lib/rules/common/info-license.js +17 -0
  79. package/lib/rules/common/no-ambiguous-paths.js +1 -1
  80. package/lib/rules/common/no-enum-type-mismatch.js +1 -3
  81. package/lib/rules/common/no-identical-paths.js +4 -4
  82. package/lib/rules/common/no-invalid-parameter-examples.js +3 -3
  83. package/lib/rules/common/no-invalid-schema-examples.js +3 -3
  84. package/lib/rules/common/operation-2xx-response.js +15 -9
  85. package/lib/rules/common/operation-4xx-response.js +15 -9
  86. package/lib/rules/common/operation-operationId.js +2 -2
  87. package/lib/rules/common/operation-tag-defined.js +1 -1
  88. package/lib/rules/common/path-not-include-query.js +2 -2
  89. package/lib/rules/common/path-params-defined.js +7 -2
  90. package/lib/rules/common/paths-kebab-case.js +4 -1
  91. package/lib/rules/common/required-string-property-missing-min-length.d.ts +2 -0
  92. package/lib/rules/common/required-string-property-missing-min-length.js +37 -0
  93. package/lib/rules/common/response-contains-header.d.ts +2 -0
  94. package/lib/rules/common/response-contains-header.js +29 -0
  95. package/lib/rules/common/scalar-property-missing-example.d.ts +2 -0
  96. package/lib/rules/common/scalar-property-missing-example.js +42 -0
  97. package/lib/rules/common/security-defined.d.ts +2 -0
  98. package/lib/rules/common/{operation-security-defined.js → security-defined.js} +25 -6
  99. package/lib/rules/common/spec-strict-refs.d.ts +2 -0
  100. package/lib/rules/common/spec-strict-refs.js +30 -0
  101. package/lib/rules/common/spec.js +41 -18
  102. package/lib/rules/common/tags-alphabetical.js +1 -1
  103. package/lib/rules/oas2/index.d.ts +6 -2
  104. package/lib/rules/oas2/index.js +16 -8
  105. package/lib/rules/oas2/remove-unused-components.js +6 -6
  106. package/lib/rules/oas2/request-mime-type.d.ts +1 -1
  107. package/lib/rules/oas2/request-mime-type.js +1 -1
  108. package/lib/rules/oas2/response-contains-property.d.ts +2 -0
  109. package/lib/rules/oas2/response-contains-property.js +38 -0
  110. package/lib/rules/oas2/response-mime-type.d.ts +1 -1
  111. package/lib/rules/oas2/response-mime-type.js +1 -1
  112. package/lib/rules/oas3/component-name-unique.d.ts +2 -0
  113. package/lib/rules/oas3/component-name-unique.js +124 -0
  114. package/lib/rules/oas3/index.js +24 -10
  115. package/lib/rules/oas3/no-empty-servers.js +2 -2
  116. package/lib/rules/oas3/no-invalid-media-type-examples.js +2 -2
  117. package/lib/rules/oas3/no-server-variables-empty-enum.d.ts +2 -0
  118. package/lib/rules/oas3/{no-servers-empty-enum.js → no-server-variables-empty-enum.js} +5 -5
  119. package/lib/rules/oas3/no-unused-components.js +2 -2
  120. package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.d.ts +5 -0
  121. package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.js +36 -0
  122. package/lib/rules/oas3/remove-unused-components.js +6 -6
  123. package/lib/rules/oas3/request-mime-type.d.ts +1 -1
  124. package/lib/rules/oas3/request-mime-type.js +1 -1
  125. package/lib/rules/oas3/response-contains-property.d.ts +2 -0
  126. package/lib/rules/oas3/response-contains-property.js +40 -0
  127. package/lib/rules/oas3/response-mime-type.d.ts +1 -1
  128. package/lib/rules/oas3/response-mime-type.js +1 -1
  129. package/lib/rules/oas3/spec-components-invalid-map-name.d.ts +2 -0
  130. package/lib/rules/oas3/spec-components-invalid-map-name.js +62 -0
  131. package/lib/rules/other/stats.d.ts +2 -2
  132. package/lib/rules/other/stats.js +45 -16
  133. package/lib/rules/utils.d.ts +5 -2
  134. package/lib/rules/utils.js +54 -6
  135. package/lib/types/config-external-schemas.d.ts +2193 -0
  136. package/lib/types/config-external-schemas.js +805 -0
  137. package/lib/types/index.d.ts +3 -2
  138. package/lib/types/index.js +9 -1
  139. package/lib/types/oas2.js +91 -15
  140. package/lib/types/oas3.js +139 -49
  141. package/lib/types/oas3_1.js +32 -26
  142. package/lib/types/redocly-yaml.js +414 -58
  143. package/lib/typings/openapi.d.ts +3 -2
  144. package/lib/utils.d.ts +15 -3
  145. package/lib/utils.js +73 -7
  146. package/lib/visitors.d.ts +20 -16
  147. package/lib/visitors.js +28 -3
  148. package/lib/walk.d.ts +11 -19
  149. package/lib/walk.js +74 -53
  150. package/package.json +5 -6
  151. package/__tests__/__snapshots__/bundle.test.ts.snap +0 -229
  152. package/__tests__/bundle.test.ts +0 -132
  153. package/__tests__/codeframes.test.ts +0 -531
  154. package/__tests__/fixtures/extension.js +0 -24
  155. package/__tests__/fixtures/refs/definitions.yaml +0 -3
  156. package/__tests__/fixtures/refs/examples.yaml +0 -8
  157. package/__tests__/fixtures/refs/external-request-body.yaml +0 -13
  158. package/__tests__/fixtures/refs/externalref.yaml +0 -35
  159. package/__tests__/fixtures/refs/hosted.yaml +0 -35
  160. package/__tests__/fixtures/refs/openapi-with-external-refs-conflicting-names.yaml +0 -21
  161. package/__tests__/fixtures/refs/openapi-with-external-refs.yaml +0 -33
  162. package/__tests__/fixtures/refs/param-b.yaml +0 -1
  163. package/__tests__/fixtures/refs/param-c.yaml +0 -1
  164. package/__tests__/fixtures/refs/rename.yaml +0 -1
  165. package/__tests__/fixtures/refs/requestBody.yaml +0 -9
  166. package/__tests__/fixtures/refs/schema-a.yaml +0 -1
  167. package/__tests__/fixtures/refs/simple.yaml +0 -1
  168. package/__tests__/fixtures/refs/vendor.schema.yaml +0 -20
  169. package/__tests__/fixtures/resolve/External.yaml +0 -10
  170. package/__tests__/fixtures/resolve/External2.yaml +0 -4
  171. package/__tests__/fixtures/resolve/description.md +0 -3
  172. package/__tests__/fixtures/resolve/externalInfo.yaml +0 -4
  173. package/__tests__/fixtures/resolve/externalLicense.yaml +0 -1
  174. package/__tests__/fixtures/resolve/openapi-with-back.yaml +0 -13
  175. package/__tests__/fixtures/resolve/openapi-with-md-description.yaml +0 -5
  176. package/__tests__/fixtures/resolve/openapi.yaml +0 -28
  177. package/__tests__/fixtures/resolve/schemas/type-a.yaml +0 -10
  178. package/__tests__/fixtures/resolve/schemas/type-b.yaml +0 -6
  179. package/__tests__/fixtures/resolve/transitive/a.yaml +0 -1
  180. package/__tests__/fixtures/resolve/transitive/components.yaml +0 -5
  181. package/__tests__/fixtures/resolve/transitive/schemas.yaml +0 -3
  182. package/__tests__/lint.test.ts +0 -17
  183. package/__tests__/login.test.ts +0 -17
  184. package/__tests__/normalizeVisitors.test.ts +0 -151
  185. package/__tests__/ref-utils.test.ts +0 -120
  186. package/__tests__/resolve-http.test.ts +0 -77
  187. package/__tests__/resolve.test.ts +0 -405
  188. package/__tests__/utils.ts +0 -86
  189. package/__tests__/walk.test.ts +0 -1485
  190. package/lib/rules/common/info-description.d.ts +0 -2
  191. package/lib/rules/common/info-description.js +0 -12
  192. package/lib/rules/common/license-url.d.ts +0 -2
  193. package/lib/rules/common/license-url.js +0 -12
  194. package/lib/rules/common/operation-security-defined.d.ts +0 -2
  195. package/lib/rules/oas3/no-servers-empty-enum.d.ts +0 -2
  196. package/src/__tests__/js-yaml.test.ts +0 -71
  197. package/src/__tests__/lint.test.ts +0 -182
  198. package/src/__tests__/utils.test.ts +0 -74
  199. package/src/benchmark/benches/lint-with-many-rules.bench.ts +0 -35
  200. package/src/benchmark/benches/lint-with-nested-rule.bench.ts +0 -39
  201. package/src/benchmark/benches/lint-with-no-rules.bench.ts +0 -20
  202. package/src/benchmark/benches/lint-with-top-level-rule-report.bench.ts +0 -36
  203. package/src/benchmark/benches/lint-with-top-level-rule.bench.ts +0 -32
  204. package/src/benchmark/benches/rebilly.yaml +0 -32267
  205. package/src/benchmark/benches/recommended-oas3.bench.ts +0 -22
  206. package/src/benchmark/benches/resolve-with-no-external.bench.ts +0 -23
  207. package/src/benchmark/benchmark.js +0 -307
  208. package/src/benchmark/colors.js +0 -29
  209. package/src/benchmark/fork.js +0 -83
  210. package/src/benchmark/utils.ts +0 -36
  211. package/src/bundle.ts +0 -371
  212. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +0 -157
  213. package/src/config/__tests__/config-resolvers.test.ts +0 -429
  214. package/src/config/__tests__/config.test.ts +0 -244
  215. package/src/config/__tests__/fixtures/plugin-config.yaml +0 -3
  216. package/src/config/__tests__/fixtures/plugin.js +0 -56
  217. package/src/config/__tests__/fixtures/resolve-config/api/nested-config.yaml +0 -12
  218. package/src/config/__tests__/fixtures/resolve-config/api/plugin.js +0 -67
  219. package/src/config/__tests__/fixtures/resolve-config/local-config-with-circular.yaml +0 -8
  220. package/src/config/__tests__/fixtures/resolve-config/local-config-with-file.yaml +0 -19
  221. package/src/config/__tests__/fixtures/resolve-config/local-config.yaml +0 -10
  222. package/src/config/__tests__/fixtures/resolve-config/plugin.js +0 -66
  223. package/src/config/__tests__/fixtures/resolve-remote-configs/nested-remote-config.yaml +0 -4
  224. package/src/config/__tests__/fixtures/resolve-remote-configs/remote-config.yaml +0 -5
  225. package/src/config/__tests__/load.test.ts +0 -83
  226. package/src/config/__tests__/resolve-plugins.test.ts +0 -27
  227. package/src/config/all.ts +0 -65
  228. package/src/config/builtIn.ts +0 -37
  229. package/src/config/config-resolvers.ts +0 -359
  230. package/src/config/config.ts +0 -312
  231. package/src/config/index.ts +0 -7
  232. package/src/config/load.ts +0 -84
  233. package/src/config/minimal.ts +0 -58
  234. package/src/config/recommended.ts +0 -58
  235. package/src/config/rules.ts +0 -46
  236. package/src/config/types.ts +0 -168
  237. package/src/config/utils.ts +0 -208
  238. package/src/decorators/__tests__/remove-x-internal.test.ts +0 -316
  239. package/src/decorators/common/info-description-override.ts +0 -24
  240. package/src/decorators/common/operation-description-override.ts +0 -30
  241. package/src/decorators/common/registry-dependencies.ts +0 -25
  242. package/src/decorators/common/remove-x-internal.ts +0 -59
  243. package/src/decorators/common/tag-description-override.ts +0 -25
  244. package/src/decorators/oas2/index.ts +0 -14
  245. package/src/decorators/oas3/index.ts +0 -14
  246. package/src/format/codeframes.ts +0 -210
  247. package/src/format/format.ts +0 -339
  248. package/src/index.ts +0 -68
  249. package/src/js-yaml/index.ts +0 -18
  250. package/src/lint.ts +0 -125
  251. package/src/oas-types.ts +0 -62
  252. package/src/redocly/__tests__/redocly-client.test.ts +0 -140
  253. package/src/redocly/index.ts +0 -182
  254. package/src/redocly/redocly-client-types.ts +0 -10
  255. package/src/redocly/registry-api-types.ts +0 -32
  256. package/src/redocly/registry-api.ts +0 -134
  257. package/src/ref-utils.ts +0 -79
  258. package/src/resolve.ts +0 -378
  259. package/src/rules/__tests__/fixtures/invalid-yaml.yaml +0 -1
  260. package/src/rules/__tests__/fixtures/ref.yaml +0 -1
  261. package/src/rules/__tests__/no-unresolved-refs.test.ts +0 -168
  262. package/src/rules/ajv.ts +0 -103
  263. package/src/rules/common/__tests__/info-description.test.ts +0 -102
  264. package/src/rules/common/__tests__/info-license.test.ts +0 -62
  265. package/src/rules/common/__tests__/license-url.test.ts +0 -63
  266. package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +0 -96
  267. package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +0 -209
  268. package/src/rules/common/__tests__/no-identical-paths.test.ts +0 -58
  269. package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +0 -85
  270. package/src/rules/common/__tests__/operation-2xx-response.test.ts +0 -91
  271. package/src/rules/common/__tests__/operation-4xx-response.test.ts +0 -107
  272. package/src/rules/common/__tests__/operation-operationId-unique.test.ts +0 -76
  273. package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +0 -45
  274. package/src/rules/common/__tests__/operation-parameters-unique.test.ts +0 -167
  275. package/src/rules/common/__tests__/operation-security-defined.test.ts +0 -69
  276. package/src/rules/common/__tests__/operation-singular-tag.test.ts +0 -72
  277. package/src/rules/common/__tests__/path-http-verbs-order.test.ts +0 -95
  278. package/src/rules/common/__tests__/path-not-include-query.test.ts +0 -64
  279. package/src/rules/common/__tests__/path-params-defined.test.ts +0 -133
  280. package/src/rules/common/__tests__/paths-kebab-case.test.ts +0 -108
  281. package/src/rules/common/__tests__/spec.test.ts +0 -62
  282. package/src/rules/common/__tests__/tag-description.test.ts +0 -65
  283. package/src/rules/common/__tests__/tags-alphabetical.test.ts +0 -64
  284. package/src/rules/common/assertions/__tests__/asserts.test.ts +0 -231
  285. package/src/rules/common/assertions/__tests__/index.test.ts +0 -65
  286. package/src/rules/common/assertions/__tests__/utils.test.ts +0 -89
  287. package/src/rules/common/assertions/asserts.ts +0 -137
  288. package/src/rules/common/assertions/index.ts +0 -75
  289. package/src/rules/common/assertions/utils.ts +0 -167
  290. package/src/rules/common/info-contact.ts +0 -15
  291. package/src/rules/common/info-description.ts +0 -10
  292. package/src/rules/common/info-license-url.ts +0 -15
  293. package/src/rules/common/license-url.ts +0 -10
  294. package/src/rules/common/no-ambiguous-paths.ts +0 -50
  295. package/src/rules/common/no-enum-type-mismatch.ts +0 -49
  296. package/src/rules/common/no-http-verbs-in-paths.ts +0 -36
  297. package/src/rules/common/no-identical-paths.ts +0 -24
  298. package/src/rules/common/no-invalid-parameter-examples.ts +0 -36
  299. package/src/rules/common/no-invalid-schema-examples.ts +0 -27
  300. package/src/rules/common/no-path-trailing-slash.ts +0 -15
  301. package/src/rules/common/operation-2xx-response.ts +0 -16
  302. package/src/rules/common/operation-4xx-response.ts +0 -17
  303. package/src/rules/common/operation-description.ts +0 -13
  304. package/src/rules/common/operation-operationId-unique.ts +0 -21
  305. package/src/rules/common/operation-operationId-url-safe.ts +0 -19
  306. package/src/rules/common/operation-operationId.ts +0 -17
  307. package/src/rules/common/operation-parameters-unique.ts +0 -48
  308. package/src/rules/common/operation-security-defined.ts +0 -45
  309. package/src/rules/common/operation-singular-tag.ts +0 -17
  310. package/src/rules/common/operation-summary.ts +0 -13
  311. package/src/rules/common/operation-tag-defined.ts +0 -26
  312. package/src/rules/common/parameter-description.ts +0 -22
  313. package/src/rules/common/path-declaration-must-exist.ts +0 -15
  314. package/src/rules/common/path-excludes-patterns.ts +0 -23
  315. package/src/rules/common/path-http-verbs-order.ts +0 -30
  316. package/src/rules/common/path-not-include-query.ts +0 -17
  317. package/src/rules/common/path-params-defined.ts +0 -58
  318. package/src/rules/common/path-segment-plural.ts +0 -31
  319. package/src/rules/common/paths-kebab-case.ts +0 -16
  320. package/src/rules/common/spec.ts +0 -143
  321. package/src/rules/common/tag-description.ts +0 -10
  322. package/src/rules/common/tags-alphabetical.ts +0 -20
  323. package/src/rules/no-unresolved-refs.ts +0 -51
  324. package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +0 -110
  325. package/src/rules/oas2/__tests__/spec/fixtures/description.md +0 -1
  326. package/src/rules/oas2/__tests__/spec/info.test.ts +0 -355
  327. package/src/rules/oas2/__tests__/spec/operation.test.ts +0 -123
  328. package/src/rules/oas2/__tests__/spec/paths.test.ts +0 -245
  329. package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +0 -31
  330. package/src/rules/oas2/__tests__/spec/utils.ts +0 -32
  331. package/src/rules/oas2/boolean-parameter-prefixes.ts +0 -26
  332. package/src/rules/oas2/index.ts +0 -83
  333. package/src/rules/oas2/remove-unused-components.ts +0 -76
  334. package/src/rules/oas2/request-mime-type.ts +0 -17
  335. package/src/rules/oas2/response-mime-type.ts +0 -17
  336. package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +0 -111
  337. package/src/rules/oas3/__tests__/fixtures/common.yaml +0 -11
  338. package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +0 -205
  339. package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +0 -65
  340. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +0 -392
  341. package/src/rules/oas3/__tests__/no-server-example.com.test.ts +0 -60
  342. package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +0 -79
  343. package/src/rules/oas3/__tests__/no-unused-components.test.ts +0 -131
  344. package/src/rules/oas3/__tests__/spec/callbacks.test.ts +0 -41
  345. package/src/rules/oas3/__tests__/spec/fixtures/description.md +0 -1
  346. package/src/rules/oas3/__tests__/spec/info.test.ts +0 -391
  347. package/src/rules/oas3/__tests__/spec/operation.test.ts +0 -253
  348. package/src/rules/oas3/__tests__/spec/paths.test.ts +0 -284
  349. package/src/rules/oas3/__tests__/spec/referenceableScalars.test.ts +0 -77
  350. package/src/rules/oas3/__tests__/spec/servers.test.ts +0 -499
  351. package/src/rules/oas3/__tests__/spec/spec.test.ts +0 -288
  352. package/src/rules/oas3/__tests__/spec/utils.ts +0 -32
  353. package/src/rules/oas3/boolean-parameter-prefixes.ts +0 -28
  354. package/src/rules/oas3/index.ts +0 -99
  355. package/src/rules/oas3/no-empty-servers.ts +0 -22
  356. package/src/rules/oas3/no-example-value-and-externalValue.ts +0 -14
  357. package/src/rules/oas3/no-invalid-media-type-examples.ts +0 -41
  358. package/src/rules/oas3/no-server-example.com.ts +0 -14
  359. package/src/rules/oas3/no-server-trailing-slash.ts +0 -15
  360. package/src/rules/oas3/no-servers-empty-enum.ts +0 -67
  361. package/src/rules/oas3/no-undefined-server-variable.ts +0 -30
  362. package/src/rules/oas3/no-unused-components.ts +0 -75
  363. package/src/rules/oas3/remove-unused-components.ts +0 -84
  364. package/src/rules/oas3/request-mime-type.ts +0 -31
  365. package/src/rules/oas3/response-mime-type.ts +0 -31
  366. package/src/rules/other/stats.ts +0 -44
  367. package/src/rules/utils.ts +0 -123
  368. package/src/types/index.ts +0 -138
  369. package/src/types/oas2.ts +0 -397
  370. package/src/types/oas3.ts +0 -506
  371. package/src/types/oas3_1.ts +0 -251
  372. package/src/types/redocly-yaml.ts +0 -637
  373. package/src/typings/common.ts +0 -9
  374. package/src/typings/openapi.ts +0 -297
  375. package/src/typings/swagger.ts +0 -236
  376. package/src/utils.ts +0 -190
  377. package/src/visitors.ts +0 -448
  378. package/src/walk.ts +0 -416
  379. package/tsconfig.json +0 -8
  380. package/tsconfig.tsbuildinfo +0 -1
package/lib/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { UserContext } from './walk';
2
- import type { HttpResolveConfig } from './config';
2
+ import { HttpResolveConfig } from './config';
3
3
  export { parseYaml, stringifyYaml } from './js-yaml';
4
4
  export declare type StackFrame<T> = {
5
5
  prev: StackFrame<T> | null;
@@ -13,8 +13,8 @@ export declare function pushStack<T, P extends Stack<T> = Stack<T>>(head: P, val
13
13
  };
14
14
  export declare function popStack<T, P extends Stack<T>>(head: P): StackFrame<T> | null;
15
15
  export declare type BundleOutputFormat = 'json' | 'yml' | 'yaml';
16
- export declare function loadYaml(filename: string): Promise<unknown>;
17
- export declare function notUndefined<T>(x: T | undefined): x is T;
16
+ export declare function loadYaml<T>(filename: string): Promise<T>;
17
+ export declare function isDefined<T>(x: T | undefined): x is T;
18
18
  export declare function isPlainObject(value: any): value is object;
19
19
  export declare function isEmptyObject(value: any): value is object;
20
20
  export declare function isEmptyArray(value: any): boolean;
@@ -29,6 +29,7 @@ export declare function validateMimeType({ type, value }: any, { report, locatio
29
29
  export declare function validateMimeTypeOAS3({ type, value }: any, { report, location }: UserContext, allowedValues: string[]): void;
30
30
  export declare function isSingular(path: string): boolean;
31
31
  export declare function readFileAsStringSync(filePath: string): string;
32
+ export declare function yamlAndJsonSyncReader<T>(filePath: string): T;
32
33
  export declare function isPathParameter(pathSegment: string): boolean;
33
34
  /**
34
35
  * Convert Windows backslash paths to slash paths: foo\\bar ➔ foo/bar
@@ -38,3 +39,14 @@ export declare function isNotEmptyObject(obj: any): boolean;
38
39
  export declare function isString(value: unknown): value is string;
39
40
  export declare function isNotString<T>(value: string | T): value is T;
40
41
  export declare function assignExisting<T>(target: Record<string, T>, obj: Record<string, T>): void;
42
+ export declare function getMatchingStatusCodeRange(code: number | string): string;
43
+ export declare function isCustomRuleId(id: string): boolean;
44
+ export declare function doesYamlFileExist(filePath: string): boolean;
45
+ export declare function showWarningForDeprecatedField(deprecatedField: string, updatedField?: string, updatedObject?: string): void;
46
+ export declare function showErrorForDeprecatedField(deprecatedField: string, updatedField?: string, updatedObject?: string): void;
47
+ export declare type Falsy = undefined | null | false | '' | 0;
48
+ export declare function isTruthy<Truthy>(value: Truthy | Falsy): value is Truthy;
49
+ export declare function identity<T>(value: T): T;
50
+ export declare function keysOf<T>(obj: T): (keyof T)[];
51
+ export declare function pickDefined<T extends Record<string, unknown>>(obj?: T): Record<string, unknown> | undefined;
52
+ export declare function nextTick(): void;
package/lib/utils.js CHANGED
@@ -9,13 +9,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.assignExisting = exports.isNotString = exports.isString = exports.isNotEmptyObject = exports.slash = exports.isPathParameter = exports.readFileAsStringSync = exports.isSingular = exports.validateMimeTypeOAS3 = exports.validateMimeType = exports.splitCamelCaseIntoWords = exports.omitObjectProps = exports.pickObjectProps = exports.readFileFromUrl = exports.isEmptyArray = exports.isEmptyObject = exports.isPlainObject = exports.notUndefined = exports.loadYaml = exports.popStack = exports.pushStack = exports.stringifyYaml = exports.parseYaml = void 0;
12
+ 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.isSingular = 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;
13
13
  const fs = require("fs");
14
+ const path_1 = require("path");
14
15
  const minimatch = require("minimatch");
15
16
  const node_fetch_1 = require("node-fetch");
16
17
  const pluralize = require("pluralize");
17
18
  const js_yaml_1 = require("./js-yaml");
18
- const config_1 = require("./config");
19
+ const env_1 = require("./env");
20
+ const logger_1 = require("./logger");
19
21
  var js_yaml_2 = require("./js-yaml");
20
22
  Object.defineProperty(exports, "parseYaml", { enumerable: true, get: function () { return js_yaml_2.parseYaml; } });
21
23
  Object.defineProperty(exports, "stringifyYaml", { enumerable: true, get: function () { return js_yaml_2.stringifyYaml; } });
@@ -35,10 +37,10 @@ function loadYaml(filename) {
35
37
  });
36
38
  }
37
39
  exports.loadYaml = loadYaml;
38
- function notUndefined(x) {
40
+ function isDefined(x) {
39
41
  return x !== undefined;
40
42
  }
41
- exports.notUndefined = notUndefined;
43
+ exports.isDefined = isDefined;
42
44
  function isPlainObject(value) {
43
45
  return value !== null && typeof value === 'object' && !Array.isArray(value);
44
46
  }
@@ -57,7 +59,7 @@ function readFileFromUrl(url, config) {
57
59
  for (const header of config.headers) {
58
60
  if (match(url, header.matches)) {
59
61
  headers[header.name] =
60
- header.envVariable !== undefined ? config_1.env[header.envVariable] || '' : header.value;
62
+ header.envVariable !== undefined ? env_1.env[header.envVariable] || '' : header.value;
61
63
  }
62
64
  }
63
65
  const req = yield (config.customFetch || node_fetch_1.default)(url, {
@@ -88,7 +90,7 @@ exports.omitObjectProps = omitObjectProps;
88
90
  function splitCamelCaseIntoWords(str) {
89
91
  const camel = str
90
92
  .split(/(?:[-._])|([A-Z][a-z]+)/)
91
- .filter(Boolean)
93
+ .filter(isTruthy)
92
94
  .map((item) => item.toLocaleLowerCase());
93
95
  const caps = str
94
96
  .split(/([A-Z]{2,})/)
@@ -137,6 +139,11 @@ function readFileAsStringSync(filePath) {
137
139
  return fs.readFileSync(filePath, 'utf-8');
138
140
  }
139
141
  exports.readFileAsStringSync = readFileAsStringSync;
142
+ function yamlAndJsonSyncReader(filePath) {
143
+ const content = fs.readFileSync(filePath, 'utf-8');
144
+ return js_yaml_1.parseYaml(content);
145
+ }
146
+ exports.yamlAndJsonSyncReader = yamlAndJsonSyncReader;
140
147
  function isPathParameter(pathSegment) {
141
148
  return pathSegment.startsWith('{') && pathSegment.endsWith('}');
142
149
  }
@@ -166,10 +173,69 @@ function isNotString(value) {
166
173
  }
167
174
  exports.isNotString = isNotString;
168
175
  function assignExisting(target, obj) {
169
- for (let k of Object.keys(obj)) {
176
+ for (const k of Object.keys(obj)) {
170
177
  if (target.hasOwnProperty(k)) {
171
178
  target[k] = obj[k];
172
179
  }
173
180
  }
174
181
  }
175
182
  exports.assignExisting = assignExisting;
183
+ function getMatchingStatusCodeRange(code) {
184
+ return `${code}`.replace(/^(\d)\d\d$/, (_, firstDigit) => `${firstDigit}XX`);
185
+ }
186
+ exports.getMatchingStatusCodeRange = getMatchingStatusCodeRange;
187
+ function isCustomRuleId(id) {
188
+ return id.includes('/');
189
+ }
190
+ exports.isCustomRuleId = isCustomRuleId;
191
+ function doesYamlFileExist(filePath) {
192
+ return ((path_1.extname(filePath) === '.yaml' || path_1.extname(filePath) === '.yml') &&
193
+ fs.hasOwnProperty('existsSync') &&
194
+ fs.existsSync(filePath));
195
+ }
196
+ exports.doesYamlFileExist = doesYamlFileExist;
197
+ function showWarningForDeprecatedField(deprecatedField, updatedField, updatedObject) {
198
+ logger_1.logger.warn(`The '${logger_1.colorize.red(deprecatedField)}' field is deprecated. ${updatedField
199
+ ? `Use ${logger_1.colorize.green(getUpdatedFieldName(updatedField, updatedObject))} instead. `
200
+ : ''}Read more about this change: https://redocly.com/docs/api-registry/guides/migration-guide-config-file/#changed-properties\n`);
201
+ }
202
+ exports.showWarningForDeprecatedField = showWarningForDeprecatedField;
203
+ function showErrorForDeprecatedField(deprecatedField, updatedField, updatedObject) {
204
+ throw new Error(`Do not use '${deprecatedField}' field. ${updatedField ? `Use '${getUpdatedFieldName(updatedField, updatedObject)}' instead. ` : ''}\n`);
205
+ }
206
+ exports.showErrorForDeprecatedField = showErrorForDeprecatedField;
207
+ function isTruthy(value) {
208
+ return !!value;
209
+ }
210
+ exports.isTruthy = isTruthy;
211
+ function identity(value) {
212
+ return value;
213
+ }
214
+ exports.identity = identity;
215
+ function keysOf(obj) {
216
+ if (!obj)
217
+ return [];
218
+ return Object.keys(obj);
219
+ }
220
+ exports.keysOf = keysOf;
221
+ function pickDefined(obj) {
222
+ if (!obj)
223
+ return undefined;
224
+ const res = {};
225
+ for (const key in obj) {
226
+ if (obj[key] !== undefined) {
227
+ res[key] = obj[key];
228
+ }
229
+ }
230
+ return res;
231
+ }
232
+ exports.pickDefined = pickDefined;
233
+ function nextTick() {
234
+ new Promise((resolve) => {
235
+ setTimeout(resolve);
236
+ });
237
+ }
238
+ exports.nextTick = nextTick;
239
+ function getUpdatedFieldName(updatedField, updatedObject) {
240
+ return `${typeof updatedObject !== 'undefined' ? `${updatedObject}.` : ''}${updatedField}`;
241
+ }
package/lib/visitors.d.ts CHANGED
@@ -1,14 +1,15 @@
1
1
  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';
2
- import { Oas2Definition, Oas2Tag, Oas2ExternalDocs, Oas2SecurityRequirement, Oas2Info, Oas2Contact, Oas2License, Oas2PathItem, Oas2Operation, Oas2Header, Oas2Response, Oas2Schema, Oas2Xml, Oas2Parameter, Oas2SecurityScheme } from './typings/swagger';
2
+ import type { Oas2Definition, Oas2Tag, Oas2ExternalDocs, Oas2SecurityRequirement, Oas2Info, Oas2Contact, Oas2License, Oas2PathItem, Oas2Operation, Oas2Header, Oas2Response, Oas2Schema, Oas2Xml, Oas2Parameter, Oas2SecurityScheme } from './typings/swagger';
3
3
  import { NormalizedNodeType } from './types';
4
- import { Stack } from './utils';
5
- import { UserContext, ResolveResult, ProblemSeverity } from './walk';
6
- import { Location } from './ref-utils';
4
+ import type { Stack } from './utils';
5
+ import type { UserContext, ResolveResult, ProblemSeverity } from './walk';
6
+ import type { Location } from './ref-utils';
7
+ export declare type SkipFunctionContext = Pick<UserContext, 'location' | 'rawNode' | 'resolve' | 'rawLocation'>;
7
8
  export declare type VisitFunction<T> = (node: T, ctx: UserContext & {
8
9
  ignoreNextVisitorsOnNode: () => void;
9
10
  }, parents?: any, context?: any) => void;
10
11
  declare type VisitRefFunction = (node: OasRef, ctx: UserContext, resolved: ResolveResult<any>) => void;
11
- declare type SkipFunction<T> = (node: T, key: string | number) => boolean;
12
+ declare type SkipFunction<T> = (node: T, key: string | number, ctx: SkipFunctionContext) => boolean;
12
13
  declare type VisitObject<T> = {
13
14
  enter?: VisitFunction<T>;
14
15
  leave?: VisitFunction<T>;
@@ -16,7 +17,7 @@ declare type VisitObject<T> = {
16
17
  };
17
18
  declare type NestedVisitObject<T, P> = VisitObject<T> & NestedVisitor<P>;
18
19
  declare type VisitFunctionOrObject<T> = VisitFunction<T> | VisitObject<T>;
19
- declare type VisitorNode<T extends any> = {
20
+ declare type VisitorNode<T> = {
20
21
  ruleId: string;
21
22
  severity: ProblemSeverity;
22
23
  context: VisitorLevelContext | VisitorSkippedLevelContext;
@@ -61,7 +62,7 @@ export declare type BaseVisitor = {
61
62
  } | VisitRefFunction;
62
63
  };
63
64
  declare type Oas3FlatVisitor = {
64
- DefinitionRoot?: VisitFunctionOrObject<Oas3Definition>;
65
+ Root?: VisitFunctionOrObject<Oas3Definition>;
65
66
  Tag?: VisitFunctionOrObject<Oas3Tag>;
66
67
  ExternalDocs?: VisitFunctionOrObject<Oas3ExternalDocs>;
67
68
  Server?: VisitFunctionOrObject<Oas3Server>;
@@ -70,18 +71,19 @@ declare type Oas3FlatVisitor = {
70
71
  Info?: VisitFunctionOrObject<Oas3Info>;
71
72
  Contact?: VisitFunctionOrObject<Oas3Contact>;
72
73
  License?: VisitFunctionOrObject<Oas3License>;
73
- PathMap?: VisitFunctionOrObject<Record<string, Oas3PathItem>>;
74
+ Paths?: VisitFunctionOrObject<Record<string, Oas3PathItem>>;
74
75
  PathItem?: VisitFunctionOrObject<Oas3PathItem>;
75
- Callback?: VisitFunctionOrObject<Record<string, Oas3PathItem>>;
76
+ Callback?: VisitFunctionOrObject<Oas3Callback>;
77
+ CallbacksMap?: VisitFunctionOrObject<Record<string, Oas3Callback>>;
76
78
  Parameter?: VisitFunctionOrObject<Oas3Parameter>;
77
79
  Operation?: VisitFunctionOrObject<Oas3Operation>;
78
80
  RequestBody?: VisitFunctionOrObject<Oas3RequestBody>;
79
- MediaTypeMap?: VisitFunctionOrObject<Record<string, Oas3MediaType>>;
81
+ MediaTypesMap?: VisitFunctionOrObject<Record<string, Oas3MediaType>>;
80
82
  MediaType?: VisitFunctionOrObject<Oas3MediaType>;
81
83
  Example?: VisitFunctionOrObject<Oas3Example>;
82
84
  Encoding?: VisitFunctionOrObject<Oas3Encoding>;
83
85
  Header?: VisitFunctionOrObject<Oas3Header>;
84
- ResponsesMap?: VisitFunctionOrObject<Record<string, Oas3Response>>;
86
+ Responses?: VisitFunctionOrObject<Record<string, Oas3Response>>;
85
87
  Response?: VisitFunctionOrObject<Oas3Response>;
86
88
  Link?: VisitFunctionOrObject<Oas3Link>;
87
89
  Schema?: VisitFunctionOrObject<Oas3Schema>;
@@ -103,24 +105,25 @@ declare type Oas3FlatVisitor = {
103
105
  PasswordFlow?: VisitFunctionOrObject<Oas3SecurityScheme['flows']['password']>;
104
106
  ClientCredentials?: VisitFunctionOrObject<Oas3SecurityScheme['flows']['clientCredentials']>;
105
107
  AuthorizationCode?: VisitFunctionOrObject<Oas3SecurityScheme['flows']['authorizationCode']>;
106
- SecuritySchemeFlows?: VisitFunctionOrObject<Oas3SecurityScheme['flows']>;
108
+ OAuth2Flows?: VisitFunctionOrObject<Oas3SecurityScheme['flows']>;
107
109
  SecurityScheme?: VisitFunctionOrObject<Oas3SecurityScheme>;
110
+ SpecExtension?: VisitFunctionOrObject<unknown>;
108
111
  };
109
112
  declare type Oas2FlatVisitor = {
110
- DefinitionRoot?: VisitFunctionOrObject<Oas2Definition>;
113
+ Root?: VisitFunctionOrObject<Oas2Definition>;
111
114
  Tag?: VisitFunctionOrObject<Oas2Tag>;
112
115
  ExternalDocs?: VisitFunctionOrObject<Oas2ExternalDocs>;
113
116
  SecurityRequirement?: VisitFunctionOrObject<Oas2SecurityRequirement>;
114
117
  Info?: VisitFunctionOrObject<Oas2Info>;
115
118
  Contact?: VisitFunctionOrObject<Oas2Contact>;
116
119
  License?: VisitFunctionOrObject<Oas2License>;
117
- PathMap?: VisitFunctionOrObject<Record<string, Oas2PathItem>>;
120
+ Paths?: VisitFunctionOrObject<Record<string, Oas2PathItem>>;
118
121
  PathItem?: VisitFunctionOrObject<Oas2PathItem>;
119
122
  Parameter?: VisitFunctionOrObject<any>;
120
123
  Operation?: VisitFunctionOrObject<Oas2Operation>;
121
124
  Examples?: VisitFunctionOrObject<Record<string, any>>;
122
125
  Header?: VisitFunctionOrObject<Oas2Header>;
123
- ResponsesMap?: VisitFunctionOrObject<Record<string, Oas2Response>>;
126
+ Responses?: VisitFunctionOrObject<Record<string, Oas2Response>>;
124
127
  Response?: VisitFunctionOrObject<Oas2Response>;
125
128
  Schema?: VisitFunctionOrObject<Oas2Schema>;
126
129
  Xml?: VisitFunctionOrObject<Oas2Xml>;
@@ -129,6 +132,7 @@ declare type Oas2FlatVisitor = {
129
132
  NamedResponses?: VisitFunctionOrObject<Record<string, Oas2Response>>;
130
133
  NamedParameters?: VisitFunctionOrObject<Record<string, Oas2Parameter>>;
131
134
  SecurityScheme?: VisitFunctionOrObject<Oas2SecurityScheme>;
135
+ SpecExtension?: VisitFunctionOrObject<unknown>;
132
136
  };
133
137
  declare type Oas3NestedVisitor = {
134
138
  [T in keyof Oas3FlatVisitor]: Oas3FlatVisitor[T] extends Function ? Oas3FlatVisitor[T] : Oas3FlatVisitor[T] & NestedVisitor<Oas3NestedVisitor>;
@@ -140,7 +144,7 @@ export declare type Oas3Visitor = BaseVisitor & Oas3NestedVisitor & Record<strin
140
144
  export declare type Oas2Visitor = BaseVisitor & Oas2NestedVisitor & Record<string, VisitFunction<any> | NestedVisitObject<any, Oas2NestedVisitor>>;
141
145
  export declare type Oas3TransformVisitor = BaseVisitor & Oas3FlatVisitor & Record<string, VisitFunction<any> | VisitObject<any>>;
142
146
  export declare type Oas2TransformVisitor = BaseVisitor & Oas2FlatVisitor & Record<string, VisitFunction<any> | VisitObject<any>>;
143
- export declare type NestedVisitor<T> = Exclude<T, 'any' | 'ref' | 'DefinitionRoot'>;
147
+ export declare type NestedVisitor<T> = Exclude<T, 'any' | 'ref' | 'Root'>;
144
148
  export declare type NormalizedOasVisitors<T extends BaseVisitor> = {
145
149
  [V in keyof T]-?: {
146
150
  enter: Array<NormalizeVisitor<T[V]>>;
package/lib/visitors.js CHANGED
@@ -1,6 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeVisitors = void 0;
4
+ const types_1 = require("./types");
5
+ const legacyTypesMap = {
6
+ Root: 'DefinitionRoot',
7
+ ServerVariablesMap: 'ServerVariableMap',
8
+ Paths: ['PathMap', 'PathsMap'],
9
+ CallbacksMap: 'CallbackMap',
10
+ MediaTypesMap: 'MediaTypeMap',
11
+ ExamplesMap: 'ExampleMap',
12
+ EncodingMap: 'EncodingsMap',
13
+ HeadersMap: 'HeaderMap',
14
+ LinksMap: 'LinkMap',
15
+ OAuth2Flows: 'SecuritySchemeFlows',
16
+ Responses: 'ResponsesMap',
17
+ };
4
18
  function normalizeVisitors(visitorsConfig, types) {
5
19
  const normalizedVisitors = {};
6
20
  normalizedVisitors.any = {
@@ -30,7 +44,7 @@ function normalizeVisitors(visitorsConfig, types) {
30
44
  return;
31
45
  stack = [...stack, from];
32
46
  const possibleChildren = new Set();
33
- for (let type of Object.values(from.properties)) {
47
+ for (const type of Object.values(from.properties)) {
34
48
  if (type === to) {
35
49
  addWeakFromStack(ruleConf, stack);
36
50
  continue;
@@ -55,7 +69,10 @@ function normalizeVisitors(visitorsConfig, types) {
55
69
  possibleChildren.add(from.items);
56
70
  }
57
71
  }
58
- for (let fromType of Array.from(possibleChildren.values())) {
72
+ if (from.extensionsPrefix) {
73
+ possibleChildren.add(types_1.SpecExtension);
74
+ }
75
+ for (const fromType of Array.from(possibleChildren.values())) {
59
76
  addWeakNodes(ruleConf, fromType, to, parentContext, stack);
60
77
  }
61
78
  function addWeakFromStack(ruleConf, stack) {
@@ -74,6 +91,13 @@ function normalizeVisitors(visitorsConfig, types) {
74
91
  }
75
92
  }
76
93
  }
94
+ function findLegacyVisitorNode(visitor, typeName) {
95
+ if (Array.isArray(typeName)) {
96
+ const name = typeName.find((name) => visitor[name]) || undefined;
97
+ return name && visitor[name];
98
+ }
99
+ return visitor[typeName];
100
+ }
77
101
  function normalizeVisitorLevel(ruleConf, visitor, parentContext, depth = 0) {
78
102
  const visitorKeys = Object.keys(types);
79
103
  if (depth === 0) {
@@ -89,7 +113,8 @@ function normalizeVisitors(visitorsConfig, types) {
89
113
  }
90
114
  }
91
115
  for (const typeName of visitorKeys) {
92
- const typeVisitor = visitor[typeName];
116
+ const typeVisitor = (visitor[typeName] ||
117
+ findLegacyVisitorNode(visitor, legacyTypesMap[typeName]));
93
118
  const normalizedTypeVisitor = normalizedVisitors[typeName];
94
119
  if (!typeVisitor)
95
120
  continue;
package/lib/walk.d.ts CHANGED
@@ -1,9 +1,11 @@
1
- import { Referenced } from './typings/openapi';
1
+ import type { Referenced } from './typings/openapi';
2
+ import type { NormalizedOasVisitors } from './visitors';
3
+ import type { ResolvedRefMap, Document } from './resolve';
4
+ import type { NormalizedNodeType } from './types';
5
+ import type { RuleSeverity } from './config';
2
6
  import { Location } from './ref-utils';
3
- import { NormalizedOasVisitors } from './visitors';
4
- import { ResolvedRefMap, Document, ResolveError, YamlParseError, Source } from './resolve';
7
+ import { ResolveError, YamlParseError, Source } from './resolve';
5
8
  import { OasVersion } from './oas-types';
6
- import { NormalizedNodeType } from './types';
7
9
  declare type NonUndefined = string | number | boolean | symbol | bigint | object | Record<string, any>;
8
10
  export declare type ResolveResult<T extends NonUndefined> = {
9
11
  node: T;
@@ -14,23 +16,13 @@ export declare type ResolveResult<T extends NonUndefined> = {
14
16
  location: undefined;
15
17
  error?: ResolveError | YamlParseError;
16
18
  };
17
- export declare type ResolveFn<T> = (node: Referenced<T>, from?: string) => {
18
- location: Location;
19
- node: T;
20
- } | {
21
- location: undefined;
22
- node: undefined;
23
- };
19
+ export declare type ResolveFn = <T>(node: Referenced<T>, from?: string) => ResolveResult<T>;
24
20
  export declare type UserContext = {
25
21
  report(problem: Problem): void;
26
22
  location: Location;
27
- resolve<T>(node: Referenced<T>): {
28
- location: Location;
29
- node: T;
30
- } | {
31
- location: undefined;
32
- node: undefined;
33
- };
23
+ rawNode: any;
24
+ rawLocation: Location;
25
+ resolve: ResolveFn;
34
26
  parentLocations: Record<string, Location>;
35
27
  type: NormalizedNodeType;
36
28
  key: string | number;
@@ -59,7 +51,7 @@ export declare type Problem = {
59
51
  suggest?: string[];
60
52
  location?: Partial<LocationObject> | Array<Partial<LocationObject>>;
61
53
  from?: LocationObject;
62
- forceSeverity?: ProblemSeverity;
54
+ forceSeverity?: RuleSeverity;
63
55
  ruleId?: string;
64
56
  };
65
57
  export declare type NormalizedProblem = {
package/lib/walk.js CHANGED
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.walkDocument = void 0;
4
4
  const ref_utils_1 = require("./ref-utils");
5
- const resolve_1 = require("./resolve");
6
5
  const utils_1 = require("./utils");
6
+ const resolve_1 = require("./resolve");
7
7
  const types_1 = require("./types");
8
8
  function collectParents(ctx) {
9
9
  var _a;
@@ -28,33 +28,53 @@ function collectParentsLocations(ctx) {
28
28
  function walkDocument(opts) {
29
29
  const { document, rootType, normalizedVisitors, resolvedRefMap, ctx } = opts;
30
30
  const seenNodesPerType = {};
31
- const seenRefs = new Set();
31
+ const ignoredNodes = new Set();
32
32
  walkNode(document.parsed, rootType, new ref_utils_1.Location(document.source, '#/'), undefined, '');
33
33
  function walkNode(node, type, location, parent, key) {
34
34
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
35
+ const resolve = (ref, from = currentLocation.source.absoluteRef) => {
36
+ if (!ref_utils_1.isRef(ref))
37
+ return { location, node: ref };
38
+ const refId = resolve_1.makeRefId(from, ref.$ref);
39
+ const resolvedRef = resolvedRefMap.get(refId);
40
+ if (!resolvedRef) {
41
+ return {
42
+ location: undefined,
43
+ node: undefined,
44
+ };
45
+ }
46
+ const { resolved, node, document, nodePointer, error } = resolvedRef;
47
+ const newLocation = resolved
48
+ ? new ref_utils_1.Location(document.source, nodePointer)
49
+ : error instanceof resolve_1.YamlParseError
50
+ ? new ref_utils_1.Location(error.source, '')
51
+ : undefined;
52
+ return { location: newLocation, node, error };
53
+ };
54
+ const rawLocation = location;
35
55
  let currentLocation = location;
36
56
  const { node: resolvedNode, location: resolvedLocation, error } = resolve(node);
37
57
  const enteredContexts = new Set();
38
58
  if (ref_utils_1.isRef(node)) {
39
59
  const refEnterVisitors = normalizedVisitors.ref.enter;
40
60
  for (const { visit: visitor, ruleId, severity, context } of refEnterVisitors) {
41
- if (!seenRefs.has(node)) {
42
- enteredContexts.add(context);
43
- const report = reportFn.bind(undefined, ruleId, severity);
44
- visitor(node, {
45
- report,
46
- resolve,
47
- location,
48
- type,
49
- parent,
50
- key,
51
- parentLocations: {},
52
- oasVersion: ctx.oasVersion,
53
- getVisitorData: getVisitorDataFn.bind(undefined, ruleId)
54
- }, { node: resolvedNode, location: resolvedLocation, error });
55
- if ((resolvedLocation === null || resolvedLocation === void 0 ? void 0 : resolvedLocation.source.absoluteRef) && ctx.refTypes) {
56
- ctx.refTypes.set(resolvedLocation === null || resolvedLocation === void 0 ? void 0 : resolvedLocation.source.absoluteRef, type);
57
- }
61
+ enteredContexts.add(context);
62
+ const report = reportFn.bind(undefined, ruleId, severity);
63
+ visitor(node, {
64
+ report,
65
+ resolve,
66
+ rawNode: node,
67
+ rawLocation,
68
+ location,
69
+ type,
70
+ parent,
71
+ key,
72
+ parentLocations: {},
73
+ oasVersion: ctx.oasVersion,
74
+ getVisitorData: getVisitorDataFn.bind(undefined, ruleId),
75
+ }, { 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);
58
78
  }
59
79
  }
60
80
  }
@@ -66,6 +86,8 @@ function walkDocument(opts) {
66
86
  const currentEnterVisitors = anyEnterVisitors.concat(((_c = normalizedVisitors[type.name]) === null || _c === void 0 ? void 0 : _c.enter) || []);
67
87
  const activatedContexts = [];
68
88
  for (const { context, visit, skip, ruleId, severity } of currentEnterVisitors) {
89
+ if (ignoredNodes.has(currentLocation.pointer))
90
+ break;
69
91
  if (context.isSkippedLevel) {
70
92
  if (context.parent.activatedOn &&
71
93
  !context.parent.activatedOn.value.nextLevelTypeActivated &&
@@ -90,7 +112,13 @@ function walkDocument(opts) {
90
112
  location: resolvedLocation,
91
113
  nextLevelTypeActivated: null,
92
114
  withParentNode: (_g = (_f = context.parent) === null || _f === void 0 ? void 0 : _f.activatedOn) === null || _g === void 0 ? void 0 : _g.value.node,
93
- skipped: (_k = (((_j = (_h = context.parent) === null || _h === void 0 ? void 0 : _h.activatedOn) === null || _j === void 0 ? void 0 : _j.value.skipped) || (skip === null || skip === void 0 ? void 0 : skip(resolvedNode, key)))) !== null && _k !== void 0 ? _k : false,
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, {
117
+ location,
118
+ rawLocation,
119
+ resolve,
120
+ rawNode: node,
121
+ })))) !== null && _k !== void 0 ? _k : false,
94
122
  };
95
123
  context.activatedOn = utils_1.pushStack(context.activatedOn, activatedOn);
96
124
  let ctx = context.parent;
@@ -101,9 +129,7 @@ function walkDocument(opts) {
101
129
  if (!activatedOn.skipped) {
102
130
  visitedBySome = true;
103
131
  enteredContexts.add(context);
104
- const { ignoreNextVisitorsOnNode } = visitWithContext(visit, resolvedNode, context, ruleId, severity);
105
- if (ignoreNextVisitorsOnNode)
106
- break;
132
+ visitWithContext(visit, resolvedNode, node, context, ruleId, severity);
107
133
  }
108
134
  }
109
135
  }
@@ -125,6 +151,9 @@ function walkDocument(opts) {
125
151
  if (type.additionalProperties) {
126
152
  props.push(...Object.keys(resolvedNode).filter((k) => !props.includes(k)));
127
153
  }
154
+ else if (type.extensionsPrefix) {
155
+ props.push(...Object.keys(resolvedNode).filter((k) => k.startsWith(type.extensionsPrefix)));
156
+ }
128
157
  if (ref_utils_1.isRef(node)) {
129
158
  props.push(...Object.keys(node).filter((k) => k !== '$ref' && !props.includes(k))); // properties on the same level as $ref
130
159
  }
@@ -140,6 +169,11 @@ function walkDocument(opts) {
140
169
  propType = type.additionalProperties;
141
170
  if (typeof propType === 'function')
142
171
  propType = propType(value, propName);
172
+ if (propType === undefined &&
173
+ type.extensionsPrefix &&
174
+ propName.startsWith(type.extensionsPrefix)) {
175
+ propType = types_1.SpecExtension;
176
+ }
143
177
  if (!types_1.isNamedType(propType) && (propType === null || propType === void 0 ? void 0 : propType.directResolveAs)) {
144
178
  propType = propType.directResolveAs;
145
179
  value = { $ref: value };
@@ -173,7 +207,7 @@ function walkDocument(opts) {
173
207
  }
174
208
  for (const { context, visit, ruleId, severity } of currentLeaveVisitors) {
175
209
  if (!context.isSkippedLevel && enteredContexts.has(context)) {
176
- visitWithContext(visit, resolvedNode, context, ruleId, severity);
210
+ visitWithContext(visit, resolvedNode, node, context, ruleId, severity);
177
211
  }
178
212
  }
179
213
  }
@@ -186,63 +220,50 @@ function walkDocument(opts) {
186
220
  visitor(node, {
187
221
  report,
188
222
  resolve,
223
+ rawNode: node,
224
+ rawLocation,
189
225
  location,
190
226
  type,
191
227
  parent,
192
228
  key,
193
229
  parentLocations: {},
194
230
  oasVersion: ctx.oasVersion,
195
- getVisitorData: getVisitorDataFn.bind(undefined, ruleId)
231
+ getVisitorData: getVisitorDataFn.bind(undefined, ruleId),
196
232
  }, { node: resolvedNode, location: resolvedLocation, error });
197
233
  }
198
234
  }
199
235
  }
200
236
  // returns true ignores all the next visitors on the specific node
201
- function visitWithContext(visit, node, context, ruleId, severity) {
237
+ function visitWithContext(visit, resolvedNode, node, context, ruleId, severity) {
202
238
  const report = reportFn.bind(undefined, ruleId, severity);
203
- let ignoreNextVisitorsOnNode = false;
204
- visit(node, {
239
+ visit(resolvedNode, {
205
240
  report,
206
241
  resolve,
242
+ rawNode: node,
207
243
  location: currentLocation,
244
+ rawLocation,
208
245
  type,
209
246
  parent,
210
247
  key,
211
248
  parentLocations: collectParentsLocations(context),
212
249
  oasVersion: ctx.oasVersion,
213
- ignoreNextVisitorsOnNode: () => { ignoreNextVisitorsOnNode = true; },
250
+ ignoreNextVisitorsOnNode: () => {
251
+ ignoredNodes.add(currentLocation.pointer);
252
+ },
214
253
  getVisitorData: getVisitorDataFn.bind(undefined, ruleId),
215
254
  }, collectParents(context), context);
216
- return { ignoreNextVisitorsOnNode };
217
- }
218
- function resolve(ref, from = currentLocation.source.absoluteRef) {
219
- if (!ref_utils_1.isRef(ref))
220
- return { location, node: ref };
221
- const refId = resolve_1.makeRefId(from, ref.$ref);
222
- const resolvedRef = resolvedRefMap.get(refId);
223
- if (!resolvedRef) {
224
- return {
225
- location: undefined,
226
- node: undefined,
227
- };
228
- }
229
- const { resolved, node, document, nodePointer, error } = resolvedRef;
230
- const newLocation = resolved
231
- ? new ref_utils_1.Location(document.source, nodePointer)
232
- : error instanceof resolve_1.YamlParseError
233
- ? new ref_utils_1.Location(error.source, '')
234
- : undefined;
235
- return { location: newLocation, node, error };
236
255
  }
237
256
  function reportFn(ruleId, severity, opts) {
238
- const loc = opts.location
257
+ const normalizedLocation = opts.location
239
258
  ? Array.isArray(opts.location)
240
259
  ? opts.location
241
260
  : [opts.location]
242
261
  : [Object.assign(Object.assign({}, currentLocation), { reportOnKey: false })];
243
- ctx.problems.push(Object.assign(Object.assign({ ruleId: opts.ruleId || ruleId, severity: opts.forceSeverity || severity }, opts), { suggest: opts.suggest || [], location: loc.map((loc) => {
244
- return Object.assign(Object.assign(Object.assign({}, currentLocation), { reportOnKey: false }), loc);
245
- }) }));
262
+ const location = normalizedLocation.map((l) => (Object.assign(Object.assign(Object.assign({}, currentLocation), { reportOnKey: false }), l)));
263
+ const ruleSeverity = opts.forceSeverity || severity;
264
+ if (ruleSeverity !== 'off') {
265
+ ctx.problems.push(Object.assign(Object.assign({ ruleId: opts.ruleId || ruleId, severity: ruleSeverity }, opts), { suggest: opts.suggest || [], location }));
266
+ }
246
267
  }
247
268
  function getVisitorDataFn(ruleId) {
248
269
  ctx.visitorsData[ruleId] = ctx.visitorsData[ruleId] || {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redocly/openapi-core",
3
- "version": "1.0.0-beta.98",
3
+ "version": "1.0.0-rc.1",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "engines": {
@@ -16,7 +16,8 @@
16
16
  "fs": false,
17
17
  "path": "path-browserify",
18
18
  "os": false,
19
- "node-fetch": false
19
+ "node-fetch": false,
20
+ "colorette": false
20
21
  },
21
22
  "homepage": "https://github.com/Redocly/redocly-cli",
22
23
  "keywords": [
@@ -28,12 +29,10 @@
28
29
  "oas"
29
30
  ],
30
31
  "contributors": [
31
- "Sergey Dubovyk <serhii@redoc.ly> (https://redoc.ly/)",
32
- "Roman Hotsiy <roman@redoc.ly> (https://redoc.ly/)",
33
- "Andriy Leliv <andriy@redoc.ly> (https://redoc.ly/)"
32
+ "Roman Hotsiy <roman@redoc.ly> (https://redoc.ly/)"
34
33
  ],
35
34
  "dependencies": {
36
- "@redocly/ajv": "^8.6.4",
35
+ "@redocly/ajv": "^8.11.0",
37
36
  "@types/node": "^14.11.8",
38
37
  "colorette": "^1.2.0",
39
38
  "js-levenshtein": "^1.1.6",