openapi-typesafe 1.0.0-rc.0 → 1.0.0-rc.2

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 (513) hide show
  1. package/README.md +12 -5
  2. package/dist/adapters/redocly-loader/configured-headers.cjs +32 -0
  3. package/dist/adapters/redocly-loader/configured-headers.cjs.map +1 -0
  4. package/dist/adapters/redocly-loader/configured-headers.mjs +30 -0
  5. package/dist/adapters/redocly-loader/configured-headers.mjs.map +1 -0
  6. package/dist/adapters/redocly-loader/redocly-config-source.cjs +21 -2
  7. package/dist/adapters/redocly-loader/redocly-config-source.cjs.map +1 -1
  8. package/dist/adapters/redocly-loader/redocly-config-source.mjs +22 -3
  9. package/dist/adapters/redocly-loader/redocly-config-source.mjs.map +1 -1
  10. package/dist/adapters/redocly-loader/redocly-schema-loader.cjs +34 -11
  11. package/dist/adapters/redocly-loader/redocly-schema-loader.cjs.map +1 -1
  12. package/dist/adapters/redocly-loader/redocly-schema-loader.mjs +33 -10
  13. package/dist/adapters/redocly-loader/redocly-schema-loader.mjs.map +1 -1
  14. package/dist/adapters/redocly-loader/ref-access.cjs +37 -4
  15. package/dist/adapters/redocly-loader/ref-access.cjs.map +1 -1
  16. package/dist/adapters/redocly-loader/ref-access.mjs +37 -4
  17. package/dist/adapters/redocly-loader/ref-access.mjs.map +1 -1
  18. package/dist/adapters/redocly-loader/ref-resolution-check.cjs +191 -0
  19. package/dist/adapters/redocly-loader/ref-resolution-check.cjs.map +1 -0
  20. package/dist/adapters/redocly-loader/ref-resolution-check.mjs +189 -0
  21. package/dist/adapters/redocly-loader/ref-resolution-check.mjs.map +1 -0
  22. package/dist/adapters/redocly-loader/ref-resolution-steps.cjs +73 -0
  23. package/dist/adapters/redocly-loader/ref-resolution-steps.cjs.map +1 -0
  24. package/dist/adapters/redocly-loader/ref-resolution-steps.mjs +60 -0
  25. package/dist/adapters/redocly-loader/ref-resolution-steps.mjs.map +1 -0
  26. package/dist/adapters/redocly-loader/remote-fetch.cjs +41 -14
  27. package/dist/adapters/redocly-loader/remote-fetch.cjs.map +1 -1
  28. package/dist/adapters/redocly-loader/remote-fetch.mjs +40 -14
  29. package/dist/adapters/redocly-loader/remote-fetch.mjs.map +1 -1
  30. package/dist/adapters/redocly-loader/schema-load-errors.cjs +23 -5
  31. package/dist/adapters/redocly-loader/schema-load-errors.cjs.map +1 -1
  32. package/dist/adapters/redocly-loader/schema-load-errors.mjs +23 -5
  33. package/dist/adapters/redocly-loader/schema-load-errors.mjs.map +1 -1
  34. package/dist/adapters/redocly-loader/unsupported-keys.cjs +9 -1
  35. package/dist/adapters/redocly-loader/unsupported-keys.cjs.map +1 -1
  36. package/dist/adapters/redocly-loader/unsupported-keys.mjs +9 -1
  37. package/dist/adapters/redocly-loader/unsupported-keys.mjs.map +1 -1
  38. package/dist/adapters/terminal-logger/terminal-logger.cjs +6 -4
  39. package/dist/adapters/terminal-logger/terminal-logger.cjs.map +1 -1
  40. package/dist/adapters/terminal-logger/terminal-logger.mjs +6 -4
  41. package/dist/adapters/terminal-logger/terminal-logger.mjs.map +1 -1
  42. package/dist/adapters/type-ast-bridge/ir-to-typescript.cjs +5 -1
  43. package/dist/adapters/type-ast-bridge/ir-to-typescript.cjs.map +1 -1
  44. package/dist/adapters/type-ast-bridge/ir-to-typescript.mjs +5 -1
  45. package/dist/adapters/type-ast-bridge/ir-to-typescript.mjs.map +1 -1
  46. package/dist/adapters/type-ast-bridge/print-typescript.cjs.map +1 -1
  47. package/dist/adapters/type-ast-bridge/print-typescript.mjs.map +1 -1
  48. package/dist/adapters/type-ast-bridge/typescript-to-ir.cjs +15 -9
  49. package/dist/adapters/type-ast-bridge/typescript-to-ir.cjs.map +1 -1
  50. package/dist/adapters/type-ast-bridge/typescript-to-ir.mjs +15 -9
  51. package/dist/adapters/type-ast-bridge/typescript-to-ir.mjs.map +1 -1
  52. package/dist/api/default-ports.cjs +9 -0
  53. package/dist/api/default-ports.cjs.map +1 -1
  54. package/dist/api/default-ports.mjs +8 -1
  55. package/dist/api/default-ports.mjs.map +1 -1
  56. package/dist/api/discriminator-conflict-warnings.cjs +25 -0
  57. package/dist/api/discriminator-conflict-warnings.cjs.map +1 -0
  58. package/dist/api/discriminator-conflict-warnings.mjs +23 -0
  59. package/dist/api/discriminator-conflict-warnings.mjs.map +1 -0
  60. package/dist/api/discriminator-enum-names.cjs +19 -0
  61. package/dist/api/discriminator-enum-names.cjs.map +1 -0
  62. package/dist/api/discriminator-enum-names.mjs +17 -0
  63. package/dist/api/discriminator-enum-names.mjs.map +1 -0
  64. package/dist/api/discriminator-enum-parent.cjs +59 -0
  65. package/dist/api/discriminator-enum-parent.cjs.map +1 -0
  66. package/dist/api/discriminator-enum-parent.mjs +57 -0
  67. package/dist/api/discriminator-enum-parent.mjs.map +1 -0
  68. package/dist/api/discriminator-enum.cjs +25 -0
  69. package/dist/api/discriminator-enum.cjs.map +1 -1
  70. package/dist/api/discriminator-enum.mjs +25 -1
  71. package/dist/api/discriminator-enum.mjs.map +1 -1
  72. package/dist/api/discriminator-other-owners.cjs +67 -0
  73. package/dist/api/discriminator-other-owners.cjs.map +1 -0
  74. package/dist/api/discriminator-other-owners.mjs +64 -0
  75. package/dist/api/discriminator-other-owners.mjs.map +1 -0
  76. package/dist/api/discriminator-patch.cjs +92 -0
  77. package/dist/api/discriminator-patch.cjs.map +1 -0
  78. package/dist/api/discriminator-patch.mjs +86 -0
  79. package/dist/api/discriminator-patch.mjs.map +1 -0
  80. package/dist/api/discriminator-scan.cjs +50 -65
  81. package/dist/api/discriminator-scan.cjs.map +1 -1
  82. package/dist/api/discriminator-scan.mjs +44 -59
  83. package/dist/api/discriminator-scan.mjs.map +1 -1
  84. package/dist/api/document-refs.cjs +15 -12
  85. package/dist/api/document-refs.cjs.map +1 -1
  86. package/dist/api/document-refs.mjs +15 -12
  87. package/dist/api/document-refs.mjs.map +1 -1
  88. package/dist/api/document-run.cjs +21 -4
  89. package/dist/api/document-run.cjs.map +1 -1
  90. package/dist/api/document-run.mjs +22 -5
  91. package/dist/api/document-run.mjs.map +1 -1
  92. package/dist/api/enum-values-warnings.cjs +16 -0
  93. package/dist/api/enum-values-warnings.cjs.map +1 -0
  94. package/dist/api/enum-values-warnings.mjs +14 -0
  95. package/dist/api/enum-values-warnings.mjs.map +1 -0
  96. package/dist/api/footer-sink.cjs +25 -2
  97. package/dist/api/footer-sink.cjs.map +1 -1
  98. package/dist/api/footer-sink.mjs +25 -2
  99. package/dist/api/footer-sink.mjs.map +1 -1
  100. package/dist/api/legacy-callback-warning.cjs +4 -1
  101. package/dist/api/legacy-callback-warning.cjs.map +1 -1
  102. package/dist/api/legacy-callback-warning.mjs +4 -1
  103. package/dist/api/legacy-callback-warning.mjs.map +1 -1
  104. package/dist/api/legacy-ts-helpers.cjs.map +1 -1
  105. package/dist/api/legacy-ts-helpers.mjs.map +1 -1
  106. package/dist/api/legacy-utils.cjs.map +1 -1
  107. package/dist/api/legacy-utils.mjs.map +1 -1
  108. package/dist/api/openapi-ts.cjs +2 -1
  109. package/dist/api/openapi-ts.cjs.map +1 -1
  110. package/dist/api/openapi-ts.mjs +3 -2
  111. package/dist/api/openapi-ts.mjs.map +1 -1
  112. package/dist/api/path-template-warnings.cjs +21 -0
  113. package/dist/api/path-template-warnings.cjs.map +1 -0
  114. package/dist/api/path-template-warnings.mjs +19 -0
  115. package/dist/api/path-template-warnings.mjs.map +1 -0
  116. package/dist/api/transform-context.cjs +4 -2
  117. package/dist/api/transform-context.cjs.map +1 -1
  118. package/dist/api/transform-context.mjs +4 -2
  119. package/dist/api/transform-context.mjs.map +1 -1
  120. package/dist/api/transform-schema.cjs +52 -3
  121. package/dist/api/transform-schema.cjs.map +1 -1
  122. package/dist/api/transform-schema.mjs +53 -4
  123. package/dist/api/transform-schema.mjs.map +1 -1
  124. package/dist/api/unsupported-feature-warnings.cjs +6 -1
  125. package/dist/api/unsupported-feature-warnings.cjs.map +1 -1
  126. package/dist/api/unsupported-feature-warnings.mjs +6 -1
  127. package/dist/api/unsupported-feature-warnings.mjs.map +1 -1
  128. package/dist/application/print/type-printer.cjs +7 -1
  129. package/dist/application/print/type-printer.cjs.map +1 -1
  130. package/dist/application/print/type-printer.mjs +7 -1
  131. package/dist/application/print/type-printer.mjs.map +1 -1
  132. package/dist/application/transform/document/assignability.cjs +144 -0
  133. package/dist/application/transform/document/assignability.cjs.map +1 -0
  134. package/dist/application/transform/document/assignability.mjs +138 -0
  135. package/dist/application/transform/document/assignability.mjs.map +1 -0
  136. package/dist/application/transform/document/components.cjs +2 -2
  137. package/dist/application/transform/document/components.cjs.map +1 -1
  138. package/dist/application/transform/document/components.mjs +4 -4
  139. package/dist/application/transform/document/components.mjs.map +1 -1
  140. package/dist/application/transform/document/declared-types.cjs +66 -0
  141. package/dist/application/transform/document/declared-types.cjs.map +1 -0
  142. package/dist/application/transform/document/declared-types.mjs +63 -0
  143. package/dist/application/transform/document/declared-types.mjs.map +1 -0
  144. package/dist/application/transform/document/document.cjs +32 -9
  145. package/dist/application/transform/document/document.cjs.map +1 -1
  146. package/dist/application/transform/document/document.mjs +34 -11
  147. package/dist/application/transform/document/document.mjs.map +1 -1
  148. package/dist/application/transform/document/exploded-query.cjs +46 -0
  149. package/dist/application/transform/document/exploded-query.cjs.map +1 -0
  150. package/dist/application/transform/document/exploded-query.mjs +43 -0
  151. package/dist/application/transform/document/exploded-query.mjs.map +1 -0
  152. package/dist/application/transform/document/global-type-references.cjs +63 -0
  153. package/dist/application/transform/document/global-type-references.cjs.map +1 -0
  154. package/dist/application/transform/document/global-type-references.mjs +61 -0
  155. package/dist/application/transform/document/global-type-references.mjs.map +1 -0
  156. package/dist/application/transform/document/list-assignability.cjs +54 -0
  157. package/dist/application/transform/document/list-assignability.cjs.map +1 -0
  158. package/dist/application/transform/document/list-assignability.mjs +52 -0
  159. package/dist/application/transform/document/list-assignability.mjs.map +1 -0
  160. package/dist/application/transform/document/parameters.cjs +41 -9
  161. package/dist/application/transform/document/parameters.cjs.map +1 -1
  162. package/dist/application/transform/document/parameters.mjs +42 -10
  163. package/dist/application/transform/document/parameters.mjs.map +1 -1
  164. package/dist/application/transform/document/path-key-overlaps.cjs +83 -33
  165. package/dist/application/transform/document/path-key-overlaps.cjs.map +1 -1
  166. package/dist/application/transform/document/path-key-overlaps.mjs +83 -33
  167. package/dist/application/transform/document/path-key-overlaps.mjs.map +1 -1
  168. package/dist/application/transform/document/path-template-replace.cjs +48 -0
  169. package/dist/application/transform/document/path-template-replace.cjs.map +1 -0
  170. package/dist/application/transform/document/path-template-replace.mjs +45 -0
  171. package/dist/application/transform/document/path-template-replace.mjs.map +1 -0
  172. package/dist/application/transform/document/paths.cjs +55 -29
  173. package/dist/application/transform/document/paths.cjs.map +1 -1
  174. package/dist/application/transform/document/paths.mjs +54 -30
  175. package/dist/application/transform/document/paths.mjs.map +1 -1
  176. package/dist/application/transform/document/root-type-aliases.cjs +15 -14
  177. package/dist/application/transform/document/root-type-aliases.cjs.map +1 -1
  178. package/dist/application/transform/document/root-type-aliases.mjs +15 -13
  179. package/dist/application/transform/document/root-type-aliases.mjs.map +1 -1
  180. package/dist/application/transform/document/template-key-match.cjs +128 -0
  181. package/dist/application/transform/document/template-key-match.cjs.map +1 -0
  182. package/dist/application/transform/document/template-key-match.mjs +125 -0
  183. package/dist/application/transform/document/template-key-match.mjs.map +1 -0
  184. package/dist/application/transform/document/type-assignability.cjs +192 -0
  185. package/dist/application/transform/document/type-assignability.cjs.map +1 -0
  186. package/dist/application/transform/document/type-assignability.mjs +190 -0
  187. package/dist/application/transform/document/type-assignability.mjs.map +1 -0
  188. package/dist/application/transform/document/type-key.cjs +70 -0
  189. package/dist/application/transform/document/type-key.cjs.map +1 -0
  190. package/dist/application/transform/document/type-key.mjs +68 -0
  191. package/dist/application/transform/document/type-key.mjs.map +1 -0
  192. package/dist/application/transform/document/type-resolution.cjs +131 -0
  193. package/dist/application/transform/document/type-resolution.cjs.map +1 -0
  194. package/dist/application/transform/document/type-resolution.mjs +125 -0
  195. package/dist/application/transform/document/type-resolution.mjs.map +1 -0
  196. package/dist/application/transform/footer/document-footer.cjs +66 -4
  197. package/dist/application/transform/footer/document-footer.cjs.map +1 -1
  198. package/dist/application/transform/footer/document-footer.mjs +67 -5
  199. package/dist/application/transform/footer/document-footer.mjs.map +1 -1
  200. package/dist/application/transform/footer/enum-naming.cjs +17 -0
  201. package/dist/application/transform/footer/enum-naming.cjs.map +1 -1
  202. package/dist/application/transform/footer/enum-naming.mjs +17 -1
  203. package/dist/application/transform/footer/enum-naming.mjs.map +1 -1
  204. package/dist/application/transform/footer/enum-values-check.cjs +129 -0
  205. package/dist/application/transform/footer/enum-values-check.cjs.map +1 -0
  206. package/dist/application/transform/footer/enum-values-check.mjs +127 -0
  207. package/dist/application/transform/footer/enum-values-check.mjs.map +1 -0
  208. package/dist/application/transform/footer/evaluation.cjs +42 -0
  209. package/dist/application/transform/footer/evaluation.cjs.map +1 -0
  210. package/dist/application/transform/footer/evaluation.mjs +33 -0
  211. package/dist/application/transform/footer/evaluation.mjs.map +1 -0
  212. package/dist/application/transform/footer/shared-enum-names.cjs +60 -0
  213. package/dist/application/transform/footer/shared-enum-names.cjs.map +1 -0
  214. package/dist/application/transform/footer/shared-enum-names.mjs +57 -0
  215. package/dist/application/transform/footer/shared-enum-names.mjs.map +1 -0
  216. package/dist/application/transform/footer/type-evaluation.cjs +138 -0
  217. package/dist/application/transform/footer/type-evaluation.cjs.map +1 -0
  218. package/dist/application/transform/footer/type-evaluation.mjs +136 -0
  219. package/dist/application/transform/footer/type-evaluation.mjs.map +1 -0
  220. package/dist/application/transform/footer/type-indexing.cjs +107 -0
  221. package/dist/application/transform/footer/type-indexing.cjs.map +1 -0
  222. package/dist/application/transform/footer/type-indexing.mjs +105 -0
  223. package/dist/application/transform/footer/type-indexing.mjs.map +1 -0
  224. package/dist/application/transform/footer/type-rules.cjs +172 -0
  225. package/dist/application/transform/footer/type-rules.cjs.map +1 -0
  226. package/dist/application/transform/footer/type-rules.mjs +166 -0
  227. package/dist/application/transform/footer/type-rules.mjs.map +1 -0
  228. package/dist/application/transform/ref-pointer/generated-location.cjs +138 -0
  229. package/dist/application/transform/ref-pointer/generated-location.cjs.map +1 -0
  230. package/dist/application/transform/ref-pointer/generated-location.mjs +136 -0
  231. package/dist/application/transform/ref-pointer/generated-location.mjs.map +1 -0
  232. package/dist/application/transform/ref-pointer/generated-shape.cjs +171 -0
  233. package/dist/application/transform/ref-pointer/generated-shape.cjs.map +1 -0
  234. package/dist/application/transform/ref-pointer/generated-shape.mjs +162 -0
  235. package/dist/application/transform/ref-pointer/generated-shape.mjs.map +1 -0
  236. package/dist/application/transform/ref-pointer/inline-cycles.cjs +44 -0
  237. package/dist/application/transform/ref-pointer/inline-cycles.cjs.map +1 -0
  238. package/dist/application/transform/ref-pointer/inline-cycles.mjs +42 -0
  239. package/dist/application/transform/ref-pointer/inline-cycles.mjs.map +1 -0
  240. package/dist/application/transform/ref-pointer/original-index.cjs +62 -0
  241. package/dist/application/transform/ref-pointer/original-index.cjs.map +1 -0
  242. package/dist/application/transform/ref-pointer/original-index.mjs +60 -0
  243. package/dist/application/transform/ref-pointer/original-index.mjs.map +1 -0
  244. package/dist/application/transform/ref-pointer/pointer-type.cjs +60 -0
  245. package/dist/application/transform/ref-pointer/pointer-type.cjs.map +1 -0
  246. package/dist/application/transform/ref-pointer/pointer-type.mjs +57 -0
  247. package/dist/application/transform/ref-pointer/pointer-type.mjs.map +1 -0
  248. package/dist/application/transform/ref-pointer/pointer-walk.cjs +66 -0
  249. package/dist/application/transform/ref-pointer/pointer-walk.cjs.map +1 -0
  250. package/dist/application/transform/ref-pointer/pointer-walk.mjs +56 -0
  251. package/dist/application/transform/ref-pointer/pointer-walk.mjs.map +1 -0
  252. package/dist/application/transform/ref-pointer/typed-walk.cjs +124 -0
  253. package/dist/application/transform/ref-pointer/typed-walk.cjs.map +1 -0
  254. package/dist/application/transform/ref-pointer/typed-walk.mjs +122 -0
  255. package/dist/application/transform/ref-pointer/typed-walk.mjs.map +1 -0
  256. package/dist/application/transform/ref-type.cjs +7 -2
  257. package/dist/application/transform/ref-type.cjs.map +1 -1
  258. package/dist/application/transform/ref-type.mjs +3 -2
  259. package/dist/application/transform/ref-type.mjs.map +1 -1
  260. package/dist/application/transform/schema/access-flags.cjs +38 -0
  261. package/dist/application/transform/schema/access-flags.cjs.map +1 -0
  262. package/dist/application/transform/schema/access-flags.mjs +36 -0
  263. package/dist/application/transform/schema/access-flags.mjs.map +1 -0
  264. package/dist/application/transform/schema/array-type.cjs +32 -1
  265. package/dist/application/transform/schema/array-type.cjs.map +1 -1
  266. package/dist/application/transform/schema/array-type.mjs +33 -2
  267. package/dist/application/transform/schema/array-type.mjs.map +1 -1
  268. package/dist/application/transform/schema/composition-type.cjs +50 -15
  269. package/dist/application/transform/schema/composition-type.cjs.map +1 -1
  270. package/dist/application/transform/schema/composition-type.mjs +50 -15
  271. package/dist/application/transform/schema/composition-type.mjs.map +1 -1
  272. package/dist/application/transform/schema/core-type.cjs +3 -1
  273. package/dist/application/transform/schema/core-type.cjs.map +1 -1
  274. package/dist/application/transform/schema/core-type.mjs +3 -1
  275. package/dist/application/transform/schema/core-type.mjs.map +1 -1
  276. package/dist/application/transform/schema/discriminated-union.cjs +30 -0
  277. package/dist/application/transform/schema/discriminated-union.cjs.map +1 -0
  278. package/dist/application/transform/schema/discriminated-union.mjs +27 -0
  279. package/dist/application/transform/schema/discriminated-union.mjs.map +1 -0
  280. package/dist/application/transform/schema/discriminator-property.cjs +3 -2
  281. package/dist/application/transform/schema/discriminator-property.cjs.map +1 -1
  282. package/dist/application/transform/schema/discriminator-property.mjs +3 -2
  283. package/dist/application/transform/schema/discriminator-property.mjs.map +1 -1
  284. package/dist/application/transform/schema/enum-rule.cjs +66 -10
  285. package/dist/application/transform/schema/enum-rule.cjs.map +1 -1
  286. package/dist/application/transform/schema/enum-rule.mjs +67 -12
  287. package/dist/application/transform/schema/enum-rule.mjs.map +1 -1
  288. package/dist/application/transform/schema/inherited-discriminator.cjs +29 -0
  289. package/dist/application/transform/schema/inherited-discriminator.cjs.map +1 -0
  290. package/dist/application/transform/schema/inherited-discriminator.mjs +26 -0
  291. package/dist/application/transform/schema/inherited-discriminator.mjs.map +1 -0
  292. package/dist/application/transform/schema/object-type.cjs +38 -25
  293. package/dist/application/transform/schema/object-type.cjs.map +1 -1
  294. package/dist/application/transform/schema/object-type.mjs +39 -27
  295. package/dist/application/transform/schema/object-type.mjs.map +1 -1
  296. package/dist/application/transform/schema/required-variants.cjs +45 -0
  297. package/dist/application/transform/schema/required-variants.cjs.map +1 -0
  298. package/dist/application/transform/schema/required-variants.mjs +42 -0
  299. package/dist/application/transform/schema/required-variants.mjs.map +1 -0
  300. package/dist/application/transform/schema/schema-transform.cjs +2 -2
  301. package/dist/application/transform/schema/schema-transform.cjs.map +1 -1
  302. package/dist/application/transform/schema/schema-transform.mjs +2 -2
  303. package/dist/application/transform/schema/schema-transform.mjs.map +1 -1
  304. package/dist/application/transform/schema-comment.cjs +51 -5
  305. package/dist/application/transform/schema-comment.cjs.map +1 -1
  306. package/dist/application/transform/schema-comment.mjs +50 -6
  307. package/dist/application/transform/schema-comment.mjs.map +1 -1
  308. package/dist/application/transform/type-combinators.mjs +1 -1
  309. package/dist/cli/api-settings.cjs +78 -0
  310. package/dist/cli/api-settings.cjs.map +1 -0
  311. package/dist/cli/api-settings.mjs +73 -0
  312. package/dist/cli/api-settings.mjs.map +1 -0
  313. package/dist/cli/cli-arguments.cjs +12 -3
  314. package/dist/cli/cli-arguments.cjs.map +1 -1
  315. package/dist/cli/cli-arguments.mjs +12 -4
  316. package/dist/cli/cli-arguments.mjs.map +1 -1
  317. package/dist/cli/cli-errors.cjs +3 -2
  318. package/dist/cli/cli-errors.cjs.map +1 -1
  319. package/dist/cli/cli-errors.mjs +3 -2
  320. package/dist/cli/cli-errors.mjs.map +1 -1
  321. package/dist/cli/cli-output.cjs +8 -3
  322. package/dist/cli/cli-output.cjs.map +1 -1
  323. package/dist/cli/cli-output.mjs +9 -4
  324. package/dist/cli/cli-output.mjs.map +1 -1
  325. package/dist/cli/help-text.cjs +3 -3
  326. package/dist/cli/help-text.cjs.map +1 -1
  327. package/dist/cli/help-text.mjs +3 -3
  328. package/dist/cli/help-text.mjs.map +1 -1
  329. package/dist/cli/main.cjs +5 -0
  330. package/dist/cli/main.cjs.map +1 -1
  331. package/dist/cli/main.mjs +5 -0
  332. package/dist/cli/main.mjs.map +1 -1
  333. package/dist/cli/redocly-apis.cjs +15 -7
  334. package/dist/cli/redocly-apis.cjs.map +1 -1
  335. package/dist/cli/redocly-apis.mjs +15 -7
  336. package/dist/cli/redocly-apis.mjs.map +1 -1
  337. package/dist/cli/ref-limits.cjs +1 -1
  338. package/dist/cli/ref-limits.cjs.map +1 -1
  339. package/dist/cli/ref-limits.mjs +2 -2
  340. package/dist/cli/ref-limits.mjs.map +1 -1
  341. package/dist/cli/run-cli.cjs +20 -3
  342. package/dist/cli/run-cli.cjs.map +1 -1
  343. package/dist/cli/run-cli.mjs +21 -4
  344. package/dist/cli/run-cli.mjs.map +1 -1
  345. package/dist/domain/errors.cjs +6 -1
  346. package/dist/domain/errors.cjs.map +1 -1
  347. package/dist/domain/errors.mjs +6 -1
  348. package/dist/domain/errors.mjs.map +1 -1
  349. package/dist/domain/ir/constructors.cjs +7 -1
  350. package/dist/domain/ir/constructors.cjs.map +1 -1
  351. package/dist/domain/ir/constructors.mjs +6 -2
  352. package/dist/domain/ir/constructors.mjs.map +1 -1
  353. package/dist/domain/openapi/admitted-values.cjs +75 -0
  354. package/dist/domain/openapi/admitted-values.cjs.map +1 -0
  355. package/dist/domain/openapi/admitted-values.mjs +72 -0
  356. package/dist/domain/openapi/admitted-values.mjs.map +1 -0
  357. package/dist/domain/openapi/discriminated-union.cjs +68 -0
  358. package/dist/domain/openapi/discriminated-union.cjs.map +1 -0
  359. package/dist/domain/openapi/discriminated-union.mjs +62 -0
  360. package/dist/domain/openapi/discriminated-union.mjs.map +1 -0
  361. package/dist/domain/openapi/discriminator-conflicts.cjs +143 -0
  362. package/dist/domain/openapi/discriminator-conflicts.cjs.map +1 -0
  363. package/dist/domain/openapi/discriminator-conflicts.mjs +141 -0
  364. package/dist/domain/openapi/discriminator-conflicts.mjs.map +1 -0
  365. package/dist/domain/openapi/parameter-object.cjs.map +1 -1
  366. package/dist/domain/openapi/parameter-object.mjs.map +1 -1
  367. package/dist/domain/openapi/path-templates.cjs +23 -0
  368. package/dist/domain/openapi/path-templates.cjs.map +1 -0
  369. package/dist/domain/openapi/path-templates.mjs +21 -0
  370. package/dist/domain/openapi/path-templates.mjs.map +1 -0
  371. package/dist/domain/output-fixes.cjs +36 -1
  372. package/dist/domain/output-fixes.cjs.map +1 -1
  373. package/dist/domain/output-fixes.mjs +36 -1
  374. package/dist/domain/output-fixes.mjs.map +1 -1
  375. package/dist/domain/url-credentials.cjs +10 -0
  376. package/dist/domain/url-credentials.cjs.map +1 -0
  377. package/dist/domain/url-credentials.mjs +8 -0
  378. package/dist/domain/url-credentials.mjs.map +1 -0
  379. package/dist/domain/warnings.cjs +23 -0
  380. package/dist/domain/warnings.cjs.map +1 -0
  381. package/dist/domain/warnings.mjs +20 -0
  382. package/dist/domain/warnings.mjs.map +1 -0
  383. package/dist/index.cjs +2 -0
  384. package/dist/index.cjs.map +1 -1
  385. package/dist/index.d.cts +1182 -46
  386. package/dist/index.d.mts +1182 -46
  387. package/dist/index.d.ts +1182 -46
  388. package/dist/index.mjs +1 -0
  389. package/dist/index.mjs.map +1 -1
  390. package/dist/transform/components-object.cjs +2 -1
  391. package/dist/transform/components-object.cjs.map +1 -1
  392. package/dist/transform/components-object.mjs +2 -1
  393. package/dist/transform/components-object.mjs.map +1 -1
  394. package/dist/transform/path-item-object.cjs.map +1 -1
  395. package/dist/transform/path-item-object.mjs.map +1 -1
  396. package/package.json +6 -5
  397. package/src/adapters/redocly-loader/configured-headers.ts +65 -0
  398. package/src/adapters/redocly-loader/redocly-config-source.ts +41 -6
  399. package/src/adapters/redocly-loader/redocly-schema-loader.ts +44 -13
  400. package/src/adapters/redocly-loader/ref-access.ts +60 -5
  401. package/src/adapters/redocly-loader/ref-resolution-check.ts +257 -0
  402. package/src/adapters/redocly-loader/ref-resolution-steps.ts +113 -0
  403. package/src/adapters/redocly-loader/remote-fetch.ts +77 -21
  404. package/src/adapters/redocly-loader/schema-load-errors.ts +33 -11
  405. package/src/adapters/redocly-loader/unsupported-keys.ts +17 -2
  406. package/src/adapters/terminal-logger/terminal-logger.ts +9 -5
  407. package/src/adapters/type-ast-bridge/ir-to-typescript.ts +5 -1
  408. package/src/adapters/type-ast-bridge/print-typescript.ts +3 -1
  409. package/src/adapters/type-ast-bridge/typescript-to-ir.ts +26 -12
  410. package/src/adapters/type-ast-bridge/typescript-types.ts +57 -5
  411. package/src/api/default-ports.ts +16 -0
  412. package/src/api/discriminator-conflict-warnings.ts +43 -0
  413. package/src/api/discriminator-enum-names.ts +26 -0
  414. package/src/api/discriminator-enum-parent.ts +129 -0
  415. package/src/api/discriminator-enum.ts +39 -0
  416. package/src/api/discriminator-other-owners.ts +97 -0
  417. package/src/api/discriminator-patch.ts +152 -0
  418. package/src/api/discriminator-scan.ts +78 -90
  419. package/src/api/document-refs.ts +19 -15
  420. package/src/api/document-run.ts +32 -11
  421. package/src/api/enum-values-warnings.ts +21 -0
  422. package/src/api/footer-sink.ts +34 -2
  423. package/src/api/legacy-callback-warning.ts +7 -3
  424. package/src/api/legacy-ts-helpers.ts +7 -5
  425. package/src/api/legacy-utils.ts +1 -1
  426. package/src/api/openapi-ts.ts +2 -0
  427. package/src/api/path-template-warnings.ts +27 -0
  428. package/src/api/run-context.ts +34 -0
  429. package/src/api/transform-context.ts +17 -9
  430. package/src/api/transform-schema.ts +90 -5
  431. package/src/api/unsupported-feature-warnings.ts +8 -1
  432. package/src/application/ports/redocly-config-source.ts +5 -1
  433. package/src/application/print/type-printer.ts +8 -1
  434. package/src/application/transform/document/assignability.ts +203 -0
  435. package/src/application/transform/document/components.ts +6 -6
  436. package/src/application/transform/document/declared-types.ts +93 -0
  437. package/src/application/transform/document/document.ts +71 -13
  438. package/src/application/transform/document/exploded-query.ts +91 -0
  439. package/src/application/transform/document/global-type-references.ts +78 -0
  440. package/src/application/transform/document/list-assignability.ts +87 -0
  441. package/src/application/transform/document/parameters.ts +78 -12
  442. package/src/application/transform/document/path-key-overlaps.ts +148 -59
  443. package/src/application/transform/document/path-template-replace.ts +90 -0
  444. package/src/application/transform/document/paths.ts +101 -38
  445. package/src/application/transform/document/root-type-aliases.ts +29 -28
  446. package/src/application/transform/document/template-key-match.ts +183 -0
  447. package/src/application/transform/document/type-assignability.ts +268 -0
  448. package/src/application/transform/document/type-key.ts +80 -0
  449. package/src/application/transform/document/type-resolution.ts +163 -0
  450. package/src/application/transform/footer/document-footer.ts +91 -6
  451. package/src/application/transform/footer/enum-naming.ts +29 -0
  452. package/src/application/transform/footer/enum-values-check.ts +171 -0
  453. package/src/application/transform/footer/evaluation.ts +57 -0
  454. package/src/application/transform/footer/shared-enum-names.ts +86 -0
  455. package/src/application/transform/footer/type-evaluation.ts +167 -0
  456. package/src/application/transform/footer/type-indexing.ts +152 -0
  457. package/src/application/transform/footer/type-rules.ts +269 -0
  458. package/src/application/transform/ref-pointer/generated-location.ts +211 -0
  459. package/src/application/transform/ref-pointer/generated-shape.ts +275 -0
  460. package/src/application/transform/ref-pointer/inline-cycles.ts +56 -0
  461. package/src/application/transform/ref-pointer/original-index.ts +95 -0
  462. package/src/application/transform/ref-pointer/pointer-type.ts +92 -0
  463. package/src/application/transform/ref-pointer/pointer-walk.ts +96 -0
  464. package/src/application/transform/ref-pointer/typed-walk.ts +192 -0
  465. package/src/application/transform/ref-type.ts +11 -6
  466. package/src/application/transform/schema/access-flags.ts +63 -0
  467. package/src/application/transform/schema/array-type.ts +66 -5
  468. package/src/application/transform/schema/composition-type.ts +96 -24
  469. package/src/application/transform/schema/core-type.ts +8 -4
  470. package/src/application/transform/schema/discriminated-union.ts +58 -0
  471. package/src/application/transform/schema/discriminator-property.ts +8 -3
  472. package/src/application/transform/schema/enum-rule.ts +136 -13
  473. package/src/application/transform/schema/inherited-discriminator.ts +54 -0
  474. package/src/application/transform/schema/object-type.ts +51 -33
  475. package/src/application/transform/schema/required-variants.ts +88 -0
  476. package/src/application/transform/schema/schema-context.ts +26 -0
  477. package/src/application/transform/schema/schema-transform.ts +2 -2
  478. package/src/application/transform/schema-comment.ts +84 -4
  479. package/src/cli/api-settings.ts +109 -0
  480. package/src/cli/cli-arguments.ts +18 -5
  481. package/src/cli/cli-dependencies.ts +5 -0
  482. package/src/cli/cli-errors.ts +4 -2
  483. package/src/cli/cli-output.ts +18 -4
  484. package/src/cli/help-text.ts +4 -4
  485. package/src/cli/main.ts +6 -0
  486. package/src/cli/redocly-apis.ts +21 -11
  487. package/src/cli/ref-limits.ts +2 -2
  488. package/src/cli/run-cli.ts +25 -4
  489. package/src/domain/errors.ts +10 -2
  490. package/src/domain/ir/constructors.ts +9 -1
  491. package/src/domain/ir/nodes.ts +11 -7
  492. package/src/domain/openapi/admitted-values.ts +113 -0
  493. package/src/domain/openapi/discriminated-union.ts +109 -0
  494. package/src/domain/openapi/discriminator-conflicts.ts +251 -0
  495. package/src/domain/openapi/parameter-object.ts +4 -0
  496. package/src/domain/openapi/path-templates.ts +32 -0
  497. package/src/domain/openapi/schema-object.ts +2 -0
  498. package/src/domain/output-fixes.ts +43 -2
  499. package/src/domain/url-credentials.ts +18 -0
  500. package/src/domain/warnings.ts +28 -0
  501. package/src/index.ts +1 -0
  502. package/src/transform/components-object.ts +3 -1
  503. package/src/transform/path-item-object.ts +6 -2
  504. package/src/types/generator-options.ts +12 -21
  505. package/src/types/openapi-common.ts +1 -0
  506. package/src/types/openapi-request.ts +3 -0
  507. package/src/types/openapi-schema.ts +2 -0
  508. package/src/types/openapi-security.ts +1 -0
  509. package/dist/application/transform/document/path-item-conflicts.cjs +0 -51
  510. package/dist/application/transform/document/path-item-conflicts.cjs.map +0 -1
  511. package/dist/application/transform/document/path-item-conflicts.mjs +0 -49
  512. package/dist/application/transform/document/path-item-conflicts.mjs.map +0 -1
  513. package/src/application/transform/document/path-item-conflicts.ts +0 -79
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access-flags.cjs","sources":["../../../../src/application/transform/schema/access-flags.ts"],"sourcesContent":["import type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { OutputFix } from \"../../../domain/output-fixes.js\";\nimport type { SchemaContext } from \"./schema-context.js\";\n\n/** Whether a property is `readOnly` or `writeOnly` (JSON Schema 2020-12 Validation §9.4). */\nexport interface AccessFlags {\n readonly isReadOnly: boolean;\n readonly isWriteOnly: boolean;\n}\n\nconst NO_FLAGS: AccessFlags = { isReadOnly: false, isWriteOnly: false };\n\nfunction ownFlags(schema: SchemaObject): AccessFlags {\n return { isReadOnly: Boolean(schema.readOnly), isWriteOnly: Boolean(schema.writeOnly) };\n}\n\nfunction merged(left: AccessFlags, right: AccessFlags): AccessFlags {\n return {\n isReadOnly: left.isReadOnly || right.isReadOnly,\n isWriteOnly: left.isWriteOnly || right.isWriteOnly,\n };\n}\n\n/**\n * The flags of a schema and of the schemas that always apply to the same value: the one its\n * `$ref` names and its `allOf` members, followed until a schema repeats. `readOnly` is an\n * annotation, and the annotations of those schemas are the value's (2020-12 Core §7.7.1); in\n * OpenAPI 3.0 a referenced schema is the property's definition. `anyOf` and `oneOf` members apply\n * only when they match, which the type cannot tell, so they are not read.\n */\nfunction appliedFlags(\n schema: Schema | undefined,\n context: SchemaContext,\n seen: ReadonlySet<Schema>,\n): AccessFlags {\n if (typeof schema !== \"object\" || schema === null || seen.has(schema)) {\n return NO_FLAGS;\n }\n const inner = new Set([...seen, schema]);\n // `readOnly` next to a `$ref` is read too, as the generator always has.\n const object = schema as SchemaObject & { readonly $ref?: unknown };\n const target =\n typeof object.$ref === \"string\" ? (context.refs.resolve(object.$ref) as Schema) : undefined;\n return (object.allOf ?? []).reduce<AccessFlags>(\n (flags, member) => merged(flags, appliedFlags(member, context, inner)),\n merged(ownFlags(object), appliedFlags(target, context, inner)),\n );\n}\n\n/**\n * The flags of a property schema. Without the `read-write-refs` fix only the keywords written on\n * it count, as in openapi-typescript; with it, also those of the schemas its `$ref` and `allOf`\n * apply (upstream #1938).\n */\nexport function propertyAccessFlags(value: Schema, context: SchemaContext): AccessFlags {\n if (typeof value !== \"object\") {\n return NO_FLAGS;\n }\n if (!context.options.fixes.has(OutputFix.READ_WRITE_REFS)) {\n return ownFlags(value as SchemaObject);\n }\n return appliedFlags(value, context, new Set());\n}\n"],"names":["OutputFix"],"mappings":";;;;AAUA,MAAM,QAAA,GAAwB,EAAE,UAAA,EAAY,KAAA,EAAO,aAAa,KAAA,EAAM;AAEtE,SAAS,SAAS,MAAA,EAAmC;AACnD,EAAA,OAAO,EAAE,UAAA,EAAY,OAAA,CAAQ,MAAA,CAAO,QAAQ,GAAG,WAAA,EAAa,OAAA,CAAQ,MAAA,CAAO,SAAS,CAAA,EAAE;AACxF;AAEA,SAAS,MAAA,CAAO,MAAmB,KAAA,EAAiC;AAClE,EAAA,OAAO;AAAA,IACL,UAAA,EAAY,IAAA,CAAK,UAAA,IAAc,KAAA,CAAM,UAAA;AAAA,IACrC,WAAA,EAAa,IAAA,CAAK,WAAA,IAAe,KAAA,CAAM;AAAA,GACzC;AACF;AASA,SAAS,YAAA,CACP,MAAA,EACA,OAAA,EACA,IAAA,EACa;AACb,EAAA,IAAI,OAAO,WAAW,QAAA,IAAY,MAAA,KAAW,QAAQ,IAAA,CAAK,GAAA,CAAI,MAAM,CAAA,EAAG;AACrE,IAAA,OAAO,QAAA;AAAA,EACT;AACA,EAAA,MAAM,wBAAQ,IAAI,GAAA,CAAI,CAAC,GAAG,IAAA,EAAM,MAAM,CAAC,CAAA;AAEvC,EAAA,MAAM,MAAA,GAAS,MAAA;AACf,EAAA,MAAM,MAAA,GACJ,OAAO,MAAA,CAAO,IAAA,KAAS,QAAA,GAAY,QAAQ,IAAA,CAAK,OAAA,CAAQ,MAAA,CAAO,IAAI,CAAA,GAAe,MAAA;AACpF,EAAA,OAAA,CAAQ,MAAA,CAAO,KAAA,IAAS,EAAC,EAAG,MAAA;AAAA,IAC1B,CAAC,OAAO,MAAA,KAAW,MAAA,CAAO,OAAO,YAAA,CAAa,MAAA,EAAQ,OAAA,EAAS,KAAK,CAAC,CAAA;AAAA,IACrE,MAAA,CAAO,SAAS,MAAM,CAAA,EAAG,aAAa,MAAA,EAAQ,OAAA,EAAS,KAAK,CAAC;AAAA,GAC/D;AACF;AAOO,SAAS,mBAAA,CAAoB,OAAe,OAAA,EAAqC;AACtF,EAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC7B,IAAA,OAAO,QAAA;AAAA,EACT;AACA,EAAA,IAAI,CAAC,OAAA,CAAQ,OAAA,CAAQ,MAAM,GAAA,CAAIA,qBAAA,CAAU,eAAe,CAAA,EAAG;AACzD,IAAA,OAAO,SAAS,KAAqB,CAAA;AAAA,EACvC;AACA,EAAA,OAAO,YAAA,CAAa,KAAA,EAAO,OAAA,kBAAS,IAAI,KAAK,CAAA;AAC/C;;"}
@@ -0,0 +1,36 @@
1
+ import { OutputFix } from '../../../domain/output-fixes.mjs';
2
+
3
+ const NO_FLAGS = { isReadOnly: false, isWriteOnly: false };
4
+ function ownFlags(schema) {
5
+ return { isReadOnly: Boolean(schema.readOnly), isWriteOnly: Boolean(schema.writeOnly) };
6
+ }
7
+ function merged(left, right) {
8
+ return {
9
+ isReadOnly: left.isReadOnly || right.isReadOnly,
10
+ isWriteOnly: left.isWriteOnly || right.isWriteOnly
11
+ };
12
+ }
13
+ function appliedFlags(schema, context, seen) {
14
+ if (typeof schema !== "object" || schema === null || seen.has(schema)) {
15
+ return NO_FLAGS;
16
+ }
17
+ const inner = /* @__PURE__ */ new Set([...seen, schema]);
18
+ const object = schema;
19
+ const target = typeof object.$ref === "string" ? context.refs.resolve(object.$ref) : void 0;
20
+ return (object.allOf ?? []).reduce(
21
+ (flags, member) => merged(flags, appliedFlags(member, context, inner)),
22
+ merged(ownFlags(object), appliedFlags(target, context, inner))
23
+ );
24
+ }
25
+ function propertyAccessFlags(value, context) {
26
+ if (typeof value !== "object") {
27
+ return NO_FLAGS;
28
+ }
29
+ if (!context.options.fixes.has(OutputFix.READ_WRITE_REFS)) {
30
+ return ownFlags(value);
31
+ }
32
+ return appliedFlags(value, context, /* @__PURE__ */ new Set());
33
+ }
34
+
35
+ export { propertyAccessFlags };
36
+ //# sourceMappingURL=access-flags.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access-flags.mjs","sources":["../../../../src/application/transform/schema/access-flags.ts"],"sourcesContent":["import type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { OutputFix } from \"../../../domain/output-fixes.js\";\nimport type { SchemaContext } from \"./schema-context.js\";\n\n/** Whether a property is `readOnly` or `writeOnly` (JSON Schema 2020-12 Validation §9.4). */\nexport interface AccessFlags {\n readonly isReadOnly: boolean;\n readonly isWriteOnly: boolean;\n}\n\nconst NO_FLAGS: AccessFlags = { isReadOnly: false, isWriteOnly: false };\n\nfunction ownFlags(schema: SchemaObject): AccessFlags {\n return { isReadOnly: Boolean(schema.readOnly), isWriteOnly: Boolean(schema.writeOnly) };\n}\n\nfunction merged(left: AccessFlags, right: AccessFlags): AccessFlags {\n return {\n isReadOnly: left.isReadOnly || right.isReadOnly,\n isWriteOnly: left.isWriteOnly || right.isWriteOnly,\n };\n}\n\n/**\n * The flags of a schema and of the schemas that always apply to the same value: the one its\n * `$ref` names and its `allOf` members, followed until a schema repeats. `readOnly` is an\n * annotation, and the annotations of those schemas are the value's (2020-12 Core §7.7.1); in\n * OpenAPI 3.0 a referenced schema is the property's definition. `anyOf` and `oneOf` members apply\n * only when they match, which the type cannot tell, so they are not read.\n */\nfunction appliedFlags(\n schema: Schema | undefined,\n context: SchemaContext,\n seen: ReadonlySet<Schema>,\n): AccessFlags {\n if (typeof schema !== \"object\" || schema === null || seen.has(schema)) {\n return NO_FLAGS;\n }\n const inner = new Set([...seen, schema]);\n // `readOnly` next to a `$ref` is read too, as the generator always has.\n const object = schema as SchemaObject & { readonly $ref?: unknown };\n const target =\n typeof object.$ref === \"string\" ? (context.refs.resolve(object.$ref) as Schema) : undefined;\n return (object.allOf ?? []).reduce<AccessFlags>(\n (flags, member) => merged(flags, appliedFlags(member, context, inner)),\n merged(ownFlags(object), appliedFlags(target, context, inner)),\n );\n}\n\n/**\n * The flags of a property schema. Without the `read-write-refs` fix only the keywords written on\n * it count, as in openapi-typescript; with it, also those of the schemas its `$ref` and `allOf`\n * apply (upstream #1938).\n */\nexport function propertyAccessFlags(value: Schema, context: SchemaContext): AccessFlags {\n if (typeof value !== \"object\") {\n return NO_FLAGS;\n }\n if (!context.options.fixes.has(OutputFix.READ_WRITE_REFS)) {\n return ownFlags(value as SchemaObject);\n }\n return appliedFlags(value, context, new Set());\n}\n"],"names":[],"mappings":";;AAUA,MAAM,QAAA,GAAwB,EAAE,UAAA,EAAY,KAAA,EAAO,aAAa,KAAA,EAAM;AAEtE,SAAS,SAAS,MAAA,EAAmC;AACnD,EAAA,OAAO,EAAE,UAAA,EAAY,OAAA,CAAQ,MAAA,CAAO,QAAQ,GAAG,WAAA,EAAa,OAAA,CAAQ,MAAA,CAAO,SAAS,CAAA,EAAE;AACxF;AAEA,SAAS,MAAA,CAAO,MAAmB,KAAA,EAAiC;AAClE,EAAA,OAAO;AAAA,IACL,UAAA,EAAY,IAAA,CAAK,UAAA,IAAc,KAAA,CAAM,UAAA;AAAA,IACrC,WAAA,EAAa,IAAA,CAAK,WAAA,IAAe,KAAA,CAAM;AAAA,GACzC;AACF;AASA,SAAS,YAAA,CACP,MAAA,EACA,OAAA,EACA,IAAA,EACa;AACb,EAAA,IAAI,OAAO,WAAW,QAAA,IAAY,MAAA,KAAW,QAAQ,IAAA,CAAK,GAAA,CAAI,MAAM,CAAA,EAAG;AACrE,IAAA,OAAO,QAAA;AAAA,EACT;AACA,EAAA,MAAM,wBAAQ,IAAI,GAAA,CAAI,CAAC,GAAG,IAAA,EAAM,MAAM,CAAC,CAAA;AAEvC,EAAA,MAAM,MAAA,GAAS,MAAA;AACf,EAAA,MAAM,MAAA,GACJ,OAAO,MAAA,CAAO,IAAA,KAAS,QAAA,GAAY,QAAQ,IAAA,CAAK,OAAA,CAAQ,MAAA,CAAO,IAAI,CAAA,GAAe,MAAA;AACpF,EAAA,OAAA,CAAQ,MAAA,CAAO,KAAA,IAAS,EAAC,EAAG,MAAA;AAAA,IAC1B,CAAC,OAAO,MAAA,KAAW,MAAA,CAAO,OAAO,YAAA,CAAa,MAAA,EAAQ,OAAA,EAAS,KAAK,CAAC,CAAA;AAAA,IACrE,MAAA,CAAO,SAAS,MAAM,CAAA,EAAG,aAAa,MAAA,EAAQ,OAAA,EAAS,KAAK,CAAC;AAAA,GAC/D;AACF;AAOO,SAAS,mBAAA,CAAoB,OAAe,OAAA,EAAqC;AACtF,EAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC7B,IAAA,OAAO,QAAA;AAAA,EACT;AACA,EAAA,IAAI,CAAC,OAAA,CAAQ,OAAA,CAAQ,MAAM,GAAA,CAAI,SAAA,CAAU,eAAe,CAAA,EAAG;AACzD,IAAA,OAAO,SAAS,KAAqB,CAAA;AAAA,EACvC;AACA,EAAA,OAAO,YAAA,CAAa,KAAA,EAAO,OAAA,kBAAS,IAAI,KAAK,CAAA;AAC/C;;"}
@@ -8,6 +8,9 @@ const typeCombinators = require('../type-combinators.cjs');
8
8
  const MAX_LENGTH_TUPLE_ELEMENTS = 30;
9
9
  function prefixTupleType(schema, request) {
10
10
  const { items } = schema;
11
+ if (schema.prefixItems && isPrefixItemsFixed(schema, request)) {
12
+ return prefixItemsTupleType(schema.prefixItems, schema, request);
13
+ }
11
14
  if (!schema.prefixItems && !Array.isArray(items)) {
12
15
  return null;
13
16
  }
@@ -16,6 +19,34 @@ function prefixTupleType(schema, request) {
16
19
  prefixItems.map((item) => constructors.irTupleElement(request.transformNested(item, request.location)))
17
20
  );
18
21
  }
22
+ function restItemType(schema, request) {
23
+ return schema === false ? null : request.transformNested(schema, request.location);
24
+ }
25
+ function prefixRestType(schema, request) {
26
+ const { items, unevaluatedItems, contains } = schema;
27
+ if (items !== void 0 && !Array.isArray(items)) {
28
+ return restItemType(items, request);
29
+ }
30
+ if (unevaluatedItems === void 0 || items !== void 0) {
31
+ return sharedTypes.UNKNOWN_TYPE;
32
+ }
33
+ const unevaluated = restItemType(unevaluatedItems, request);
34
+ const matched = contains === void 0 ? null : restItemType(contains, request);
35
+ const types = [unevaluated, matched].filter((type) => type !== null);
36
+ return types.length === 0 ? null : typeCombinators.unionOf(types);
37
+ }
38
+ function prefixItemsTupleType(prefixItems, schema, request) {
39
+ const { min } = lengthBounds(schema);
40
+ const elements = prefixItems.map((item, index) => {
41
+ const type = request.transformNested(item, request.location);
42
+ return index < min ? constructors.irTupleElement(type) : constructors.irOptionalTupleElement(type);
43
+ });
44
+ const rest = prefixRestType(schema, request);
45
+ return constructors.irTuple(rest === null ? elements : [...elements, constructors.irTupleElement(constructors.irArray(rest), true)]);
46
+ }
47
+ function isPrefixItemsFixed(schema, request) {
48
+ return schema.prefixItems !== void 0 && request.context.options.fixes.has(outputFixes.OutputFix.PREFIX_ITEMS);
49
+ }
19
50
  function singleItemType(schema, request) {
20
51
  const { items } = schema;
21
52
  return items ? request.transformNested(items, request.location) : sharedTypes.UNKNOWN_TYPE;
@@ -94,7 +125,7 @@ function arrayType(schema, request) {
94
125
  }
95
126
  const item = itemType(schema, request);
96
127
  const bounds = lengthBounds(schema);
97
- if (isLengthTupleWanted(bounds, request)) {
128
+ if (!isPrefixItemsFixed(schema, request) && isLengthTupleWanted(bounds, request)) {
98
129
  return lengthTupleType(schema, item, bounds);
99
130
  }
100
131
  const type = item.kind === "tuple" || item.kind === "array" ? item : constructors.irArray(item);
@@ -1 +1 @@
1
- {"version":3,"file":"array-type.cjs","sources":["../../../../src/application/transform/schema/array-type.ts"],"sourcesContent":["import { irArray, irReadonly, irTuple, irTupleElement } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport type { SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { OutputFix } from \"../../../domain/output-fixes.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { unionOf } from \"../type-combinators.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\n\n/**\n * `--array-length` writes tuples only while the estimated number of tuple elements stays below\n * this; the original chose it as roughly where TypeScript starts to struggle with tuple inference.\n */\nconst MAX_LENGTH_TUPLE_ELEMENTS = 30;\n\n/** The tuple of `prefixItems` (or of an `items` list); null without either. */\nfunction prefixTupleType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const { items } = schema;\n if (!schema.prefixItems && !Array.isArray(items)) {\n return null;\n }\n const prefixItems = schema.prefixItems ?? (items as SchemaObject[]);\n return irTuple(\n prefixItems.map((item) => irTupleElement(request.transformNested(item, request.location))),\n );\n}\n\n/** The type of one item; `unknown` without `items`. */\nfunction singleItemType(schema: SchemaObject, request: SchemaRequest): IrType {\n const { items } = schema;\n return items ? request.transformNested(items as SchemaObject, request.location) : UNKNOWN_TYPE;\n}\n\n/**\n * The item type as the original returns it: a tuple stands for the whole array, and a nested\n * `type: array` item is wrapped in an array here already.\n */\nfunction itemType(schema: SchemaObject, request: SchemaRequest): IrType {\n const tuple = prefixTupleType(schema, request);\n if (tuple !== null) {\n return tuple;\n }\n const { items } = schema;\n // Checked first: the `in` test below throws for `items: null`.\n if (!items) {\n return UNKNOWN_TYPE;\n }\n const nested = singleItemType(schema, request);\n const isNestedArray = typeof items === \"object\" && \"type\" in items && items.type === \"array\";\n return isNestedArray ? irArray(nested) : nested;\n}\n\nfunction repeat(type: IrType, count: number): IrType[] {\n return Array.from({ length: count }, () => type);\n}\n\ninterface LengthBounds {\n readonly min: number;\n readonly max: number | undefined;\n}\n\nfunction lengthBounds(schema: SchemaObject): LengthBounds {\n const { minItems, maxItems } = schema;\n const min = typeof minItems === \"number\" && minItems >= 0 ? minItems : 0;\n const isMaxValid = typeof maxItems === \"number\" && maxItems >= 0 && min <= maxItems;\n return { min, max: isMaxValid ? maxItems : undefined };\n}\n\n/**\n * Tuples for `--array-length`, as the original builds them. With both bounds it emits tuples of\n * length 0 to `max - min` (not `min` to `max`); the `array-length-tuples` fix corrects it.\n */\nfunction lengthTupleType(schema: SchemaObject, item: IrType, bounds: LengthBounds): IrType {\n const { min, max } = bounds;\n if (min === max) {\n return unionOf([irTuple(repeat(item, min).map((type) => irTupleElement(type)))]);\n }\n if ((schema.maxItems as number) > 0) {\n const lengths = Array.from({ length: Math.max(0, (max ?? 0) - min + 1) }, (_, index) => index);\n return unionOf(\n lengths.map((length) => irTuple(repeat(item, length).map((type) => irTupleElement(type)))),\n );\n }\n const elements = repeat(item, min).map((type) => irTupleElement(type));\n return irTuple([...elements, irTupleElement(irArray(item), true)]);\n}\n\nfunction isLengthTupleWanted(bounds: LengthBounds, request: SchemaRequest): boolean {\n const { min, max } = bounds;\n const estimatedSize = max === undefined ? min : (max * (max + 1) - min * (min - 1)) / 2;\n const hasBounds = min !== 0 || max !== undefined;\n return (\n request.context.options.arrayLength && hasBounds && estimatedSize < MAX_LENGTH_TUPLE_ELEMENTS\n );\n}\n\n/** Applies `--immutable` to one array or tuple type. */\ntype ArrayWrapper = (type: IrType) => IrType;\n\nfunction tupleOf(item: IrType, length: number, isOpen: boolean): IrType {\n const elements = repeat(item, length).map((type) => irTupleElement(type));\n return irTuple(isOpen ? [...elements, irTupleElement(irArray(item), true)] : elements);\n}\n\n/** Tuples of every length from `min` to `max`; without `max`, `min` items and a rest element. */\nfunction fixedLengthTupleType(item: IrType, bounds: LengthBounds, wrap: ArrayWrapper): IrType {\n const { min, max } = bounds;\n if (max === undefined) {\n return wrap(tupleOf(item, min, true));\n }\n const lengths = Array.from({ length: max - min + 1 }, (_, index) => min + index);\n return unionOf(lengths.map((length) => wrap(tupleOf(item, length, false))));\n}\n\n/**\n * `type: array` with `--array-length` and the `array-length-tuples` fix (#2048, #2330, #2546):\n * the tuples have `min` to `max` items, the item type is used as it is (a nested array stays one\n * level deep), a `prefixItems` tuple gets no length tuples around it, and `--immutable` makes\n * every tuple `readonly`.\n */\nfunction fixedArrayType(schema: SchemaObject, request: SchemaRequest): IrType {\n const wrap: ArrayWrapper = (type) =>\n request.context.options.immutable ? irReadonly(type) : type;\n const tuple = prefixTupleType(schema, request);\n if (tuple !== null) {\n return wrap(tuple);\n }\n const item = singleItemType(schema, request);\n const bounds = lengthBounds(schema);\n return isLengthTupleWanted(bounds, request)\n ? fixedLengthTupleType(item, bounds, wrap)\n : wrap(irArray(item));\n}\n\nfunction isArrayLengthFixed(request: SchemaRequest): boolean {\n const { arrayLength, fixes } = request.context.options;\n return arrayLength && fixes.has(OutputFix.ARRAY_LENGTH_TUPLES);\n}\n\n/** `type: array`, including tuples (`prefixItems`, array `items`) and `--array-length`. */\nexport function arrayType(schema: SchemaObject, request: SchemaRequest): IrType {\n if (isArrayLengthFixed(request)) {\n return fixedArrayType(schema, request);\n }\n const item = itemType(schema, request);\n const bounds = lengthBounds(schema);\n if (isLengthTupleWanted(bounds, request)) {\n return lengthTupleType(schema, item, bounds);\n }\n // A tuple or an array item is used as the array type itself.\n const type = item.kind === \"tuple\" || item.kind === \"array\" ? item : irArray(item);\n return request.context.options.immutable ? irReadonly(type) : type;\n}\n"],"names":["irTuple","irTupleElement","UNKNOWN_TYPE","irArray","unionOf","irReadonly","OutputFix"],"mappings":";;;;;;;AAYA,MAAM,yBAAA,GAA4B,EAAA;AAGlC,SAAS,eAAA,CAAgB,QAAsB,OAAA,EAAuC;AACpF,EAAA,MAAM,EAAE,OAAM,GAAI,MAAA;AAClB,EAAA,IAAI,CAAC,MAAA,CAAO,WAAA,IAAe,CAAC,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AAChD,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,WAAA,G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AAA;AACrC,EAAA,MAAM,MAAA,GAAS,aAAa,MAAM,CAAA;AAClC,EAAA,IAAI,mBAAA,CAAoB,MAAA,EAAQ,OAAO,CAAA,EAAG;AACxC,IAAA,OAAO,eAAA,CAAgB,MAAA,EAAQ,IAAA,EAAM,MAAM,CAAA;AAAA,EAC7C;AAEA,EAAA,MAAM,IAAA,GAAO,KAAK,IAAA,KAAS,OAAA,IAAW,KAAK,IAAA,KAAS,OAAA,GAAU,IAAA,GAAOH,oBAAA,CAAQ,IAAI,CAAA;AACjF,EAAA,OAAO,QAAQ,OAAA,CAAQ,OAAA,CAAQ,SAAA,GAAYE,uBAAA,CAAW,IAAI,CAAA,GAAI,IAAA;AAChE;;"}
1
+ {"version":3,"file":"array-type.cjs","sources":["../../../../src/application/transform/schema/array-type.ts"],"sourcesContent":["import {\n irArray,\n irOptionalTupleElement,\n irReadonly,\n irTuple,\n irTupleElement,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrTupleElement, IrType } from \"../../../domain/ir/nodes.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { OutputFix } from \"../../../domain/output-fixes.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { unionOf } from \"../type-combinators.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\n\n/**\n * `--array-length` writes tuples only while the estimated number of tuple elements stays below\n * this; the original chose it as roughly where TypeScript starts to struggle with tuple inference.\n */\nconst MAX_LENGTH_TUPLE_ELEMENTS = 30;\n\n/**\n * The tuple of `prefixItems` (or of an `items` list); null without either. The original closes a\n * `prefixItems` tuple and requires every element; the `prefix-items` fix does not.\n */\nfunction prefixTupleType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const { items } = schema;\n if (schema.prefixItems && isPrefixItemsFixed(schema, request)) {\n return prefixItemsTupleType(schema.prefixItems, schema, request);\n }\n if (!schema.prefixItems && !Array.isArray(items)) {\n return null;\n }\n const prefixItems = schema.prefixItems ?? (items as SchemaObject[]);\n return irTuple(\n prefixItems.map((item) => irTupleElement(request.transformNested(item, request.location))),\n );\n}\n\n/** The type of the items after the prefix, or null when there may be none (`false`). */\nfunction restItemType(schema: Schema, request: SchemaRequest): IrType | null {\n return schema === false ? null : request.transformNested(schema, request.location);\n}\n\n/**\n * The type of the items after a `prefixItems` tuple (JSON Schema 2020-12 §10.3.1): `items`, else\n * `unevaluatedItems`, which does not apply to the items `contains` matches, else any item. Null\n * when no item may follow. An `items` list is not a schema in 2020-12, so it allows any item.\n */\nfunction prefixRestType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const { items, unevaluatedItems, contains } = schema;\n if (items !== undefined && !Array.isArray(items)) {\n return restItemType(items as Schema, request);\n }\n if (unevaluatedItems === undefined || items !== undefined) {\n return UNKNOWN_TYPE;\n }\n const unevaluated = restItemType(unevaluatedItems, request);\n const matched = contains === undefined ? null : restItemType(contains, request);\n const types = [unevaluated, matched].filter((type): type is IrType => type !== null);\n return types.length === 0 ? null : unionOf(types);\n}\n\n/**\n * The `prefix-items` tuple of `prefixItems`: an array may end before the prefix does, so the\n * elements from `minItems` on are optional (`T?`), and a rest element types the items after it.\n */\nfunction prefixItemsTupleType(\n prefixItems: readonly Schema[],\n schema: SchemaObject,\n request: SchemaRequest,\n): IrType {\n const { min } = lengthBounds(schema);\n const elements = prefixItems.map((item, index): IrTupleElement => {\n const type = request.transformNested(item, request.location);\n return index < min ? irTupleElement(type) : irOptionalTupleElement(type);\n });\n const rest = prefixRestType(schema, request);\n return irTuple(rest === null ? elements : [...elements, irTupleElement(irArray(rest), true)]);\n}\n\nfunction isPrefixItemsFixed(schema: SchemaObject, request: SchemaRequest): boolean {\n return (\n schema.prefixItems !== undefined && request.context.options.fixes.has(OutputFix.PREFIX_ITEMS)\n );\n}\n\n/** The type of one item; `unknown` without `items`. */\nfunction singleItemType(schema: SchemaObject, request: SchemaRequest): IrType {\n const { items } = schema;\n return items ? request.transformNested(items as SchemaObject, request.location) : UNKNOWN_TYPE;\n}\n\n/**\n * The item type as the original returns it: a tuple stands for the whole array, and a nested\n * `type: array` item is wrapped in an array here already.\n */\nfunction itemType(schema: SchemaObject, request: SchemaRequest): IrType {\n const tuple = prefixTupleType(schema, request);\n if (tuple !== null) {\n return tuple;\n }\n const { items } = schema;\n // Checked first: the `in` test below throws for `items: null`.\n if (!items) {\n return UNKNOWN_TYPE;\n }\n const nested = singleItemType(schema, request);\n const isNestedArray = typeof items === \"object\" && \"type\" in items && items.type === \"array\";\n return isNestedArray ? irArray(nested) : nested;\n}\n\nfunction repeat(type: IrType, count: number): IrType[] {\n return Array.from({ length: count }, () => type);\n}\n\ninterface LengthBounds {\n readonly min: number;\n readonly max: number | undefined;\n}\n\nfunction lengthBounds(schema: SchemaObject): LengthBounds {\n const { minItems, maxItems } = schema;\n const min = typeof minItems === \"number\" && minItems >= 0 ? minItems : 0;\n const isMaxValid = typeof maxItems === \"number\" && maxItems >= 0 && min <= maxItems;\n return { min, max: isMaxValid ? maxItems : undefined };\n}\n\n/**\n * Tuples for `--array-length`, as the original builds them. With both bounds it emits tuples of\n * length 0 to `max - min` (not `min` to `max`); the `array-length-tuples` fix corrects it.\n */\nfunction lengthTupleType(schema: SchemaObject, item: IrType, bounds: LengthBounds): IrType {\n const { min, max } = bounds;\n if (min === max) {\n return unionOf([irTuple(repeat(item, min).map((type) => irTupleElement(type)))]);\n }\n if ((schema.maxItems as number) > 0) {\n const lengths = Array.from({ length: Math.max(0, (max ?? 0) - min + 1) }, (_, index) => index);\n return unionOf(\n lengths.map((length) => irTuple(repeat(item, length).map((type) => irTupleElement(type)))),\n );\n }\n const elements = repeat(item, min).map((type) => irTupleElement(type));\n return irTuple([...elements, irTupleElement(irArray(item), true)]);\n}\n\nfunction isLengthTupleWanted(bounds: LengthBounds, request: SchemaRequest): boolean {\n const { min, max } = bounds;\n const estimatedSize = max === undefined ? min : (max * (max + 1) - min * (min - 1)) / 2;\n const hasBounds = min !== 0 || max !== undefined;\n return (\n request.context.options.arrayLength && hasBounds && estimatedSize < MAX_LENGTH_TUPLE_ELEMENTS\n );\n}\n\n/** Applies `--immutable` to one array or tuple type. */\ntype ArrayWrapper = (type: IrType) => IrType;\n\nfunction tupleOf(item: IrType, length: number, isOpen: boolean): IrType {\n const elements = repeat(item, length).map((type) => irTupleElement(type));\n return irTuple(isOpen ? [...elements, irTupleElement(irArray(item), true)] : elements);\n}\n\n/** Tuples of every length from `min` to `max`; without `max`, `min` items and a rest element. */\nfunction fixedLengthTupleType(item: IrType, bounds: LengthBounds, wrap: ArrayWrapper): IrType {\n const { min, max } = bounds;\n if (max === undefined) {\n return wrap(tupleOf(item, min, true));\n }\n const lengths = Array.from({ length: max - min + 1 }, (_, index) => min + index);\n return unionOf(lengths.map((length) => wrap(tupleOf(item, length, false))));\n}\n\n/**\n * `type: array` with `--array-length` and the `array-length-tuples` fix (#2048, #2330, #2546):\n * the tuples have `min` to `max` items, the item type is used as it is (a nested array stays one\n * level deep), a `prefixItems` tuple gets no length tuples around it, and `--immutable` makes\n * every tuple `readonly`.\n */\nfunction fixedArrayType(schema: SchemaObject, request: SchemaRequest): IrType {\n const wrap: ArrayWrapper = (type) =>\n request.context.options.immutable ? irReadonly(type) : type;\n const tuple = prefixTupleType(schema, request);\n if (tuple !== null) {\n return wrap(tuple);\n }\n const item = singleItemType(schema, request);\n const bounds = lengthBounds(schema);\n return isLengthTupleWanted(bounds, request)\n ? fixedLengthTupleType(item, bounds, wrap)\n : wrap(irArray(item));\n}\n\nfunction isArrayLengthFixed(request: SchemaRequest): boolean {\n const { arrayLength, fixes } = request.context.options;\n return arrayLength && fixes.has(OutputFix.ARRAY_LENGTH_TUPLES);\n}\n\n/** `type: array`, including tuples (`prefixItems`, array `items`) and `--array-length`. */\nexport function arrayType(schema: SchemaObject, request: SchemaRequest): IrType {\n if (isArrayLengthFixed(request)) {\n return fixedArrayType(schema, request);\n }\n const item = itemType(schema, request);\n const bounds = lengthBounds(schema);\n // A `prefix-items` tuple has its own lengths, so `--array-length` adds no tuples around it.\n if (!isPrefixItemsFixed(schema, request) && isLengthTupleWanted(bounds, request)) {\n return lengthTupleType(schema, item, bounds);\n }\n // A tuple or an array item is used as the array type itself.\n const type = item.kind === \"tuple\" || item.kind === \"array\" ? item : irArray(item);\n return request.context.options.immutable ? irReadonly(type) : type;\n}\n"],"names":["irTuple","irTupleElement","UNKNOWN_TYPE","unionOf","irOptionalTupleElement","irArray","OutputFix","irReadonly"],"mappings":";;;;;;;AAkBA,MAAM,yBAAA,GAA4B,EAAA;AAMlC,SAAS,eAAA,CAAgB,QAAsB,OAAA,EAAuC;AACpF,EAAA,MAAM,EAAE,OAAM,GAAI,MAAA;AAClB,EAAA,IAAI,MAAA,CAAO,WAAA,IAAe,kBAAA,CAAmB,MAAA,EAAQ,OAAO,CAAA,EAAG;AAC7D,IAAA,OAAO,oBAAA,CAAqB,MAAA,CAAO,WAAA,EAAa,MAAA,EAAQ,OAAO,CAAA;AAAA,EACjE;AACA,EAAA,IAAI,CAAC,MAAA,CAAO,WAAA,IAAe,CAAC,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AAChD,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,WAAA,GAAc,OAAO,WAAA,IAAgB,KAAA;AAC3C,EAAA,OAAOA,oBAAA;AAAA,IACL,WAAA,CAAY,GAAA,CAAI,CAAC,IAAA,KAASC,2BAAA,CAAe,OAAA,CAAQ,eAAA,CAAgB,IAAA,EAAM,OAAA,CAAQ,QAAQ,CAAC,CAAC;AAAA,GAC3F;AACF;AAGA,SAAS,YAAA,CAAa,QAAgB,OAAA,EAAuC;AAC3E,EAAA,OAAO,WAAW,KAAA,GAAQ,IAAA,GAAO,QAAQ,eAAA,CAAgB,MAAA,EAAQ,QAAQ,QAAQ,CAAA;AACnF;AAOA,SAAS,cAAA,CAAe,QAAsB,OAAA,EAAuC;AACnF,EAAA,MAAM,EAAE,KAAA,EAAO,gBAAA,EAAkB,QAAA,EAAS,GAAI,MAA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AAA,EAAQ,OAAO,CAAA;AACrC,EAAA,MAAM,MAAA,GAAS,aAAa,MAAM,CAAA;AAElC,EAAA,IAAI,CAAC,mBAAmB,MAAA,EAAQ,OAAO,KAAK,mBAAA,CAAoB,MAAA,EAAQ,OAAO,CAAA,EAAG;AAChF,IAAA,OAAO,eAAA,CAAgB,MAAA,EAAQ,IAAA,EAAM,MAAM,CAAA;AAAA,EAC7C;AAEA,EAAA,MAAM,IAAA,GAAO,KAAK,IAAA,KAAS,OAAA,IAAW,KAAK,IAAA,KAAS,OAAA,GAAU,IAAA,GAAOD,oBAAA,CAAQ,IAAI,CAAA;AACjF,EAAA,OAAO,QAAQ,OAAA,CAAQ,OAAA,CAAQ,SAAA,GAAYE,uBAAA,CAAW,IAAI,CAAA,GAAI,IAAA;AAChE;;"}
@@ -1,4 +1,4 @@
1
- import { irArray, irReadonly, irTuple, irTupleElement } from '../../../domain/ir/constructors.mjs';
1
+ import { irArray, irReadonly, irTuple, irTupleElement, irOptionalTupleElement } from '../../../domain/ir/constructors.mjs';
2
2
  import { OutputFix } from '../../../domain/output-fixes.mjs';
3
3
  import { UNKNOWN_TYPE } from '../shared-types.mjs';
4
4
  import { unionOf } from '../type-combinators.mjs';
@@ -6,6 +6,9 @@ import { unionOf } from '../type-combinators.mjs';
6
6
  const MAX_LENGTH_TUPLE_ELEMENTS = 30;
7
7
  function prefixTupleType(schema, request) {
8
8
  const { items } = schema;
9
+ if (schema.prefixItems && isPrefixItemsFixed(schema, request)) {
10
+ return prefixItemsTupleType(schema.prefixItems, schema, request);
11
+ }
9
12
  if (!schema.prefixItems && !Array.isArray(items)) {
10
13
  return null;
11
14
  }
@@ -14,6 +17,34 @@ function prefixTupleType(schema, request) {
14
17
  prefixItems.map((item) => irTupleElement(request.transformNested(item, request.location)))
15
18
  );
16
19
  }
20
+ function restItemType(schema, request) {
21
+ return schema === false ? null : request.transformNested(schema, request.location);
22
+ }
23
+ function prefixRestType(schema, request) {
24
+ const { items, unevaluatedItems, contains } = schema;
25
+ if (items !== void 0 && !Array.isArray(items)) {
26
+ return restItemType(items, request);
27
+ }
28
+ if (unevaluatedItems === void 0 || items !== void 0) {
29
+ return UNKNOWN_TYPE;
30
+ }
31
+ const unevaluated = restItemType(unevaluatedItems, request);
32
+ const matched = contains === void 0 ? null : restItemType(contains, request);
33
+ const types = [unevaluated, matched].filter((type) => type !== null);
34
+ return types.length === 0 ? null : unionOf(types);
35
+ }
36
+ function prefixItemsTupleType(prefixItems, schema, request) {
37
+ const { min } = lengthBounds(schema);
38
+ const elements = prefixItems.map((item, index) => {
39
+ const type = request.transformNested(item, request.location);
40
+ return index < min ? irTupleElement(type) : irOptionalTupleElement(type);
41
+ });
42
+ const rest = prefixRestType(schema, request);
43
+ return irTuple(rest === null ? elements : [...elements, irTupleElement(irArray(rest), true)]);
44
+ }
45
+ function isPrefixItemsFixed(schema, request) {
46
+ return schema.prefixItems !== void 0 && request.context.options.fixes.has(OutputFix.PREFIX_ITEMS);
47
+ }
17
48
  function singleItemType(schema, request) {
18
49
  const { items } = schema;
19
50
  return items ? request.transformNested(items, request.location) : UNKNOWN_TYPE;
@@ -92,7 +123,7 @@ function arrayType(schema, request) {
92
123
  }
93
124
  const item = itemType(schema, request);
94
125
  const bounds = lengthBounds(schema);
95
- if (isLengthTupleWanted(bounds, request)) {
126
+ if (!isPrefixItemsFixed(schema, request) && isLengthTupleWanted(bounds, request)) {
96
127
  return lengthTupleType(schema, item, bounds);
97
128
  }
98
129
  const type = item.kind === "tuple" || item.kind === "array" ? item : irArray(item);
@@ -1 +1 @@
1
- {"version":3,"file":"array-type.mjs","sources":["../../../../src/application/transform/schema/array-type.ts"],"sourcesContent":["import { irArray, irReadonly, irTuple, irTupleElement } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport type { SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { OutputFix } from \"../../../domain/output-fixes.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { unionOf } from \"../type-combinators.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\n\n/**\n * `--array-length` writes tuples only while the estimated number of tuple elements stays below\n * this; the original chose it as roughly where TypeScript starts to struggle with tuple inference.\n */\nconst MAX_LENGTH_TUPLE_ELEMENTS = 30;\n\n/** The tuple of `prefixItems` (or of an `items` list); null without either. */\nfunction prefixTupleType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const { items } = schema;\n if (!schema.prefixItems && !Array.isArray(items)) {\n return null;\n }\n const prefixItems = schema.prefixItems ?? (items as SchemaObject[]);\n return irTuple(\n prefixItems.map((item) => irTupleElement(request.transformNested(item, request.location))),\n );\n}\n\n/** The type of one item; `unknown` without `items`. */\nfunction singleItemType(schema: SchemaObject, request: SchemaRequest): IrType {\n const { items } = schema;\n return items ? request.transformNested(items as SchemaObject, request.location) : UNKNOWN_TYPE;\n}\n\n/**\n * The item type as the original returns it: a tuple stands for the whole array, and a nested\n * `type: array` item is wrapped in an array here already.\n */\nfunction itemType(schema: SchemaObject, request: SchemaRequest): IrType {\n const tuple = prefixTupleType(schema, request);\n if (tuple !== null) {\n return tuple;\n }\n const { items } = schema;\n // Checked first: the `in` test below throws for `items: null`.\n if (!items) {\n return UNKNOWN_TYPE;\n }\n const nested = singleItemType(schema, request);\n const isNestedArray = typeof items === \"object\" && \"type\" in items && items.type === \"array\";\n return isNestedArray ? irArray(nested) : nested;\n}\n\nfunction repeat(type: IrType, count: number): IrType[] {\n return Array.from({ length: count }, () => type);\n}\n\ninterface LengthBounds {\n readonly min: number;\n readonly max: number | undefined;\n}\n\nfunction lengthBounds(schema: SchemaObject): LengthBounds {\n const { minItems, maxItems } = schema;\n const min = typeof minItems === \"number\" && minItems >= 0 ? minItems : 0;\n const isMaxValid = typeof maxItems === \"number\" && maxItems >= 0 && min <= maxItems;\n return { min, max: isMaxValid ? maxItems : undefined };\n}\n\n/**\n * Tuples for `--array-length`, as the original builds them. With both bounds it emits tuples of\n * length 0 to `max - min` (not `min` to `max`); the `array-length-tuples` fix corrects it.\n */\nfunction lengthTupleType(schema: SchemaObject, item: IrType, bounds: LengthBounds): IrType {\n const { min, max } = bounds;\n if (min === max) {\n return unionOf([irTuple(repeat(item, min).map((type) => irTupleElement(type)))]);\n }\n if ((schema.maxItems as number) > 0) {\n const lengths = Array.from({ length: Math.max(0, (max ?? 0) - min + 1) }, (_, index) => index);\n return unionOf(\n lengths.map((length) => irTuple(repeat(item, length).map((type) => irTupleElement(type)))),\n );\n }\n const elements = repeat(item, min).map((type) => irTupleElement(type));\n return irTuple([...elements, irTupleElement(irArray(item), true)]);\n}\n\nfunction isLengthTupleWanted(bounds: LengthBounds, request: SchemaRequest): boolean {\n const { min, max } = bounds;\n const estimatedSize = max === undefined ? min : (max * (max + 1) - min * (min - 1)) / 2;\n const hasBounds = min !== 0 || max !== undefined;\n return (\n request.context.options.arrayLength && hasBounds && estimatedSize < MAX_LENGTH_TUPLE_ELEMENTS\n );\n}\n\n/** Applies `--immutable` to one array or tuple type. */\ntype ArrayWrapper = (type: IrType) => IrType;\n\nfunction tupleOf(item: IrType, length: number, isOpen: boolean): IrType {\n const elements = repeat(item, length).map((type) => irTupleElement(type));\n return irTuple(isOpen ? [...elements, irTupleElement(irArray(item), true)] : elements);\n}\n\n/** Tuples of every length from `min` to `max`; without `max`, `min` items and a rest element. */\nfunction fixedLengthTupleType(item: IrType, bounds: LengthBounds, wrap: ArrayWrapper): IrType {\n const { min, max } = bounds;\n if (max === undefined) {\n return wrap(tupleOf(item, min, true));\n }\n const lengths = Array.from({ length: max - min + 1 }, (_, index) => min + index);\n return unionOf(lengths.map((length) => wrap(tupleOf(item, length, false))));\n}\n\n/**\n * `type: array` with `--array-length` and the `array-length-tuples` fix (#2048, #2330, #2546):\n * the tuples have `min` to `max` items, the item type is used as it is (a nested array stays one\n * level deep), a `prefixItems` tuple gets no length tuples around it, and `--immutable` makes\n * every tuple `readonly`.\n */\nfunction fixedArrayType(schema: SchemaObject, request: SchemaRequest): IrType {\n const wrap: ArrayWrapper = (type) =>\n request.context.options.immutable ? irReadonly(type) : type;\n const tuple = prefixTupleType(schema, request);\n if (tuple !== null) {\n return wrap(tuple);\n }\n const item = singleItemType(schema, request);\n const bounds = lengthBounds(schema);\n return isLengthTupleWanted(bounds, request)\n ? fixedLengthTupleType(item, bounds, wrap)\n : wrap(irArray(item));\n}\n\nfunction isArrayLengthFixed(request: SchemaRequest): boolean {\n const { arrayLength, fixes } = request.context.options;\n return arrayLength && fixes.has(OutputFix.ARRAY_LENGTH_TUPLES);\n}\n\n/** `type: array`, including tuples (`prefixItems`, array `items`) and `--array-length`. */\nexport function arrayType(schema: SchemaObject, request: SchemaRequest): IrType {\n if (isArrayLengthFixed(request)) {\n return fixedArrayType(schema, request);\n }\n const item = itemType(schema, request);\n const bounds = lengthBounds(schema);\n if (isLengthTupleWanted(bounds, request)) {\n return lengthTupleType(schema, item, bounds);\n }\n // A tuple or an array item is used as the array type itself.\n const type = item.kind === \"tuple\" || item.kind === \"array\" ? item : irArray(item);\n return request.context.options.immutable ? irReadonly(type) : type;\n}\n"],"names":[],"mappings":";;;;;AAYA,MAAM,yBAAA,GAA4B,EAAA;AAGlC,SAAS,eAAA,CAAgB,QAAsB,OAAA,EAAuC;AACpF,EAAA,MAAM,EAAE,OAAM,GAAI,MAAA;AAClB,EAAA,IAAI,CAAC,MAAA,CAAO,WAAA,IAAe,CAAC,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AAChD,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,WAAA,GAAc,OAAO,WAAA,IAAgB,KAAA;AAC3C,EAAA,OAAO,OAAA;AAAA,IACL,WAAA,CAAY,GAAA,CAAI,CAAC,IAAA,KAAS,cAAA,CAAe,OAAA,CAAQ,eAAA,CAAgB,IAAA,EAAM,OAAA,CAAQ,QAAQ,CAAC,CAAC;AAAA,GAC3F;AACF;AAGA,SAAS,cAAA,CAAe,QAAsB,OAAA,EAAgC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AA,CAAQ,IAAI,CAAA;AACjF,EAAA,OAAO,QAAQ,OAAA,CAAQ,OAAA,CAAQ,SAAA,GAAY,UAAA,CAAW,IAAI,CAAA,GAAI,IAAA;AAChE;;"}
1
+ {"version":3,"file":"array-type.mjs","sources":["../../../../src/application/transform/schema/array-type.ts"],"sourcesContent":["import {\n irArray,\n irOptionalTupleElement,\n irReadonly,\n irTuple,\n irTupleElement,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrTupleElement, IrType } from \"../../../domain/ir/nodes.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { OutputFix } from \"../../../domain/output-fixes.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { unionOf } from \"../type-combinators.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\n\n/**\n * `--array-length` writes tuples only while the estimated number of tuple elements stays below\n * this; the original chose it as roughly where TypeScript starts to struggle with tuple inference.\n */\nconst MAX_LENGTH_TUPLE_ELEMENTS = 30;\n\n/**\n * The tuple of `prefixItems` (or of an `items` list); null without either. The original closes a\n * `prefixItems` tuple and requires every element; the `prefix-items` fix does not.\n */\nfunction prefixTupleType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const { items } = schema;\n if (schema.prefixItems && isPrefixItemsFixed(schema, request)) {\n return prefixItemsTupleType(schema.prefixItems, schema, request);\n }\n if (!schema.prefixItems && !Array.isArray(items)) {\n return null;\n }\n const prefixItems = schema.prefixItems ?? (items as SchemaObject[]);\n return irTuple(\n prefixItems.map((item) => irTupleElement(request.transformNested(item, request.location))),\n );\n}\n\n/** The type of the items after the prefix, or null when there may be none (`false`). */\nfunction restItemType(schema: Schema, request: SchemaRequest): IrType | null {\n return schema === false ? null : request.transformNested(schema, request.location);\n}\n\n/**\n * The type of the items after a `prefixItems` tuple (JSON Schema 2020-12 §10.3.1): `items`, else\n * `unevaluatedItems`, which does not apply to the items `contains` matches, else any item. Null\n * when no item may follow. An `items` list is not a schema in 2020-12, so it allows any item.\n */\nfunction prefixRestType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const { items, unevaluatedItems, contains } = schema;\n if (items !== undefined && !Array.isArray(items)) {\n return restItemType(items as Schema, request);\n }\n if (unevaluatedItems === undefined || items !== undefined) {\n return UNKNOWN_TYPE;\n }\n const unevaluated = restItemType(unevaluatedItems, request);\n const matched = contains === undefined ? null : restItemType(contains, request);\n const types = [unevaluated, matched].filter((type): type is IrType => type !== null);\n return types.length === 0 ? null : unionOf(types);\n}\n\n/**\n * The `prefix-items` tuple of `prefixItems`: an array may end before the prefix does, so the\n * elements from `minItems` on are optional (`T?`), and a rest element types the items after it.\n */\nfunction prefixItemsTupleType(\n prefixItems: readonly Schema[],\n schema: SchemaObject,\n request: SchemaRequest,\n): IrType {\n const { min } = lengthBounds(schema);\n const elements = prefixItems.map((item, index): IrTupleElement => {\n const type = request.transformNested(item, request.location);\n return index < min ? irTupleElement(type) : irOptionalTupleElement(type);\n });\n const rest = prefixRestType(schema, request);\n return irTuple(rest === null ? elements : [...elements, irTupleElement(irArray(rest), true)]);\n}\n\nfunction isPrefixItemsFixed(schema: SchemaObject, request: SchemaRequest): boolean {\n return (\n schema.prefixItems !== undefined && request.context.options.fixes.has(OutputFix.PREFIX_ITEMS)\n );\n}\n\n/** The type of one item; `unknown` without `items`. */\nfunction singleItemType(schema: SchemaObject, request: SchemaRequest): IrType {\n const { items } = schema;\n return items ? request.transformNested(items as SchemaObject, request.location) : UNKNOWN_TYPE;\n}\n\n/**\n * The item type as the original returns it: a tuple stands for the whole array, and a nested\n * `type: array` item is wrapped in an array here already.\n */\nfunction itemType(schema: SchemaObject, request: SchemaRequest): IrType {\n const tuple = prefixTupleType(schema, request);\n if (tuple !== null) {\n return tuple;\n }\n const { items } = schema;\n // Checked first: the `in` test below throws for `items: null`.\n if (!items) {\n return UNKNOWN_TYPE;\n }\n const nested = singleItemType(schema, request);\n const isNestedArray = typeof items === \"object\" && \"type\" in items && items.type === \"array\";\n return isNestedArray ? irArray(nested) : nested;\n}\n\nfunction repeat(type: IrType, count: number): IrType[] {\n return Array.from({ length: count }, () => type);\n}\n\ninterface LengthBounds {\n readonly min: number;\n readonly max: number | undefined;\n}\n\nfunction lengthBounds(schema: SchemaObject): LengthBounds {\n const { minItems, maxItems } = schema;\n const min = typeof minItems === \"number\" && minItems >= 0 ? minItems : 0;\n const isMaxValid = typeof maxItems === \"number\" && maxItems >= 0 && min <= maxItems;\n return { min, max: isMaxValid ? maxItems : undefined };\n}\n\n/**\n * Tuples for `--array-length`, as the original builds them. With both bounds it emits tuples of\n * length 0 to `max - min` (not `min` to `max`); the `array-length-tuples` fix corrects it.\n */\nfunction lengthTupleType(schema: SchemaObject, item: IrType, bounds: LengthBounds): IrType {\n const { min, max } = bounds;\n if (min === max) {\n return unionOf([irTuple(repeat(item, min).map((type) => irTupleElement(type)))]);\n }\n if ((schema.maxItems as number) > 0) {\n const lengths = Array.from({ length: Math.max(0, (max ?? 0) - min + 1) }, (_, index) => index);\n return unionOf(\n lengths.map((length) => irTuple(repeat(item, length).map((type) => irTupleElement(type)))),\n );\n }\n const elements = repeat(item, min).map((type) => irTupleElement(type));\n return irTuple([...elements, irTupleElement(irArray(item), true)]);\n}\n\nfunction isLengthTupleWanted(bounds: LengthBounds, request: SchemaRequest): boolean {\n const { min, max } = bounds;\n const estimatedSize = max === undefined ? min : (max * (max + 1) - min * (min - 1)) / 2;\n const hasBounds = min !== 0 || max !== undefined;\n return (\n request.context.options.arrayLength && hasBounds && estimatedSize < MAX_LENGTH_TUPLE_ELEMENTS\n );\n}\n\n/** Applies `--immutable` to one array or tuple type. */\ntype ArrayWrapper = (type: IrType) => IrType;\n\nfunction tupleOf(item: IrType, length: number, isOpen: boolean): IrType {\n const elements = repeat(item, length).map((type) => irTupleElement(type));\n return irTuple(isOpen ? [...elements, irTupleElement(irArray(item), true)] : elements);\n}\n\n/** Tuples of every length from `min` to `max`; without `max`, `min` items and a rest element. */\nfunction fixedLengthTupleType(item: IrType, bounds: LengthBounds, wrap: ArrayWrapper): IrType {\n const { min, max } = bounds;\n if (max === undefined) {\n return wrap(tupleOf(item, min, true));\n }\n const lengths = Array.from({ length: max - min + 1 }, (_, index) => min + index);\n return unionOf(lengths.map((length) => wrap(tupleOf(item, length, false))));\n}\n\n/**\n * `type: array` with `--array-length` and the `array-length-tuples` fix (#2048, #2330, #2546):\n * the tuples have `min` to `max` items, the item type is used as it is (a nested array stays one\n * level deep), a `prefixItems` tuple gets no length tuples around it, and `--immutable` makes\n * every tuple `readonly`.\n */\nfunction fixedArrayType(schema: SchemaObject, request: SchemaRequest): IrType {\n const wrap: ArrayWrapper = (type) =>\n request.context.options.immutable ? irReadonly(type) : type;\n const tuple = prefixTupleType(schema, request);\n if (tuple !== null) {\n return wrap(tuple);\n }\n const item = singleItemType(schema, request);\n const bounds = lengthBounds(schema);\n return isLengthTupleWanted(bounds, request)\n ? fixedLengthTupleType(item, bounds, wrap)\n : wrap(irArray(item));\n}\n\nfunction isArrayLengthFixed(request: SchemaRequest): boolean {\n const { arrayLength, fixes } = request.context.options;\n return arrayLength && fixes.has(OutputFix.ARRAY_LENGTH_TUPLES);\n}\n\n/** `type: array`, including tuples (`prefixItems`, array `items`) and `--array-length`. */\nexport function arrayType(schema: SchemaObject, request: SchemaRequest): IrType {\n if (isArrayLengthFixed(request)) {\n return fixedArrayType(schema, request);\n }\n const item = itemType(schema, request);\n const bounds = lengthBounds(schema);\n // A `prefix-items` tuple has its own lengths, so `--array-length` adds no tuples around it.\n if (!isPrefixItemsFixed(schema, request) && isLengthTupleWanted(bounds, request)) {\n return lengthTupleType(schema, item, bounds);\n }\n // A tuple or an array item is used as the array type itself.\n const type = item.kind === \"tuple\" || item.kind === \"array\" ? item : irArray(item);\n return request.context.options.immutable ? irReadonly(type) : type;\n}\n"],"names":[],"mappings":";;;;;AAkBA,MAAM,yBAAA,GAA4B,EAAA;AAMlC,SAAS,eAAA,CAAgB,QAAsB,OAAA,EAAuC;AACpF,EAAA,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UAAA,CAAW,IAAI,CAAA,GAAI,IAAA;AAChE;;"}
@@ -3,10 +3,13 @@
3
3
  const constructors = require('../../../domain/ir/constructors.cjs');
4
4
  const jsonPointer = require('../../../domain/openapi/json-pointer.cjs');
5
5
  const outputFixes = require('../../../domain/output-fixes.cjs');
6
+ const pointerType = require('../ref-pointer/pointer-type.cjs');
6
7
  const sharedTypes = require('../shared-types.cjs');
7
8
  const typeCombinators = require('../type-combinators.cjs');
8
9
  const coreType = require('./core-type.cjs');
10
+ const discriminatedUnion = require('./discriminated-union.cjs');
9
11
  const presenceMembers = require('./presence-members.cjs');
12
+ const requiredVariants = require('./required-variants.cjs');
10
13
  const unevaluatedProperties = require('./unevaluated-properties.cjs');
11
14
 
12
15
  function variantTypes(variants, keyword, request) {
@@ -20,19 +23,28 @@ function variantTypes(variants, keyword, request) {
20
23
  function isRefItem(item) {
21
24
  return "$ref" in item;
22
25
  }
26
+ function keysToRequire(ref, target, required, request) {
27
+ const defined = required.filter((key) => Boolean(target.properties?.[key]));
28
+ if (!request.context.discriminators.isHandled(ref)) {
29
+ return defined;
30
+ }
31
+ if (!request.context.options.fixes.has(outputFixes.OutputFix.DISCRIMINATOR_MEMBER_REQUIRED)) {
32
+ return [];
33
+ }
34
+ return defined.filter((key) => !target.required?.includes(key));
35
+ }
23
36
  function refItemType(item, required, request) {
24
37
  const type = request.transformNested(item, request.location);
25
- const { refs, discriminators, footer } = request.context;
26
- const resolved = refs.resolve(item.$ref);
27
- const isEligible = resolved && typeof resolved === "object" && "properties" in resolved && !discriminators.isHandled(item.$ref);
28
- if (!isEligible) {
38
+ const resolved = request.context.refs.resolve(item.$ref);
39
+ if (!resolved || typeof resolved !== "object" || !("properties" in resolved)) {
29
40
  return type;
30
41
  }
31
- const keys = required.filter((key) => Boolean(resolved.properties?.[key]));
32
- if (keys.length > 0) {
33
- footer.requireWithRequired();
42
+ const keys = keysToRequire(item.$ref, resolved, required, request);
43
+ if (keys.length === 0) {
44
+ return type;
34
45
  }
35
- return typeCombinators.withRequiredKeys(type, keys);
46
+ request.context.footer.requireWithRequired();
47
+ return typeCombinators.withRequiredKeys(pointerType.requirableRefType(item.$ref, type, request), keys);
36
48
  }
37
49
  function inlineItemType(item, required, request) {
38
50
  const own = typeof item === "object" && Array.isArray(item.required) ? item.required ?? [] : [];
@@ -41,13 +53,29 @@ function inlineItemType(item, required, request) {
41
53
  request.location
42
54
  );
43
55
  }
56
+ function ownKeywordsType(own, ref, request) {
57
+ return combinedType(own, { ...request, location: { ...request.location, path: ref } });
58
+ }
59
+ function allOfItemType(item, required, request) {
60
+ const isRef = isRefItem(item);
61
+ const discriminator = isRef && request.context.discriminators.objectAt(item.$ref) || item.discriminator;
62
+ const propertyName = discriminator?.propertyName;
63
+ const unionItem = isRef && propertyName ? discriminatedUnion.unionItemOf(item.$ref, request) : void 0;
64
+ if (isRef && propertyName && unionItem?.isMember) {
65
+ const own = discriminatedUnion.unionOwnKeywords(unionItem.union, propertyName, required);
66
+ return ownKeywordsType(own, item.$ref, request);
67
+ }
68
+ const type = isRef ? refItemType(item, required, request) : inlineItemType(item, required, request);
69
+ const isUnion = unionItem !== void 0 && !unionItem.isMapped && request.context.options.fixes.has(outputFixes.OutputFix.ALLOF_DISCRIMINATED_UNION);
70
+ if (!propertyName || isUnion) {
71
+ return type;
72
+ }
73
+ const { path } = request.location;
74
+ const others = path === void 0 ? [] : request.context.discriminators.otherPropertiesAt(path);
75
+ return typeCombinators.omitKeys(type, [propertyName, ...others]);
76
+ }
44
77
  function allOfTypes(items, required, request) {
45
- return items.map((item) => {
46
- const isRef = isRefItem(item);
47
- const type = isRef ? refItemType(item, required, request) : inlineItemType(item, required, request);
48
- const discriminator = isRef && request.context.discriminators.objectAt(item.$ref) || item.discriminator;
49
- return discriminator?.propertyName ? typeCombinators.omitKeys(type, [discriminator.propertyName]) : type;
50
- });
78
+ return items.flatMap((item) => allOfItemType(item, required, request) ?? []);
51
79
  }
52
80
  function oneOfType(previous, variants) {
53
81
  const before = previous === null ? [] : [previous];
@@ -80,7 +108,14 @@ function composedType(schema, request) {
80
108
  const allOfType = allOf.length > 0 ? [typeCombinators.intersectionOf(allOf)] : [];
81
109
  type = typeCombinators.intersectionOf([...core === null ? [] : [core], ...allOfType]);
82
110
  }
83
- type = anyOfType(type, schema, request);
111
+ return variantsType(type, schema, request);
112
+ }
113
+ function variantsType(previous, schema, request) {
114
+ const type = requiredVariants.requiredVariantsType(previous, schema, schema.anyOf ?? [], request) ?? anyOfType(previous, schema, request);
115
+ const oneOfRequired = requiredVariants.requiredVariantsType(type, schema, schema.oneOf ?? [], request);
116
+ if (oneOfRequired !== null) {
117
+ return oneOfRequired;
118
+ }
84
119
  const oneOf = variantTypes(oneOfVariants(schema), "oneOf", request);
85
120
  return oneOf.length > 0 ? oneOfType(type, oneOf) : type;
86
121
  }
@@ -1 +1 @@
1
- {"version":3,"file":"composition-type.cjs","sources":["../../../../src/application/transform/schema/composition-type.ts"],"sourcesContent":["import { irKeyword, irRecord } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { createRef } from \"../../../domain/openapi/json-pointer.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { OutputFix } from \"../../../domain/output-fixes.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport {\n intersectionOf,\n isPrimitiveType,\n nullableOf,\n omitKeys,\n unionOf,\n withRequiredKeys,\n} from \"../type-combinators.js\";\nimport { coreType } from \"./core-type.js\";\nimport { allOfMembers } from \"./presence-members.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\nimport { unevaluatedPropertiesType } from \"./unevaluated-properties.js\";\n\n/** `anyOf` / `oneOf` variants; the position is part of the path so nested names stay unique. */\nfunction variantTypes(\n variants: readonly Schema[],\n keyword: \"anyOf\" | \"oneOf\",\n request: SchemaRequest,\n): IrType[] {\n return variants.map((variant, index) =>\n request.transformNested(variant, {\n ...request.location,\n path: createRef([request.location.path, keyword, String(index)]),\n }),\n );\n}\n\n/**\n * Whether an `allOf` item is a `$ref`. Like the original, this uses `in`, so a boolean item throws\n * a TypeError instead of being accepted.\n */\nfunction isRefItem(item: Schema): item is { readonly $ref: string } {\n return \"$ref\" in (item as object);\n}\n\n/** A `$ref` item gets the parent's `required` keys that its target defines (`WithRequired`). */\nfunction refItemType(\n item: { readonly $ref: string },\n required: readonly string[],\n request: SchemaRequest,\n): IrType {\n const type = request.transformNested(item, request.location);\n const { refs, discriminators, footer } = request.context;\n const resolved = refs.resolve(item.$ref) as SchemaObject | undefined;\n const isEligible =\n resolved &&\n typeof resolved === \"object\" &&\n \"properties\" in resolved &&\n !discriminators.isHandled(item.$ref);\n if (!isEligible) {\n return type;\n }\n const keys = required.filter((key) => Boolean(resolved.properties?.[key]));\n if (keys.length > 0) {\n footer.requireWithRequired();\n }\n return withRequiredKeys(type, keys);\n}\n\n/** An inline item merges the parent's `required` keys with its own. */\nfunction inlineItemType(item: Schema, required: readonly string[], request: SchemaRequest): IrType {\n const own =\n typeof item === \"object\" && Array.isArray((item as SchemaObject).required)\n ? ((item as SchemaObject).required ?? [])\n : [];\n return request.transformNested(\n { ...(item as SchemaObject), required: [...required, ...own] },\n request.location,\n );\n}\n\n/** `allOf` items; an item with a discriminator omits that property (the parent redefines it). */\nfunction allOfTypes(\n items: readonly Schema[],\n required: readonly string[],\n request: SchemaRequest,\n): IrType[] {\n return items.map((item) => {\n const isRef = isRefItem(item);\n const type = isRef\n ? refItemType(item, required, request)\n : inlineItemType(item, required, request);\n const discriminator =\n (isRef && request.context.discriminators.objectAt(item.$ref)) ||\n (item as SchemaObject).discriminator;\n return discriminator?.propertyName ? omitKeys(type, [discriminator.propertyName]) : type;\n });\n}\n\nfunction oneOfType(previous: IrType | null, variants: readonly IrType[]): IrType {\n const before = previous === null ? [] : [previous];\n // Only `oneOf` may list primitives; then it stays a flat union.\n return variants.every(isPrimitiveType)\n ? unionOf([...before, ...variants])\n : intersectionOf([...before, unionOf(variants)]);\n}\n\n/**\n * `anyOf` is a union: TypeScript unions are not exclusive, which matches anyOf better than oneOf.\n * By default the sibling type is one more member, as in the original. With `anyof-properties` it\n * is intersected with the union, so it applies to every variant (#2380); for a `type` list, each\n * listed type has applied `anyOf` already (`multipleTypes`), so the list is the whole type.\n */\nfunction anyOfType(\n previous: IrType | null,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrType | null {\n const variants = variantTypes(schema.anyOf ?? [], \"anyOf\", request);\n if (variants.length === 0 || previous === null) {\n return variants.length === 0 ? previous : unionOf(variants);\n }\n if (!request.context.options.fixes.has(OutputFix.ANYOF_PROPERTIES)) {\n return unionOf([previous, ...variants]);\n }\n return Array.isArray(schema.type) ? previous : intersectionOf([previous, unionOf(variants)]);\n}\n\n/** Object enums are written as `oneOf` over their values. */\nfunction oneOfVariants(schema: SchemaObject): readonly Schema[] {\n const objectEnum =\n \"type\" in schema && schema.type === \"object\" && (schema.enum as Schema[] | undefined);\n return schema.oneOf || objectEnum || [];\n}\n\n/**\n * The parent's `required` keys, plus the keys of left-out `allOf` members (`allof-required`).\n * Without such keys the parent's list stays as it is, duplicates included, as in the original.\n */\nfunction requiredKeys(schema: SchemaObject, presenceKeys: readonly string[]): readonly string[] {\n const own = schema.required ?? [];\n return presenceKeys.length === 0 ? own : [...new Set([...own, ...presenceKeys])];\n}\n\nfunction composedType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n let type: IrType | null = null;\n const core = coreType(schema, request);\n const { members, required } = allOfMembers(schema.allOf ?? [], request);\n const allOf = allOfTypes(members, requiredKeys(schema, required), request);\n if (core !== null || allOf.length > 0) {\n const allOfType = allOf.length > 0 ? [intersectionOf(allOf)] : [];\n type = intersectionOf([...(core === null ? [] : [core]), ...allOfType]);\n }\n type = anyOfType(type, schema, request);\n const oneOf = variantTypes(oneOfVariants(schema), \"oneOf\", request);\n return oneOf.length > 0 ? oneOfType(type, oneOf) : type;\n}\n\n/** The composed type, with the `unevaluatedProperties` index signature when it applies. */\nfunction combinedType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const type = composedType(schema, request);\n const unevaluated = unevaluatedPropertiesType(schema, type, request);\n if (unevaluated === null) {\n return type;\n }\n if (type === null) {\n return unevaluated;\n }\n // One flat intersection, so an `allOf` intersection is not printed in parentheses.\n const parts = type.kind === \"intersection\" ? type.types : [type];\n return intersectionOf([...parts, unevaluated]);\n}\n\n/**\n * The schema with composition: core type and `allOf` intersected, then `anyOf` and `oneOf`. Without\n * any of them: `Record<string, never>` (or `unknown` with `--empty-objects-unknown`) when `type` is\n * present, else `unknown`. `nullable: true` adds `null`, except to the shared `unknown`.\n */\nexport function compositionType(schema: SchemaObject, request: SchemaRequest): IrType {\n const { emptyObjectsUnknown } = request.context.options;\n const empty =\n \"type\" in schema\n ? irRecord(irKeyword(\"string\"), emptyObjectsUnknown ? UNKNOWN_TYPE : irKeyword(\"never\"))\n : UNKNOWN_TYPE;\n const type = combinedType(schema, request) ?? empty;\n return type !== UNKNOWN_TYPE && schema.nullable ? nullableOf([type]) : type;\n}\n"],"names":["createRef","withRequiredKeys","omitKeys","isPrimitiveType","unionOf","intersectionOf","OutputFix","coreType","allOfMembers","unevaluatedPropertiesType","irRecord","irKeyword","UNKNOWN_TYPE","nullableOf"],"mappings":";;;;;;;;;;;AAoBA,SAAS,YAAA,CACP,QAAA,EACA,OAAA,EACA,OAAA,EACU;AACV,EAAA,OAAO,QAAA,CAAS,GAAA;AAAA,IAAI,CAAC,OAAA,EAAS,KAAA,KAC5B,OAAA,CAAQ,gBAAgB,OAAA,EAAS;AAAA,MAC/B,GAAG,OAAA,CAAQ,QAAA;AAAA,MACX,IAAA,EAAMA,qBAAA,CAAU,CAAC,OAAA,CAAQ,QAAA,CAAS,MAAM,OAAA,EAAS,MAAA,CAAO,KAAK,CAAC,CAAC;AAAA,KAChE;AAAA,GACH;AACF;AAMA,SAAS,UAAU,IAAA,EAAiD;AAClE,EAAA,OAAO,MAAA,IAAW,IAAA;AACpB;AAGA,SAA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mBAAA,GAAsBC,wBAAA,GAAeD,sBAAA,CAAU,OAAO,CAAC,CAAA,GACrFC,wBAAA;AACN,EAAA,MAAM,IAAA,GAAO,YAAA,CAAa,MAAA,EAAQ,OAAO,CAAA,IAAK,KAAA;AAC9C,EAAA,OAAO,IAAA,KAASA,4BAAgB,MAAA,CAAO,QAAA,GAAWC,2BAAW,CAAC,IAAI,CAAC,CAAA,GAAI,IAAA;AACzE;;"}
1
+ {"version":3,"file":"composition-type.cjs","sources":["../../../../src/application/transform/schema/composition-type.ts"],"sourcesContent":["import { irKeyword, irRecord } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { createRef } from \"../../../domain/openapi/json-pointer.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { OutputFix } from \"../../../domain/output-fixes.js\";\nimport { requirableRefType } from \"../ref-pointer/pointer-type.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport {\n intersectionOf,\n isPrimitiveType,\n nullableOf,\n omitKeys,\n unionOf,\n withRequiredKeys,\n} from \"../type-combinators.js\";\nimport { coreType } from \"./core-type.js\";\nimport { unionItemOf, unionOwnKeywords } from \"./discriminated-union.js\";\nimport { allOfMembers } from \"./presence-members.js\";\nimport { requiredVariantsType } from \"./required-variants.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\nimport { unevaluatedPropertiesType } from \"./unevaluated-properties.js\";\n\n/** `anyOf` / `oneOf` variants; the position is part of the path so nested names stay unique. */\nfunction variantTypes(\n variants: readonly Schema[],\n keyword: \"anyOf\" | \"oneOf\",\n request: SchemaRequest,\n): IrType[] {\n return variants.map((variant, index) =>\n request.transformNested(variant, {\n ...request.location,\n path: createRef([request.location.path, keyword, String(index)]),\n }),\n );\n}\n\n/**\n * Whether an `allOf` item is a `$ref`. Like the original, this uses `in`, so a boolean item throws\n * a TypeError instead of being accepted.\n */\nfunction isRefItem(item: Schema): item is { readonly $ref: string } {\n return \"$ref\" in (item as object);\n}\n\n/**\n * The parent's `required` keys that the target at `ref` defines. A target that the discriminator\n * scan gave its property got none: the scan made that property required, but the other keys were\n * lost too. With `discriminator-member-required` only keys the target requires already are left\n * out (#2162).\n */\nfunction keysToRequire(\n ref: string,\n target: SchemaObject,\n required: readonly string[],\n request: SchemaRequest,\n): readonly string[] {\n const defined = required.filter((key) => Boolean(target.properties?.[key]));\n if (!request.context.discriminators.isHandled(ref)) {\n return defined;\n }\n if (!request.context.options.fixes.has(OutputFix.DISCRIMINATOR_MEMBER_REQUIRED)) {\n return [];\n }\n return defined.filter((key) => !target.required?.includes(key));\n}\n\n/** A `$ref` item gets the parent's `required` keys that its target defines (`WithRequired`). */\nfunction refItemType(\n item: { readonly $ref: string },\n required: readonly string[],\n request: SchemaRequest,\n): IrType {\n const type = request.transformNested(item, request.location);\n const resolved = request.context.refs.resolve(item.$ref) as SchemaObject | undefined;\n if (!resolved || typeof resolved !== \"object\" || !(\"properties\" in resolved)) {\n return type;\n }\n const keys = keysToRequire(item.$ref, resolved, required, request);\n if (keys.length === 0) {\n return type;\n }\n request.context.footer.requireWithRequired();\n return withRequiredKeys(requirableRefType(item.$ref, type, request), keys);\n}\n\n/** An inline item merges the parent's `required` keys with its own. */\nfunction inlineItemType(item: Schema, required: readonly string[], request: SchemaRequest): IrType {\n const own =\n typeof item === \"object\" && Array.isArray((item as SchemaObject).required)\n ? ((item as SchemaObject).required ?? [])\n : [];\n return request.transformNested(\n { ...(item as SchemaObject), required: [...required, ...own] },\n request.location,\n );\n}\n\n/**\n * The union's own keywords at the union's location, so nested names (enums) stay the union's.\n * Null when the union has none.\n */\nfunction ownKeywordsType(own: SchemaObject, ref: string, request: SchemaRequest): IrType | null {\n return combinedType(own, { ...request, location: { ...request.location, path: ref } });\n}\n\n/**\n * An `allOf` item; one with a discriminator omits that property (the parent redefines it). A\n * `$ref` to a discriminated union is not such a parent: for a member of the union it is the\n * union's own keywords, since the union contains the member (#1665); with\n * `allof-discriminated-union` it is the union, since `Omit` on a union drops keys (#1464), unless\n * the union's mapping names the schema: then it is a member, as the discriminator scan has it.\n */\nfunction allOfItemType(\n item: Schema,\n required: readonly string[],\n request: SchemaRequest,\n): IrType | null {\n const isRef = isRefItem(item);\n const discriminator =\n (isRef && request.context.discriminators.objectAt(item.$ref)) ||\n (item as SchemaObject).discriminator;\n const propertyName = discriminator?.propertyName;\n const unionItem = isRef && propertyName ? unionItemOf(item.$ref, request) : undefined;\n if (isRef && propertyName && unionItem?.isMember) {\n const own = unionOwnKeywords(unionItem.union, propertyName, required);\n return ownKeywordsType(own, item.$ref, request);\n }\n const type = isRef\n ? refItemType(item, required, request)\n : inlineItemType(item, required, request);\n const isUnion =\n unionItem !== undefined &&\n !unionItem.isMapped &&\n request.context.options.fixes.has(OutputFix.ALLOF_DISCRIMINATED_UNION);\n if (!propertyName || isUnion) {\n return type;\n }\n // With `discriminator-values` the schema also redefines the properties of other owners above\n // it, so no item may keep a value of its own for them (a parent mapped as `content`).\n const { path } = request.location;\n const others = path === undefined ? [] : request.context.discriminators.otherPropertiesAt(path);\n return omitKeys(type, [propertyName, ...others]);\n}\n\nfunction allOfTypes(\n items: readonly Schema[],\n required: readonly string[],\n request: SchemaRequest,\n): IrType[] {\n return items.flatMap((item) => allOfItemType(item, required, request) ?? []);\n}\n\nfunction oneOfType(previous: IrType | null, variants: readonly IrType[]): IrType {\n const before = previous === null ? [] : [previous];\n // Only `oneOf` may list primitives; then it stays a flat union.\n return variants.every(isPrimitiveType)\n ? unionOf([...before, ...variants])\n : intersectionOf([...before, unionOf(variants)]);\n}\n\n/**\n * `anyOf` is a union: TypeScript unions are not exclusive, which matches anyOf better than oneOf.\n * By default the sibling type is one more member, as in the original. With `anyof-properties` it\n * is intersected with the union, so it applies to every variant (#2380); for a `type` list, each\n * listed type has applied `anyOf` already (`multipleTypes`), so the list is the whole type.\n */\nfunction anyOfType(\n previous: IrType | null,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrType | null {\n const variants = variantTypes(schema.anyOf ?? [], \"anyOf\", request);\n if (variants.length === 0 || previous === null) {\n return variants.length === 0 ? previous : unionOf(variants);\n }\n if (!request.context.options.fixes.has(OutputFix.ANYOF_PROPERTIES)) {\n return unionOf([previous, ...variants]);\n }\n return Array.isArray(schema.type) ? previous : intersectionOf([previous, unionOf(variants)]);\n}\n\n/** Object enums are written as `oneOf` over their values. */\nfunction oneOfVariants(schema: SchemaObject): readonly Schema[] {\n const objectEnum =\n \"type\" in schema && schema.type === \"object\" && (schema.enum as Schema[] | undefined);\n return schema.oneOf || objectEnum || [];\n}\n\n/**\n * The parent's `required` keys, plus the keys of left-out `allOf` members (`allof-required`).\n * Without such keys the parent's list stays as it is, duplicates included, as in the original.\n */\nfunction requiredKeys(schema: SchemaObject, presenceKeys: readonly string[]): readonly string[] {\n const own = schema.required ?? [];\n return presenceKeys.length === 0 ? own : [...new Set([...own, ...presenceKeys])];\n}\n\nfunction composedType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n let type: IrType | null = null;\n const core = coreType(schema, request);\n const { members, required } = allOfMembers(schema.allOf ?? [], request);\n const allOf = allOfTypes(members, requiredKeys(schema, required), request);\n if (core !== null || allOf.length > 0) {\n const allOfType = allOf.length > 0 ? [intersectionOf(allOf)] : [];\n type = intersectionOf([...(core === null ? [] : [core]), ...allOfType]);\n }\n return variantsType(type, schema, request);\n}\n\n/** `anyOf`, then `oneOf`, applied to the core and `allOf` type (`anyof-oneof-required` first). */\nfunction variantsType(\n previous: IrType | null,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrType | null {\n const type =\n requiredVariantsType(previous, schema, schema.anyOf ?? [], request) ??\n anyOfType(previous, schema, request);\n const oneOfRequired = requiredVariantsType(type, schema, schema.oneOf ?? [], request);\n if (oneOfRequired !== null) {\n return oneOfRequired;\n }\n const oneOf = variantTypes(oneOfVariants(schema), \"oneOf\", request);\n return oneOf.length > 0 ? oneOfType(type, oneOf) : type;\n}\n\n/** The composed type, with the `unevaluatedProperties` index signature when it applies. */\nfunction combinedType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const type = composedType(schema, request);\n const unevaluated = unevaluatedPropertiesType(schema, type, request);\n if (unevaluated === null) {\n return type;\n }\n if (type === null) {\n return unevaluated;\n }\n // One flat intersection, so an `allOf` intersection is not printed in parentheses.\n const parts = type.kind === \"intersection\" ? type.types : [type];\n return intersectionOf([...parts, unevaluated]);\n}\n\n/**\n * The schema with composition: core type and `allOf` intersected, then `anyOf` and `oneOf`. Without\n * any of them: `Record<string, never>` (or `unknown` with `--empty-objects-unknown`) when `type` is\n * present, else `unknown`. `nullable: true` adds `null`, except to the shared `unknown`.\n */\nexport function compositionType(schema: SchemaObject, request: SchemaRequest): IrType {\n const { emptyObjectsUnknown } = request.context.options;\n const empty =\n \"type\" in schema\n ? irRecord(irKeyword(\"string\"), emptyObjectsUnknown ? UNKNOWN_TYPE : irKeyword(\"never\"))\n : UNKNOWN_TYPE;\n const type = combinedType(schema, request) ?? empty;\n return type !== UNKNOWN_TYPE && schema.nullable ? nullableOf([type]) : type;\n}\n"],"names":["createRef","OutputFix","withRequiredKeys","requirableRefType","unionItemOf","unionOwnKeywords","omitKeys","isPrimitiveType","unionOf","intersectionOf","coreType","allOfMembers","requiredVariantsType","unevaluatedPropertiesType","irRecord","irKeyword","UNKNOWN_TYPE","nullableOf"],"mappings":";;;;;;;;;;;;;;AAuBA,SAAS,YAAA,CACP,QAAA,EACA,OAAA,EACA,OAAA,EACU;AACV,EAAA,OAAO,QAAA,CAAS,GAAA;AAAA,IAAI,CAAC,OAAA,EAAS,KAAA,KAC5B,OAAA,CAAQ,gBAAgB,OAAA,EAAS;AAAA,MAC/B,GAAG,OAAA,CAAQ,QAAA;AAAA,MACX,IAAA,EAAMA,qBAAA,CAAU,CAAC,OAAA,CAAQ,QAAA,CAAS,MAAM,OAAA,EAAS,MAAA,CAAO,KAAK,CAAC,CAAC;AAAA,KAChE;AAAA,GACH;AACF;AAMA,SAAS,UAAU,IAAA,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AAM,MAAA,GAAS,CAAA,GAAI,SAAA,CAAU,IAAA,EAAM,KAAK,CAAA,GAAI,IAAA;AACrD;AAGA,SAAS,YAAA,CAAa,QAAsB,OAAA,EAAuC;AACjF,EAAA,MAAM,IAAA,GAAO,YAAA,CAAa,MAAA,EAAQ,OAAO,CAAA;AACzC,EAAA,MAAM,WAAA,GAAcC,+CAAA,CAA0B,MAAA,EAAQ,IAAA,EAAM,OAAO,CAAA;AACnE,EAAA,IAAI,gBAAgB,IAAA,EAAM;AACxB,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,IAAI,SAAS,IAAA,EAAM;AACjB,IAAA,OAAO,WAAA;AAAA,EACT;AAEA,EAAA,MAAM,QAAQ,IAAA,CAAK,IAAA,KAAS,iBAAiB,IAAA,CAAK,KAAA,GAAQ,CAAC,IAAI,CAAA;AAC/D,EAAA,OAAOJ,8BAAA,CAAe,CAAC,GAAG,KAAA,EAAO,WAAW,CAAC,CAAA;AAC/C;AAOO,SAAS,eAAA,CAAgB,QAAsB,OAAA,EAAgC;AACpF,EAAA,MAAM,EAAE,mBAAA,EAAoB,GAAI,OAAA,CAAQ,OAAA,CAAQ,OAAA;AAChD,EAAA,MAAM,KAAA,GACJ,MAAA,IAAU,MAAA,GACNK,qBAAA,CAASC,sBAAA,CAAU,QAAQ,CAAA,EAAG,mBAAA,GAAsBC,wBAAA,GAAeD,sBAAA,CAAU,OAAO,CAAC,CAAA,GACrFC,wBAAA;AACN,EAAA,MAAM,IAAA,GAAO,YAAA,CAAa,MAAA,EAAQ,OAAO,CAAA,IAAK,KAAA;AAC9C,EAAA,OAAO,IAAA,KAASA,4BAAgB,MAAA,CAAO,QAAA,GAAWC,2BAAW,CAAC,IAAI,CAAC,CAAA,GAAI,IAAA;AACzE;;"}
@@ -1,10 +1,13 @@
1
1
  import { irRecord, irKeyword } from '../../../domain/ir/constructors.mjs';
2
2
  import { createRef } from '../../../domain/openapi/json-pointer.mjs';
3
3
  import { OutputFix } from '../../../domain/output-fixes.mjs';
4
+ import { requirableRefType } from '../ref-pointer/pointer-type.mjs';
4
5
  import { UNKNOWN_TYPE } from '../shared-types.mjs';
5
6
  import { nullableOf, intersectionOf, omitKeys, unionOf, isPrimitiveType, withRequiredKeys } from '../type-combinators.mjs';
6
7
  import { coreType } from './core-type.mjs';
8
+ import { unionItemOf, unionOwnKeywords } from './discriminated-union.mjs';
7
9
  import { allOfMembers } from './presence-members.mjs';
10
+ import { requiredVariantsType } from './required-variants.mjs';
8
11
  import { unevaluatedPropertiesType } from './unevaluated-properties.mjs';
9
12
 
10
13
  function variantTypes(variants, keyword, request) {
@@ -18,19 +21,28 @@ function variantTypes(variants, keyword, request) {
18
21
  function isRefItem(item) {
19
22
  return "$ref" in item;
20
23
  }
24
+ function keysToRequire(ref, target, required, request) {
25
+ const defined = required.filter((key) => Boolean(target.properties?.[key]));
26
+ if (!request.context.discriminators.isHandled(ref)) {
27
+ return defined;
28
+ }
29
+ if (!request.context.options.fixes.has(OutputFix.DISCRIMINATOR_MEMBER_REQUIRED)) {
30
+ return [];
31
+ }
32
+ return defined.filter((key) => !target.required?.includes(key));
33
+ }
21
34
  function refItemType(item, required, request) {
22
35
  const type = request.transformNested(item, request.location);
23
- const { refs, discriminators, footer } = request.context;
24
- const resolved = refs.resolve(item.$ref);
25
- const isEligible = resolved && typeof resolved === "object" && "properties" in resolved && !discriminators.isHandled(item.$ref);
26
- if (!isEligible) {
36
+ const resolved = request.context.refs.resolve(item.$ref);
37
+ if (!resolved || typeof resolved !== "object" || !("properties" in resolved)) {
27
38
  return type;
28
39
  }
29
- const keys = required.filter((key) => Boolean(resolved.properties?.[key]));
30
- if (keys.length > 0) {
31
- footer.requireWithRequired();
40
+ const keys = keysToRequire(item.$ref, resolved, required, request);
41
+ if (keys.length === 0) {
42
+ return type;
32
43
  }
33
- return withRequiredKeys(type, keys);
44
+ request.context.footer.requireWithRequired();
45
+ return withRequiredKeys(requirableRefType(item.$ref, type, request), keys);
34
46
  }
35
47
  function inlineItemType(item, required, request) {
36
48
  const own = typeof item === "object" && Array.isArray(item.required) ? item.required ?? [] : [];
@@ -39,13 +51,29 @@ function inlineItemType(item, required, request) {
39
51
  request.location
40
52
  );
41
53
  }
54
+ function ownKeywordsType(own, ref, request) {
55
+ return combinedType(own, { ...request, location: { ...request.location, path: ref } });
56
+ }
57
+ function allOfItemType(item, required, request) {
58
+ const isRef = isRefItem(item);
59
+ const discriminator = isRef && request.context.discriminators.objectAt(item.$ref) || item.discriminator;
60
+ const propertyName = discriminator?.propertyName;
61
+ const unionItem = isRef && propertyName ? unionItemOf(item.$ref, request) : void 0;
62
+ if (isRef && propertyName && unionItem?.isMember) {
63
+ const own = unionOwnKeywords(unionItem.union, propertyName, required);
64
+ return ownKeywordsType(own, item.$ref, request);
65
+ }
66
+ const type = isRef ? refItemType(item, required, request) : inlineItemType(item, required, request);
67
+ const isUnion = unionItem !== void 0 && !unionItem.isMapped && request.context.options.fixes.has(OutputFix.ALLOF_DISCRIMINATED_UNION);
68
+ if (!propertyName || isUnion) {
69
+ return type;
70
+ }
71
+ const { path } = request.location;
72
+ const others = path === void 0 ? [] : request.context.discriminators.otherPropertiesAt(path);
73
+ return omitKeys(type, [propertyName, ...others]);
74
+ }
42
75
  function allOfTypes(items, required, request) {
43
- return items.map((item) => {
44
- const isRef = isRefItem(item);
45
- const type = isRef ? refItemType(item, required, request) : inlineItemType(item, required, request);
46
- const discriminator = isRef && request.context.discriminators.objectAt(item.$ref) || item.discriminator;
47
- return discriminator?.propertyName ? omitKeys(type, [discriminator.propertyName]) : type;
48
- });
76
+ return items.flatMap((item) => allOfItemType(item, required, request) ?? []);
49
77
  }
50
78
  function oneOfType(previous, variants) {
51
79
  const before = previous === null ? [] : [previous];
@@ -78,7 +106,14 @@ function composedType(schema, request) {
78
106
  const allOfType = allOf.length > 0 ? [intersectionOf(allOf)] : [];
79
107
  type = intersectionOf([...core === null ? [] : [core], ...allOfType]);
80
108
  }
81
- type = anyOfType(type, schema, request);
109
+ return variantsType(type, schema, request);
110
+ }
111
+ function variantsType(previous, schema, request) {
112
+ const type = requiredVariantsType(previous, schema, schema.anyOf ?? [], request) ?? anyOfType(previous, schema, request);
113
+ const oneOfRequired = requiredVariantsType(type, schema, schema.oneOf ?? [], request);
114
+ if (oneOfRequired !== null) {
115
+ return oneOfRequired;
116
+ }
82
117
  const oneOf = variantTypes(oneOfVariants(schema), "oneOf", request);
83
118
  return oneOf.length > 0 ? oneOfType(type, oneOf) : type;
84
119
  }