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
@@ -1 +1 @@
1
- {"version":3,"file":"composition-type.mjs","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":[],"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,EAAM,SAAA,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,SAAS,WAAA,CACP,IAAA,EACA,QAAA,EACA,OAAA,EACQ;AACR,EAAA,MAAM,IAAA,GAAO,OAAA,CAAQ,eAAA,CAAgB,IAAA,EAAM,QAAQ,QAAQ,CAAA;AAC3D,EAAA,MAAM,EAAE,IAAA,EAAM,cAAA,EAAgB,MAAA,KAAW,OAAA,CAAQ,OAAA;AACjD,EAAA,MAAM,QAAA,GAAW,IAAA,CAAK,OAAA,CAAQ,IAAA,CAAK,IAAI,CAAA;AACvC,EAAA,MAAM,UAAA,GACJ,QAAA,IACA,OAAO,QAAA,KAAa,QAAA,IACpB,YAAA,IAAgB,QAAA,IAChB,CAAC,cAAA,CAAe,SAAA,CAAU,IAAA,CAAK,IAAI,CAAA;AACrC,EAAA,IAAI,CAAC,UAAA,EAAY;AACf,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EA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AAO,YAAA,CAAa,MAAA,EAAQ,OAAO,CAAA;AACzC,EAAA,MAAM,WAAA,GAAc,yBAAA,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,OAAO,cAAA,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,GACN,QAAA,CAAS,SAAA,CAAU,QAAQ,CAAA,EAAG,mBAAA,GAAsB,YAAA,GAAe,SAAA,CAAU,OAAO,CAAC,CAAA,GACrF,YAAA;AACN,EAAA,MAAM,IAAA,GAAO,YAAA,CAAa,MAAA,EAAQ,OAAO,CAAA,IAAK,KAAA;AAC9C,EAAA,OAAO,IAAA,KAAS,gBAAgB,MAAA,CAAO,QAAA,GAAW,WAAW,CAAC,IAAI,CAAC,CAAA,GAAI,IAAA;AACzE;;"}
1
+ {"version":3,"file":"composition-type.mjs","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 : UN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CAAS,SAAA,CAAU,QAAQ,CAAA,EAAG,mBAAA,GAAsB,YAAA,GAAe,SAAA,CAAU,OAAO,CAAC,CAAA,GACrF,YAAA;AACN,EAAA,MAAM,IAAA,GAAO,YAAA,CAAa,MAAA,EAAQ,OAAO,CAAA,IAAK,KAAA;AAC9C,EAAA,OAAO,IAAA,KAAS,gBAAgB,MAAA,CAAO,QAAA,GAAW,WAAW,CAAC,IAAI,CAAC,CAAA,GAAI,IAAA;AACzE;;"}
@@ -5,6 +5,7 @@ const binaryContent = require('../../../domain/openapi/binary-content.cjs');
5
5
  const typeCombinators = require('../type-combinators.cjs');
6
6
  const arrayType = require('./array-type.cjs');
7
7
  const objectType = require('./object-type.cjs');
8
+ const requiredVariants = require('./required-variants.cjs');
8
9
 
9
10
  const PRIMITIVE_TYPE_NAMES = /* @__PURE__ */ new Set([
10
11
  "boolean",
@@ -24,7 +25,8 @@ function multipleTypes(schema, request) {
24
25
  if (isInOneOf) {
25
26
  continue;
26
27
  }
27
- const variant = Array.isArray(oneOf) ? { ...schema, type: typeName, oneOf: void 0 } : { ...schema, type: typeName };
28
+ const isKept = typeName === "object" && requiredVariants.hasRequiredVariants(schema, oneOf ?? [], request);
29
+ const variant = Array.isArray(oneOf) && !isKept ? { ...schema, type: typeName, oneOf: void 0 } : { ...schema, type: typeName };
28
30
  members.push(
29
31
  typeName === "null" || typeName === null ? constructors.irKeyword("null") : request.transformNested(variant, request.location)
30
32
  );
@@ -1 +1 @@
1
- {"version":3,"file":"core-type.cjs","sources":["../../../../src/application/transform/schema/core-type.ts"],"sourcesContent":["import { irKeyword, irReference, irUnion } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { isRawBinarySchema } from \"../../../domain/openapi/binary-content.js\";\nimport type {\n Schema,\n SchemaObject,\n SchemaTypeName,\n} from \"../../../domain/openapi/schema-object.js\";\nimport { unionOf } from \"../type-combinators.js\";\nimport { arrayType } from \"./array-type.js\";\nimport { objectType } from \"./object-type.js\";\nimport type { SchemaRequest, SchemaRule } from \"./schema-rule.js\";\n\nconst PRIMITIVE_TYPE_NAMES: ReadonlySet<SchemaTypeName | null> = new Set([\n \"boolean\",\n \"string\",\n \"number\",\n \"integer\",\n \"null\",\n]);\n\n/** Each `type` of a list becomes a union member; one already listed in `oneOf` is skipped. */\nfunction multipleTypes(schema: SchemaObject, request: SchemaRequest): IrType {\n const typeNames = schema.type as readonly (SchemaTypeName | null)[];\n const { oneOf } = schema;\n const members: IrType[] = [];\n for (const typeName of typeNames) {\n const isInOneOf =\n Array.isArray(oneOf) &&\n PRIMITIVE_TYPE_NAMES.has(typeName) &&\n oneOf.some(\n (variant) => typeof variant === \"object\" && \"type\" in variant && variant.type === typeName,\n );\n if (isInOneOf) {\n continue;\n }\n // With oneOf, the member drops it, so oneOf is not applied once per member.\n const variant = Array.isArray(oneOf)\n ? { ...schema, type: typeName, oneOf: undefined }\n : { ...schema, type: typeName };\n members.push(\n typeName === \"null\" || typeName === null\n ? irKeyword(\"null\")\n : request.transformNested(variant as Schema, request.location),\n );\n }\n return unionOf(members);\n}\n\nfunction keywordRule(\n name: string,\n typeNames: readonly string[],\n keyword: \"null\" | \"number\" | \"boolean\",\n): SchemaRule {\n return {\n name,\n matches: (schema) => typeNames.includes(schema.type as string),\n transform: () => irKeyword(keyword),\n };\n}\n\n/** The global type of raw binary data with `--binary-as-blob` (DOM lib, `@types/node`). */\nconst BLOB_TYPE_NAME = \"Blob\";\n\nfunction isBinaryAsBlob(schema: SchemaObject, request: SchemaRequest): boolean {\n return request.context.options.binaryAsBlob && isRawBinarySchema(schema);\n}\n\nfunction stringType(schema: SchemaObject, request: SchemaRequest): IrType {\n return isBinaryAsBlob(schema, request) ? irReference(BLOB_TYPE_NAME) : irKeyword(\"string\");\n}\n\n/** Rules for schemas with a `type`, in the original order. */\nconst TYPED_RULES: readonly SchemaRule[] = [\n keywordRule(\"null\", [\"null\"], \"null\"),\n { name: \"string\", matches: (schema) => schema.type === \"string\", transform: stringType },\n keywordRule(\"number\", [\"number\", \"integer\"], \"number\"),\n keywordRule(\"boolean\", [\"boolean\"], \"boolean\"),\n { name: \"array\", matches: (schema) => schema.type === \"array\", transform: arrayType },\n {\n name: \"multiple types\",\n matches: (schema) => Array.isArray(schema.type),\n transform: multipleTypes,\n },\n];\n\n/** The `transform` callback's type; a `questionToken` adds `undefined` here. */\nfunction customType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const custom = request.context.callbacks.transform(schema, request.location);\n if (custom === null) {\n return null;\n }\n return custom.isOptional ? irUnion([custom.type, irKeyword(\"undefined\")]) : custom.type;\n}\n\n/**\n * The schema without composition keywords: the `transform` callback, then a typed rule, then raw\n * binary without `type` (OpenAPI 3.1 allows leaving it out), then the object keywords. Null means\n * the schema has no type of its own.\n */\nexport function coreType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n if (\"type\" in schema && schema.type) {\n const custom = customType(schema, request);\n if (custom !== null) {\n return custom;\n }\n const rule = TYPED_RULES.find((candidate) => candidate.matches(schema));\n if (rule !== undefined) {\n return rule.transform(schema, request);\n }\n } else if (isBinaryAsBlob(schema, request)) {\n return irReference(BLOB_TYPE_NAME);\n }\n return objectType(schema, request);\n}\n"],"names":["variant","irKeyword","unionOf","isRawBinarySchema","irReference","arrayType","irUnion","objectType"],"mappings":";;;;;;;;AAaA,MAAM,oBAAA,uBAA+D,GAAA,CAAI;AAAA,EACvE,SAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,SAAA;AAAA,EACA;AACF,CAAC,CAAA;AAGD,SAAS,aAAA,CAAc,QAAsB,OAAA,EAAgC;AAC3E,EAAA,MAAM,YAAY,MAAA,CAAO,IAAA;AACzB,EAAA,MAAM,EAAE,OAAM,GAAI,MAAA;AAClB,EAAA,MAAM,UAAoB,EAAC;AAC3B,EAAA,KAAA,MAAW,YAAY,SAAA,EAAW;AAChC,IAAA,MAAM,SAAA,GACJ,MAAM,OAAA,CAAQ,KAAK,KACn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,EAAM;AACnB,MAAA,OAAO,MAAA;AAAA,IACT;AACA,IAAA,MAAM,IAAA,GAAO,YAAY,IAAA,CAAK,CAAC,cAAc,SAAA,CAAU,OAAA,CAAQ,MAAM,CAAC,CAAA;AACtE,IAAA,IAAI,SAAS,MAAA,EAAW;AACtB,MAAA,OAAO,IAAA,CAAK,SAAA,CAAU,MAAA,EAAQ,OAAO,CAAA;AAAA,IACvC;AAAA,EACF,CAAA,MAAA,IAAW,cAAA,CAAe,MAAA,EAAQ,OAAO,CAAA,EAAG;AAC1C,IAAA,OAAOG,yBAAY,cAAc,CAAA;AAAA,EACnC;AACA,EAAA,OAAOG,qBAAA,CAAW,QAAQ,OAAO,CAAA;AACnC;;"}
1
+ {"version":3,"file":"core-type.cjs","sources":["../../../../src/application/transform/schema/core-type.ts"],"sourcesContent":["import { irKeyword, irReference, irUnion } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { isRawBinarySchema } from \"../../../domain/openapi/binary-content.js\";\nimport type {\n Schema,\n SchemaObject,\n SchemaTypeName,\n} from \"../../../domain/openapi/schema-object.js\";\nimport { unionOf } from \"../type-combinators.js\";\nimport { arrayType } from \"./array-type.js\";\nimport { objectType } from \"./object-type.js\";\nimport { hasRequiredVariants } from \"./required-variants.js\";\nimport type { SchemaRequest, SchemaRule } from \"./schema-rule.js\";\n\nconst PRIMITIVE_TYPE_NAMES: ReadonlySet<SchemaTypeName | null> = new Set([\n \"boolean\",\n \"string\",\n \"number\",\n \"integer\",\n \"null\",\n]);\n\n/** Each `type` of a list becomes a union member; one already listed in `oneOf` is skipped. */\nfunction multipleTypes(schema: SchemaObject, request: SchemaRequest): IrType {\n const typeNames = schema.type as readonly (SchemaTypeName | null)[];\n const { oneOf } = schema;\n const members: IrType[] = [];\n for (const typeName of typeNames) {\n const isInOneOf =\n Array.isArray(oneOf) &&\n PRIMITIVE_TYPE_NAMES.has(typeName) &&\n oneOf.some(\n (variant) => typeof variant === \"object\" && \"type\" in variant && variant.type === typeName,\n );\n if (isInOneOf) {\n continue;\n }\n // With oneOf, the member drops it, so oneOf is not applied once per member. Variants that\n // only require properties (`anyof-oneof-required`) belong to the object member.\n const isKept = typeName === \"object\" && hasRequiredVariants(schema, oneOf ?? [], request);\n const variant =\n Array.isArray(oneOf) && !isKept\n ? { ...schema, type: typeName, oneOf: undefined }\n : { ...schema, type: typeName };\n members.push(\n typeName === \"null\" || typeName === null\n ? irKeyword(\"null\")\n : request.transformNested(variant as Schema, request.location),\n );\n }\n return unionOf(members);\n}\n\nfunction keywordRule(\n name: string,\n typeNames: readonly string[],\n keyword: \"null\" | \"number\" | \"boolean\",\n): SchemaRule {\n return {\n name,\n matches: (schema) => typeNames.includes(schema.type as string),\n transform: () => irKeyword(keyword),\n };\n}\n\n/** The global type of raw binary data with `--binary-as-blob` (DOM lib, `@types/node`). */\nconst BLOB_TYPE_NAME = \"Blob\";\n\nfunction isBinaryAsBlob(schema: SchemaObject, request: SchemaRequest): boolean {\n return request.context.options.binaryAsBlob && isRawBinarySchema(schema);\n}\n\nfunction stringType(schema: SchemaObject, request: SchemaRequest): IrType {\n return isBinaryAsBlob(schema, request) ? irReference(BLOB_TYPE_NAME) : irKeyword(\"string\");\n}\n\n/** Rules for schemas with a `type`, in the original order. */\nconst TYPED_RULES: readonly SchemaRule[] = [\n keywordRule(\"null\", [\"null\"], \"null\"),\n { name: \"string\", matches: (schema) => schema.type === \"string\", transform: stringType },\n keywordRule(\"number\", [\"number\", \"integer\"], \"number\"),\n keywordRule(\"boolean\", [\"boolean\"], \"boolean\"),\n { name: \"array\", matches: (schema) => schema.type === \"array\", transform: arrayType },\n {\n name: \"multiple types\",\n matches: (schema) => Array.isArray(schema.type),\n transform: multipleTypes,\n },\n];\n\n/** The `transform` callback's type; a `questionToken` adds `undefined` here. */\nfunction customType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const custom = request.context.callbacks.transform(schema, request.location);\n if (custom === null) {\n return null;\n }\n return custom.isOptional ? irUnion([custom.type, irKeyword(\"undefined\")]) : custom.type;\n}\n\n/**\n * The schema without composition keywords: the `transform` callback, then a typed rule, then raw\n * binary without `type` (OpenAPI 3.1 allows leaving it out), then the object keywords. Null means\n * the schema has no type of its own.\n */\nexport function coreType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n if (\"type\" in schema && schema.type) {\n const custom = customType(schema, request);\n if (custom !== null) {\n return custom;\n }\n const rule = TYPED_RULES.find((candidate) => candidate.matches(schema));\n if (rule !== undefined) {\n return rule.transform(schema, request);\n }\n } else if (isBinaryAsBlob(schema, request)) {\n return irReference(BLOB_TYPE_NAME);\n }\n return objectType(schema, request);\n}\n"],"names":["variant","hasRequiredVariants","irKeyword","unionOf","isRawBinarySchema","irReference","arrayType","irUnion","objectType"],"mappings":";;;;;;;;;AAcA,MAAM,oBAAA,uBAA+D,GAAA,CAAI;AAAA,EACvE,SAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,SAAA;AAAA,EACA;AACF,CAAC,CAAA;AAGD,SAAS,aAAA,CAAc,QAAsB,OAAA,EAAgC;AAC3E,EAAA,MAAM,YAAY,MAAA,CAAO,IAAA;AACzB,EAAA,MAAM,EAAE,OAAM,GAAI,MAAA;AAClB,EAAA,MAAM,UAAoB,EAAC;AAC3B,EAAA,KAAA,MAAW,YAAY,SAAA,EAAW;AAChC,IAAA,MAAM,SAAA,GACJ,MAAM,OAAA,CAAQ,KAAK,KACnB,oBAAA,CAAqB,GAAA,CAAI,QAAQ,CAAA,IACjC,KAAA,CAAM,IAAA;AAAA,MACJ,CAACA,aAAY,OAAOA,QAAAA,KAAY,YAAY,MAAA,IAAUA,QAAAA,IAAWA,SAAQ,IAAA,KAAS;AAAA,KACpF;AACF,IAAA,IAAI,SAAA,EAAW;AACb,MAAA;AAAA,IACF;AAGA,IAAA,MAAM,MAAA,GAAS,aAAa,QAAA,IAAYC,oCAAA,CAAoB,QAAQ,KAAA,IAAS,IAAI,OAAO,CAAA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U,MAAA,EAAQ,OAAO,CAAA;AAAA,IACvC;AAAA,EACF,CAAA,MAAA,IAAW,cAAA,CAAe,MAAA,EAAQ,OAAO,CAAA,EAAG;AAC1C,IAAA,OAAOG,yBAAY,cAAc,CAAA;AAAA,EACnC;AACA,EAAA,OAAOG,qBAAA,CAAW,QAAQ,OAAO,CAAA;AACnC;;"}
@@ -3,6 +3,7 @@ import { isRawBinarySchema } from '../../../domain/openapi/binary-content.mjs';
3
3
  import { unionOf } from '../type-combinators.mjs';
4
4
  import { arrayType } from './array-type.mjs';
5
5
  import { objectType } from './object-type.mjs';
6
+ import { hasRequiredVariants } from './required-variants.mjs';
6
7
 
7
8
  const PRIMITIVE_TYPE_NAMES = /* @__PURE__ */ new Set([
8
9
  "boolean",
@@ -22,7 +23,8 @@ function multipleTypes(schema, request) {
22
23
  if (isInOneOf) {
23
24
  continue;
24
25
  }
25
- const variant = Array.isArray(oneOf) ? { ...schema, type: typeName, oneOf: void 0 } : { ...schema, type: typeName };
26
+ const isKept = typeName === "object" && hasRequiredVariants(schema, oneOf ?? [], request);
27
+ const variant = Array.isArray(oneOf) && !isKept ? { ...schema, type: typeName, oneOf: void 0 } : { ...schema, type: typeName };
26
28
  members.push(
27
29
  typeName === "null" || typeName === null ? irKeyword("null") : request.transformNested(variant, request.location)
28
30
  );
@@ -1 +1 @@
1
- {"version":3,"file":"core-type.mjs","sources":["../../../../src/application/transform/schema/core-type.ts"],"sourcesContent":["import { irKeyword, irReference, irUnion } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { isRawBinarySchema } from \"../../../domain/openapi/binary-content.js\";\nimport type {\n Schema,\n SchemaObject,\n SchemaTypeName,\n} from \"../../../domain/openapi/schema-object.js\";\nimport { unionOf } from \"../type-combinators.js\";\nimport { arrayType } from \"./array-type.js\";\nimport { objectType } from \"./object-type.js\";\nimport type { SchemaRequest, SchemaRule } from \"./schema-rule.js\";\n\nconst PRIMITIVE_TYPE_NAMES: ReadonlySet<SchemaTypeName | null> = new Set([\n \"boolean\",\n \"string\",\n \"number\",\n \"integer\",\n \"null\",\n]);\n\n/** Each `type` of a list becomes a union member; one already listed in `oneOf` is skipped. */\nfunction multipleTypes(schema: SchemaObject, request: SchemaRequest): IrType {\n const typeNames = schema.type as readonly (SchemaTypeName | null)[];\n const { oneOf } = schema;\n const members: IrType[] = [];\n for (const typeName of typeNames) {\n const isInOneOf =\n Array.isArray(oneOf) &&\n PRIMITIVE_TYPE_NAMES.has(typeName) &&\n oneOf.some(\n (variant) => typeof variant === \"object\" && \"type\" in variant && variant.type === typeName,\n );\n if (isInOneOf) {\n continue;\n }\n // With oneOf, the member drops it, so oneOf is not applied once per member.\n const variant = Array.isArray(oneOf)\n ? { ...schema, type: typeName, oneOf: undefined }\n : { ...schema, type: typeName };\n members.push(\n typeName === \"null\" || typeName === null\n ? irKeyword(\"null\")\n : request.transformNested(variant as Schema, request.location),\n );\n }\n return unionOf(members);\n}\n\nfunction keywordRule(\n name: string,\n typeNames: readonly string[],\n keyword: \"null\" | \"number\" | \"boolean\",\n): SchemaRule {\n return {\n name,\n matches: (schema) => typeNames.includes(schema.type as string),\n transform: () => irKeyword(keyword),\n };\n}\n\n/** The global type of raw binary data with `--binary-as-blob` (DOM lib, `@types/node`). */\nconst BLOB_TYPE_NAME = \"Blob\";\n\nfunction isBinaryAsBlob(schema: SchemaObject, request: SchemaRequest): boolean {\n return request.context.options.binaryAsBlob && isRawBinarySchema(schema);\n}\n\nfunction stringType(schema: SchemaObject, request: SchemaRequest): IrType {\n return isBinaryAsBlob(schema, request) ? irReference(BLOB_TYPE_NAME) : irKeyword(\"string\");\n}\n\n/** Rules for schemas with a `type`, in the original order. */\nconst TYPED_RULES: readonly SchemaRule[] = [\n keywordRule(\"null\", [\"null\"], \"null\"),\n { name: \"string\", matches: (schema) => schema.type === \"string\", transform: stringType },\n keywordRule(\"number\", [\"number\", \"integer\"], \"number\"),\n keywordRule(\"boolean\", [\"boolean\"], \"boolean\"),\n { name: \"array\", matches: (schema) => schema.type === \"array\", transform: arrayType },\n {\n name: \"multiple types\",\n matches: (schema) => Array.isArray(schema.type),\n transform: multipleTypes,\n },\n];\n\n/** The `transform` callback's type; a `questionToken` adds `undefined` here. */\nfunction customType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const custom = request.context.callbacks.transform(schema, request.location);\n if (custom === null) {\n return null;\n }\n return custom.isOptional ? irUnion([custom.type, irKeyword(\"undefined\")]) : custom.type;\n}\n\n/**\n * The schema without composition keywords: the `transform` callback, then a typed rule, then raw\n * binary without `type` (OpenAPI 3.1 allows leaving it out), then the object keywords. Null means\n * the schema has no type of its own.\n */\nexport function coreType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n if (\"type\" in schema && schema.type) {\n const custom = customType(schema, request);\n if (custom !== null) {\n return custom;\n }\n const rule = TYPED_RULES.find((candidate) => candidate.matches(schema));\n if (rule !== undefined) {\n return rule.transform(schema, request);\n }\n } else if (isBinaryAsBlob(schema, request)) {\n return irReference(BLOB_TYPE_NAME);\n }\n return objectType(schema, request);\n}\n"],"names":["variant"],"mappings":";;;;;;AAaA,MAAM,oBAAA,uBAA+D,GAAA,CAAI;AAAA,EACvE,SAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,SAAA;AAAA,EACA;AACF,CAAC,CAAA;AAGD,SAAS,aAAA,CAAc,QAAsB,OAAA,EAAgC;AAC3E,EAAA,MAAM,YAAY,MAAA,CAAO,IAAA;AACzB,EAAA,MAAM,EAAE,OAAM,GAAI,MAAA;AAClB,EAAA,MAAM,UAAoB,EAAC;AAC3B,EAAA,KAAA,MAAW,YAAY,SAAA,EAAW;AAChC,IAAA,MAAM,SAAA,GACJ,MAAM,OAAA,CAAQ,KAAK,KACnB,oBAAA,CAAqB,GAAA,CAAI,QAAQ,CAAA,IACjC,KAAA,CAAM,IAAA;AAAA,MACJ,CAACA,aAAY,OAAOA,QAAAA,KAAY,YAAY,MAAA,IAAUA,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,IAAA,IAAI,SAAS,MAAA,EAAW;AACtB,MAAA,OAAO,IAAA,CAAK,SAAA,CAAU,MAAA,EAAQ,OAAO,CAAA;AAAA,IACvC;AAAA,EACF,CAAA,MAAA,IAAW,cAAA,CAAe,MAAA,EAAQ,OAAO,CAAA,EAAG;AAC1C,IAAA,OAAO,YAAY,cAAc,CAAA;AAAA,EACnC;AACA,EAAA,OAAO,UAAA,CAAW,QAAQ,OAAO,CAAA;AACnC;;"}
1
+ {"version":3,"file":"core-type.mjs","sources":["../../../../src/application/transform/schema/core-type.ts"],"sourcesContent":["import { irKeyword, irReference, irUnion } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { isRawBinarySchema } from \"../../../domain/openapi/binary-content.js\";\nimport type {\n Schema,\n SchemaObject,\n SchemaTypeName,\n} from \"../../../domain/openapi/schema-object.js\";\nimport { unionOf } from \"../type-combinators.js\";\nimport { arrayType } from \"./array-type.js\";\nimport { objectType } from \"./object-type.js\";\nimport { hasRequiredVariants } from \"./required-variants.js\";\nimport type { SchemaRequest, SchemaRule } from \"./schema-rule.js\";\n\nconst PRIMITIVE_TYPE_NAMES: ReadonlySet<SchemaTypeName | null> = new Set([\n \"boolean\",\n \"string\",\n \"number\",\n \"integer\",\n \"null\",\n]);\n\n/** Each `type` of a list becomes a union member; one already listed in `oneOf` is skipped. */\nfunction multipleTypes(schema: SchemaObject, request: SchemaRequest): IrType {\n const typeNames = schema.type as readonly (SchemaTypeName | null)[];\n const { oneOf } = schema;\n const members: IrType[] = [];\n for (const typeName of typeNames) {\n const isInOneOf =\n Array.isArray(oneOf) &&\n PRIMITIVE_TYPE_NAMES.has(typeName) &&\n oneOf.some(\n (variant) => typeof variant === \"object\" && \"type\" in variant && variant.type === typeName,\n );\n if (isInOneOf) {\n continue;\n }\n // With oneOf, the member drops it, so oneOf is not applied once per member. Variants that\n // only require properties (`anyof-oneof-required`) belong to the object member.\n const isKept = typeName === \"object\" && hasRequiredVariants(schema, oneOf ?? [], request);\n const variant =\n Array.isArray(oneOf) && !isKept\n ? { ...schema, type: typeName, oneOf: undefined }\n : { ...schema, type: typeName };\n members.push(\n typeName === \"null\" || typeName === null\n ? irKeyword(\"null\")\n : request.transformNested(variant as Schema, request.location),\n );\n }\n return unionOf(members);\n}\n\nfunction keywordRule(\n name: string,\n typeNames: readonly string[],\n keyword: \"null\" | \"number\" | \"boolean\",\n): SchemaRule {\n return {\n name,\n matches: (schema) => typeNames.includes(schema.type as string),\n transform: () => irKeyword(keyword),\n };\n}\n\n/** The global type of raw binary data with `--binary-as-blob` (DOM lib, `@types/node`). */\nconst BLOB_TYPE_NAME = \"Blob\";\n\nfunction isBinaryAsBlob(schema: SchemaObject, request: SchemaRequest): boolean {\n return request.context.options.binaryAsBlob && isRawBinarySchema(schema);\n}\n\nfunction stringType(schema: SchemaObject, request: SchemaRequest): IrType {\n return isBinaryAsBlob(schema, request) ? irReference(BLOB_TYPE_NAME) : irKeyword(\"string\");\n}\n\n/** Rules for schemas with a `type`, in the original order. */\nconst TYPED_RULES: readonly SchemaRule[] = [\n keywordRule(\"null\", [\"null\"], \"null\"),\n { name: \"string\", matches: (schema) => schema.type === \"string\", transform: stringType },\n keywordRule(\"number\", [\"number\", \"integer\"], \"number\"),\n keywordRule(\"boolean\", [\"boolean\"], \"boolean\"),\n { name: \"array\", matches: (schema) => schema.type === \"array\", transform: arrayType },\n {\n name: \"multiple types\",\n matches: (schema) => Array.isArray(schema.type),\n transform: multipleTypes,\n },\n];\n\n/** The `transform` callback's type; a `questionToken` adds `undefined` here. */\nfunction customType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const custom = request.context.callbacks.transform(schema, request.location);\n if (custom === null) {\n return null;\n }\n return custom.isOptional ? irUnion([custom.type, irKeyword(\"undefined\")]) : custom.type;\n}\n\n/**\n * The schema without composition keywords: the `transform` callback, then a typed rule, then raw\n * binary without `type` (OpenAPI 3.1 allows leaving it out), then the object keywords. Null means\n * the schema has no type of its own.\n */\nexport function coreType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n if (\"type\" in schema && schema.type) {\n const custom = customType(schema, request);\n if (custom !== null) {\n return custom;\n }\n const rule = TYPED_RULES.find((candidate) => candidate.matches(schema));\n if (rule !== undefined) {\n return rule.transform(schema, request);\n }\n } else if (isBinaryAsBlob(schema, request)) {\n return irReference(BLOB_TYPE_NAME);\n }\n return objectType(schema, request);\n}\n"],"names":["variant"],"mappings":";;;;;;;AAcA,MAAM,oBAAA,uBAA+D,GAAA,CAAI;AAAA,EACvE,SAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,SAAA;AAAA,EACA;AACF,CAAC,CAAA;AAGD,SAAS,aAAA,CAAc,QAAsB,OAAA,EAAgC;AAC3E,EAAA,MAAM,YAAY,MAAA,CAAO,IAAA;AACzB,EAAA,MAAM,EAAE,OAAM,GAAI,MAAA;AAClB,EAAA,MAAM,UAAoB,EAAC;AAC3B,EAAA,KAAA,MAAW,YAAY,SAAA,EAAW;AAChC,IAAA,MAAM,SAAA,GACJ,MAAM,OAAA,CAAQ,KAAK,KACnB,oBAAA,CAAqB,GAAA,CAAI,QAAQ,CAAA,IACjC,KAAA,CAAM,IAAA;AAAA,MACJ,CAACA,aAAY,OAAOA,QAAAA,KAAY,YAAY,MAAA,IAAUA,QAAAA,IAAWA,SAAQ,IAAA,KAAS;AAAA,KACpF;AACF,IAAA,IAAI,SAAA,EAAW;AACb,MAAA;AAAA,IACF;AAGA,IAAA,MAAM,MAAA,GAAS,aAAa,QAAA,IAAY,mBAAA,CAAoB,QAAQ,KAAA,IAAS,IAAI,OAAO,CAAA;AACxF,IAAA,MAAM,UACJ,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,IAAK,CAAC,SACrB,EAAE,GAAG,QAAQ,IAAA,EAAM,QAAA,EAAU,OAAO,MAAA,EAAU,GAC9C,EAAE,GAAG,MAAA,EAAQ,MAAM,QAAA,EAAS;AAClC,IAAA,OAAA,CAAQ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@@
1
+ 'use strict';
2
+
3
+ const discriminatedUnion = require('../../../domain/openapi/discriminated-union.cjs');
4
+
5
+ function unionItemOf(ref, request) {
6
+ const path = request.location.path;
7
+ const resolve = (target) => request.context.refs.resolve(target);
8
+ const union = discriminatedUnion.unionAt(ref, resolve);
9
+ if (union === void 0) {
10
+ return void 0;
11
+ }
12
+ const isMember = path !== void 0 && discriminatedUnion.unionReaches(union, path, resolve);
13
+ return { union, isMember, isMapped: path !== void 0 && discriminatedUnion.unionMaps(union, path) };
14
+ }
15
+ function withoutKey(record, key) {
16
+ return Object.fromEntries(Object.entries(record).filter(([name]) => name !== key));
17
+ }
18
+ function unionOwnKeywords(union, propertyName, required) {
19
+ const { oneOf: _oneOf, anyOf: _anyOf, ...own } = union;
20
+ const ownRequired = (union.required ?? []).filter((key) => key !== propertyName);
21
+ return {
22
+ ...own,
23
+ ...union.properties === void 0 ? {} : { properties: withoutKey(union.properties, propertyName) },
24
+ required: [...required, ...ownRequired]
25
+ };
26
+ }
27
+
28
+ exports.unionItemOf = unionItemOf;
29
+ exports.unionOwnKeywords = unionOwnKeywords;
30
+ //# sourceMappingURL=discriminated-union.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discriminated-union.cjs","sources":["../../../../src/application/transform/schema/discriminated-union.ts"],"sourcesContent":["import { unionAt, unionMaps, unionReaches } from \"../../../domain/openapi/discriminated-union.js\";\nimport type { SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\n\n/**\n * `allOf` items that are a `$ref` to a discriminated union (`oneOf` / `anyOf` and a\n * discriminator). Such an item cannot be typed as the parent of the inheritance pattern,\n * `Omit<Union, \"kind\">`.\n */\n\n/** The union an `allOf` item refers to, and whether the union's type contains this schema. */\nexport interface UnionItem {\n readonly union: SchemaObject;\n /**\n * The schema is one of the union's members: intersecting the union would make it refer to\n * itself, which does not compile (TS2502, upstream #1665).\n */\n readonly isMember: boolean;\n /** The union's mapping names the schema, so it is a member even where the type is not. */\n readonly isMapped: boolean;\n}\n\n/** The union at `ref`, if the schema there is one. */\nexport function unionItemOf(ref: string, request: SchemaRequest): UnionItem | undefined {\n const path = request.location.path;\n const resolve = (target: string) => request.context.refs.resolve(target);\n const union = unionAt(ref, resolve);\n if (union === undefined) {\n return undefined;\n }\n const isMember = path !== undefined && unionReaches(union, path, resolve);\n return { union, isMember, isMapped: path !== undefined && unionMaps(union, path) };\n}\n\nfunction withoutKey<T>(record: Readonly<Record<string, T>>, key: string): Record<string, T> {\n return Object.fromEntries(Object.entries(record).filter(([name]) => name !== key));\n}\n\n/**\n * The keywords of a union that its members inherit: everything but the members and the\n * discriminator property, which each member redefines (as `Omit` does for a parent). The item's\n * `required` keys are added, as for an inline `allOf` item.\n */\nexport function unionOwnKeywords(\n union: SchemaObject,\n propertyName: string,\n required: readonly string[],\n): SchemaObject {\n const { oneOf: _oneOf, anyOf: _anyOf, ...own } = union;\n const ownRequired = (union.required ?? []).filter((key) => key !== propertyName);\n return {\n ...own,\n ...(union.properties === undefined\n ? {}\n : { properties: withoutKey(union.properties, propertyName) }),\n required: [...required, ...ownRequired],\n };\n}\n"],"names":["unionAt","unionReaches","unionMaps"],"mappings":";;;;AAuBO,SAAS,WAAA,CAAY,KAAa,OAAA,EAA+C;AACtF,EAAA,MAAM,IAAA,GAAO,QAAQ,QAAA,CAAS,IAAA;AAC9B,EAAA,MAAM,UAAU,CAAC,MAAA,KAAmB,QAAQ,OAAA,CAAQ,IAAA,CAAK,QAAQ,MAAM,CAAA;AACvE,EAAA,MAAM,KAAA,GAAQA,0BAAA,CAAQ,GAAA,EAAK,OAAO,CAAA;AAClC,EAAA,IAAI,UAAU,MAAA,EAAW;AACvB,IAAA,OAAO,MAAA;AAAA,EACT;AACA,EAAA,MAAM,WAAW,IAAA,KAAS,MAAA,IAAaC,+BAAA,CAAa,KAAA,EAAO,MAAM,OAAO,CAAA;AACxE,EAAA,OAAO,EAAE,OAAO,QAAA,EAAU,QAAA,EAAU,SAAS,MAAA,IAAaC,4BAAA,CAAU,KAAA,EAAO,IAAI,CAAA,EAAE;AACnF;AAEA,SAAS,UAAA,CAAc,QAAqC,GAAA,EAAgC;AAC1F,EAAA,OAAO,MAAA,CAAO,WAAA,CAAY,MAAA,CAAO,OAAA,CAAQ,MAAM,CAAA,CAAE,MAAA,CAAO,CAAC,CAAC,IAAI,CAAA,KAAM,IAAA,KAAS,GAAG,CAAC,CAAA;AACnF;AAOO,SAAS,gBAAA,CACd,KAAA,EACA,YAAA,EACA,QAAA,EACc;AACd,EAAA,MAAM,EAAE,KAAA,EAAO,MAAA,EAAQ,OAAO,MAAA,EAAQ,GAAG,KAAI,GAAI,KAAA;AACjD,EAAA,MAAM,WAAA,GAAA,CAAe,MAAM,QAAA,IAAY,IAAI,MAAA,CAAO,CAAC,GAAA,KAAQ,GAAA,KAAQ,YAAY,CAAA;AAC/E,EAAA,OAAO;AAAA,IACL,GAAG,GAAA;AAAA,IACH,GAAI,KAAA,CAAM,UAAA,KAAe,MAAA,GACrB,EAAC,GACD,EAAE,UAAA,EAAY,UAAA,CAAW,KAAA,CAAM,UAAA,EAAY,YAAY,CAAA,EAAE;AAAA,IAC7D,QAAA,EAAU,CAAC,GAAG,QAAA,EAAU,GAAG,WAAW;AAAA,GACxC;AACF;;;"}
@@ -0,0 +1,27 @@
1
+ import { unionAt, unionReaches, unionMaps } from '../../../domain/openapi/discriminated-union.mjs';
2
+
3
+ function unionItemOf(ref, request) {
4
+ const path = request.location.path;
5
+ const resolve = (target) => request.context.refs.resolve(target);
6
+ const union = unionAt(ref, resolve);
7
+ if (union === void 0) {
8
+ return void 0;
9
+ }
10
+ const isMember = path !== void 0 && unionReaches(union, path, resolve);
11
+ return { union, isMember, isMapped: path !== void 0 && unionMaps(union, path) };
12
+ }
13
+ function withoutKey(record, key) {
14
+ return Object.fromEntries(Object.entries(record).filter(([name]) => name !== key));
15
+ }
16
+ function unionOwnKeywords(union, propertyName, required) {
17
+ const { oneOf: _oneOf, anyOf: _anyOf, ...own } = union;
18
+ const ownRequired = (union.required ?? []).filter((key) => key !== propertyName);
19
+ return {
20
+ ...own,
21
+ ...union.properties === void 0 ? {} : { properties: withoutKey(union.properties, propertyName) },
22
+ required: [...required, ...ownRequired]
23
+ };
24
+ }
25
+
26
+ export { unionItemOf, unionOwnKeywords };
27
+ //# sourceMappingURL=discriminated-union.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discriminated-union.mjs","sources":["../../../../src/application/transform/schema/discriminated-union.ts"],"sourcesContent":["import { unionAt, unionMaps, unionReaches } from \"../../../domain/openapi/discriminated-union.js\";\nimport type { SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\n\n/**\n * `allOf` items that are a `$ref` to a discriminated union (`oneOf` / `anyOf` and a\n * discriminator). Such an item cannot be typed as the parent of the inheritance pattern,\n * `Omit<Union, \"kind\">`.\n */\n\n/** The union an `allOf` item refers to, and whether the union's type contains this schema. */\nexport interface UnionItem {\n readonly union: SchemaObject;\n /**\n * The schema is one of the union's members: intersecting the union would make it refer to\n * itself, which does not compile (TS2502, upstream #1665).\n */\n readonly isMember: boolean;\n /** The union's mapping names the schema, so it is a member even where the type is not. */\n readonly isMapped: boolean;\n}\n\n/** The union at `ref`, if the schema there is one. */\nexport function unionItemOf(ref: string, request: SchemaRequest): UnionItem | undefined {\n const path = request.location.path;\n const resolve = (target: string) => request.context.refs.resolve(target);\n const union = unionAt(ref, resolve);\n if (union === undefined) {\n return undefined;\n }\n const isMember = path !== undefined && unionReaches(union, path, resolve);\n return { union, isMember, isMapped: path !== undefined && unionMaps(union, path) };\n}\n\nfunction withoutKey<T>(record: Readonly<Record<string, T>>, key: string): Record<string, T> {\n return Object.fromEntries(Object.entries(record).filter(([name]) => name !== key));\n}\n\n/**\n * The keywords of a union that its members inherit: everything but the members and the\n * discriminator property, which each member redefines (as `Omit` does for a parent). The item's\n * `required` keys are added, as for an inline `allOf` item.\n */\nexport function unionOwnKeywords(\n union: SchemaObject,\n propertyName: string,\n required: readonly string[],\n): SchemaObject {\n const { oneOf: _oneOf, anyOf: _anyOf, ...own } = union;\n const ownRequired = (union.required ?? []).filter((key) => key !== propertyName);\n return {\n ...own,\n ...(union.properties === undefined\n ? {}\n : { properties: withoutKey(union.properties, propertyName) }),\n required: [...required, ...ownRequired],\n };\n}\n"],"names":[],"mappings":";;AAuBO,SAAS,WAAA,CAAY,KAAa,OAAA,EAA+C;AACtF,EAAA,MAAM,IAAA,GAAO,QAAQ,QAAA,CAAS,IAAA;AAC9B,EAAA,MAAM,UAAU,CAAC,MAAA,KAAmB,QAAQ,OAAA,CAAQ,IAAA,CAAK,QAAQ,MAAM,CAAA;AACvE,EAAA,MAAM,KAAA,GAAQ,OAAA,CAAQ,GAAA,EAAK,OAAO,CAAA;AAClC,EAAA,IAAI,UAAU,MAAA,EAAW;AACvB,IAAA,OAAO,MAAA;AAAA,EACT;AACA,EAAA,MAAM,WAAW,IAAA,KAAS,MAAA,IAAa,YAAA,CAAa,KAAA,EAAO,MAAM,OAAO,CAAA;AACxE,EAAA,OAAO,EAAE,OAAO,QAAA,EAAU,QAAA,EAAU,SAAS,MAAA,IAAa,SAAA,CAAU,KAAA,EAAO,IAAI,CAAA,EAAE;AACnF;AAEA,SAAS,UAAA,CAAc,QAAqC,GAAA,EAAgC;AAC1F,EAAA,OAAO,MAAA,CAAO,WAAA,CAAY,MAAA,CAAO,OAAA,CAAQ,MAAM,CAAA,CAAE,MAAA,CAAO,CAAC,CAAC,IAAI,CAAA,KAAM,IAAA,KAAS,GAAG,CAAC,CAAA;AACnF;AAOO,SAAS,gBAAA,CACd,KAAA,EACA,YAAA,EACA,QAAA,EACc;AACd,EAAA,MAAM,EAAE,KAAA,EAAO,MAAA,EAAQ,OAAO,MAAA,EAAQ,GAAG,KAAI,GAAI,KAAA;AACjD,EAAA,MAAM,WAAA,GAAA,CAAe,MAAM,QAAA,IAAY,IAAI,MAAA,CAAO,CAAC,GAAA,KAAQ,GAAA,KAAQ,YAAY,CAAA;AAC/E,EAAA,OAAO;AAAA,IACL,GAAG,GAAA;AAAA,IACH,GAAI,KAAA,CAAM,UAAA,KAAe,MAAA,GACrB,EAAC,GACD,EAAE,UAAA,EAAY,UAAA,CAAW,KAAA,CAAM,UAAA,EAAY,YAAY,CAAA,EAAE;AAAA,IAC7D,QAAA,EAAU,CAAC,GAAG,QAAA,EAAU,GAAG,WAAW;AAAA,GACxC;AACF;;"}
@@ -12,9 +12,10 @@ function discriminatorValue(discriminator, path) {
12
12
  );
13
13
  return match ? match[0] : name;
14
14
  }
15
- function discriminatorProperty(discriminator, path, isReadonly) {
15
+ function discriminatorProperty(discriminator, path, isReadonly, valueType = () => null) {
16
16
  const value = discriminatorValue(discriminator, path);
17
- return constructors.irProperty(propertyName.toPropertyName(discriminator.propertyName), literalType.literalType(value), { isReadonly });
17
+ const type = valueType(value) ?? literalType.literalType(value);
18
+ return constructors.irProperty(propertyName.toPropertyName(discriminator.propertyName), type, { isReadonly });
18
19
  }
19
20
 
20
21
  exports.discriminatorProperty = discriminatorProperty;
@@ -1 +1 @@
1
- {"version":3,"file":"discriminator-property.cjs","sources":["../../../../src/application/transform/schema/discriminator-property.ts"],"sourcesContent":["import { irProperty } from \"../../../domain/ir/constructors.js\";\nimport type { IrPropertySignature } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { parseRefPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport { literalType } from \"../literal-type.js\";\nimport type { Discriminator } from \"./schema-context.js\";\n\n/**\n * The value a schema has for its parent's discriminator: the mapping key whose target is this\n * schema (a full `$ref` or a bare schema name), else the schema's own name (the last segment).\n */\nfunction discriminatorValue(discriminator: Discriminator, path: string): string | undefined {\n const name = parseRefPointer(path).pop();\n const match = Object.entries(discriminator.mapping ?? {}).find(([, target]) =>\n target.startsWith(\"#\") ? parseRefPointer(target).pop() === name : target === name,\n );\n return match ? match[0] : name;\n}\n\n/** The discriminator property, typed as its literal value (`createDiscriminatorProperty`). */\nexport function discriminatorProperty(\n discriminator: Discriminator,\n path: string,\n isReadonly: boolean,\n): IrPropertySignature {\n const value = discriminatorValue(discriminator, path);\n return irProperty(toPropertyName(discriminator.propertyName), literalType(value), { isReadonly });\n}\n"],"names":["parseRefPointer","irProperty","toPropertyName","literalType"],"mappings":";;;;;;;AAWA,SAAS,kBAAA,CAAmB,eAA8B,IAAA,EAAkC;AAC1F,EAAA,MAAM,IAAA,GAAOA,2BAAA,CAAgB,IAAI,CAAA,CAAE,GAAA,EAAI;AACvC,EAAA,MAAM,QAAQ,MAAA,CAAO,OAAA,CAAQ,cAAc,OAAA,IAAW,EAAE,CAAA,CAAE,IAAA;AAAA,IAAK,CAAC,GAAG,MAAM,MACvE,MAAA,CAAO,UAAA,CAAW,GAAG,CAAA,GAAIA,4BAAgB,MAAM,CAAA,CAAE,GAAA,EAAI,KAAM,OAAO,MAAA,KAAW;AAAA,GAC/E;AACA,EAAA,OAAO,KAAA,GAAQ,KAAA,CAAM,CAAC,CAAA,GAAI,IAAA;AAC5B;AAGO,SAAS,qBAAA,CACd,aAAA,EACA,IAAA,EACA,UAAA,EACqB;AACrB,EAAA,MAAM,KAAA,GAAQ,kBAAA,CAAmB,aAAA,EAAe,IAAI,CAAA;AACpD,EAAA,OAAOC,uBAAA,CAAWC,2BAAA,CAAe,aAAA,CAAc,YAAY,CAAA,EAAGC,wBAAY,KAAK,CAAA,EAAG,EAAE,UAAA,EAAY,CAAA;AAClG;;"}
1
+ {"version":3,"file":"discriminator-property.cjs","sources":["../../../../src/application/transform/schema/discriminator-property.ts"],"sourcesContent":["import { irProperty } from \"../../../domain/ir/constructors.js\";\nimport type { IrPropertySignature, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { parseRefPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport { literalType } from \"../literal-type.js\";\nimport type { Discriminator } from \"./schema-context.js\";\n\n/**\n * The value a schema has for its parent's discriminator: the mapping key whose target is this\n * schema (a full `$ref` or a bare schema name), else the schema's own name (the last segment).\n */\nfunction discriminatorValue(discriminator: Discriminator, path: string): string | undefined {\n const name = parseRefPointer(path).pop();\n const match = Object.entries(discriminator.mapping ?? {}).find(([, target]) =>\n target.startsWith(\"#\") ? parseRefPointer(target).pop() === name : target === name,\n );\n return match ? match[0] : name;\n}\n\n/**\n * The discriminator property, typed as its literal value (`createDiscriminatorProperty`), or as\n * `valueType` gives it; `valueType` returns null to keep the literal.\n */\nexport function discriminatorProperty(\n discriminator: Discriminator,\n path: string,\n isReadonly: boolean,\n valueType: (value: string | undefined) => IrType | null = () => null,\n): IrPropertySignature {\n const value = discriminatorValue(discriminator, path);\n const type = valueType(value) ?? literalType(value);\n return irProperty(toPropertyName(discriminator.propertyName), type, { isReadonly });\n}\n"],"names":["parseRefPointer","literalType","irProperty","toPropertyName"],"mappings":";;;;;;;AAWA,SAAS,kBAAA,CAAmB,eAA8B,IAAA,EAAkC;AAC1F,EAAA,MAAM,IAAA,GAAOA,2BAAA,CAAgB,IAAI,CAAA,CAAE,GAAA,EAAI;AACvC,EAAA,MAAM,QAAQ,MAAA,CAAO,OAAA,CAAQ,cAAc,OAAA,IAAW,EAAE,CAAA,CAAE,IAAA;AAAA,IAAK,CAAC,GAAG,MAAM,MACvE,MAAA,CAAO,UAAA,CAAW,GAAG,CAAA,GAAIA,4BAAgB,MAAM,CAAA,CAAE,GAAA,EAAI,KAAM,OAAO,MAAA,KAAW;AAAA,GAC/E;AACA,EAAA,OAAO,KAAA,GAAQ,KAAA,CAAM,CAAC,CAAA,GAAI,IAAA;AAC5B;AAMO,SAAS,sBACd,aAAA,EACA,IAAA,EACA,UAAA,EACA,SAAA,GAA0D,MAAM,IAAA,EAC3C;AACrB,EAAA,MAAM,KAAA,GAAQ,kBAAA,CAAmB,aAAA,EAAe,IAAI,CAAA;AACpD,EAAA,MAAM,IAAA,GAAO,SAAA,CAAU,KAAK,CAAA,IAAKC,wBAAY,KAAK,CAAA;AAClD,EAAA,OAAOC,uBAAA,CAAWC,4BAAe,aAAA,CAAc,YAAY,GAAG,IAAA,EAAM,EAAE,YAAY,CAAA;AACpF;;"}
@@ -10,9 +10,10 @@ function discriminatorValue(discriminator, path) {
10
10
  );
11
11
  return match ? match[0] : name;
12
12
  }
13
- function discriminatorProperty(discriminator, path, isReadonly) {
13
+ function discriminatorProperty(discriminator, path, isReadonly, valueType = () => null) {
14
14
  const value = discriminatorValue(discriminator, path);
15
- return irProperty(toPropertyName(discriminator.propertyName), literalType(value), { isReadonly });
15
+ const type = valueType(value) ?? literalType(value);
16
+ return irProperty(toPropertyName(discriminator.propertyName), type, { isReadonly });
16
17
  }
17
18
 
18
19
  export { discriminatorProperty };
@@ -1 +1 @@
1
- {"version":3,"file":"discriminator-property.mjs","sources":["../../../../src/application/transform/schema/discriminator-property.ts"],"sourcesContent":["import { irProperty } from \"../../../domain/ir/constructors.js\";\nimport type { IrPropertySignature } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { parseRefPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport { literalType } from \"../literal-type.js\";\nimport type { Discriminator } from \"./schema-context.js\";\n\n/**\n * The value a schema has for its parent's discriminator: the mapping key whose target is this\n * schema (a full `$ref` or a bare schema name), else the schema's own name (the last segment).\n */\nfunction discriminatorValue(discriminator: Discriminator, path: string): string | undefined {\n const name = parseRefPointer(path).pop();\n const match = Object.entries(discriminator.mapping ?? {}).find(([, target]) =>\n target.startsWith(\"#\") ? parseRefPointer(target).pop() === name : target === name,\n );\n return match ? match[0] : name;\n}\n\n/** The discriminator property, typed as its literal value (`createDiscriminatorProperty`). */\nexport function discriminatorProperty(\n discriminator: Discriminator,\n path: string,\n isReadonly: boolean,\n): IrPropertySignature {\n const value = discriminatorValue(discriminator, path);\n return irProperty(toPropertyName(discriminator.propertyName), literalType(value), { isReadonly });\n}\n"],"names":[],"mappings":";;;;;AAWA,SAAS,kBAAA,CAAmB,eAA8B,IAAA,EAAkC;AAC1F,EAAA,MAAM,IAAA,GAAO,eAAA,CAAgB,IAAI,CAAA,CAAE,GAAA,EAAI;AACvC,EAAA,MAAM,QAAQ,MAAA,CAAO,OAAA,CAAQ,cAAc,OAAA,IAAW,EAAE,CAAA,CAAE,IAAA;AAAA,IAAK,CAAC,GAAG,MAAM,MACvE,MAAA,CAAO,UAAA,CAAW,GAAG,CAAA,GAAI,gBAAgB,MAAM,CAAA,CAAE,GAAA,EAAI,KAAM,OAAO,MAAA,KAAW;AAAA,GAC/E;AACA,EAAA,OAAO,KAAA,GAAQ,KAAA,CAAM,CAAC,CAAA,GAAI,IAAA;AAC5B;AAGO,SAAS,qBAAA,CACd,aAAA,EACA,IAAA,EACA,UAAA,EACqB;AACrB,EAAA,MAAM,KAAA,GAAQ,kBAAA,CAAmB,aAAA,EAAe,IAAI,CAAA;AACpD,EAAA,OAAO,UAAA,CAAW,cAAA,CAAe,aAAA,CAAc,YAAY,CAAA,EAAG,YAAY,KAAK,CAAA,EAAG,EAAE,UAAA,EAAY,CAAA;AAClG;;"}
1
+ {"version":3,"file":"discriminator-property.mjs","sources":["../../../../src/application/transform/schema/discriminator-property.ts"],"sourcesContent":["import { irProperty } from \"../../../domain/ir/constructors.js\";\nimport type { IrPropertySignature, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { parseRefPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport { literalType } from \"../literal-type.js\";\nimport type { Discriminator } from \"./schema-context.js\";\n\n/**\n * The value a schema has for its parent's discriminator: the mapping key whose target is this\n * schema (a full `$ref` or a bare schema name), else the schema's own name (the last segment).\n */\nfunction discriminatorValue(discriminator: Discriminator, path: string): string | undefined {\n const name = parseRefPointer(path).pop();\n const match = Object.entries(discriminator.mapping ?? {}).find(([, target]) =>\n target.startsWith(\"#\") ? parseRefPointer(target).pop() === name : target === name,\n );\n return match ? match[0] : name;\n}\n\n/**\n * The discriminator property, typed as its literal value (`createDiscriminatorProperty`), or as\n * `valueType` gives it; `valueType` returns null to keep the literal.\n */\nexport function discriminatorProperty(\n discriminator: Discriminator,\n path: string,\n isReadonly: boolean,\n valueType: (value: string | undefined) => IrType | null = () => null,\n): IrPropertySignature {\n const value = discriminatorValue(discriminator, path);\n const type = valueType(value) ?? literalType(value);\n return irProperty(toPropertyName(discriminator.propertyName), type, { isReadonly });\n}\n"],"names":[],"mappings":";;;;;AAWA,SAAS,kBAAA,CAAmB,eAA8B,IAAA,EAAkC;AAC1F,EAAA,MAAM,IAAA,GAAO,eAAA,CAAgB,IAAI,CAAA,CAAE,GAAA,EAAI;AACvC,EAAA,MAAM,QAAQ,MAAA,CAAO,OAAA,CAAQ,cAAc,OAAA,IAAW,EAAE,CAAA,CAAE,IAAA;AAAA,IAAK,CAAC,GAAG,MAAM,MACvE,MAAA,CAAO,UAAA,CAAW,GAAG,CAAA,GAAI,gBAAgB,MAAM,CAAA,CAAE,GAAA,EAAI,KAAM,OAAO,MAAA,KAAW;AAAA,GAC/E;AACA,EAAA,OAAO,KAAA,GAAQ,KAAA,CAAM,CAAC,CAAA,GAAI,IAAA;AAC5B;AAMO,SAAS,sBACd,aAAA,EACA,IAAA,EACA,UAAA,EACA,SAAA,GAA0D,MAAM,IAAA,EAC3C;AACrB,EAAA,MAAM,KAAA,GAAQ,kBAAA,CAAmB,aAAA,EAAe,IAAI,CAAA;AACpD,EAAA,MAAM,IAAA,GAAO,SAAA,CAAU,KAAK,CAAA,IAAK,YAAY,KAAK,CAAA;AAClD,EAAA,OAAO,UAAA,CAAW,eAAe,aAAA,CAAc,YAAY,GAAG,IAAA,EAAM,EAAE,YAAY,CAAA;AACpF;;"}
@@ -2,6 +2,7 @@
2
2
 
3
3
  const constructors = require('../../../domain/ir/constructors.cjs');
4
4
  const jsonPointer = require('../../../domain/openapi/json-pointer.cjs');
5
+ const outputFixes = require('../../../domain/output-fixes.cjs');
5
6
  const literalType = require('../literal-type.cjs');
6
7
  const refType = require('../ref-type.cjs');
7
8
  const typeCombinators = require('../type-combinators.cjs');
@@ -15,6 +16,7 @@ function hasAdditionalProperties(schema) {
15
16
  function nameFromPath(path) {
16
17
  return jsonPointer.parseRefPointer(path ?? "").join("/").replace(COMPONENT_SCHEMAS_PREFIX, "");
17
18
  }
19
+ const COMPONENT_SCHEMA_RE = /^#\/components\/schemas\/[^/]+$/;
18
20
  function hasEnumMetadata(schema) {
19
21
  return [
20
22
  schema["x-enum-varnames"],
@@ -23,39 +25,92 @@ function hasEnumMetadata(schema) {
23
25
  schema["x-enumDescriptions"]
24
26
  ].some(Array.isArray);
25
27
  }
28
+ function tsEnumEntries(schema, options) {
29
+ const entries = (schema.enum ?? []).map((value, index) => [value, index]);
30
+ return options.fixes.has(outputFixes.OutputFix.NULLABLE_ENUMS) ? entries.filter(([value]) => value !== null) : entries;
31
+ }
26
32
  function isTsEnum(schema, options) {
27
33
  if (!options.enum || !schema.enum) {
28
34
  return false;
29
35
  }
30
- const isSupported = schema.enum.every((value) => ["string", "number"].includes(typeof value));
36
+ const entries = tsEnumEntries(schema, options);
37
+ const isOnlyNull = entries.length === 0 && schema.enum.length > 0;
38
+ const isSupported = !isOnlyNull && entries.every(([value]) => ["string", "number"].includes(typeof value));
31
39
  return isSupported && (!options.conditionalEnums || hasEnumMetadata(schema));
32
40
  }
33
- function enumMetadata(schema) {
34
- return (schema.enum ?? []).map((_, index) => ({
41
+ function enumMetadata(schema, entries) {
42
+ return entries.map(([, index]) => ({
35
43
  name: schema["x-enum-varnames"]?.[index] ?? schema["x-enumNames"]?.[index],
36
44
  description: schema["x-enum-descriptions"]?.[index] ?? schema["x-enumDescriptions"]?.[index]
37
45
  }));
38
46
  }
47
+ function isNullAllowed(schema) {
48
+ const { type } = schema;
49
+ const isTypeNullable = type === void 0 || Array.isArray(type) && type.includes("null") || Boolean(schema.nullable);
50
+ return (schema.enum ?? []).includes(null) && isTypeNullable;
51
+ }
39
52
  function withOtherStrings(type, schema) {
40
53
  if (!hasAdditionalProperties(schema) || schema.type !== "string") {
41
54
  return type;
42
55
  }
43
56
  return typeCombinators.unionOf([type, typeCombinators.intersectionOf([constructors.irKeyword("string"), constructors.irObject([])])]);
44
57
  }
58
+ function enumRequest(schema, path, options) {
59
+ const entries = tsEnumEntries(schema, options);
60
+ return {
61
+ name: nameFromPath(path),
62
+ isComponentSchema: COMPONENT_SCHEMA_RE.test(path ?? ""),
63
+ values: entries.map(([value]) => value),
64
+ metadata: enumMetadata(schema, entries)
65
+ };
66
+ }
67
+ function enumMemberType(enumName, member) {
68
+ return member.startsWith('"') ? constructors.irIndexedAccess(constructors.irReference(`typeof ${enumName}`), constructors.irString(JSON.parse(member), "escaped")) : constructors.irReference(`${enumName}.${member}`);
69
+ }
70
+ function ownerEnumMembersType(key, values, request) {
71
+ const { options, discriminators, footer } = request.context;
72
+ const parent = options.fixes.has(
73
+ outputFixes.OutputFix.DISCRIMINATOR_VALUES
74
+ ) ? discriminators.enumParentOf(key) : void 0;
75
+ if (parent === void 0 || !isTsEnum(parent.schema, options)) {
76
+ return null;
77
+ }
78
+ const reference = { ...enumRequest(parent.schema, parent.path, options), isOwnerReference: true };
79
+ const name = footer.addEnum(reference);
80
+ const members = footer.enumMembers(name);
81
+ const names = values.map((value) => members.get(value));
82
+ if (names.length === 0 || names.some((member) => member === void 0)) {
83
+ return null;
84
+ }
85
+ return typeCombinators.unionOf(names.map((member) => enumMemberType(name, member)));
86
+ }
45
87
  function tsEnumType(schema, request) {
46
- const name = request.context.footer.addEnum({
47
- name: nameFromPath(request.location.path),
48
- values: schema.enum ?? [],
49
- metadata: enumMetadata(schema)
50
- });
51
- return withOtherStrings(constructors.irReference(name), schema);
88
+ const { options, footer } = request.context;
89
+ const values = tsEnumEntries(schema, options).map(([value]) => value);
90
+ const type = ownerEnumMembersType(schema, values, request) ?? withOtherStrings(
91
+ constructors.irReference(footer.addEnum(enumRequest(schema, request.location.path, options))),
92
+ schema
93
+ );
94
+ return options.fixes.has(outputFixes.OutputFix.NULLABLE_ENUMS) && isNullAllowed(schema) ? typeCombinators.unionOf([type, constructors.irKeyword("null")]) : type;
52
95
  }
53
96
  function isUnionPosition(pointer, index) {
54
97
  const next = pointer[index + 1];
55
98
  return UNION_KEYWORDS.has(pointer[index]) && next !== void 0 && INDEX_RE.test(next);
56
99
  }
100
+ const PARAMETERS = "parameters";
101
+ function pathItemParametersIndex(pointer) {
102
+ if (pointer[0] === "paths" || pointer[0] === "webhooks") {
103
+ return 2;
104
+ }
105
+ return pointer[0] === "components" && pointer[1] === "pathItems" ? 3 : null;
106
+ }
107
+ function withSingleParametersSegment(pointer) {
108
+ const index = pathItemParametersIndex(pointer);
109
+ const isRepeated = index !== null && pointer[index] === PARAMETERS && pointer[index + 1] === PARAMETERS;
110
+ return isRepeated ? [...pointer.slice(0, index), ...pointer.slice(index + 1)] : pointer;
111
+ }
57
112
  function enumValuesPointer(path) {
58
- const pointer = jsonPointer.parseRefPointer(path ?? "");
113
+ const pointer = withSingleParametersSegment(jsonPointer.parseRefPointer(path ?? ""));
59
114
  const kept = [];
60
115
  let firstVariantStart = null;
61
116
  for (let index = 0; index < pointer.length; index++) {
@@ -104,4 +159,5 @@ const enumRule = {
104
159
  };
105
160
 
106
161
  exports.enumRule = enumRule;
162
+ exports.ownerEnumMembersType = ownerEnumMembersType;
107
163
  //# sourceMappingURL=enum-rule.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"enum-rule.cjs","sources":["../../../../src/application/transform/schema/enum-rule.ts"],"sourcesContent":["import {\n irIndexedAccess,\n irKeyword,\n irObject,\n irReference,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { createRef, parseRefPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport type { SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { literalType } from \"../literal-type.js\";\nimport { refType } from \"../ref-type.js\";\nimport { intersectionOf, unionOf } from \"../type-combinators.js\";\nimport type { EnumMemberMetadata, SchemaOptions } from \"./schema-context.js\";\nimport type { SchemaRequest, SchemaRule } from \"./schema-rule.js\";\n\n/** Removed from generated names, so `#/components/schemas/Status` gives `Status`. */\nconst COMPONENT_SCHEMAS_PREFIX = \"components/schemas\";\nconst UNION_KEYWORDS: ReadonlySet<string> = new Set([\"anyOf\", \"oneOf\"]);\nconst INDEX_RE = /^\\d+$/;\n\nfunction hasAdditionalProperties(schema: SchemaObject): boolean {\n return \"additionalProperties\" in schema && Boolean(schema.additionalProperties);\n}\n\n/** A name from the schema's pointer: `#/components/schemas/Pet/status` → `/Pet/status`. */\nfunction nameFromPath(path: string | undefined): string {\n return parseRefPointer(path ?? \"\")\n .join(\"/\")\n .replace(COMPONENT_SCHEMAS_PREFIX, \"\");\n}\n\nfunction hasEnumMetadata(schema: SchemaObject): boolean {\n return [\n schema[\"x-enum-varnames\"],\n schema[\"x-enumNames\"],\n schema[\"x-enum-descriptions\"],\n schema[\"x-enumDescriptions\"],\n ].some(Array.isArray);\n}\n\n/**\n * `--enum`: string and number enums become TypeScript enums. The original meant to allow `null`\n * too, but tested `typeof value` against `null`, so an enum containing null stays a union.\n */\nfunction isTsEnum(schema: SchemaObject, options: SchemaOptions): boolean {\n if (!options.enum || !schema.enum) {\n return false;\n }\n const isSupported = schema.enum.every((value) => [\"string\", \"number\"].includes(typeof value));\n // `--conditional-enums` converts only enums that carry x-enum-* metadata.\n return isSupported && (!options.conditionalEnums || hasEnumMetadata(schema));\n}\n\nfunction enumMetadata(schema: SchemaObject): EnumMemberMetadata[] {\n return (schema.enum ?? []).map((_, index) => ({\n name: schema[\"x-enum-varnames\"]?.[index] ?? schema[\"x-enumNames\"]?.[index],\n description: schema[\"x-enum-descriptions\"]?.[index] ?? schema[\"x-enumDescriptions\"]?.[index],\n }));\n}\n\n/**\n * `additionalProperties: true` on a string enum keeps other strings allowed but still offers the\n * listed values in editors: `\"a\" | \"b\" | (string & {})`.\n */\nfunction withOtherStrings(type: IrType, schema: SchemaObject): IrType {\n if (!hasAdditionalProperties(schema) || schema.type !== \"string\") {\n return type;\n }\n return unionOf([type, intersectionOf([irKeyword(\"string\"), irObject([])])]);\n}\n\nfunction tsEnumType(schema: SchemaObject, request: SchemaRequest): IrType {\n // `isTsEnum` admits only strings and numbers, so there is no null member to split off.\n const name = request.context.footer.addEnum({\n name: nameFromPath(request.location.path),\n values: (schema.enum ?? []) as (string | number)[],\n metadata: enumMetadata(schema),\n });\n return withOtherStrings(irReference(name), schema);\n}\n\nfunction isUnionPosition(pointer: readonly string[], index: number): boolean {\n const next = pointer[index + 1];\n return UNION_KEYWORDS.has(pointer[index] as string) && next !== undefined && INDEX_RE.test(next);\n}\n\n/**\n * The pointer of `--enum-values` arrays without union positions (`anyOf/0`), so names stay\n * stable. Every property after the first union position is narrowed with `Extract`: a no-op where\n * all variants have it, and the needed narrowing where only some do.\n */\nfunction enumValuesPointer(path: string | undefined): { ref: string; extract: string[] } {\n const pointer = parseRefPointer(path ?? \"\");\n const kept: string[] = [];\n let firstVariantStart: number | null = null;\n for (let index = 0; index < pointer.length; index++) {\n if (isUnionPosition(pointer, index)) {\n firstVariantStart ??= index + 2;\n index++;\n continue;\n }\n kept.push(pointer[index] as string);\n }\n const extract =\n firstVariantStart === null\n ? []\n : pointer\n .slice(firstVariantStart)\n .filter((segment) => !UNION_KEYWORDS.has(segment) && !INDEX_RE.test(segment));\n return { ref: createRef(kept), extract };\n}\n\nfunction addEnumValues(schema: SchemaObject, request: SchemaRequest): void {\n const { ref, extract } = enumValuesPointer(request.location.path);\n const valuesType = refType(ref, { isDeep: true, extractProperties: extract });\n request.context.footer.addEnumValues({\n name: `${nameFromPath(request.location.path)}Values`,\n // A record value (`additionalProperties`) is reached by indexing with `string`.\n type: request.isFromAdditionalProperties\n ? irIndexedAccess(valuesType, irReference(\"string\"))\n : valuesType,\n values: (schema.enum ?? []) as (string | number)[],\n });\n}\n\nfunction literalEnumType(schema: SchemaObject, request: SchemaRequest): IrType {\n const values = schema.enum ?? [];\n const isNullable =\n (Array.isArray(schema.type) && schema.type.includes(\"null\")) || Boolean(schema.nullable);\n const literals = [...values.map(literalType), ...(isNullable ? [irKeyword(\"null\")] : [])];\n const type = withOtherStrings(unionOf(literals), schema);\n const isListable = values.every(\n (value) => typeof value === \"string\" || typeof value === \"number\",\n );\n if (request.context.options.enumValues && isListable) {\n addEnumValues(schema, request);\n }\n return type;\n}\n\n/**\n * `enum` on anything but an object (object enums are handled as `oneOf`). With\n * `additionalProperties`, only string enums are handled here; others fall through to composition.\n */\nexport const enumRule: SchemaRule = {\n name: \"enum\",\n matches(schema) {\n const isCandidate =\n Array.isArray(schema.enum) && schema.type !== \"object\" && !(\"properties\" in schema);\n return isCandidate && (!hasAdditionalProperties(schema) || schema.type === \"string\");\n },\n transform(schema, request) {\n return isTsEnum(schema, request.context.options)\n ? tsEnumType(schema, request)\n : literalEnumType(schema, request);\n },\n};\n"],"names":["parseRefPointer","unionOf","intersectionOf","irKeyword","irObject","irReference","createRef","refType","irIndexedAccess","literalType"],"mappings":";;;;;;;;AAgBA,MAAM,wBAAA,GAA2B,oBAAA;AACjC,MAAM,iCAAsC,IAAI,GAAA,CAAI,CAAC,OAAA,EAAS,OAAO,CAAC,CAAA;AACtE,MAAM,QAAA,GAAW,OAAA;AAEjB,SAAS,wBAAwB,MAAA,EAA+B;AAC9D,EAAA,OAAO,sBAAA,IAA0B,MAAA,IAAU,OAAA,CAAQ,MAAA,CAAO,oBAAoB,CAAA;AAChF;AAGA,SAAS,aAAa,IAAA,EAAkC;AACtD,EAAA,OAAOA,2BAAA,CAAgB,QAAQ,EAAE,CAAA,CAC9B,KAAK,GAAG,CAAA,CACR,OAAA,CAAQ,wBAAA,EAA0B,EAAE,CAAA;AACzC;AAEA,SAAS,gBAAgB,MAAA,EAA+B;AACtD,EAAA,OAAO;AAAA,IACL,OAAO,iBAAiB,CAAA;AAAA,IACxB,OAAO,aAAa,CAAA;AAAA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;AACxF,EAAA,MAAM,IAAA,GAAO,gBAAA,CAAiBF,uBAAA,CAAQ,QAAQ,GAAG,MAAM,CAAA;AACvD,EAAA,MAAM,aAAa,MAAA,CAAO,KAAA;AAAA,IACxB,CAAC,KAAA,KAAU,OAAO,KAAA,KAAU,QAAA,IAAY,OAAO,KAAA,KAAU;AAAA,GAC3D;AACA,EAAA,IAAI,OAAA,CAAQ,OAAA,CAAQ,OAAA,CAAQ,UAAA,IAAc,UAAA,EAAY;AACpD,IAAA,aAAA,CAAc,QAAQ,OAAO,CAAA;AAAA,EAC/B;AACA,EAAA,OAAO,IAAA;AACT;AAMO,MAAM,QAAA,GAAuB;AAAA,EAClC,IAAA,EAAM,MAAA;AAAA,EACN,QAAQ,MAAA,EAAQ;AACd,IAAA,MAAM,WAAA,GACJ,KAAA,CAAM,OAAA,CAAQ,MAAA,CAAO,IAAI,KAAK,MAAA,CAAO,IAAA,KAAS,QAAA,IAAY,EAAE,YAAA,IAAgB,MAAA,CAAA;AAC9E,IAAA,OAAO,gBAAgB,CAAC,uBAAA,CAAwB,MAAM,CAAA,IAAK,OAAO,IAAA,KAAS,QAAA,CAAA;AAAA,EAC7E,CAAA;AAAA,EACA,SAAA,CAAU,QAAQ,OAAA,EAAS;AACzB,IAAA,OAAO,QAAA,CAAS,MAAA,EAAQ,OAAA,CAAQ,OAAA,CAAQ,OAAO,CAAA,GAC3C,UAAA,CAAW,MAAA,EAAQ,OAAO,CAAA,GAC1B,eAAA,CAAgB,MAAA,EAAQ,OAAO,CAAA;AAAA,EACrC;AACF;;"}
1
+ {"version":3,"file":"enum-rule.cjs","sources":["../../../../src/application/transform/schema/enum-rule.ts"],"sourcesContent":["import {\n irIndexedAccess,\n irKeyword,\n irObject,\n irReference,\n irString,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { createRef, parseRefPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport type { SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { OutputFix } from \"../../../domain/output-fixes.js\";\nimport { literalType } from \"../literal-type.js\";\nimport { refType } from \"../ref-type.js\";\nimport { intersectionOf, unionOf } from \"../type-combinators.js\";\nimport type {\n DiscriminatorEnumParent,\n EnumDeclarationRequest,\n EnumMemberMetadata,\n SchemaOptions,\n} from \"./schema-context.js\";\nimport type { SchemaRequest, SchemaRule } from \"./schema-rule.js\";\n\n/** Removed from generated names, so `#/components/schemas/Status` gives `Status`. */\nconst COMPONENT_SCHEMAS_PREFIX = \"components/schemas\";\nconst UNION_KEYWORDS: ReadonlySet<string> = new Set([\"anyOf\", \"oneOf\"]);\nconst INDEX_RE = /^\\d+$/;\n\nfunction hasAdditionalProperties(schema: SchemaObject): boolean {\n return \"additionalProperties\" in schema && Boolean(schema.additionalProperties);\n}\n\n/** A name from the schema's pointer: `#/components/schemas/Pet/status` → `/Pet/status`. */\nfunction nameFromPath(path: string | undefined): string {\n return parseRefPointer(path ?? \"\")\n .join(\"/\")\n .replace(COMPONENT_SCHEMAS_PREFIX, \"\");\n}\n\n/** `#/components/schemas/Name`, and no deeper pointer. */\nconst COMPONENT_SCHEMA_RE = /^#\\/components\\/schemas\\/[^/]+$/;\n\nfunction hasEnumMetadata(schema: SchemaObject): boolean {\n return [\n schema[\"x-enum-varnames\"],\n schema[\"x-enumNames\"],\n schema[\"x-enum-descriptions\"],\n schema[\"x-enumDescriptions\"],\n ].some(Array.isArray);\n}\n\n/**\n * The values a TypeScript enum declares, with their positions in `enum`. With the\n * `nullable-enums` fix a `null` value is left out (upstream #1872): an enum member cannot be\n * `null`, so the type adds it as `| null` instead (`tsEnumType`).\n */\nfunction tsEnumEntries(schema: SchemaObject, options: SchemaOptions): [unknown, number][] {\n const entries = (schema.enum ?? []).map((value, index): [unknown, number] => [value, index]);\n return options.fixes.has(OutputFix.NULLABLE_ENUMS)\n ? entries.filter(([value]) => value !== null)\n : entries;\n}\n\n/**\n * `--enum`: string and number enums become TypeScript enums. The original meant to allow `null`\n * too, but tested `typeof value` against `null`, so an enum containing null stays a union; the\n * `nullable-enums` fix declares its other values.\n */\nfunction isTsEnum(schema: SchemaObject, options: SchemaOptions): boolean {\n if (!options.enum || !schema.enum) {\n return false;\n }\n const entries = tsEnumEntries(schema, options);\n // An empty `enum` stays an empty TypeScript enum, as the original made it; an enum of only\n // `null` has no member left once the fix drops `null`, so it stays a union.\n const isOnlyNull = entries.length === 0 && schema.enum.length > 0;\n const isSupported =\n !isOnlyNull && entries.every(([value]) => [\"string\", \"number\"].includes(typeof value));\n // `--conditional-enums` converts only enums that carry x-enum-* metadata.\n return isSupported && (!options.conditionalEnums || hasEnumMetadata(schema));\n}\n\nfunction enumMetadata(\n schema: SchemaObject,\n entries: readonly [unknown, number][],\n): EnumMemberMetadata[] {\n return entries.map(([, index]) => ({\n name: schema[\"x-enum-varnames\"]?.[index] ?? schema[\"x-enumNames\"]?.[index],\n description: schema[\"x-enum-descriptions\"]?.[index] ?? schema[\"x-enumDescriptions\"]?.[index],\n }));\n}\n\n/**\n * Whether `null` is a valid value: it is in `enum` and the schema's type admits it (`type`\n * absent or listing `\"null\"`, or OpenAPI 3.0 `nullable: true`). Both keywords must pass.\n */\nfunction isNullAllowed(schema: SchemaObject): boolean {\n const { type } = schema;\n const isTypeNullable =\n type === undefined ||\n (Array.isArray(type) && type.includes(\"null\")) ||\n Boolean(schema.nullable);\n return (schema.enum ?? []).includes(null) && isTypeNullable;\n}\n\n/**\n * `additionalProperties: true` on a string enum keeps other strings allowed but still offers the\n * listed values in editors: `\"a\" | \"b\" | (string & {})`.\n */\nfunction withOtherStrings(type: IrType, schema: SchemaObject): IrType {\n if (!hasAdditionalProperties(schema) || schema.type !== \"string\") {\n return type;\n }\n return unionOf([type, intersectionOf([irKeyword(\"string\"), irObject([])])]);\n}\n\n/** The enum declaration of `schema` typed at `path`; its values are strings and numbers. */\nfunction enumRequest(\n schema: SchemaObject,\n path: string | undefined,\n options: SchemaOptions,\n): EnumDeclarationRequest {\n const entries = tsEnumEntries(schema, options);\n return {\n name: nameFromPath(path),\n isComponentSchema: COMPONENT_SCHEMA_RE.test(path ?? \"\"),\n values: entries.map(([value]) => value as string | number),\n metadata: enumMetadata(schema, entries),\n };\n}\n\n/** One member's type; a quoted member cannot follow a dot, `typeof E[\"+\"]` is the same type. */\nfunction enumMemberType(enumName: string, member: string): IrType {\n return member.startsWith('\"')\n ? irIndexedAccess(irReference(`typeof ${enumName}`), irString(JSON.parse(member), \"escaped\"))\n : irReference(`${enumName}.${member}`);\n}\n\n/**\n * The `discriminator-values` fix: a member's discriminator value is typed with members of\n * the owner's enum (`PetType.Cat`), so the member is one of the owner's type (#1700). `key` is the\n * enum the scan added or the inherited discriminator object. Null when the fix is off, or the\n * owner's property is no TypeScript enum with every value.\n */\nexport function ownerEnumMembersType(\n key: object,\n values: readonly unknown[],\n request: SchemaRequest,\n): IrType | null {\n const { options, discriminators, footer } = request.context;\n const parent: DiscriminatorEnumParent | undefined = options.fixes.has(\n OutputFix.DISCRIMINATOR_VALUES,\n )\n ? discriminators.enumParentOf(key)\n : undefined;\n if (parent === undefined || !isTsEnum(parent.schema, options)) {\n return null;\n }\n const reference = { ...enumRequest(parent.schema, parent.path, options), isOwnerReference: true };\n const name = footer.addEnum(reference);\n const members = footer.enumMembers(name);\n const names = values.map((value) => members.get(value as string | number));\n if (names.length === 0 || names.some((member) => member === undefined)) {\n return null;\n }\n return unionOf(names.map((member) => enumMemberType(name, member as string)));\n}\n\nfunction tsEnumType(schema: SchemaObject, request: SchemaRequest): IrType {\n const { options, footer } = request.context;\n // `isTsEnum` admits only strings and numbers, and the fix leaves `null` out of the members.\n const values = tsEnumEntries(schema, options).map(([value]) => value);\n const type =\n ownerEnumMembersType(schema, values, request) ??\n withOtherStrings(\n irReference(footer.addEnum(enumRequest(schema, request.location.path, options))),\n schema,\n );\n return options.fixes.has(OutputFix.NULLABLE_ENUMS) && isNullAllowed(schema)\n ? unionOf([type, irKeyword(\"null\")])\n : type;\n}\n\nfunction isUnionPosition(pointer: readonly string[], index: number): boolean {\n const next = pointer[index + 1];\n return UNION_KEYWORDS.has(pointer[index] as string) && next !== undefined && INDEX_RE.test(next);\n}\n\nconst PARAMETERS = \"parameters\";\n\n/** Where the `parameters` of a path item sit in its pointer: `paths/<key>/…`, `components/…`. */\nfunction pathItemParametersIndex(pointer: readonly string[]): number | null {\n if (pointer[0] === \"paths\" || pointer[0] === \"webhooks\") {\n return 2;\n }\n return pointer[0] === \"components\" && pointer[1] === \"pathItems\" ? 3 : null;\n}\n\n/**\n * The location of a path item parameter repeats `parameters` (`paths/~1a/parameters/parameters/\n * path/id`), which keeps the generated names as they were. The generated type has the segment\n * once: `paths[\"/a\"][\"parameters\"][\"path\"][\"id\"]`.\n */\nfunction withSingleParametersSegment(pointer: readonly string[]): readonly string[] {\n const index = pathItemParametersIndex(pointer);\n const isRepeated =\n index !== null && pointer[index] === PARAMETERS && pointer[index + 1] === PARAMETERS;\n return isRepeated ? [...pointer.slice(0, index), ...pointer.slice(index + 1)] : pointer;\n}\n\n/**\n * The pointer of `--enum-values` arrays without union positions (`anyOf/0`), so names stay\n * stable. Every property after the first union position is narrowed with `Extract`: a no-op where\n * all variants have it, and the needed narrowing where only some do.\n */\nfunction enumValuesPointer(path: string | undefined): { ref: string; extract: string[] } {\n const pointer = withSingleParametersSegment(parseRefPointer(path ?? \"\"));\n const kept: string[] = [];\n let firstVariantStart: number | null = null;\n for (let index = 0; index < pointer.length; index++) {\n if (isUnionPosition(pointer, index)) {\n firstVariantStart ??= index + 2;\n index++;\n continue;\n }\n kept.push(pointer[index] as string);\n }\n const extract =\n firstVariantStart === null\n ? []\n : pointer\n .slice(firstVariantStart)\n .filter((segment) => !UNION_KEYWORDS.has(segment) && !INDEX_RE.test(segment));\n return { ref: createRef(kept), extract };\n}\n\nfunction addEnumValues(schema: SchemaObject, request: SchemaRequest): void {\n const { ref, extract } = enumValuesPointer(request.location.path);\n const valuesType = refType(ref, { isDeep: true, extractProperties: extract });\n request.context.footer.addEnumValues({\n name: `${nameFromPath(request.location.path)}Values`,\n // A record value (`additionalProperties`) is reached by indexing with `string`.\n type: request.isFromAdditionalProperties\n ? irIndexedAccess(valuesType, irReference(\"string\"))\n : valuesType,\n values: (schema.enum ?? []) as (string | number)[],\n });\n}\n\nfunction literalEnumType(schema: SchemaObject, request: SchemaRequest): IrType {\n const values = schema.enum ?? [];\n const isNullable =\n (Array.isArray(schema.type) && schema.type.includes(\"null\")) || Boolean(schema.nullable);\n const literals = [...values.map(literalType), ...(isNullable ? [irKeyword(\"null\")] : [])];\n const type = withOtherStrings(unionOf(literals), schema);\n const isListable = values.every(\n (value) => typeof value === \"string\" || typeof value === \"number\",\n );\n if (request.context.options.enumValues && isListable) {\n addEnumValues(schema, request);\n }\n return type;\n}\n\n/**\n * `enum` on anything but an object (object enums are handled as `oneOf`). With\n * `additionalProperties`, only string enums are handled here; others fall through to composition.\n */\nexport const enumRule: SchemaRule = {\n name: \"enum\",\n matches(schema) {\n const isCandidate =\n Array.isArray(schema.enum) && schema.type !== \"object\" && !(\"properties\" in schema);\n return isCandidate && (!hasAdditionalProperties(schema) || schema.type === \"string\");\n },\n transform(schema, request) {\n return isTsEnum(schema, request.context.options)\n ? tsEnumType(schema, request)\n : literalEnumType(schema, request);\n },\n};\n"],"names":["parseRefPointer","OutputFix","unionOf","intersectionOf","irKeyword","irObject","irIndexedAccess","irReference","irString","createRef","refType","literalType"],"mappings":";;;;;;;;;AAuBA,MAAM,wBAAA,GAA2B,oBAAA;AACjC,MAAM,iCAAsC,IAAI,GAAA,CAAI,CAAC,OAAA,EAAS,OAAO,CAAC,CAAA;AACtE,MAAM,QAAA,GAAW,OAAA;AAEjB,SAAS,wBAAwB,MAAA,EAA+B;AAC9D,EAAA,OAAO,sBAAA,IAA0B,MAAA,IAAU,OAAA,CAAQ,MAAA,CAAO,oBAAoB,CAAA;AAChF;AAGA,SAAS,aAAa,IAAA,EAAkC;AACtD,EAAA,OAAOA,2BAAA,CAAgB,QAAQ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