@redocly/openapi-core 1.18.1 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (411) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/__tests__/utils.ts +14 -7
  3. package/lib/benchmark/benches/lint-with-many-rules.bench.d.ts +1 -0
  4. package/lib/benchmark/benches/lint-with-many-rules.bench.js +7 -3
  5. package/lib/benchmark/benches/lint-with-nested-rule.bench.d.ts +1 -0
  6. package/lib/benchmark/benches/lint-with-nested-rule.bench.js +7 -3
  7. package/lib/benchmark/benches/lint-with-no-rules.bench.d.ts +1 -0
  8. package/lib/benchmark/benches/lint-with-no-rules.bench.js +7 -3
  9. package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.d.ts +1 -0
  10. package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +19 -15
  11. package/lib/benchmark/benches/lint-with-top-level-rule.bench.d.ts +1 -0
  12. package/lib/benchmark/benches/lint-with-top-level-rule.bench.js +18 -14
  13. package/lib/benchmark/benches/recommended-oas3.bench.js +2 -2
  14. package/lib/benchmark/benches/resolve-with-no-external.bench.js +2 -2
  15. package/lib/benchmark/utils.d.ts +3 -3
  16. package/lib/benchmark/utils.js +10 -7
  17. package/lib/bundle.d.ts +2 -2
  18. package/lib/bundle.js +127 -120
  19. package/lib/config/all.js +13 -1
  20. package/lib/config/builtIn.js +18 -17
  21. package/lib/config/config-resolvers.d.ts +1 -1
  22. package/lib/config/config-resolvers.js +241 -158
  23. package/lib/config/config.d.ts +4 -3
  24. package/lib/config/config.js +53 -34
  25. package/lib/config/load.d.ts +1 -1
  26. package/lib/config/load.js +105 -117
  27. package/lib/config/minimal.js +13 -0
  28. package/lib/config/recommended-strict.js +14 -1
  29. package/lib/config/recommended.js +14 -1
  30. package/lib/config/rules.d.ts +3 -3
  31. package/lib/config/rules.js +1 -2
  32. package/lib/config/types.d.ts +17 -4
  33. package/lib/config/utils.d.ts +3 -1
  34. package/lib/config/utils.js +78 -49
  35. package/lib/decorators/async3/index.d.ts +1 -0
  36. package/lib/decorators/async3/index.js +4 -0
  37. package/lib/decorators/common/filters/filter-helper.d.ts +1 -1
  38. package/lib/decorators/common/filters/filter-helper.js +2 -3
  39. package/lib/decorators/common/filters/filter-in.d.ts +1 -1
  40. package/lib/decorators/common/filters/filter-in.js +1 -1
  41. package/lib/decorators/common/filters/filter-out.d.ts +1 -1
  42. package/lib/decorators/common/filters/filter-out.js +1 -1
  43. package/lib/decorators/common/info-description-override.d.ts +1 -1
  44. package/lib/decorators/common/info-override.d.ts +1 -1
  45. package/lib/decorators/common/info-override.js +1 -12
  46. package/lib/decorators/common/media-type-examples-override.d.ts +1 -1
  47. package/lib/decorators/common/media-type-examples-override.js +8 -2
  48. package/lib/decorators/common/operation-description-override.d.ts +1 -1
  49. package/lib/decorators/common/registry-dependencies.d.ts +1 -1
  50. package/lib/decorators/common/remove-x-internal.d.ts +1 -1
  51. package/lib/decorators/common/remove-x-internal.js +4 -5
  52. package/lib/decorators/common/tag-description-override.d.ts +1 -1
  53. package/lib/decorators/oas2/index.d.ts +1 -1
  54. package/lib/decorators/oas2/remove-unused-components.js +1 -2
  55. package/lib/decorators/oas3/index.d.ts +1 -1
  56. package/lib/decorators/oas3/remove-unused-components.js +1 -2
  57. package/lib/env.d.ts +0 -1
  58. package/lib/env.js +1 -1
  59. package/lib/format/codeframes.d.ts +1 -1
  60. package/lib/format/codeframes.js +10 -8
  61. package/lib/format/format.d.ts +1 -1
  62. package/lib/format/format.js +24 -16
  63. package/lib/index.d.ts +2 -1
  64. package/lib/index.js +6 -4
  65. package/lib/js-yaml/index.d.ts +1 -1
  66. package/lib/js-yaml/index.js +1 -1
  67. package/lib/lint.d.ts +3 -1
  68. package/lib/lint.js +92 -99
  69. package/lib/logger.js +2 -2
  70. package/lib/oas-types.d.ts +9 -5
  71. package/lib/oas-types.js +22 -12
  72. package/lib/redocly/domains.d.ts +1 -1
  73. package/lib/redocly/domains.js +6 -6
  74. package/lib/redocly/index.d.ts +1 -1
  75. package/lib/redocly/index.js +60 -73
  76. package/lib/redocly/registry-api.js +64 -82
  77. package/lib/ref-utils.d.ts +2 -2
  78. package/lib/ref-utils.js +14 -13
  79. package/lib/resolve.d.ts +2 -2
  80. package/lib/resolve.js +186 -205
  81. package/lib/rules/ajv.d.ts +1 -1
  82. package/lib/rules/ajv.js +10 -8
  83. package/lib/rules/arazzo/index.js +2 -0
  84. package/lib/rules/async2/channels-kebab-case.d.ts +1 -1
  85. package/lib/rules/async2/index.js +2 -0
  86. package/lib/rules/async2/no-channel-trailing-slash.d.ts +1 -1
  87. package/lib/rules/async3/channels-kebab-case.d.ts +2 -0
  88. package/lib/rules/async3/channels-kebab-case.js +19 -0
  89. package/lib/rules/async3/index.d.ts +3 -0
  90. package/lib/rules/async3/index.js +24 -0
  91. package/lib/rules/async3/no-channel-trailing-slash.d.ts +2 -0
  92. package/lib/rules/async3/no-channel-trailing-slash.js +16 -0
  93. package/lib/rules/common/assertions/asserts.d.ts +2 -2
  94. package/lib/rules/common/assertions/asserts.js +5 -5
  95. package/lib/rules/common/assertions/index.d.ts +4 -4
  96. package/lib/rules/common/assertions/utils.d.ts +1 -1
  97. package/lib/rules/common/assertions/utils.js +43 -28
  98. package/lib/rules/common/info-contact.d.ts +1 -1
  99. package/lib/rules/common/info-license-strict.d.ts +2 -0
  100. package/lib/rules/common/info-license-strict.js +26 -0
  101. package/lib/rules/common/info-license-url.d.ts +1 -1
  102. package/lib/rules/common/info-license.d.ts +1 -1
  103. package/lib/rules/common/no-ambiguous-paths.d.ts +1 -1
  104. package/lib/rules/common/no-enum-type-mismatch.d.ts +1 -1
  105. package/lib/rules/common/no-http-verbs-in-paths.d.ts +1 -1
  106. package/lib/rules/common/no-identical-paths.d.ts +1 -1
  107. package/lib/rules/common/no-invalid-parameter-examples.js +1 -2
  108. package/lib/rules/common/no-invalid-schema-examples.js +1 -2
  109. package/lib/rules/common/no-path-trailing-slash.d.ts +1 -1
  110. package/lib/rules/common/no-required-schema-properties-undefined.d.ts +1 -1
  111. package/lib/rules/common/no-required-schema-properties-undefined.js +1 -2
  112. package/lib/rules/common/operation-2xx-response.d.ts +1 -1
  113. package/lib/rules/common/operation-4xx-response.d.ts +1 -1
  114. package/lib/rules/common/operation-description.d.ts +1 -1
  115. package/lib/rules/common/operation-operationId-unique.d.ts +1 -1
  116. package/lib/rules/common/operation-operationId-url-safe.d.ts +1 -1
  117. package/lib/rules/common/operation-operationId-url-safe.js +1 -0
  118. package/lib/rules/common/operation-operationId.d.ts +1 -1
  119. package/lib/rules/common/operation-parameters-unique.d.ts +1 -1
  120. package/lib/rules/common/operation-singular-tag.d.ts +1 -1
  121. package/lib/rules/common/operation-summary.d.ts +1 -1
  122. package/lib/rules/common/operation-tag-defined.d.ts +1 -1
  123. package/lib/rules/common/operation-tag-defined.js +1 -2
  124. package/lib/rules/common/parameter-description.d.ts +1 -1
  125. package/lib/rules/common/path-declaration-must-exist.d.ts +1 -1
  126. package/lib/rules/common/path-excludes-patterns.d.ts +1 -1
  127. package/lib/rules/common/path-http-verbs-order.d.ts +1 -1
  128. package/lib/rules/common/path-http-verbs-order.js +1 -1
  129. package/lib/rules/common/path-not-include-query.d.ts +1 -1
  130. package/lib/rules/common/path-params-defined.d.ts +1 -1
  131. package/lib/rules/common/path-segment-plural.d.ts +1 -1
  132. package/lib/rules/common/paths-kebab-case.d.ts +1 -1
  133. package/lib/rules/common/required-string-property-missing-min-length.d.ts +1 -1
  134. package/lib/rules/common/required-string-property-missing-min-length.js +2 -2
  135. package/lib/rules/common/response-contains-header.d.ts +1 -1
  136. package/lib/rules/common/response-contains-header.js +2 -2
  137. package/lib/rules/common/security-defined.d.ts +1 -1
  138. package/lib/rules/common/security-defined.js +3 -7
  139. package/lib/rules/common/spec-strict-refs.d.ts +1 -1
  140. package/lib/rules/common/spec.d.ts +2 -2
  141. package/lib/rules/common/spec.js +6 -7
  142. package/lib/rules/common/tag-description.d.ts +1 -1
  143. package/lib/rules/common/tags-alphabetical.d.ts +1 -1
  144. package/lib/rules/no-unresolved-refs.d.ts +3 -3
  145. package/lib/rules/no-unresolved-refs.js +3 -4
  146. package/lib/rules/oas2/boolean-parameter-prefixes.d.ts +1 -1
  147. package/lib/rules/oas2/index.d.ts +1 -1
  148. package/lib/rules/oas2/index.js +2 -0
  149. package/lib/rules/oas2/response-contains-property.d.ts +1 -1
  150. package/lib/rules/oas2/response-contains-property.js +1 -2
  151. package/lib/rules/oas3/array-parameter-serialization.d.ts +1 -1
  152. package/lib/rules/oas3/array-parameter-serialization.js +1 -2
  153. package/lib/rules/oas3/boolean-parameter-prefixes.d.ts +1 -1
  154. package/lib/rules/oas3/component-name-unique.d.ts +1 -1
  155. package/lib/rules/oas3/component-name-unique.js +2 -4
  156. package/lib/rules/oas3/index.d.ts +1 -1
  157. package/lib/rules/oas3/index.js +2 -0
  158. package/lib/rules/oas3/no-empty-servers.d.ts +1 -1
  159. package/lib/rules/oas3/no-example-value-and-externalValue.d.ts +1 -1
  160. package/lib/rules/oas3/no-invalid-media-type-examples.d.ts +1 -1
  161. package/lib/rules/oas3/no-invalid-media-type-examples.js +1 -2
  162. package/lib/rules/oas3/no-server-example.com.d.ts +1 -1
  163. package/lib/rules/oas3/no-server-example.com.js +1 -0
  164. package/lib/rules/oas3/no-server-trailing-slash.d.ts +1 -1
  165. package/lib/rules/oas3/no-server-variables-empty-enum.d.ts +1 -1
  166. package/lib/rules/oas3/no-server-variables-empty-enum.js +1 -2
  167. package/lib/rules/oas3/no-undefined-server-variable.d.ts +1 -1
  168. package/lib/rules/oas3/no-undefined-server-variable.js +2 -3
  169. package/lib/rules/oas3/no-unused-components.d.ts +1 -1
  170. package/lib/rules/oas3/no-unused-components.js +1 -2
  171. package/lib/rules/oas3/response-contains-property.d.ts +1 -1
  172. package/lib/rules/oas3/response-contains-property.js +1 -2
  173. package/lib/rules/oas3/spec-components-invalid-map-name.d.ts +1 -1
  174. package/lib/rules/other/stats.d.ts +3 -3
  175. package/lib/rules/other/stats.js +5 -3
  176. package/lib/rules/spot/parameters-no-body-inside-in.d.ts +2 -0
  177. package/lib/rules/spot/parameters-no-body-inside-in.js +18 -0
  178. package/lib/rules/utils.d.ts +4 -2
  179. package/lib/rules/utils.js +41 -13
  180. package/lib/types/arazzo.d.ts +1 -2275
  181. package/lib/types/arazzo.js +246 -309
  182. package/lib/types/asyncapi2.d.ts +17 -0
  183. package/lib/types/{asyncapi.js → asyncapi2.js} +59 -53
  184. package/lib/types/asyncapi3.d.ts +2 -0
  185. package/lib/types/asyncapi3.js +347 -0
  186. package/lib/types/index.js +19 -10
  187. package/lib/types/json-schema-adapter.d.ts +1 -1
  188. package/lib/types/json-schema-adapter.js +4 -18
  189. package/lib/types/oas2.js +6 -6
  190. package/lib/types/oas3.d.ts +4 -0
  191. package/lib/types/oas3.js +19 -19
  192. package/lib/types/oas3_1.d.ts +3 -0
  193. package/lib/types/oas3_1.js +20 -14
  194. package/lib/types/redocly-yaml.d.ts +8 -6
  195. package/lib/types/redocly-yaml.js +135 -36
  196. package/lib/typings/arazzo.d.ts +145 -27
  197. package/lib/typings/asyncapi3.d.ts +53 -0
  198. package/lib/typings/asyncapi3.js +2 -0
  199. package/lib/typings/common.d.ts +1 -1
  200. package/lib/typings/swagger.d.ts +2 -2
  201. package/lib/utils.d.ts +4 -3
  202. package/lib/utils.js +55 -72
  203. package/lib/visitors.d.ts +29 -1
  204. package/lib/visitors.js +21 -8
  205. package/lib/walk.d.ts +3 -3
  206. package/lib/walk.js +30 -23
  207. package/package.json +3 -3
  208. package/src/__tests__/bundle.test.ts +144 -2
  209. package/src/__tests__/lint.test.ts +29 -21
  210. package/src/__tests__/walk.test.ts +25 -25
  211. package/src/benchmark/benches/lint-with-many-rules.bench.ts +7 -1
  212. package/src/benchmark/benches/lint-with-nested-rule.bench.ts +7 -1
  213. package/src/benchmark/benches/lint-with-no-rules.bench.ts +8 -1
  214. package/src/benchmark/benches/lint-with-top-level-rule-report.bench.ts +18 -13
  215. package/src/benchmark/benches/lint-with-top-level-rule.bench.ts +17 -11
  216. package/src/benchmark/fork.js +4 -0
  217. package/src/benchmark/utils.ts +6 -5
  218. package/src/bundle.ts +19 -4
  219. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +32 -2
  220. package/src/config/__tests__/__snapshots__/config.test.ts.snap +24 -0
  221. package/src/config/__tests__/config-resolvers.test.ts +82 -0
  222. package/src/config/__tests__/config.test.ts +11 -0
  223. package/src/config/__tests__/fixtures/resolve-config/local-config-with-commonjs-export-function.yaml +2 -0
  224. package/src/config/__tests__/fixtures/resolve-config/local-config-with-esm.yaml +2 -0
  225. package/src/config/__tests__/fixtures/resolve-config/plugin-esm.mjs +10 -0
  226. package/src/config/__tests__/fixtures/resolve-config/plugin-with-export-function.cjs +10 -0
  227. package/src/config/__tests__/resolve-plugins.test.ts +4 -1
  228. package/src/config/all.ts +13 -1
  229. package/src/config/builtIn.ts +9 -8
  230. package/src/config/config-resolvers.ts +92 -21
  231. package/src/config/config.ts +31 -13
  232. package/src/config/load.ts +2 -2
  233. package/src/config/minimal.ts +13 -0
  234. package/src/config/recommended-strict.ts +14 -1
  235. package/src/config/recommended.ts +14 -1
  236. package/src/config/rules.ts +12 -4
  237. package/src/config/types.ts +34 -5
  238. package/src/config/utils.ts +28 -2
  239. package/src/decorators/__tests__/filter-in.test.ts +29 -26
  240. package/src/decorators/__tests__/filter-out.test.ts +32 -23
  241. package/src/decorators/__tests__/media-type-examples-override.test.ts +45 -45
  242. package/src/decorators/__tests__/remove-x-internal.test.ts +8 -5
  243. package/src/decorators/async3/index.ts +1 -0
  244. package/src/decorators/common/filters/filter-helper.ts +2 -1
  245. package/src/decorators/common/filters/filter-in.ts +2 -1
  246. package/src/decorators/common/filters/filter-out.ts +2 -1
  247. package/src/decorators/common/info-description-override.ts +3 -2
  248. package/src/decorators/common/info-override.ts +1 -1
  249. package/src/decorators/common/media-type-examples-override.ts +4 -3
  250. package/src/decorators/common/operation-description-override.ts +5 -4
  251. package/src/decorators/common/registry-dependencies.ts +2 -2
  252. package/src/decorators/common/remove-x-internal.ts +5 -4
  253. package/src/decorators/common/tag-description-override.ts +3 -2
  254. package/src/decorators/oas2/__tests__/remove-unused-components.test.ts +3 -3
  255. package/src/decorators/oas2/index.ts +2 -1
  256. package/src/decorators/oas2/remove-unused-components.ts +1 -1
  257. package/src/decorators/oas3/__tests__/remove-unused-components.test.ts +4 -4
  258. package/src/decorators/oas3/index.ts +2 -1
  259. package/src/decorators/oas3/remove-unused-components.ts +1 -1
  260. package/src/format/codeframes.ts +2 -1
  261. package/src/format/format.ts +9 -4
  262. package/src/index.ts +2 -1
  263. package/src/js-yaml/index.ts +3 -1
  264. package/src/lint.ts +28 -4
  265. package/src/logger.ts +2 -2
  266. package/src/oas-types.ts +41 -22
  267. package/src/redocly/domains.ts +1 -1
  268. package/src/redocly/index.ts +3 -3
  269. package/src/redocly/registry-api.ts +5 -3
  270. package/src/ref-utils.ts +4 -2
  271. package/src/resolve.ts +6 -4
  272. package/src/rules/__tests__/no-unresolved-refs.test.ts +21 -7
  273. package/src/rules/ajv.ts +2 -1
  274. package/src/rules/arazzo/__tests__/parameters-no-body-inside-in.test.ts +76 -0
  275. package/src/rules/arazzo/index.ts +6 -3
  276. package/src/rules/async2/__tests__/channels-kebab-case.test.ts +9 -5
  277. package/src/rules/async2/__tests__/no-channel-trailing-slash.test.ts +3 -3
  278. package/src/rules/async2/channels-kebab-case.ts +2 -2
  279. package/src/rules/async2/index.ts +9 -6
  280. package/src/rules/async2/no-channel-trailing-slash.ts +2 -2
  281. package/src/rules/async3/__tests__/channels-kebab-case.test.ts +145 -0
  282. package/src/rules/async3/__tests__/no-channel-trailing-slash.test.ts +96 -0
  283. package/src/rules/async3/channels-kebab-case.ts +19 -0
  284. package/src/rules/async3/index.ts +26 -0
  285. package/src/rules/async3/no-channel-trailing-slash.ts +16 -0
  286. package/src/rules/common/__tests__/info-license-strict.test.ts +141 -0
  287. package/src/rules/common/__tests__/info-license.test.ts +2 -2
  288. package/src/rules/common/__tests__/license-url.test.ts +2 -2
  289. package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +1 -1
  290. package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +5 -5
  291. package/src/rules/common/__tests__/no-identical-paths.test.ts +1 -1
  292. package/src/rules/common/__tests__/no-invalid-parameter-examples.test.ts +1 -1
  293. package/src/rules/common/__tests__/no-invalid-schema-examples.test.ts +1 -1
  294. package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +4 -4
  295. package/src/rules/common/__tests__/no-required-schema-properties-undefined.test.ts +11 -11
  296. package/src/rules/common/__tests__/operation-2xx-response.test.ts +8 -6
  297. package/src/rules/common/__tests__/operation-4xx-response.test.ts +9 -7
  298. package/src/rules/common/__tests__/operation-operationId-unique.test.ts +2 -2
  299. package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +1 -1
  300. package/src/rules/common/__tests__/operation-parameters-unique.test.ts +4 -4
  301. package/src/rules/common/__tests__/operation-singular-tag.test.ts +2 -2
  302. package/src/rules/common/__tests__/path-http-verbs-order.test.ts +2 -2
  303. package/src/rules/common/__tests__/path-not-include-query.test.ts +2 -2
  304. package/src/rules/common/__tests__/path-params-defined.test.ts +5 -5
  305. package/src/rules/common/__tests__/paths-kebab-case.test.ts +6 -4
  306. package/src/rules/common/__tests__/scalar-property-missing-example.test.ts +8 -8
  307. package/src/rules/common/__tests__/security-defined.test.ts +14 -8
  308. package/src/rules/common/__tests__/spec-strict-refs.test.ts +1 -1
  309. package/src/rules/common/__tests__/spec.test.ts +10 -10
  310. package/src/rules/common/__tests__/tag-description.test.ts +2 -2
  311. package/src/rules/common/__tests__/tags-alphabetical.test.ts +6 -4
  312. package/src/rules/common/assertions/asserts.ts +5 -9
  313. package/src/rules/common/assertions/index.ts +12 -4
  314. package/src/rules/common/assertions/utils.ts +4 -2
  315. package/src/rules/common/info-contact.ts +2 -1
  316. package/src/rules/common/info-license-strict.ts +24 -0
  317. package/src/rules/common/info-license-url.ts +2 -1
  318. package/src/rules/common/info-license.ts +2 -1
  319. package/src/rules/common/no-ambiguous-paths.ts +4 -4
  320. package/src/rules/common/no-enum-type-mismatch.ts +5 -4
  321. package/src/rules/common/no-http-verbs-in-paths.ts +5 -4
  322. package/src/rules/common/no-identical-paths.ts +4 -4
  323. package/src/rules/common/no-invalid-parameter-examples.ts +3 -2
  324. package/src/rules/common/no-path-trailing-slash.ts +2 -2
  325. package/src/rules/common/no-required-schema-properties-undefined.ts +5 -4
  326. package/src/rules/common/operation-2xx-response.ts +3 -2
  327. package/src/rules/common/operation-4xx-response.ts +3 -2
  328. package/src/rules/common/operation-description.ts +5 -4
  329. package/src/rules/common/operation-operationId-unique.ts +4 -4
  330. package/src/rules/common/operation-operationId-url-safe.ts +5 -4
  331. package/src/rules/common/operation-operationId.ts +5 -4
  332. package/src/rules/common/operation-parameters-unique.ts +4 -4
  333. package/src/rules/common/operation-singular-tag.ts +4 -4
  334. package/src/rules/common/operation-summary.ts +5 -4
  335. package/src/rules/common/operation-tag-defined.ts +4 -4
  336. package/src/rules/common/parameter-description.ts +4 -4
  337. package/src/rules/common/path-declaration-must-exist.ts +2 -2
  338. package/src/rules/common/path-excludes-patterns.ts +4 -4
  339. package/src/rules/common/path-http-verbs-order.ts +4 -4
  340. package/src/rules/common/path-not-include-query.ts +2 -2
  341. package/src/rules/common/path-params-defined.ts +4 -4
  342. package/src/rules/common/path-segment-plural.ts +3 -2
  343. package/src/rules/common/paths-kebab-case.ts +2 -2
  344. package/src/rules/common/required-string-property-missing-min-length.ts +4 -4
  345. package/src/rules/common/response-contains-header.ts +5 -4
  346. package/src/rules/common/scalar-property-missing-example.ts +2 -1
  347. package/src/rules/common/security-defined.ts +5 -5
  348. package/src/rules/common/spec-strict-refs.ts +2 -1
  349. package/src/rules/common/spec.ts +4 -3
  350. package/src/rules/common/tag-description.ts +2 -1
  351. package/src/rules/common/tags-alphabetical.ts +4 -4
  352. package/src/rules/no-unresolved-refs.ts +4 -3
  353. package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +7 -5
  354. package/src/rules/oas2/__tests__/response-contains-header.test.ts +14 -8
  355. package/src/rules/oas2/__tests__/response-contains-property.test.ts +14 -8
  356. package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +3 -1
  357. package/src/rules/oas2/boolean-parameter-prefixes.ts +1 -1
  358. package/src/rules/oas2/index.ts +8 -6
  359. package/src/rules/oas2/request-mime-type.ts +2 -1
  360. package/src/rules/oas2/response-contains-property.ts +3 -2
  361. package/src/rules/oas2/response-mime-type.ts +2 -1
  362. package/src/rules/oas3/__tests__/array-parameter-serialization.test.ts +18 -6
  363. package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +7 -5
  364. package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +6 -6
  365. package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +2 -2
  366. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +34 -24
  367. package/src/rules/oas3/__tests__/no-server-example.com.test.ts +3 -3
  368. package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +3 -3
  369. package/src/rules/oas3/__tests__/no-unused-components.test.ts +1 -1
  370. package/src/rules/oas3/__tests__/operation-4xx-problem-details-rfc7807.test.ts +3 -3
  371. package/src/rules/oas3/__tests__/response-contains-header.test.ts +34 -22
  372. package/src/rules/oas3/__tests__/response-contains-property.test.ts +34 -20
  373. package/src/rules/oas3/__tests__/spec/spec.test.ts +12 -3
  374. package/src/rules/oas3/__tests__/spec-components-invalid-map-name.test.ts +9 -3
  375. package/src/rules/oas3/__tests__/utils/lint-document-for-test.ts +1 -1
  376. package/src/rules/oas3/array-parameter-serialization.ts +3 -2
  377. package/src/rules/oas3/boolean-parameter-prefixes.ts +1 -1
  378. package/src/rules/oas3/component-name-unique.ts +3 -3
  379. package/src/rules/oas3/index.ts +42 -38
  380. package/src/rules/oas3/no-empty-servers.ts +1 -1
  381. package/src/rules/oas3/no-example-value-and-externalValue.ts +1 -1
  382. package/src/rules/oas3/no-invalid-media-type-examples.ts +6 -4
  383. package/src/rules/oas3/no-server-example.com.ts +2 -1
  384. package/src/rules/oas3/no-server-trailing-slash.ts +1 -1
  385. package/src/rules/oas3/no-server-variables-empty-enum.ts +2 -2
  386. package/src/rules/oas3/no-undefined-server-variable.ts +1 -1
  387. package/src/rules/oas3/no-unused-components.ts +2 -2
  388. package/src/rules/oas3/operation-4xx-problem-details-rfc7807.ts +2 -1
  389. package/src/rules/oas3/request-mime-type.ts +2 -1
  390. package/src/rules/oas3/response-contains-property.ts +3 -2
  391. package/src/rules/oas3/response-mime-type.ts +2 -1
  392. package/src/rules/oas3/spec-components-invalid-map-name.ts +3 -3
  393. package/src/rules/other/stats.ts +8 -6
  394. package/src/rules/spot/parameters-no-body-inside-in.ts +17 -0
  395. package/src/rules/utils.ts +41 -4
  396. package/src/types/arazzo.ts +257 -334
  397. package/src/types/{asyncapi.ts → asyncapi2.ts} +41 -35
  398. package/src/types/asyncapi3.ts +383 -0
  399. package/src/types/json-schema-adapter.ts +2 -2
  400. package/src/types/oas3.ts +4 -4
  401. package/src/types/oas3_1.ts +5 -4
  402. package/src/types/redocly-yaml.ts +21 -4
  403. package/src/typings/arazzo.ts +169 -41
  404. package/src/typings/asyncapi3.ts +61 -0
  405. package/src/typings/common.ts +1 -0
  406. package/src/typings/swagger.ts +2 -2
  407. package/src/utils.ts +5 -3
  408. package/src/visitors.ts +58 -1
  409. package/src/walk.ts +3 -3
  410. package/tsconfig.tsbuildinfo +1 -1
  411. package/lib/types/asyncapi.d.ts +0 -2
@@ -1,5 +1,5 @@
1
- import { Oas3Rule } from '../visitors';
2
- import { ResolveResult, Problem } from '../walk';
3
- import { Location } from '../ref-utils';
1
+ import type { Oas3Rule } from '../visitors';
2
+ import type { ResolveResult, Problem } from '../walk';
3
+ import type { Location } from '../ref-utils';
4
4
  export declare const NoUnresolvedRefs: Oas3Rule;
5
5
  export declare function reportUnresolvedRef(resolved: ResolveResult<any>, report: (m: Problem) => void, location: Location): void;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.reportUnresolvedRef = exports.NoUnresolvedRefs = void 0;
3
+ exports.NoUnresolvedRefs = void 0;
4
+ exports.reportUnresolvedRef = reportUnresolvedRef;
4
5
  const resolve_1 = require("../resolve");
5
6
  const NoUnresolvedRefs = () => {
6
7
  return {
@@ -23,7 +24,6 @@ const NoUnresolvedRefs = () => {
23
24
  };
24
25
  exports.NoUnresolvedRefs = NoUnresolvedRefs;
25
26
  function reportUnresolvedRef(resolved, report, location) {
26
- var _a;
27
27
  const error = resolved.error;
28
28
  if (error instanceof resolve_1.YamlParseError) {
29
29
  report({
@@ -38,10 +38,9 @@ function reportUnresolvedRef(resolved, report, location) {
38
38
  },
39
39
  });
40
40
  }
41
- const message = (_a = resolved.error) === null || _a === void 0 ? void 0 : _a.message;
41
+ const message = resolved.error?.message;
42
42
  report({
43
43
  location,
44
44
  message: `Can't resolve $ref${message ? ': ' + message : ''}`,
45
45
  });
46
46
  }
47
- exports.reportUnresolvedRef = reportUnresolvedRef;
@@ -1,4 +1,4 @@
1
- import { Oas2Rule } from '../../visitors';
1
+ import type { Oas2Rule } from '../../visitors';
2
2
  export type BooleanParameterPrefixesOptions = {
3
3
  prefixes?: string[];
4
4
  };
@@ -1,3 +1,3 @@
1
- import type { Oas2RuleSet } from 'core/src/oas-types';
1
+ import type { Oas2RuleSet } from '../../oas-types';
2
2
  export declare const rules: Oas2RuleSet<'built-in'>;
3
3
  export declare const preprocessors: {};
@@ -7,6 +7,7 @@ const no_invalid_parameter_examples_1 = require("../common/no-invalid-parameter-
7
7
  const info_contact_1 = require("../common/info-contact");
8
8
  const info_license_1 = require("../common/info-license");
9
9
  const info_license_url_1 = require("../common/info-license-url");
10
+ const info_license_strict_1 = require("../common/info-license-strict");
10
11
  const boolean_parameter_prefixes_1 = require("./boolean-parameter-prefixes");
11
12
  const tag_description_1 = require("../common/tag-description");
12
13
  const tags_alphabetical_1 = require("../common/tags-alphabetical");
@@ -51,6 +52,7 @@ exports.rules = {
51
52
  'info-contact': info_contact_1.InfoContact,
52
53
  'info-license': info_license_1.InfoLicense,
53
54
  'info-license-url': info_license_url_1.InfoLicenseUrl,
55
+ 'info-license-strict': info_license_strict_1.InfoLicenseStrict,
54
56
  'tag-description': tag_description_1.TagDescription,
55
57
  'tags-alphabetical': tags_alphabetical_1.TagsAlphabetical,
56
58
  'paths-kebab-case': paths_kebab_case_1.PathsKebabCase,
@@ -1,2 +1,2 @@
1
- import { Oas2Rule } from '../../visitors';
1
+ import type { Oas2Rule } from '../../visitors';
2
2
  export declare const ResponseContainsProperty: Oas2Rule;
@@ -15,7 +15,6 @@ const ResponseContainsProperty = (options) => {
15
15
  key = ctx.key;
16
16
  },
17
17
  Schema(schema, { report, location }) {
18
- var _a;
19
18
  if (schema.type !== 'object')
20
19
  return;
21
20
  const expectedProperties = names[key] ||
@@ -23,7 +22,7 @@ const ResponseContainsProperty = (options) => {
23
22
  names[(0, utils_1.getMatchingStatusCodeRange)(key).toLowerCase()] ||
24
23
  [];
25
24
  for (const expectedProperty of expectedProperties) {
26
- if (!((_a = schema.properties) === null || _a === void 0 ? void 0 : _a[expectedProperty])) {
25
+ if (!schema.properties?.[expectedProperty]) {
27
26
  report({
28
27
  message: `Response object must contain a top-level "${expectedProperty}" property.`,
29
28
  location: location.child('properties').key(),
@@ -1,4 +1,4 @@
1
- import { Oas3Rule } from '../../visitors';
1
+ import type { Oas3Rule } from '../../visitors';
2
2
  export type ArrayParameterSerializationOptions = {
3
3
  in?: string[];
4
4
  };
@@ -24,8 +24,7 @@ const ArrayParameterSerialization = (options) => {
24
24
  };
25
25
  exports.ArrayParameterSerialization = ArrayParameterSerialization;
26
26
  function shouldReportMissingStyleAndExplode(node, schema, options) {
27
- var _a;
28
27
  return ((schema.type === 'array' || schema.items || schema.prefixItems) &&
29
28
  (node.style === undefined || node.explode === undefined) &&
30
- (!options.in || (node.in && ((_a = options.in) === null || _a === void 0 ? void 0 : _a.includes(node.in)))));
29
+ (!options.in || (node.in && options.in?.includes(node.in))));
31
30
  }
@@ -1,4 +1,4 @@
1
- import { Oas3Rule } from '../../visitors';
1
+ import type { Oas3Rule } from '../../visitors';
2
2
  export type BooleanParameterPrefixesOptions = {
3
3
  prefixes?: string[];
4
4
  };
@@ -1,2 +1,2 @@
1
- import { Oas2Rule, Oas3Rule } from '../../visitors';
1
+ import type { Oas2Rule, Oas3Rule } from '../../visitors';
2
2
  export declare const ComponentNameUnique: Oas3Rule | Oas2Rule;
@@ -99,9 +99,8 @@ const ComponentNameUnique = (options) => {
99
99
  return componentName;
100
100
  }
101
101
  function addFoundComponent(typeName, componentName, absoluteLocation) {
102
- var _a;
103
102
  const key = getKeyForComponent(typeName, componentName);
104
- const locations = (_a = components.get(key)) !== null && _a !== void 0 ? _a : new Set();
103
+ const locations = components.get(key) ?? new Set();
105
104
  locations.add(absoluteLocation);
106
105
  components.set(key, locations);
107
106
  }
@@ -112,8 +111,7 @@ const ComponentNameUnique = (options) => {
112
111
  };
113
112
  exports.ComponentNameUnique = ComponentNameUnique;
114
113
  function getOptionComponentNameForTypeName(typeName) {
115
- var _a;
116
- return (_a = TYPE_NAME_TO_OPTION_COMPONENT_NAME[typeName]) !== null && _a !== void 0 ? _a : null;
114
+ return TYPE_NAME_TO_OPTION_COMPONENT_NAME[typeName] ?? null;
117
115
  }
118
116
  function getKeyForComponent(typeName, componentName) {
119
117
  return `${typeName}/${componentName}`;
@@ -1,3 +1,3 @@
1
- import { Oas3RuleSet } from '../../oas-types';
1
+ import type { Oas3RuleSet } from '../../oas-types';
2
2
  export declare const rules: Oas3RuleSet<'built-in'>;
3
3
  export declare const preprocessors: {};
@@ -21,6 +21,7 @@ const tag_description_1 = require("../common/tag-description");
21
21
  const info_contact_1 = require("../common/info-contact");
22
22
  const info_license_1 = require("../common/info-license");
23
23
  const info_license_url_1 = require("../common/info-license-url");
24
+ const info_license_strict_1 = require("../common/info-license-strict");
24
25
  const operation_description_1 = require("../common/operation-description");
25
26
  const no_unused_components_1 = require("./no-unused-components");
26
27
  const path_not_include_query_1 = require("../common/path-not-include-query");
@@ -61,6 +62,7 @@ exports.rules = {
61
62
  'info-contact': info_contact_1.InfoContact,
62
63
  'info-license': info_license_1.InfoLicense,
63
64
  'info-license-url': info_license_url_1.InfoLicenseUrl,
65
+ 'info-license-strict': info_license_strict_1.InfoLicenseStrict,
64
66
  'operation-2xx-response': operation_2xx_response_1.Operation2xxResponse,
65
67
  'operation-4xx-response': operation_4xx_response_1.Operation4xxResponse,
66
68
  'operation-4xx-problem-details-rfc7807': operation_4xx_problem_details_rfc7807_1.Operation4xxProblemDetailsRfc7807,
@@ -1,2 +1,2 @@
1
- import { Oas3Rule } from '../../visitors';
1
+ import type { Oas3Rule } from '../../visitors';
2
2
  export declare const NoEmptyServers: Oas3Rule;
@@ -1,2 +1,2 @@
1
- import { Oas3Rule } from '../../visitors';
1
+ import type { Oas3Rule } from '../../visitors';
2
2
  export declare const NoExampleValueAndExternalValue: Oas3Rule;
@@ -1,2 +1,2 @@
1
- import { Oas3Rule } from '../../visitors';
1
+ import type { Oas3Rule } from '../../visitors';
2
2
  export declare const ValidContentExamples: Oas3Rule;
@@ -4,8 +4,7 @@ exports.ValidContentExamples = void 0;
4
4
  const ref_utils_1 = require("../../ref-utils");
5
5
  const utils_1 = require("../utils");
6
6
  const ValidContentExamples = (opts) => {
7
- var _a;
8
- const allowAdditionalProperties = (_a = (0, utils_1.getAdditionalPropertiesOption)(opts)) !== null && _a !== void 0 ? _a : false;
7
+ const allowAdditionalProperties = (0, utils_1.getAdditionalPropertiesOption)(opts) ?? false;
9
8
  return {
10
9
  MediaType: {
11
10
  leave(mediaType, ctx) {
@@ -1,2 +1,2 @@
1
- import { Oas3Rule } from '../../visitors';
1
+ import type { Oas3Rule } from '../../visitors';
2
2
  export declare const NoServerExample: Oas3Rule;
@@ -4,6 +4,7 @@ exports.NoServerExample = void 0;
4
4
  const NoServerExample = () => {
5
5
  return {
6
6
  Server(server, { report, location }) {
7
+ // eslint-disable-next-line no-useless-escape
7
8
  const pattern = /^(.*[\/.])?(example\.com|localhost)([\/:?].*|$)/;
8
9
  if (server.url && pattern.test(server.url)) {
9
10
  report({
@@ -1,2 +1,2 @@
1
- import { Oas3Rule } from '../../visitors';
1
+ import type { Oas3Rule } from '../../visitors';
2
2
  export declare const NoServerTrailingSlash: Oas3Rule;
@@ -1,2 +1,2 @@
1
- import { Oas3Rule } from '../../visitors';
1
+ import type { Oas3Rule } from '../../visitors';
2
2
  export declare const NoServerVariablesEmptyEnum: Oas3Rule;
@@ -45,7 +45,6 @@ const NoServerVariablesEmptyEnum = () => {
45
45
  };
46
46
  exports.NoServerVariablesEmptyEnum = NoServerVariablesEmptyEnum;
47
47
  function checkEnumVariables(server) {
48
- var _a;
49
48
  if (server.variables && Object.keys(server.variables).length === 0)
50
49
  return;
51
50
  const errors = [];
@@ -53,7 +52,7 @@ function checkEnumVariables(server) {
53
52
  const serverVariable = server.variables[variable];
54
53
  if (!serverVariable.enum)
55
54
  continue;
56
- if (Array.isArray(serverVariable.enum) && ((_a = serverVariable.enum) === null || _a === void 0 ? void 0 : _a.length) === 0)
55
+ if (Array.isArray(serverVariable.enum) && serverVariable.enum?.length === 0)
57
56
  errors.push(enumError.empty);
58
57
  if (!serverVariable.default)
59
58
  continue;
@@ -1,2 +1,2 @@
1
- import { Oas3Rule } from '../../visitors';
1
+ import type { Oas3Rule } from '../../visitors';
2
2
  export declare const NoUndefinedServerVariable: Oas3Rule;
@@ -4,11 +4,10 @@ exports.NoUndefinedServerVariable = void 0;
4
4
  const NoUndefinedServerVariable = () => {
5
5
  return {
6
6
  Server(server, { report, location }) {
7
- var _a;
8
7
  if (!server.url)
9
8
  return;
10
- const urlVariables = ((_a = server.url.match(/{[^}]+}/g)) === null || _a === void 0 ? void 0 : _a.map((e) => e.slice(1, e.length - 1))) || [];
11
- const definedVariables = ((server === null || server === void 0 ? void 0 : server.variables) && Object.keys(server.variables)) || [];
9
+ const urlVariables = server.url.match(/{[^}]+}/g)?.map((e) => e.slice(1, e.length - 1)) || [];
10
+ const definedVariables = (server?.variables && Object.keys(server.variables)) || [];
12
11
  for (const serverVar of urlVariables) {
13
12
  if (!definedVariables.includes(serverVar)) {
14
13
  report({
@@ -1,2 +1,2 @@
1
- import { Oas3Rule } from '../../visitors';
1
+ import type { Oas3Rule } from '../../visitors';
2
2
  export declare const NoUnusedComponents: Oas3Rule;
@@ -4,9 +4,8 @@ exports.NoUnusedComponents = void 0;
4
4
  const NoUnusedComponents = () => {
5
5
  const components = new Map();
6
6
  function registerComponent(location, name) {
7
- var _a;
8
7
  components.set(location.absolutePointer, {
9
- used: ((_a = components.get(location.absolutePointer)) === null || _a === void 0 ? void 0 : _a.used) || false,
8
+ used: components.get(location.absolutePointer)?.used || false,
10
9
  location,
11
10
  name,
12
11
  });
@@ -1,2 +1,2 @@
1
- import { Oas3Rule } from '../../visitors';
1
+ import type { Oas3Rule } from '../../visitors';
2
2
  export declare const ResponseContainsProperty: Oas3Rule;
@@ -16,7 +16,6 @@ const ResponseContainsProperty = (options) => {
16
16
  },
17
17
  MediaType: {
18
18
  Schema(schema, { report, location }) {
19
- var _a;
20
19
  if (schema.type !== 'object')
21
20
  return;
22
21
  const expectedProperties = names[key] ||
@@ -24,7 +23,7 @@ const ResponseContainsProperty = (options) => {
24
23
  names[(0, utils_1.getMatchingStatusCodeRange)(key).toLowerCase()] ||
25
24
  [];
26
25
  for (const expectedProperty of expectedProperties) {
27
- if (!((_a = schema.properties) === null || _a === void 0 ? void 0 : _a[expectedProperty])) {
26
+ if (!schema.properties?.[expectedProperty]) {
28
27
  report({
29
28
  message: `Response object must contain a top-level "${expectedProperty}" property.`,
30
29
  location: location.child('properties').key(),
@@ -1,2 +1,2 @@
1
- import { Oas3Rule } from '../../visitors';
1
+ import type { Oas3Rule } from '../../visitors';
2
2
  export declare const SpecComponentsInvalidMapName: Oas3Rule;
@@ -1,6 +1,6 @@
1
- import { Oas3Parameter, OasRef, Oas3Tag } from '../../typings/openapi';
2
- import { Oas2Parameter } from '../../typings/swagger';
3
- import { StatsAccumulator } from '../../typings/common';
1
+ import type { Oas3Parameter, OasRef, Oas3Tag } from '../../typings/openapi';
2
+ import type { Oas2Parameter } from '../../typings/swagger';
3
+ import type { StatsAccumulator } from '../../typings/common';
4
4
  export declare const Stats: (statsAccumulator: StatsAccumulator) => {
5
5
  ExternalDocs: {
6
6
  leave(): void;
@@ -34,9 +34,11 @@ const Stats = (statsAccumulator) => {
34
34
  WebhooksMap: {
35
35
  Operation: {
36
36
  leave(operation) {
37
- operation.tags.forEach((tag) => {
38
- statsAccumulator.tags.items.add(tag);
39
- });
37
+ statsAccumulator.webhooks.total++;
38
+ operation.tags &&
39
+ operation.tags.forEach((tag) => {
40
+ statsAccumulator.tags.items.add(tag);
41
+ });
40
42
  },
41
43
  },
42
44
  },
@@ -0,0 +1,2 @@
1
+ import type { ArazzoRule } from '../../visitors';
2
+ export declare const ParametersNoBodyInsideIn: ArazzoRule;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ParametersNoBodyInsideIn = void 0;
4
+ const ParametersNoBodyInsideIn = () => {
5
+ return {
6
+ Parameter: {
7
+ enter(parameter, { report, location }) {
8
+ if (parameter.in === 'body') {
9
+ report({
10
+ message: 'The `body` value of the `in` property is not supported by Spot.',
11
+ location: location.child(['in']),
12
+ });
13
+ }
14
+ },
15
+ },
16
+ };
17
+ };
18
+ exports.ParametersNoBodyInsideIn = ParametersNoBodyInsideIn;
@@ -1,6 +1,6 @@
1
- import { UserContext } from '../walk';
2
1
  import { Location } from '../ref-utils';
3
- import { Oas3Schema, Oas3_1Schema, Referenced } from '../typings/openapi';
2
+ import type { Oas3Schema, Oas3_1Schema, Referenced } from '../typings/openapi';
3
+ import type { UserContext } from '../walk';
4
4
  export declare function oasTypeOf(value: unknown): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "integer" | "array" | "null";
5
5
  /**
6
6
  * Checks if value matches specified JSON schema type
@@ -11,8 +11,10 @@ export declare function oasTypeOf(value: unknown): "string" | "number" | "bigint
11
11
  */
12
12
  export declare function matchesJsonSchemaType(value: unknown, type: string, nullable: boolean): boolean;
13
13
  export declare function missingRequiredField(type: string, field: string): string;
14
+ export declare function missingRequiredOneOfFields(type: string, fields: string[]): string;
14
15
  export declare function fieldNonEmpty(type: string, field: string): string;
15
16
  export declare function validateDefinedAndNonEmpty(fieldName: string, value: any, ctx: UserContext): void;
17
+ export declare function validateOneOfDefinedAndNonEmpty(fieldNames: string[], value: any, ctx: UserContext): void;
16
18
  export declare function getSuggest(given: string, variants: string[]): string[];
17
19
  export declare function validateExample(example: any, schema: Referenced<Oas3Schema | Oas3_1Schema>, dataLoc: Location, { resolve, location, report }: UserContext, allowAdditionalProperties: boolean): void;
18
20
  export declare function getAdditionalPropertiesOption(opts: Record<string, any>): boolean;
@@ -1,6 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateResponseCodes = exports.validateSchemaEnumType = exports.getAdditionalPropertiesOption = exports.validateExample = exports.getSuggest = exports.validateDefinedAndNonEmpty = exports.fieldNonEmpty = exports.missingRequiredField = exports.matchesJsonSchemaType = exports.oasTypeOf = void 0;
3
+ exports.oasTypeOf = oasTypeOf;
4
+ exports.matchesJsonSchemaType = matchesJsonSchemaType;
5
+ exports.missingRequiredField = missingRequiredField;
6
+ exports.missingRequiredOneOfFields = missingRequiredOneOfFields;
7
+ exports.fieldNonEmpty = fieldNonEmpty;
8
+ exports.validateDefinedAndNonEmpty = validateDefinedAndNonEmpty;
9
+ exports.validateOneOfDefinedAndNonEmpty = validateOneOfDefinedAndNonEmpty;
10
+ exports.getSuggest = getSuggest;
11
+ exports.validateExample = validateExample;
12
+ exports.getAdditionalPropertiesOption = getAdditionalPropertiesOption;
13
+ exports.validateSchemaEnumType = validateSchemaEnumType;
14
+ exports.validateResponseCodes = validateResponseCodes;
4
15
  const levenshtein = require("js-levenshtein");
5
16
  const ref_utils_1 = require("../ref-utils");
6
17
  const ajv_1 = require("./ajv");
@@ -19,7 +30,6 @@ function oasTypeOf(value) {
19
30
  return typeof value;
20
31
  }
21
32
  }
22
- exports.oasTypeOf = oasTypeOf;
23
33
  /**
24
34
  * Checks if value matches specified JSON schema type
25
35
  *
@@ -44,17 +54,19 @@ function matchesJsonSchemaType(value, type, nullable) {
44
54
  return typeof value === type;
45
55
  }
46
56
  }
47
- exports.matchesJsonSchemaType = matchesJsonSchemaType;
48
57
  function missingRequiredField(type, field) {
49
58
  return `${type} object should contain \`${field}\` field.`;
50
59
  }
51
- exports.missingRequiredField = missingRequiredField;
60
+ function missingRequiredOneOfFields(type, fields) {
61
+ return `${type} object should contain one of the fields: ${fields
62
+ .map((field) => `\`${field}\``)
63
+ .join(', ')}.`;
64
+ }
52
65
  function fieldNonEmpty(type, field) {
53
66
  return `${type} object \`${field}\` must be non-empty string.`;
54
67
  }
55
- exports.fieldNonEmpty = fieldNonEmpty;
56
68
  function validateDefinedAndNonEmpty(fieldName, value, ctx) {
57
- if (typeof value !== 'object') {
69
+ if (!(0, utils_1.isPlainObject)(value)) {
58
70
  return;
59
71
  }
60
72
  if (value[fieldName] === undefined) {
@@ -70,7 +82,25 @@ function validateDefinedAndNonEmpty(fieldName, value, ctx) {
70
82
  });
71
83
  }
72
84
  }
73
- exports.validateDefinedAndNonEmpty = validateDefinedAndNonEmpty;
85
+ function validateOneOfDefinedAndNonEmpty(fieldNames, value, ctx) {
86
+ if (!(0, utils_1.isPlainObject)(value)) {
87
+ return;
88
+ }
89
+ if (!fieldNames.some((fieldName) => value.hasOwnProperty(fieldName))) {
90
+ ctx.report({
91
+ message: missingRequiredOneOfFields(ctx.type.name, fieldNames),
92
+ location: ctx.location.key(),
93
+ });
94
+ }
95
+ for (const fieldName of fieldNames) {
96
+ if (value.hasOwnProperty(fieldName) && !value[fieldName]) {
97
+ ctx.report({
98
+ message: fieldNonEmpty(ctx.type.name, fieldName),
99
+ location: ctx.location.child([fieldName]).key(),
100
+ });
101
+ }
102
+ }
103
+ }
74
104
  function getSuggest(given, variants) {
75
105
  if (given === null)
76
106
  return variants;
@@ -87,7 +117,6 @@ function getSuggest(given, variants) {
87
117
  // if (bestMatch.distance <= 4) return bestMatch.string;
88
118
  return distances.map((d) => d.variant);
89
119
  }
90
- exports.getSuggest = getSuggest;
91
120
  function validateExample(example, schema, dataLoc, { resolve, location, report }, allowAdditionalProperties) {
92
121
  try {
93
122
  const { valid, errors } = (0, ajv_1.validateJsonSchema)(example, schema, location.child('schema'), dataLoc.pointer, resolve, allowAdditionalProperties);
@@ -95,7 +124,10 @@ function validateExample(example, schema, dataLoc, { resolve, location, report }
95
124
  for (const error of errors) {
96
125
  report({
97
126
  message: `Example value must conform to the schema: ${error.message}.`,
98
- location: Object.assign(Object.assign({}, new ref_utils_1.Location(dataLoc.source, error.instancePath)), { reportOnKey: error.keyword === 'unevaluatedProperties' || error.keyword === 'additionalProperties' }),
127
+ location: {
128
+ ...new ref_utils_1.Location(dataLoc.source, error.instancePath),
129
+ reportOnKey: error.keyword === 'unevaluatedProperties' || error.keyword === 'additionalProperties',
130
+ },
99
131
  from: location,
100
132
  suggest: error.suggest,
101
133
  });
@@ -113,7 +145,6 @@ function validateExample(example, schema, dataLoc, { resolve, location, report }
113
145
  });
114
146
  }
115
147
  }
116
- exports.validateExample = validateExample;
117
148
  function getAdditionalPropertiesOption(opts) {
118
149
  if (opts.disallowAdditionalProperties === undefined) {
119
150
  return opts.allowAdditionalProperties;
@@ -124,7 +155,6 @@ function getAdditionalPropertiesOption(opts) {
124
155
  (0, utils_1.showWarningForDeprecatedField)('disallowAdditionalProperties', 'allowAdditionalProperties');
125
156
  return !opts.disallowAdditionalProperties;
126
157
  }
127
- exports.getAdditionalPropertiesOption = getAdditionalPropertiesOption;
128
158
  function validateSchemaEnumType(schemaEnum, propertyValue, propName, refLocation, { report, location }) {
129
159
  if (!schemaEnum) {
130
160
  return;
@@ -140,7 +170,6 @@ function validateSchemaEnumType(schemaEnum, propertyValue, propName, refLocation
140
170
  });
141
171
  }
142
172
  }
143
- exports.validateSchemaEnumType = validateSchemaEnumType;
144
173
  function validateResponseCodes(responseCodes, codeRange, { report }) {
145
174
  const responseCodeRegexp = new RegExp(`^${codeRange[0]}[0-9Xx]{2}$`);
146
175
  const containsNeededCode = responseCodes.some((code) => (codeRange === '2XX' && code === 'default') || // It's OK to replace 2xx codes with the default
@@ -152,4 +181,3 @@ function validateResponseCodes(responseCodes, codeRange, { report }) {
152
181
  });
153
182
  }
154
183
  }
155
- exports.validateResponseCodes = validateResponseCodes;