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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (513) hide show
  1. package/README.md +12 -5
  2. package/dist/adapters/redocly-loader/configured-headers.cjs +32 -0
  3. package/dist/adapters/redocly-loader/configured-headers.cjs.map +1 -0
  4. package/dist/adapters/redocly-loader/configured-headers.mjs +30 -0
  5. package/dist/adapters/redocly-loader/configured-headers.mjs.map +1 -0
  6. package/dist/adapters/redocly-loader/redocly-config-source.cjs +21 -2
  7. package/dist/adapters/redocly-loader/redocly-config-source.cjs.map +1 -1
  8. package/dist/adapters/redocly-loader/redocly-config-source.mjs +22 -3
  9. package/dist/adapters/redocly-loader/redocly-config-source.mjs.map +1 -1
  10. package/dist/adapters/redocly-loader/redocly-schema-loader.cjs +34 -11
  11. package/dist/adapters/redocly-loader/redocly-schema-loader.cjs.map +1 -1
  12. package/dist/adapters/redocly-loader/redocly-schema-loader.mjs +33 -10
  13. package/dist/adapters/redocly-loader/redocly-schema-loader.mjs.map +1 -1
  14. package/dist/adapters/redocly-loader/ref-access.cjs +37 -4
  15. package/dist/adapters/redocly-loader/ref-access.cjs.map +1 -1
  16. package/dist/adapters/redocly-loader/ref-access.mjs +37 -4
  17. package/dist/adapters/redocly-loader/ref-access.mjs.map +1 -1
  18. package/dist/adapters/redocly-loader/ref-resolution-check.cjs +191 -0
  19. package/dist/adapters/redocly-loader/ref-resolution-check.cjs.map +1 -0
  20. package/dist/adapters/redocly-loader/ref-resolution-check.mjs +189 -0
  21. package/dist/adapters/redocly-loader/ref-resolution-check.mjs.map +1 -0
  22. package/dist/adapters/redocly-loader/ref-resolution-steps.cjs +73 -0
  23. package/dist/adapters/redocly-loader/ref-resolution-steps.cjs.map +1 -0
  24. package/dist/adapters/redocly-loader/ref-resolution-steps.mjs +60 -0
  25. package/dist/adapters/redocly-loader/ref-resolution-steps.mjs.map +1 -0
  26. package/dist/adapters/redocly-loader/remote-fetch.cjs +41 -14
  27. package/dist/adapters/redocly-loader/remote-fetch.cjs.map +1 -1
  28. package/dist/adapters/redocly-loader/remote-fetch.mjs +40 -14
  29. package/dist/adapters/redocly-loader/remote-fetch.mjs.map +1 -1
  30. package/dist/adapters/redocly-loader/schema-load-errors.cjs +23 -5
  31. package/dist/adapters/redocly-loader/schema-load-errors.cjs.map +1 -1
  32. package/dist/adapters/redocly-loader/schema-load-errors.mjs +23 -5
  33. package/dist/adapters/redocly-loader/schema-load-errors.mjs.map +1 -1
  34. package/dist/adapters/redocly-loader/unsupported-keys.cjs +9 -1
  35. package/dist/adapters/redocly-loader/unsupported-keys.cjs.map +1 -1
  36. package/dist/adapters/redocly-loader/unsupported-keys.mjs +9 -1
  37. package/dist/adapters/redocly-loader/unsupported-keys.mjs.map +1 -1
  38. package/dist/adapters/terminal-logger/terminal-logger.cjs +6 -4
  39. package/dist/adapters/terminal-logger/terminal-logger.cjs.map +1 -1
  40. package/dist/adapters/terminal-logger/terminal-logger.mjs +6 -4
  41. package/dist/adapters/terminal-logger/terminal-logger.mjs.map +1 -1
  42. package/dist/adapters/type-ast-bridge/ir-to-typescript.cjs +5 -1
  43. package/dist/adapters/type-ast-bridge/ir-to-typescript.cjs.map +1 -1
  44. package/dist/adapters/type-ast-bridge/ir-to-typescript.mjs +5 -1
  45. package/dist/adapters/type-ast-bridge/ir-to-typescript.mjs.map +1 -1
  46. package/dist/adapters/type-ast-bridge/print-typescript.cjs.map +1 -1
  47. package/dist/adapters/type-ast-bridge/print-typescript.mjs.map +1 -1
  48. package/dist/adapters/type-ast-bridge/typescript-to-ir.cjs +15 -9
  49. package/dist/adapters/type-ast-bridge/typescript-to-ir.cjs.map +1 -1
  50. package/dist/adapters/type-ast-bridge/typescript-to-ir.mjs +15 -9
  51. package/dist/adapters/type-ast-bridge/typescript-to-ir.mjs.map +1 -1
  52. package/dist/api/default-ports.cjs +9 -0
  53. package/dist/api/default-ports.cjs.map +1 -1
  54. package/dist/api/default-ports.mjs +8 -1
  55. package/dist/api/default-ports.mjs.map +1 -1
  56. package/dist/api/discriminator-conflict-warnings.cjs +25 -0
  57. package/dist/api/discriminator-conflict-warnings.cjs.map +1 -0
  58. package/dist/api/discriminator-conflict-warnings.mjs +23 -0
  59. package/dist/api/discriminator-conflict-warnings.mjs.map +1 -0
  60. package/dist/api/discriminator-enum-names.cjs +19 -0
  61. package/dist/api/discriminator-enum-names.cjs.map +1 -0
  62. package/dist/api/discriminator-enum-names.mjs +17 -0
  63. package/dist/api/discriminator-enum-names.mjs.map +1 -0
  64. package/dist/api/discriminator-enum-parent.cjs +59 -0
  65. package/dist/api/discriminator-enum-parent.cjs.map +1 -0
  66. package/dist/api/discriminator-enum-parent.mjs +57 -0
  67. package/dist/api/discriminator-enum-parent.mjs.map +1 -0
  68. package/dist/api/discriminator-enum.cjs +25 -0
  69. package/dist/api/discriminator-enum.cjs.map +1 -1
  70. package/dist/api/discriminator-enum.mjs +25 -1
  71. package/dist/api/discriminator-enum.mjs.map +1 -1
  72. package/dist/api/discriminator-other-owners.cjs +67 -0
  73. package/dist/api/discriminator-other-owners.cjs.map +1 -0
  74. package/dist/api/discriminator-other-owners.mjs +64 -0
  75. package/dist/api/discriminator-other-owners.mjs.map +1 -0
  76. package/dist/api/discriminator-patch.cjs +92 -0
  77. package/dist/api/discriminator-patch.cjs.map +1 -0
  78. package/dist/api/discriminator-patch.mjs +86 -0
  79. package/dist/api/discriminator-patch.mjs.map +1 -0
  80. package/dist/api/discriminator-scan.cjs +50 -65
  81. package/dist/api/discriminator-scan.cjs.map +1 -1
  82. package/dist/api/discriminator-scan.mjs +44 -59
  83. package/dist/api/discriminator-scan.mjs.map +1 -1
  84. package/dist/api/document-refs.cjs +15 -12
  85. package/dist/api/document-refs.cjs.map +1 -1
  86. package/dist/api/document-refs.mjs +15 -12
  87. package/dist/api/document-refs.mjs.map +1 -1
  88. package/dist/api/document-run.cjs +21 -4
  89. package/dist/api/document-run.cjs.map +1 -1
  90. package/dist/api/document-run.mjs +22 -5
  91. package/dist/api/document-run.mjs.map +1 -1
  92. package/dist/api/enum-values-warnings.cjs +16 -0
  93. package/dist/api/enum-values-warnings.cjs.map +1 -0
  94. package/dist/api/enum-values-warnings.mjs +14 -0
  95. package/dist/api/enum-values-warnings.mjs.map +1 -0
  96. package/dist/api/footer-sink.cjs +25 -2
  97. package/dist/api/footer-sink.cjs.map +1 -1
  98. package/dist/api/footer-sink.mjs +25 -2
  99. package/dist/api/footer-sink.mjs.map +1 -1
  100. package/dist/api/legacy-callback-warning.cjs +4 -1
  101. package/dist/api/legacy-callback-warning.cjs.map +1 -1
  102. package/dist/api/legacy-callback-warning.mjs +4 -1
  103. package/dist/api/legacy-callback-warning.mjs.map +1 -1
  104. package/dist/api/legacy-ts-helpers.cjs.map +1 -1
  105. package/dist/api/legacy-ts-helpers.mjs.map +1 -1
  106. package/dist/api/legacy-utils.cjs.map +1 -1
  107. package/dist/api/legacy-utils.mjs.map +1 -1
  108. package/dist/api/openapi-ts.cjs +2 -1
  109. package/dist/api/openapi-ts.cjs.map +1 -1
  110. package/dist/api/openapi-ts.mjs +3 -2
  111. package/dist/api/openapi-ts.mjs.map +1 -1
  112. package/dist/api/path-template-warnings.cjs +21 -0
  113. package/dist/api/path-template-warnings.cjs.map +1 -0
  114. package/dist/api/path-template-warnings.mjs +19 -0
  115. package/dist/api/path-template-warnings.mjs.map +1 -0
  116. package/dist/api/transform-context.cjs +4 -2
  117. package/dist/api/transform-context.cjs.map +1 -1
  118. package/dist/api/transform-context.mjs +4 -2
  119. package/dist/api/transform-context.mjs.map +1 -1
  120. package/dist/api/transform-schema.cjs +52 -3
  121. package/dist/api/transform-schema.cjs.map +1 -1
  122. package/dist/api/transform-schema.mjs +53 -4
  123. package/dist/api/transform-schema.mjs.map +1 -1
  124. package/dist/api/unsupported-feature-warnings.cjs +6 -1
  125. package/dist/api/unsupported-feature-warnings.cjs.map +1 -1
  126. package/dist/api/unsupported-feature-warnings.mjs +6 -1
  127. package/dist/api/unsupported-feature-warnings.mjs.map +1 -1
  128. package/dist/application/print/type-printer.cjs +7 -1
  129. package/dist/application/print/type-printer.cjs.map +1 -1
  130. package/dist/application/print/type-printer.mjs +7 -1
  131. package/dist/application/print/type-printer.mjs.map +1 -1
  132. package/dist/application/transform/document/assignability.cjs +144 -0
  133. package/dist/application/transform/document/assignability.cjs.map +1 -0
  134. package/dist/application/transform/document/assignability.mjs +138 -0
  135. package/dist/application/transform/document/assignability.mjs.map +1 -0
  136. package/dist/application/transform/document/components.cjs +2 -2
  137. package/dist/application/transform/document/components.cjs.map +1 -1
  138. package/dist/application/transform/document/components.mjs +4 -4
  139. package/dist/application/transform/document/components.mjs.map +1 -1
  140. package/dist/application/transform/document/declared-types.cjs +66 -0
  141. package/dist/application/transform/document/declared-types.cjs.map +1 -0
  142. package/dist/application/transform/document/declared-types.mjs +63 -0
  143. package/dist/application/transform/document/declared-types.mjs.map +1 -0
  144. package/dist/application/transform/document/document.cjs +32 -9
  145. package/dist/application/transform/document/document.cjs.map +1 -1
  146. package/dist/application/transform/document/document.mjs +34 -11
  147. package/dist/application/transform/document/document.mjs.map +1 -1
  148. package/dist/application/transform/document/exploded-query.cjs +46 -0
  149. package/dist/application/transform/document/exploded-query.cjs.map +1 -0
  150. package/dist/application/transform/document/exploded-query.mjs +43 -0
  151. package/dist/application/transform/document/exploded-query.mjs.map +1 -0
  152. package/dist/application/transform/document/global-type-references.cjs +63 -0
  153. package/dist/application/transform/document/global-type-references.cjs.map +1 -0
  154. package/dist/application/transform/document/global-type-references.mjs +61 -0
  155. package/dist/application/transform/document/global-type-references.mjs.map +1 -0
  156. package/dist/application/transform/document/list-assignability.cjs +54 -0
  157. package/dist/application/transform/document/list-assignability.cjs.map +1 -0
  158. package/dist/application/transform/document/list-assignability.mjs +52 -0
  159. package/dist/application/transform/document/list-assignability.mjs.map +1 -0
  160. package/dist/application/transform/document/parameters.cjs +41 -9
  161. package/dist/application/transform/document/parameters.cjs.map +1 -1
  162. package/dist/application/transform/document/parameters.mjs +42 -10
  163. package/dist/application/transform/document/parameters.mjs.map +1 -1
  164. package/dist/application/transform/document/path-key-overlaps.cjs +83 -33
  165. package/dist/application/transform/document/path-key-overlaps.cjs.map +1 -1
  166. package/dist/application/transform/document/path-key-overlaps.mjs +83 -33
  167. package/dist/application/transform/document/path-key-overlaps.mjs.map +1 -1
  168. package/dist/application/transform/document/path-template-replace.cjs +48 -0
  169. package/dist/application/transform/document/path-template-replace.cjs.map +1 -0
  170. package/dist/application/transform/document/path-template-replace.mjs +45 -0
  171. package/dist/application/transform/document/path-template-replace.mjs.map +1 -0
  172. package/dist/application/transform/document/paths.cjs +55 -29
  173. package/dist/application/transform/document/paths.cjs.map +1 -1
  174. package/dist/application/transform/document/paths.mjs +54 -30
  175. package/dist/application/transform/document/paths.mjs.map +1 -1
  176. package/dist/application/transform/document/root-type-aliases.cjs +15 -14
  177. package/dist/application/transform/document/root-type-aliases.cjs.map +1 -1
  178. package/dist/application/transform/document/root-type-aliases.mjs +15 -13
  179. package/dist/application/transform/document/root-type-aliases.mjs.map +1 -1
  180. package/dist/application/transform/document/template-key-match.cjs +128 -0
  181. package/dist/application/transform/document/template-key-match.cjs.map +1 -0
  182. package/dist/application/transform/document/template-key-match.mjs +125 -0
  183. package/dist/application/transform/document/template-key-match.mjs.map +1 -0
  184. package/dist/application/transform/document/type-assignability.cjs +192 -0
  185. package/dist/application/transform/document/type-assignability.cjs.map +1 -0
  186. package/dist/application/transform/document/type-assignability.mjs +190 -0
  187. package/dist/application/transform/document/type-assignability.mjs.map +1 -0
  188. package/dist/application/transform/document/type-key.cjs +70 -0
  189. package/dist/application/transform/document/type-key.cjs.map +1 -0
  190. package/dist/application/transform/document/type-key.mjs +68 -0
  191. package/dist/application/transform/document/type-key.mjs.map +1 -0
  192. package/dist/application/transform/document/type-resolution.cjs +131 -0
  193. package/dist/application/transform/document/type-resolution.cjs.map +1 -0
  194. package/dist/application/transform/document/type-resolution.mjs +125 -0
  195. package/dist/application/transform/document/type-resolution.mjs.map +1 -0
  196. package/dist/application/transform/footer/document-footer.cjs +66 -4
  197. package/dist/application/transform/footer/document-footer.cjs.map +1 -1
  198. package/dist/application/transform/footer/document-footer.mjs +67 -5
  199. package/dist/application/transform/footer/document-footer.mjs.map +1 -1
  200. package/dist/application/transform/footer/enum-naming.cjs +17 -0
  201. package/dist/application/transform/footer/enum-naming.cjs.map +1 -1
  202. package/dist/application/transform/footer/enum-naming.mjs +17 -1
  203. package/dist/application/transform/footer/enum-naming.mjs.map +1 -1
  204. package/dist/application/transform/footer/enum-values-check.cjs +129 -0
  205. package/dist/application/transform/footer/enum-values-check.cjs.map +1 -0
  206. package/dist/application/transform/footer/enum-values-check.mjs +127 -0
  207. package/dist/application/transform/footer/enum-values-check.mjs.map +1 -0
  208. package/dist/application/transform/footer/evaluation.cjs +42 -0
  209. package/dist/application/transform/footer/evaluation.cjs.map +1 -0
  210. package/dist/application/transform/footer/evaluation.mjs +33 -0
  211. package/dist/application/transform/footer/evaluation.mjs.map +1 -0
  212. package/dist/application/transform/footer/shared-enum-names.cjs +60 -0
  213. package/dist/application/transform/footer/shared-enum-names.cjs.map +1 -0
  214. package/dist/application/transform/footer/shared-enum-names.mjs +57 -0
  215. package/dist/application/transform/footer/shared-enum-names.mjs.map +1 -0
  216. package/dist/application/transform/footer/type-evaluation.cjs +138 -0
  217. package/dist/application/transform/footer/type-evaluation.cjs.map +1 -0
  218. package/dist/application/transform/footer/type-evaluation.mjs +136 -0
  219. package/dist/application/transform/footer/type-evaluation.mjs.map +1 -0
  220. package/dist/application/transform/footer/type-indexing.cjs +107 -0
  221. package/dist/application/transform/footer/type-indexing.cjs.map +1 -0
  222. package/dist/application/transform/footer/type-indexing.mjs +105 -0
  223. package/dist/application/transform/footer/type-indexing.mjs.map +1 -0
  224. package/dist/application/transform/footer/type-rules.cjs +172 -0
  225. package/dist/application/transform/footer/type-rules.cjs.map +1 -0
  226. package/dist/application/transform/footer/type-rules.mjs +166 -0
  227. package/dist/application/transform/footer/type-rules.mjs.map +1 -0
  228. package/dist/application/transform/ref-pointer/generated-location.cjs +138 -0
  229. package/dist/application/transform/ref-pointer/generated-location.cjs.map +1 -0
  230. package/dist/application/transform/ref-pointer/generated-location.mjs +136 -0
  231. package/dist/application/transform/ref-pointer/generated-location.mjs.map +1 -0
  232. package/dist/application/transform/ref-pointer/generated-shape.cjs +171 -0
  233. package/dist/application/transform/ref-pointer/generated-shape.cjs.map +1 -0
  234. package/dist/application/transform/ref-pointer/generated-shape.mjs +162 -0
  235. package/dist/application/transform/ref-pointer/generated-shape.mjs.map +1 -0
  236. package/dist/application/transform/ref-pointer/inline-cycles.cjs +44 -0
  237. package/dist/application/transform/ref-pointer/inline-cycles.cjs.map +1 -0
  238. package/dist/application/transform/ref-pointer/inline-cycles.mjs +42 -0
  239. package/dist/application/transform/ref-pointer/inline-cycles.mjs.map +1 -0
  240. package/dist/application/transform/ref-pointer/original-index.cjs +62 -0
  241. package/dist/application/transform/ref-pointer/original-index.cjs.map +1 -0
  242. package/dist/application/transform/ref-pointer/original-index.mjs +60 -0
  243. package/dist/application/transform/ref-pointer/original-index.mjs.map +1 -0
  244. package/dist/application/transform/ref-pointer/pointer-type.cjs +60 -0
  245. package/dist/application/transform/ref-pointer/pointer-type.cjs.map +1 -0
  246. package/dist/application/transform/ref-pointer/pointer-type.mjs +57 -0
  247. package/dist/application/transform/ref-pointer/pointer-type.mjs.map +1 -0
  248. package/dist/application/transform/ref-pointer/pointer-walk.cjs +66 -0
  249. package/dist/application/transform/ref-pointer/pointer-walk.cjs.map +1 -0
  250. package/dist/application/transform/ref-pointer/pointer-walk.mjs +56 -0
  251. package/dist/application/transform/ref-pointer/pointer-walk.mjs.map +1 -0
  252. package/dist/application/transform/ref-pointer/typed-walk.cjs +124 -0
  253. package/dist/application/transform/ref-pointer/typed-walk.cjs.map +1 -0
  254. package/dist/application/transform/ref-pointer/typed-walk.mjs +122 -0
  255. package/dist/application/transform/ref-pointer/typed-walk.mjs.map +1 -0
  256. package/dist/application/transform/ref-type.cjs +7 -2
  257. package/dist/application/transform/ref-type.cjs.map +1 -1
  258. package/dist/application/transform/ref-type.mjs +3 -2
  259. package/dist/application/transform/ref-type.mjs.map +1 -1
  260. package/dist/application/transform/schema/access-flags.cjs +38 -0
  261. package/dist/application/transform/schema/access-flags.cjs.map +1 -0
  262. package/dist/application/transform/schema/access-flags.mjs +36 -0
  263. package/dist/application/transform/schema/access-flags.mjs.map +1 -0
  264. package/dist/application/transform/schema/array-type.cjs +32 -1
  265. package/dist/application/transform/schema/array-type.cjs.map +1 -1
  266. package/dist/application/transform/schema/array-type.mjs +33 -2
  267. package/dist/application/transform/schema/array-type.mjs.map +1 -1
  268. package/dist/application/transform/schema/composition-type.cjs +50 -15
  269. package/dist/application/transform/schema/composition-type.cjs.map +1 -1
  270. package/dist/application/transform/schema/composition-type.mjs +50 -15
  271. package/dist/application/transform/schema/composition-type.mjs.map +1 -1
  272. package/dist/application/transform/schema/core-type.cjs +3 -1
  273. package/dist/application/transform/schema/core-type.cjs.map +1 -1
  274. package/dist/application/transform/schema/core-type.mjs +3 -1
  275. package/dist/application/transform/schema/core-type.mjs.map +1 -1
  276. package/dist/application/transform/schema/discriminated-union.cjs +30 -0
  277. package/dist/application/transform/schema/discriminated-union.cjs.map +1 -0
  278. package/dist/application/transform/schema/discriminated-union.mjs +27 -0
  279. package/dist/application/transform/schema/discriminated-union.mjs.map +1 -0
  280. package/dist/application/transform/schema/discriminator-property.cjs +3 -2
  281. package/dist/application/transform/schema/discriminator-property.cjs.map +1 -1
  282. package/dist/application/transform/schema/discriminator-property.mjs +3 -2
  283. package/dist/application/transform/schema/discriminator-property.mjs.map +1 -1
  284. package/dist/application/transform/schema/enum-rule.cjs +66 -10
  285. package/dist/application/transform/schema/enum-rule.cjs.map +1 -1
  286. package/dist/application/transform/schema/enum-rule.mjs +67 -12
  287. package/dist/application/transform/schema/enum-rule.mjs.map +1 -1
  288. package/dist/application/transform/schema/inherited-discriminator.cjs +29 -0
  289. package/dist/application/transform/schema/inherited-discriminator.cjs.map +1 -0
  290. package/dist/application/transform/schema/inherited-discriminator.mjs +26 -0
  291. package/dist/application/transform/schema/inherited-discriminator.mjs.map +1 -0
  292. package/dist/application/transform/schema/object-type.cjs +38 -25
  293. package/dist/application/transform/schema/object-type.cjs.map +1 -1
  294. package/dist/application/transform/schema/object-type.mjs +39 -27
  295. package/dist/application/transform/schema/object-type.mjs.map +1 -1
  296. package/dist/application/transform/schema/required-variants.cjs +45 -0
  297. package/dist/application/transform/schema/required-variants.cjs.map +1 -0
  298. package/dist/application/transform/schema/required-variants.mjs +42 -0
  299. package/dist/application/transform/schema/required-variants.mjs.map +1 -0
  300. package/dist/application/transform/schema/schema-transform.cjs +2 -2
  301. package/dist/application/transform/schema/schema-transform.cjs.map +1 -1
  302. package/dist/application/transform/schema/schema-transform.mjs +2 -2
  303. package/dist/application/transform/schema/schema-transform.mjs.map +1 -1
  304. package/dist/application/transform/schema-comment.cjs +51 -5
  305. package/dist/application/transform/schema-comment.cjs.map +1 -1
  306. package/dist/application/transform/schema-comment.mjs +50 -6
  307. package/dist/application/transform/schema-comment.mjs.map +1 -1
  308. package/dist/application/transform/type-combinators.mjs +1 -1
  309. package/dist/cli/api-settings.cjs +78 -0
  310. package/dist/cli/api-settings.cjs.map +1 -0
  311. package/dist/cli/api-settings.mjs +73 -0
  312. package/dist/cli/api-settings.mjs.map +1 -0
  313. package/dist/cli/cli-arguments.cjs +12 -3
  314. package/dist/cli/cli-arguments.cjs.map +1 -1
  315. package/dist/cli/cli-arguments.mjs +12 -4
  316. package/dist/cli/cli-arguments.mjs.map +1 -1
  317. package/dist/cli/cli-errors.cjs +3 -2
  318. package/dist/cli/cli-errors.cjs.map +1 -1
  319. package/dist/cli/cli-errors.mjs +3 -2
  320. package/dist/cli/cli-errors.mjs.map +1 -1
  321. package/dist/cli/cli-output.cjs +8 -3
  322. package/dist/cli/cli-output.cjs.map +1 -1
  323. package/dist/cli/cli-output.mjs +9 -4
  324. package/dist/cli/cli-output.mjs.map +1 -1
  325. package/dist/cli/help-text.cjs +3 -3
  326. package/dist/cli/help-text.cjs.map +1 -1
  327. package/dist/cli/help-text.mjs +3 -3
  328. package/dist/cli/help-text.mjs.map +1 -1
  329. package/dist/cli/main.cjs +5 -0
  330. package/dist/cli/main.cjs.map +1 -1
  331. package/dist/cli/main.mjs +5 -0
  332. package/dist/cli/main.mjs.map +1 -1
  333. package/dist/cli/redocly-apis.cjs +15 -7
  334. package/dist/cli/redocly-apis.cjs.map +1 -1
  335. package/dist/cli/redocly-apis.mjs +15 -7
  336. package/dist/cli/redocly-apis.mjs.map +1 -1
  337. package/dist/cli/ref-limits.cjs +1 -1
  338. package/dist/cli/ref-limits.cjs.map +1 -1
  339. package/dist/cli/ref-limits.mjs +2 -2
  340. package/dist/cli/ref-limits.mjs.map +1 -1
  341. package/dist/cli/run-cli.cjs +20 -3
  342. package/dist/cli/run-cli.cjs.map +1 -1
  343. package/dist/cli/run-cli.mjs +21 -4
  344. package/dist/cli/run-cli.mjs.map +1 -1
  345. package/dist/domain/errors.cjs +6 -1
  346. package/dist/domain/errors.cjs.map +1 -1
  347. package/dist/domain/errors.mjs +6 -1
  348. package/dist/domain/errors.mjs.map +1 -1
  349. package/dist/domain/ir/constructors.cjs +7 -1
  350. package/dist/domain/ir/constructors.cjs.map +1 -1
  351. package/dist/domain/ir/constructors.mjs +6 -2
  352. package/dist/domain/ir/constructors.mjs.map +1 -1
  353. package/dist/domain/openapi/admitted-values.cjs +75 -0
  354. package/dist/domain/openapi/admitted-values.cjs.map +1 -0
  355. package/dist/domain/openapi/admitted-values.mjs +72 -0
  356. package/dist/domain/openapi/admitted-values.mjs.map +1 -0
  357. package/dist/domain/openapi/discriminated-union.cjs +68 -0
  358. package/dist/domain/openapi/discriminated-union.cjs.map +1 -0
  359. package/dist/domain/openapi/discriminated-union.mjs +62 -0
  360. package/dist/domain/openapi/discriminated-union.mjs.map +1 -0
  361. package/dist/domain/openapi/discriminator-conflicts.cjs +143 -0
  362. package/dist/domain/openapi/discriminator-conflicts.cjs.map +1 -0
  363. package/dist/domain/openapi/discriminator-conflicts.mjs +141 -0
  364. package/dist/domain/openapi/discriminator-conflicts.mjs.map +1 -0
  365. package/dist/domain/openapi/parameter-object.cjs.map +1 -1
  366. package/dist/domain/openapi/parameter-object.mjs.map +1 -1
  367. package/dist/domain/openapi/path-templates.cjs +23 -0
  368. package/dist/domain/openapi/path-templates.cjs.map +1 -0
  369. package/dist/domain/openapi/path-templates.mjs +21 -0
  370. package/dist/domain/openapi/path-templates.mjs.map +1 -0
  371. package/dist/domain/output-fixes.cjs +36 -1
  372. package/dist/domain/output-fixes.cjs.map +1 -1
  373. package/dist/domain/output-fixes.mjs +36 -1
  374. package/dist/domain/output-fixes.mjs.map +1 -1
  375. package/dist/domain/url-credentials.cjs +10 -0
  376. package/dist/domain/url-credentials.cjs.map +1 -0
  377. package/dist/domain/url-credentials.mjs +8 -0
  378. package/dist/domain/url-credentials.mjs.map +1 -0
  379. package/dist/domain/warnings.cjs +23 -0
  380. package/dist/domain/warnings.cjs.map +1 -0
  381. package/dist/domain/warnings.mjs +20 -0
  382. package/dist/domain/warnings.mjs.map +1 -0
  383. package/dist/index.cjs +2 -0
  384. package/dist/index.cjs.map +1 -1
  385. package/dist/index.d.cts +1182 -46
  386. package/dist/index.d.mts +1182 -46
  387. package/dist/index.d.ts +1182 -46
  388. package/dist/index.mjs +1 -0
  389. package/dist/index.mjs.map +1 -1
  390. package/dist/transform/components-object.cjs +2 -1
  391. package/dist/transform/components-object.cjs.map +1 -1
  392. package/dist/transform/components-object.mjs +2 -1
  393. package/dist/transform/components-object.mjs.map +1 -1
  394. package/dist/transform/path-item-object.cjs.map +1 -1
  395. package/dist/transform/path-item-object.mjs.map +1 -1
  396. package/package.json +6 -5
  397. package/src/adapters/redocly-loader/configured-headers.ts +65 -0
  398. package/src/adapters/redocly-loader/redocly-config-source.ts +41 -6
  399. package/src/adapters/redocly-loader/redocly-schema-loader.ts +44 -13
  400. package/src/adapters/redocly-loader/ref-access.ts +60 -5
  401. package/src/adapters/redocly-loader/ref-resolution-check.ts +257 -0
  402. package/src/adapters/redocly-loader/ref-resolution-steps.ts +113 -0
  403. package/src/adapters/redocly-loader/remote-fetch.ts +77 -21
  404. package/src/adapters/redocly-loader/schema-load-errors.ts +33 -11
  405. package/src/adapters/redocly-loader/unsupported-keys.ts +17 -2
  406. package/src/adapters/terminal-logger/terminal-logger.ts +9 -5
  407. package/src/adapters/type-ast-bridge/ir-to-typescript.ts +5 -1
  408. package/src/adapters/type-ast-bridge/print-typescript.ts +3 -1
  409. package/src/adapters/type-ast-bridge/typescript-to-ir.ts +26 -12
  410. package/src/adapters/type-ast-bridge/typescript-types.ts +57 -5
  411. package/src/api/default-ports.ts +16 -0
  412. package/src/api/discriminator-conflict-warnings.ts +43 -0
  413. package/src/api/discriminator-enum-names.ts +26 -0
  414. package/src/api/discriminator-enum-parent.ts +129 -0
  415. package/src/api/discriminator-enum.ts +39 -0
  416. package/src/api/discriminator-other-owners.ts +97 -0
  417. package/src/api/discriminator-patch.ts +152 -0
  418. package/src/api/discriminator-scan.ts +78 -90
  419. package/src/api/document-refs.ts +19 -15
  420. package/src/api/document-run.ts +32 -11
  421. package/src/api/enum-values-warnings.ts +21 -0
  422. package/src/api/footer-sink.ts +34 -2
  423. package/src/api/legacy-callback-warning.ts +7 -3
  424. package/src/api/legacy-ts-helpers.ts +7 -5
  425. package/src/api/legacy-utils.ts +1 -1
  426. package/src/api/openapi-ts.ts +2 -0
  427. package/src/api/path-template-warnings.ts +27 -0
  428. package/src/api/run-context.ts +34 -0
  429. package/src/api/transform-context.ts +17 -9
  430. package/src/api/transform-schema.ts +90 -5
  431. package/src/api/unsupported-feature-warnings.ts +8 -1
  432. package/src/application/ports/redocly-config-source.ts +5 -1
  433. package/src/application/print/type-printer.ts +8 -1
  434. package/src/application/transform/document/assignability.ts +203 -0
  435. package/src/application/transform/document/components.ts +6 -6
  436. package/src/application/transform/document/declared-types.ts +93 -0
  437. package/src/application/transform/document/document.ts +71 -13
  438. package/src/application/transform/document/exploded-query.ts +91 -0
  439. package/src/application/transform/document/global-type-references.ts +78 -0
  440. package/src/application/transform/document/list-assignability.ts +87 -0
  441. package/src/application/transform/document/parameters.ts +78 -12
  442. package/src/application/transform/document/path-key-overlaps.ts +148 -59
  443. package/src/application/transform/document/path-template-replace.ts +90 -0
  444. package/src/application/transform/document/paths.ts +101 -38
  445. package/src/application/transform/document/root-type-aliases.ts +29 -28
  446. package/src/application/transform/document/template-key-match.ts +183 -0
  447. package/src/application/transform/document/type-assignability.ts +268 -0
  448. package/src/application/transform/document/type-key.ts +80 -0
  449. package/src/application/transform/document/type-resolution.ts +163 -0
  450. package/src/application/transform/footer/document-footer.ts +91 -6
  451. package/src/application/transform/footer/enum-naming.ts +29 -0
  452. package/src/application/transform/footer/enum-values-check.ts +171 -0
  453. package/src/application/transform/footer/evaluation.ts +57 -0
  454. package/src/application/transform/footer/shared-enum-names.ts +86 -0
  455. package/src/application/transform/footer/type-evaluation.ts +167 -0
  456. package/src/application/transform/footer/type-indexing.ts +152 -0
  457. package/src/application/transform/footer/type-rules.ts +269 -0
  458. package/src/application/transform/ref-pointer/generated-location.ts +211 -0
  459. package/src/application/transform/ref-pointer/generated-shape.ts +275 -0
  460. package/src/application/transform/ref-pointer/inline-cycles.ts +56 -0
  461. package/src/application/transform/ref-pointer/original-index.ts +95 -0
  462. package/src/application/transform/ref-pointer/pointer-type.ts +92 -0
  463. package/src/application/transform/ref-pointer/pointer-walk.ts +96 -0
  464. package/src/application/transform/ref-pointer/typed-walk.ts +192 -0
  465. package/src/application/transform/ref-type.ts +11 -6
  466. package/src/application/transform/schema/access-flags.ts +63 -0
  467. package/src/application/transform/schema/array-type.ts +66 -5
  468. package/src/application/transform/schema/composition-type.ts +96 -24
  469. package/src/application/transform/schema/core-type.ts +8 -4
  470. package/src/application/transform/schema/discriminated-union.ts +58 -0
  471. package/src/application/transform/schema/discriminator-property.ts +8 -3
  472. package/src/application/transform/schema/enum-rule.ts +136 -13
  473. package/src/application/transform/schema/inherited-discriminator.ts +54 -0
  474. package/src/application/transform/schema/object-type.ts +51 -33
  475. package/src/application/transform/schema/required-variants.ts +88 -0
  476. package/src/application/transform/schema/schema-context.ts +26 -0
  477. package/src/application/transform/schema/schema-transform.ts +2 -2
  478. package/src/application/transform/schema-comment.ts +84 -4
  479. package/src/cli/api-settings.ts +109 -0
  480. package/src/cli/cli-arguments.ts +18 -5
  481. package/src/cli/cli-dependencies.ts +5 -0
  482. package/src/cli/cli-errors.ts +4 -2
  483. package/src/cli/cli-output.ts +18 -4
  484. package/src/cli/help-text.ts +4 -4
  485. package/src/cli/main.ts +6 -0
  486. package/src/cli/redocly-apis.ts +21 -11
  487. package/src/cli/ref-limits.ts +2 -2
  488. package/src/cli/run-cli.ts +25 -4
  489. package/src/domain/errors.ts +10 -2
  490. package/src/domain/ir/constructors.ts +9 -1
  491. package/src/domain/ir/nodes.ts +11 -7
  492. package/src/domain/openapi/admitted-values.ts +113 -0
  493. package/src/domain/openapi/discriminated-union.ts +109 -0
  494. package/src/domain/openapi/discriminator-conflicts.ts +251 -0
  495. package/src/domain/openapi/parameter-object.ts +4 -0
  496. package/src/domain/openapi/path-templates.ts +32 -0
  497. package/src/domain/openapi/schema-object.ts +2 -0
  498. package/src/domain/output-fixes.ts +43 -2
  499. package/src/domain/url-credentials.ts +18 -0
  500. package/src/domain/warnings.ts +28 -0
  501. package/src/index.ts +1 -0
  502. package/src/transform/components-object.ts +3 -1
  503. package/src/transform/path-item-object.ts +6 -2
  504. package/src/types/generator-options.ts +12 -21
  505. package/src/types/openapi-common.ts +1 -0
  506. package/src/types/openapi-request.ts +3 -0
  507. package/src/types/openapi-schema.ts +2 -0
  508. package/src/types/openapi-security.ts +1 -0
  509. package/dist/application/transform/document/path-item-conflicts.cjs +0 -51
  510. package/dist/application/transform/document/path-item-conflicts.cjs.map +0 -1
  511. package/dist/application/transform/document/path-item-conflicts.mjs +0 -49
  512. package/dist/application/transform/document/path-item-conflicts.mjs.map +0 -1
  513. package/src/application/transform/document/path-item-conflicts.ts +0 -79
@@ -0,0 +1,144 @@
1
+ 'use strict';
2
+
3
+ const typeResolution = require('./type-resolution.cjs');
4
+
5
+ function everyOf(items, relate) {
6
+ let result = "assignable";
7
+ for (const [index, item] of items.entries()) {
8
+ const each = relate(item, index);
9
+ if (each === "rejected") {
10
+ return "rejected";
11
+ }
12
+ if (each === "undecided") {
13
+ result = "undecided";
14
+ }
15
+ }
16
+ return result;
17
+ }
18
+ function someOf(items, relate) {
19
+ let result = "rejected";
20
+ for (const item of items) {
21
+ const each = relate(item);
22
+ if (each === "assignable") {
23
+ return "assignable";
24
+ }
25
+ if (each === "undecided") {
26
+ result = "undecided";
27
+ }
28
+ }
29
+ return result;
30
+ }
31
+ function provenBy(condition) {
32
+ return condition ? "assignable" : "rejected";
33
+ }
34
+ function categoryOf(type) {
35
+ switch (type.kind) {
36
+ case "keyword":
37
+ case "stringLiteral":
38
+ case "numberLiteral":
39
+ case "booleanLiteral":
40
+ return "primitive";
41
+ case "array":
42
+ case "tuple":
43
+ case "readonly":
44
+ return "list";
45
+ case "object":
46
+ return "object";
47
+ default:
48
+ return "opaque";
49
+ }
50
+ }
51
+ const NO_OBJECT_KEYWORDS = /* @__PURE__ */ new Set(["null", "undefined", "unknown", "never"]);
52
+ const ARRAY_MEMBER_NAMES = /* @__PURE__ */ new Set([
53
+ "length",
54
+ "toString",
55
+ "toLocaleString",
56
+ "pop",
57
+ "push",
58
+ "concat",
59
+ "join",
60
+ "reverse",
61
+ "shift",
62
+ "slice",
63
+ "sort",
64
+ "splice",
65
+ "unshift",
66
+ "indexOf",
67
+ "lastIndexOf",
68
+ "every",
69
+ "some",
70
+ "forEach",
71
+ "map",
72
+ "filter",
73
+ "reduce",
74
+ "reduceRight",
75
+ "find",
76
+ "findIndex",
77
+ "fill",
78
+ "copyWithin",
79
+ "entries",
80
+ "keys",
81
+ "values",
82
+ "includes",
83
+ "flatMap",
84
+ "flat",
85
+ "at",
86
+ "findLast",
87
+ "findLastIndex",
88
+ "toReversed",
89
+ "toSorted",
90
+ "toSpliced",
91
+ "with"
92
+ ]);
93
+ const ARRAY_LENGTH = "length";
94
+ const ELEMENT_NAME_RE = /^\d+$/;
95
+ function isListMemberName(name) {
96
+ return ARRAY_MEMBER_NAMES.has(name) || ELEMENT_NAME_RE.test(name);
97
+ }
98
+ function listToObject(target) {
99
+ const properties = [...typeResolution.propertiesOf(target).values()];
100
+ const isForeign = (property) => !isListMemberName(typeResolution.nameOf(property));
101
+ const needsForeign = properties.some((property) => !property.isOptional && isForeign(property));
102
+ const isWeak = properties.length > 0 && typeResolution.indexSignaturesOf(target).length === 0 && properties.every((property) => property.isOptional);
103
+ return needsForeign || isWeak && properties.every(isForeign) ? "rejected" : "undecided";
104
+ }
105
+ function primitiveToObject(source) {
106
+ const isNoObject = source.kind === "keyword" && NO_OBJECT_KEYWORDS.has(source.keyword);
107
+ return isNoObject ? "rejected" : "undecided";
108
+ }
109
+ function objectToList(source) {
110
+ return typeResolution.propertiesOf(source).has(ARRAY_LENGTH) ? "undecided" : "rejected";
111
+ }
112
+ function crossCategoryRelation(source, target) {
113
+ const from = categoryOf(source);
114
+ const to = categoryOf(target);
115
+ if (from === "opaque" || to === "opaque") {
116
+ return "undecided";
117
+ }
118
+ if (from === to) {
119
+ return null;
120
+ }
121
+ if (to !== "object") {
122
+ return source.kind === "object" && to === "list" ? objectToList(source) : "rejected";
123
+ }
124
+ return from === "primitive" ? primitiveToObject(source) : listToObject(target);
125
+ }
126
+ const LITERAL_KEYWORDS = {
127
+ stringLiteral: "string",
128
+ numberLiteral: "number",
129
+ booleanLiteral: "boolean"
130
+ };
131
+ function primitiveRelation(source, target) {
132
+ if (target.kind !== "keyword" || source.kind === "keyword") {
133
+ return "rejected";
134
+ }
135
+ const keyword = LITERAL_KEYWORDS[source.kind];
136
+ return provenBy(keyword === target.keyword);
137
+ }
138
+
139
+ exports.crossCategoryRelation = crossCategoryRelation;
140
+ exports.everyOf = everyOf;
141
+ exports.primitiveRelation = primitiveRelation;
142
+ exports.provenBy = provenBy;
143
+ exports.someOf = someOf;
144
+ //# sourceMappingURL=assignability.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assignability.cjs","sources":["../../../../src/application/transform/document/assignability.ts"],"sourcesContent":["import type { IrObjectType, IrPropertySignature, IrType } from \"../../../domain/ir/nodes.js\";\nimport { indexSignaturesOf, nameOf, propertiesOf } from \"./type-resolution.js\";\n\n/**\n * What the `--path-params-as-types` overlap check knows about one type where another is expected.\n * `assignable` and `rejected` are proofs of what TypeScript decides (`strict`, without\n * `exactOptionalPropertyTypes`); `undecided` is a pair the check does not model, such as a utility\n * type or raw text. Only a rejection changes the output, so an undecided pair keeps the original.\n */\nexport type Assignability = \"assignable\" | \"rejected\" | \"undecided\";\n\n/**\n * All of the relations: rejected when one is, assignable when each is. The relations are computed\n * lazily, so a rejection stops the rest.\n */\nexport function everyOf<T>(\n items: readonly T[],\n relate: (item: T, index: number) => Assignability,\n): Assignability {\n let result: Assignability = \"assignable\";\n for (const [index, item] of items.entries()) {\n const each = relate(item, index);\n if (each === \"rejected\") {\n return \"rejected\";\n }\n if (each === \"undecided\") {\n result = \"undecided\";\n }\n }\n return result;\n}\n\n/** One of the relations: assignable when one is, rejected when each is. */\nexport function someOf<T>(items: readonly T[], relate: (item: T) => Assignability): Assignability {\n let result: Assignability = \"rejected\";\n for (const item of items) {\n const each = relate(item);\n if (each === \"assignable\") {\n return \"assignable\";\n }\n if (each === \"undecided\") {\n result = \"undecided\";\n }\n }\n return result;\n}\n\n/** Assignable when the condition holds, rejected when it does not. */\nexport function provenBy(condition: boolean): Assignability {\n return condition ? \"assignable\" : \"rejected\";\n}\n\n/**\n * The kinds of resolved types the check tells apart. A type of one kind is never assignable to a\n * type of another, except that a primitive or a list may fit an object type (`string` fits\n * `{ length: number }`), which the check models only in part. `opaque` is any type it cannot\n * read.\n */\ntype TypeCategory = \"primitive\" | \"list\" | \"object\" | \"opaque\";\n\nfunction categoryOf(type: IrType): TypeCategory {\n switch (type.kind) {\n case \"keyword\":\n case \"stringLiteral\":\n case \"numberLiteral\":\n case \"booleanLiteral\":\n return \"primitive\";\n case \"array\":\n case \"tuple\":\n case \"readonly\":\n return \"list\";\n case \"object\":\n return \"object\";\n default:\n return \"opaque\";\n }\n}\n\n/** Keywords that are no object: `{}` rejects them under `strictNullChecks`. */\nconst NO_OBJECT_KEYWORDS: ReadonlySet<string> = new Set([\"null\", \"undefined\", \"unknown\", \"never\"]);\n\n/**\n * The members of `ReadonlyArray` and `Array` in the TypeScript libraries up to ESNext. An object\n * type that needs a property of another name is no list; a numeric name may be a tuple element.\n */\nconst ARRAY_MEMBER_NAMES: ReadonlySet<string> = new Set([\n \"length\",\n \"toString\",\n \"toLocaleString\",\n \"pop\",\n \"push\",\n \"concat\",\n \"join\",\n \"reverse\",\n \"shift\",\n \"slice\",\n \"sort\",\n \"splice\",\n \"unshift\",\n \"indexOf\",\n \"lastIndexOf\",\n \"every\",\n \"some\",\n \"forEach\",\n \"map\",\n \"filter\",\n \"reduce\",\n \"reduceRight\",\n \"find\",\n \"findIndex\",\n \"fill\",\n \"copyWithin\",\n \"entries\",\n \"keys\",\n \"values\",\n \"includes\",\n \"flatMap\",\n \"flat\",\n \"at\",\n \"findLast\",\n \"findLastIndex\",\n \"toReversed\",\n \"toSorted\",\n \"toSpliced\",\n \"with\",\n]);\n\nconst ARRAY_LENGTH = \"length\";\n/** A tuple element's name: `\"0\"`, `\"1\"`. */\nconst ELEMENT_NAME_RE = /^\\d+$/;\n\nfunction isListMemberName(name: string): boolean {\n return ARRAY_MEMBER_NAMES.has(name) || ELEMENT_NAME_RE.test(name);\n}\n\n/**\n * Whether a list fits an object type. It does not when the object needs a property no list has\n * (TS2741), or when the object is a weak type and no list has one of its properties (TS2559).\n */\nfunction listToObject(target: IrObjectType): Assignability {\n const properties = [...propertiesOf(target).values()];\n const isForeign = (property: IrPropertySignature) => !isListMemberName(nameOf(property));\n const needsForeign = properties.some((property) => !property.isOptional && isForeign(property));\n const isWeak =\n properties.length > 0 &&\n indexSignaturesOf(target).length === 0 &&\n properties.every((property) => property.isOptional);\n return needsForeign || (isWeak && properties.every(isForeign)) ? \"rejected\" : \"undecided\";\n}\n\n/**\n * Whether a primitive fits an object type: `null`, `undefined` and `unknown` never do; any other\n * may (`{}`, `{ length: number }`), which is not modelled.\n */\nfunction primitiveToObject(source: IrType): Assignability {\n const isNoObject = source.kind === \"keyword\" && NO_OBJECT_KEYWORDS.has(source.keyword);\n return isNoObject ? \"rejected\" : \"undecided\";\n}\n\n/** An object type fits an array only with all of its members; `length` is the first it needs. */\nfunction objectToList(source: IrObjectType): Assignability {\n return propertiesOf(source).has(ARRAY_LENGTH) ? \"undecided\" : \"rejected\";\n}\n\n/**\n * The relation of two types of different categories, or null when they are of the same one.\n * Primitive and list targets accept nothing of another category; see `TypeCategory`.\n */\nexport function crossCategoryRelation(source: IrType, target: IrType): Assignability | null {\n const from = categoryOf(source);\n const to = categoryOf(target);\n if (from === \"opaque\" || to === \"opaque\") {\n return \"undecided\";\n }\n if (from === to) {\n return null;\n }\n if (to !== \"object\") {\n return source.kind === \"object\" && to === \"list\" ? objectToList(source) : \"rejected\";\n }\n return from === \"primitive\" ? primitiveToObject(source) : listToObject(target as IrObjectType);\n}\n\n/** The keyword a literal type belongs to. */\nconst LITERAL_KEYWORDS = {\n stringLiteral: \"string\",\n numberLiteral: \"number\",\n booleanLiteral: \"boolean\",\n} as const;\n\n/**\n * The relation of two primitive types written differently (the same text is assignable). A\n * literal fits its keyword; any other pair is rejected: different keywords, different literals,\n * a keyword for one literal (a union of literals is compared in `type-assignability.ts`), and\n * anything for `never`.\n */\nexport function primitiveRelation(source: IrType, target: IrType): Assignability {\n if (target.kind !== \"keyword\" || source.kind === \"keyword\") {\n return \"rejected\";\n }\n const keyword = (LITERAL_KEYWORDS as Partial<Record<IrType[\"kind\"], string>>)[source.kind];\n return provenBy(keyword === target.keyword);\n}\n"],"names":["propertiesOf","nameOf","indexSignaturesOf"],"mappings":";;;;AAeO,SAAS,OAAA,CACd,OACA,MAAA,EACe;AACf,EAAA,IAAI,MAAA,GAAwB,YAAA;AAC5B,EAAA,KAAA,MAAW,CAAC,KAAA,EAAO,IAAI,CAAA,IAAK,KAAA,CAAM,SAAQ,EAAG;AAC3C,IAAA,MAAM,IAAA,GAAO,MAAA,CAAO,IAAA,EAAM,KAAK,CAAA;AAC/B,IAAA,IAAI,SAAS,UAAA,EAAY;AACvB,MAAA,OAAO,UAAA;AAAA,IACT;AACA,IAAA,IAAI,SAAS,WAAA,EAAa;AACxB,MAAA,MAAA,GAAS,WAAA;AAAA,IACX;AAAA,EACF;AACA,EAAA,OAAO,MAAA;AACT;AAGO,SAAS,MAAA,CAAU,OAAqB,MAAA,EAAmD;AAChG,EAAA,IAAI,MAAA,GAAwB,UAAA;AAC5B,EAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,IAAA,MAAM,IAAA,GAAO,OAAO,IAAI,CAAA;AACxB,IAAA,IAAI,SAAS,YAAA,EAAc;AACzB,MAAA,OAAO,YAAA;AAAA,IACT;AACA,IAAA,IAAI,SAAS,WAAA,EAAa;AACxB,MAAA,MAAA,GAAS,WAAA;AAAA,IACX;AAAA,EACF;AACA,EAAA,OAAO,MAAA;AACT;AAGO,SAAS,SAAS,SAAA,EAAmC;AAC1D,EAAA,OAAO,YAAY,YAAA,GAAe,UAAA;AACpC;AAUA,SAAS,WAAW,IAAA,EAA4B;AAC9C,EAAA,QAAQ,KAAK,IAAA;AAAM,IACjB,KAAK,SAAA;AAAA,IACL,KAAK,eAAA;AAAA,IACL,KAAK,eAAA;AAAA,IACL,KAAK,gBAAA;AACH,MAAA,OAAO,WAAA;AAAA,IACT,KAAK,OAAA;AAAA,IACL,KAAK,OAAA;AAAA,IACL,KAAK,UAAA;AACH,MAAA,OAAO,M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;AAAA,EAC5E;AACA,EAAA,OAAO,SAAS,WAAA,GAAc,iBAAA,CAAkB,MAAM,CAAA,GAAI,aAAa,MAAsB,CAAA;AAC/F;AAGA,MAAM,gBAAA,GAAmB;AAAA,EACvB,aAAA,EAAe,QAAA;AAAA,EACf,aAAA,EAAe,QAAA;AAAA,EACf,cAAA,EAAgB;AAClB,CAAA;AAQO,SAAS,iBAAA,CAAkB,QAAgB,MAAA,EAA+B;AAC/E,EAAA,IAAI,MAAA,CAAO,IAAA,KAAS,SAAA,IAAa,MAAA,CAAO,SAAS,SAAA,EAAW;AAC1D,IAAA,OAAO,UAAA;AAAA,EACT;AACA,EAAA,MAAM,OAAA,GAAW,gBAAA,CAA6D,MAAA,CAAO,IAAI,CAAA;AACzF,EAAA,OAAO,QAAA,CAAS,OAAA,KAAY,MAAA,CAAO,OAAO,CAAA;AAC5C;;;;;;"}
@@ -0,0 +1,138 @@
1
+ import { propertiesOf, indexSignaturesOf, nameOf } from './type-resolution.mjs';
2
+
3
+ function everyOf(items, relate) {
4
+ let result = "assignable";
5
+ for (const [index, item] of items.entries()) {
6
+ const each = relate(item, index);
7
+ if (each === "rejected") {
8
+ return "rejected";
9
+ }
10
+ if (each === "undecided") {
11
+ result = "undecided";
12
+ }
13
+ }
14
+ return result;
15
+ }
16
+ function someOf(items, relate) {
17
+ let result = "rejected";
18
+ for (const item of items) {
19
+ const each = relate(item);
20
+ if (each === "assignable") {
21
+ return "assignable";
22
+ }
23
+ if (each === "undecided") {
24
+ result = "undecided";
25
+ }
26
+ }
27
+ return result;
28
+ }
29
+ function provenBy(condition) {
30
+ return condition ? "assignable" : "rejected";
31
+ }
32
+ function categoryOf(type) {
33
+ switch (type.kind) {
34
+ case "keyword":
35
+ case "stringLiteral":
36
+ case "numberLiteral":
37
+ case "booleanLiteral":
38
+ return "primitive";
39
+ case "array":
40
+ case "tuple":
41
+ case "readonly":
42
+ return "list";
43
+ case "object":
44
+ return "object";
45
+ default:
46
+ return "opaque";
47
+ }
48
+ }
49
+ const NO_OBJECT_KEYWORDS = /* @__PURE__ */ new Set(["null", "undefined", "unknown", "never"]);
50
+ const ARRAY_MEMBER_NAMES = /* @__PURE__ */ new Set([
51
+ "length",
52
+ "toString",
53
+ "toLocaleString",
54
+ "pop",
55
+ "push",
56
+ "concat",
57
+ "join",
58
+ "reverse",
59
+ "shift",
60
+ "slice",
61
+ "sort",
62
+ "splice",
63
+ "unshift",
64
+ "indexOf",
65
+ "lastIndexOf",
66
+ "every",
67
+ "some",
68
+ "forEach",
69
+ "map",
70
+ "filter",
71
+ "reduce",
72
+ "reduceRight",
73
+ "find",
74
+ "findIndex",
75
+ "fill",
76
+ "copyWithin",
77
+ "entries",
78
+ "keys",
79
+ "values",
80
+ "includes",
81
+ "flatMap",
82
+ "flat",
83
+ "at",
84
+ "findLast",
85
+ "findLastIndex",
86
+ "toReversed",
87
+ "toSorted",
88
+ "toSpliced",
89
+ "with"
90
+ ]);
91
+ const ARRAY_LENGTH = "length";
92
+ const ELEMENT_NAME_RE = /^\d+$/;
93
+ function isListMemberName(name) {
94
+ return ARRAY_MEMBER_NAMES.has(name) || ELEMENT_NAME_RE.test(name);
95
+ }
96
+ function listToObject(target) {
97
+ const properties = [...propertiesOf(target).values()];
98
+ const isForeign = (property) => !isListMemberName(nameOf(property));
99
+ const needsForeign = properties.some((property) => !property.isOptional && isForeign(property));
100
+ const isWeak = properties.length > 0 && indexSignaturesOf(target).length === 0 && properties.every((property) => property.isOptional);
101
+ return needsForeign || isWeak && properties.every(isForeign) ? "rejected" : "undecided";
102
+ }
103
+ function primitiveToObject(source) {
104
+ const isNoObject = source.kind === "keyword" && NO_OBJECT_KEYWORDS.has(source.keyword);
105
+ return isNoObject ? "rejected" : "undecided";
106
+ }
107
+ function objectToList(source) {
108
+ return propertiesOf(source).has(ARRAY_LENGTH) ? "undecided" : "rejected";
109
+ }
110
+ function crossCategoryRelation(source, target) {
111
+ const from = categoryOf(source);
112
+ const to = categoryOf(target);
113
+ if (from === "opaque" || to === "opaque") {
114
+ return "undecided";
115
+ }
116
+ if (from === to) {
117
+ return null;
118
+ }
119
+ if (to !== "object") {
120
+ return source.kind === "object" && to === "list" ? objectToList(source) : "rejected";
121
+ }
122
+ return from === "primitive" ? primitiveToObject(source) : listToObject(target);
123
+ }
124
+ const LITERAL_KEYWORDS = {
125
+ stringLiteral: "string",
126
+ numberLiteral: "number",
127
+ booleanLiteral: "boolean"
128
+ };
129
+ function primitiveRelation(source, target) {
130
+ if (target.kind !== "keyword" || source.kind === "keyword") {
131
+ return "rejected";
132
+ }
133
+ const keyword = LITERAL_KEYWORDS[source.kind];
134
+ return provenBy(keyword === target.keyword);
135
+ }
136
+
137
+ export { crossCategoryRelation, everyOf, primitiveRelation, provenBy, someOf };
138
+ //# sourceMappingURL=assignability.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assignability.mjs","sources":["../../../../src/application/transform/document/assignability.ts"],"sourcesContent":["import type { IrObjectType, IrPropertySignature, IrType } from \"../../../domain/ir/nodes.js\";\nimport { indexSignaturesOf, nameOf, propertiesOf } from \"./type-resolution.js\";\n\n/**\n * What the `--path-params-as-types` overlap check knows about one type where another is expected.\n * `assignable` and `rejected` are proofs of what TypeScript decides (`strict`, without\n * `exactOptionalPropertyTypes`); `undecided` is a pair the check does not model, such as a utility\n * type or raw text. Only a rejection changes the output, so an undecided pair keeps the original.\n */\nexport type Assignability = \"assignable\" | \"rejected\" | \"undecided\";\n\n/**\n * All of the relations: rejected when one is, assignable when each is. The relations are computed\n * lazily, so a rejection stops the rest.\n */\nexport function everyOf<T>(\n items: readonly T[],\n relate: (item: T, index: number) => Assignability,\n): Assignability {\n let result: Assignability = \"assignable\";\n for (const [index, item] of items.entries()) {\n const each = relate(item, index);\n if (each === \"rejected\") {\n return \"rejected\";\n }\n if (each === \"undecided\") {\n result = \"undecided\";\n }\n }\n return result;\n}\n\n/** One of the relations: assignable when one is, rejected when each is. */\nexport function someOf<T>(items: readonly T[], relate: (item: T) => Assignability): Assignability {\n let result: Assignability = \"rejected\";\n for (const item of items) {\n const each = relate(item);\n if (each === \"assignable\") {\n return \"assignable\";\n }\n if (each === \"undecided\") {\n result = \"undecided\";\n }\n }\n return result;\n}\n\n/** Assignable when the condition holds, rejected when it does not. */\nexport function provenBy(condition: boolean): Assignability {\n return condition ? \"assignable\" : \"rejected\";\n}\n\n/**\n * The kinds of resolved types the check tells apart. A type of one kind is never assignable to a\n * type of another, except that a primitive or a list may fit an object type (`string` fits\n * `{ length: number }`), which the check models only in part. `opaque` is any type it cannot\n * read.\n */\ntype TypeCategory = \"primitive\" | \"list\" | \"object\" | \"opaque\";\n\nfunction categoryOf(type: IrType): TypeCategory {\n switch (type.kind) {\n case \"keyword\":\n case \"stringLiteral\":\n case \"numberLiteral\":\n case \"booleanLiteral\":\n return \"primitive\";\n case \"array\":\n case \"tuple\":\n case \"readonly\":\n return \"list\";\n case \"object\":\n return \"object\";\n default:\n return \"opaque\";\n }\n}\n\n/** Keywords that are no object: `{}` rejects them under `strictNullChecks`. */\nconst NO_OBJECT_KEYWORDS: ReadonlySet<string> = new Set([\"null\", \"undefined\", \"unknown\", \"never\"]);\n\n/**\n * The members of `ReadonlyArray` and `Array` in the TypeScript libraries up to ESNext. An object\n * type that needs a property of another name is no list; a numeric name may be a tuple element.\n */\nconst ARRAY_MEMBER_NAMES: ReadonlySet<string> = new Set([\n \"length\",\n \"toString\",\n \"toLocaleString\",\n \"pop\",\n \"push\",\n \"concat\",\n \"join\",\n \"reverse\",\n \"shift\",\n \"slice\",\n \"sort\",\n \"splice\",\n \"unshift\",\n \"indexOf\",\n \"lastIndexOf\",\n \"every\",\n \"some\",\n \"forEach\",\n \"map\",\n \"filter\",\n \"reduce\",\n \"reduceRight\",\n \"find\",\n \"findIndex\",\n \"fill\",\n \"copyWithin\",\n \"entries\",\n \"keys\",\n \"values\",\n \"includes\",\n \"flatMap\",\n \"flat\",\n \"at\",\n \"findLast\",\n \"findLastIndex\",\n \"toReversed\",\n \"toSorted\",\n \"toSpliced\",\n \"with\",\n]);\n\nconst ARRAY_LENGTH = \"length\";\n/** A tuple element's name: `\"0\"`, `\"1\"`. */\nconst ELEMENT_NAME_RE = /^\\d+$/;\n\nfunction isListMemberName(name: string): boolean {\n return ARRAY_MEMBER_NAMES.has(name) || ELEMENT_NAME_RE.test(name);\n}\n\n/**\n * Whether a list fits an object type. It does not when the object needs a property no list has\n * (TS2741), or when the object is a weak type and no list has one of its properties (TS2559).\n */\nfunction listToObject(target: IrObjectType): Assignability {\n const properties = [...propertiesOf(target).values()];\n const isForeign = (property: IrPropertySignature) => !isListMemberName(nameOf(property));\n const needsForeign = properties.some((property) => !property.isOptional && isForeign(property));\n const isWeak =\n properties.length > 0 &&\n indexSignaturesOf(target).length === 0 &&\n properties.every((property) => property.isOptional);\n return needsForeign || (isWeak && properties.every(isForeign)) ? \"rejected\" : \"undecided\";\n}\n\n/**\n * Whether a primitive fits an object type: `null`, `undefined` and `unknown` never do; any other\n * may (`{}`, `{ length: number }`), which is not modelled.\n */\nfunction primitiveToObject(source: IrType): Assignability {\n const isNoObject = source.kind === \"keyword\" && NO_OBJECT_KEYWORDS.has(source.keyword);\n return isNoObject ? \"rejected\" : \"undecided\";\n}\n\n/** An object type fits an array only with all of its members; `length` is the first it needs. */\nfunction objectToList(source: IrObjectType): Assignability {\n return propertiesOf(source).has(ARRAY_LENGTH) ? \"undecided\" : \"rejected\";\n}\n\n/**\n * The relation of two types of different categories, or null when they are of the same one.\n * Primitive and list targets accept nothing of another category; see `TypeCategory`.\n */\nexport function crossCategoryRelation(source: IrType, target: IrType): Assignability | null {\n const from = categoryOf(source);\n const to = categoryOf(target);\n if (from === \"opaque\" || to === \"opaque\") {\n return \"undecided\";\n }\n if (from === to) {\n return null;\n }\n if (to !== \"object\") {\n return source.kind === \"object\" && to === \"list\" ? objectToList(source) : \"rejected\";\n }\n return from === \"primitive\" ? primitiveToObject(source) : listToObject(target as IrObjectType);\n}\n\n/** The keyword a literal type belongs to. */\nconst LITERAL_KEYWORDS = {\n stringLiteral: \"string\",\n numberLiteral: \"number\",\n booleanLiteral: \"boolean\",\n} as const;\n\n/**\n * The relation of two primitive types written differently (the same text is assignable). A\n * literal fits its keyword; any other pair is rejected: different keywords, different literals,\n * a keyword for one literal (a union of literals is compared in `type-assignability.ts`), and\n * anything for `never`.\n */\nexport function primitiveRelation(source: IrType, target: IrType): Assignability {\n if (target.kind !== \"keyword\" || source.kind === \"keyword\") {\n return \"rejected\";\n }\n const keyword = (LITERAL_KEYWORDS as Partial<Record<IrType[\"kind\"], string>>)[source.kind];\n return provenBy(keyword === target.keyword);\n}\n"],"names":[],"mappings":";;AAeO,SAAS,OAAA,CACd,OACA,MAAA,EACe;AACf,EAAA,IAAI,MAAA,GAAwB,YAAA;AAC5B,EAAA,KAAA,MAAW,CAAC,KAAA,EAAO,IAAI,CAAA,IAAK,KAAA,CAAM,SAAQ,EAAG;AAC3C,IAAA,MAAM,IAAA,GAAO,MAAA,CAAO,IAAA,EAAM,KAAK,CAAA;AAC/B,IAAA,IAAI,SAAS,UAAA,EAAY;AACvB,MAAA,OAAO,UAAA;AAAA,IACT;AACA,IAAA,IAAI,SAAS,WAAA,EAAa;AACxB,MAAA,MAAA,GAAS,WAAA;AAAA,IACX;AAAA,EACF;AACA,EAAA,OAAO,MAAA;AACT;AAGO,SAAS,MAAA,CAAU,OAAqB,MAAA,EAAmD;AAChG,EAAA,IAAI,MAAA,GAAwB,UAAA;AAC5B,EAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,IAAA,MAAM,IAAA,GAAO,OAAO,IAAI,CAAA;AACxB,IAAA,IAAI,SAAS,YAAA,EAAc;AACzB,MAAA,OAAO,YAAA;AAAA,IACT;AACA,IAAA,IAAI,SAAS,WAAA,EAAa;AACxB,MAAA,MAAA,GAAS,WAAA;AAAA,IACX;AAAA,EACF;AACA,EAAA,OAAO,MAAA;AACT;AAGO,SAAS,SAAS,SAAA,EAAmC;AAC1D,EAAA,OAAO,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,IAAA,KAAS,QAAA,IAAY,EAAA,KAAO,QAAA,EAAU;AACxC,IAAA,OAAO,WAAA;AAAA,EACT;AACA,EAAA,IAAI,SAAS,EAAA,EAAI;AACf,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,IAAI,OAAO,QAAA,EAAU;AACnB,IAAA,OAAO,OAAO,IAAA,KAAS,QAAA,IAAY,OAAO,MAAA,GAAS,YAAA,CAAa,MAAM,CAAA,GAAI,UAAA;AAAA,EAC5E;AACA,EAAA,OAAO,SAAS,WAAA,GAAc,iBAAA,CAAkB,MAAM,CAAA,GAAI,aAAa,MAAsB,CAAA;AAC/F;AAGA,MAAM,gBAAA,GAAmB;AAAA,EACvB,aAAA,EAAe,QAAA;AAAA,EACf,aAAA,EAAe,QAAA;AAAA,EACf,cAAA,EAAgB;AAClB,CAAA;AAQO,SAAS,iBAAA,CAAkB,QAAgB,MAAA,EAA+B;AAC/E,EAAA,IAAI,MAAA,CAAO,IAAA,KAAS,SAAA,IAAa,MAAA,CAAO,SAAS,SAAA,EAAW;AAC1D,IAAA,OAAO,UAAA;AAAA,EACT;AACA,EAAA,MAAM,OAAA,GAAW,gBAAA,CAA6D,MAAA,CAAO,IAAI,CAAA;AACzF,EAAA,OAAO,QAAA,CAAS,OAAA,KAAY,MAAA,CAAO,OAAO,CAAA;AAC5C;;"}
@@ -34,7 +34,7 @@ function componentMember(kind, name, item, context) {
34
34
  isOptional: custom?.isOptional ?? false,
35
35
  isReadonly: context.options.immutable
36
36
  });
37
- return schemaComment.withSchemaComment(property, item);
37
+ return schemaComment.withSchemaComment(property, item, schemaComment.schemaCommentOptionsOf(context.options.fixes));
38
38
  }
39
39
  function rootTypeName(kind, name, aliases, context) {
40
40
  const { options, casing } = context;
@@ -96,7 +96,7 @@ function componentsType(components, context, kept = /* @__PURE__ */ new Set()) {
96
96
  const rootTypes = Object.values(aliases);
97
97
  return {
98
98
  type: constructors.irObject(members),
99
- rootTypes: [...rootTypes, ...rootTypeAliases.numberDisplacedAliases(displaced ?? [], rootTypes)]
99
+ rootTypes: [...rootTypes, ...displaced ?? []]
100
100
  };
101
101
  }
102
102
 
@@ -1 +1 @@
1
- {"version":3,"file":"components.cjs","sources":["../../../../src/application/transform/document/components.ts"],"sourcesContent":["import { irKeyword, irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport {\n hasIdentifierStart,\n isReservedTypeName,\n withIdentifierParts,\n} from \"../../../domain/ir/identifier-text.js\";\nimport type {\n IrPropertySignature,\n IrType,\n IrTypeAliasDeclaration,\n} from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport {\n COMPONENT_KINDS,\n type ComponentKind,\n type ComponentsObject,\n DECLARED_COMPONENT_KINDS,\n isEnumSchema,\n singularizeComponentKind,\n} from \"../../../domain/openapi/components-object.js\";\nimport { createRef } from \"../../../domain/openapi/json-pointer.js\";\nimport { OutputFix } from \"../../../domain/output-fixes.js\";\nimport { type DeprecatedEntryFilter, documentEntries } from \"../document-entries.js\";\nimport type { SchemaLocation } from \"../schema/schema-context.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport { withSchemaComment } from \"../schema-comment.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { headerType } from \"./header.js\";\nimport { contentEntryType } from \"./media-type.js\";\nimport { parameterType } from \"./parameter.js\";\nimport { pathItemType } from \"./path-item.js\";\nimport { requestBodyType } from \"./request-body.js\";\nimport { responseType } from \"./response.js\";\nimport { numberDisplacedAliases, rootTypeAlias } from \"./root-type-aliases.js\";\n\ntype ComponentTransform = (\n item: never,\n location: SchemaLocation,\n context: TransformContext,\n) => IrType;\n\nconst COMPONENT_TRANSFORMS: Readonly<Record<ComponentKind, ComponentTransform>> = {\n schemas: transformSchema,\n responses: responseType,\n parameters: parameterType,\n requestBodies: requestBodyType,\n headers: headerType,\n pathItems: pathItemType,\n mediaTypes: contentEntryType,\n};\n\n/** The `components` type and the `--root-types` aliases. */\nexport interface ComponentsResult {\n readonly type: IrType;\n readonly rootTypes: readonly IrTypeAliasDeclaration[];\n}\n\n/** One component; the `transform` callback may replace its type, as for nested schemas. */\nfunction componentMember(\n kind: ComponentKind,\n name: string,\n item: unknown,\n context: TransformContext,\n): IrPropertySignature {\n const location = { path: createRef([\"components\", kind, name]), schema: item };\n const type = COMPONENT_TRANSFORMS[kind](item as never, location, context);\n const custom = context.callbacks.transform(item, location);\n const property = irProperty(toPropertyName(name), custom?.type ?? type, {\n isOptional: custom?.isOptional ?? false,\n isReadonly: context.options.immutable,\n });\n return withSchemaComment(property, item);\n}\n\n/**\n * The root alias name: `SchemaPet`, `ResponseNotFound`, … A taken name gets `_2`, `_3`, … The\n * original checks for conflicts before it removes the schema prefix, and so does this; for a clash\n * of exported names see `addRootAlias`.\n *\n * The original could build a name that is no identifier, so the generated file did not parse\n * (research/legacy-bugs.md, item 16): a kept casing keeps spaces and symbols, which become `_`;\n * and a name without the prefix can start with a digit, so it keeps the prefix (`Schema1`). A\n * kept casing without the prefix can also give a reserved name (`void`, `class`), which keeps the\n * prefix too (`Schemavoid`).\n */\nfunction rootTypeName(\n kind: ComponentKind,\n name: string,\n aliases: Readonly<Record<string, IrTypeAliasDeclaration>>,\n context: TransformContext,\n): string {\n const { options, casing } = context;\n const prefix = casing.pascalCase(singularizeComponentKind(kind));\n const isSchema = kind === \"schemas\";\n const base = withIdentifierParts(\n options.rootTypesKeepCasing && isSchema ? name : casing.pascalCase(name),\n );\n const exportedName = (alias: string): string => {\n const unprefixed = alias.replace(prefix, \"\");\n const isUnprefixed = options.rootTypesNoSchemaPrefix && isSchema;\n const isTypeName = hasIdentifierStart(unprefixed) && !isReservedTypeName(unprefixed);\n return isUnprefixed && isTypeName ? unprefixed : alias;\n };\n let alias = `${prefix}${base}`;\n for (let counter = 2; aliases[alias] !== undefined; counter++) {\n alias = `${prefix}${base}_${counter}`;\n }\n return exportedName(alias);\n}\n\n/**\n * Add a root alias. When its exported name is taken (two schemas of one PascalCase name without\n * the prefix), the later schema takes the name, as in the original. Without the\n * `root-type-numbering` fix the earlier one then has no alias: that output is valid, so a number\n * for it would change it (backlog 30). With the fix the earlier alias is kept aside and numbered\n * at the end.\n */\nfunction addRootAlias(request: ComponentsRequest, alias: IrTypeAliasDeclaration): void {\n const { aliases, displaced } = request;\n const previous = aliases[alias.name];\n if (previous !== undefined && displaced !== null) {\n displaced.push(previous);\n }\n aliases[alias.name] = alias;\n}\n\n/** `--root-types` skips enum schemas under `--enum`: the enum itself is exported. */\nfunction hasRootType(kind: ComponentKind, item: unknown, context: TransformContext): boolean {\n const { options } = context;\n return options.rootTypes && !(options.enum && kind === \"schemas\" && isEnumSchema(item));\n}\n\n/** The components of one run, and the deprecated ones that kept output still references. */\ninterface ComponentsRequest {\n readonly components: ComponentsObject;\n readonly isKept: DeprecatedEntryFilter;\n readonly aliases: Record<string, IrTypeAliasDeclaration>;\n /** With the `root-type-numbering` fix: the aliases a later schema took the name of, in order. */\n readonly displaced: IrTypeAliasDeclaration[] | null;\n}\n\nfunction kindMember(\n kind: ComponentKind,\n request: ComponentsRequest,\n context: TransformContext,\n): IrPropertySignature {\n const { components, isKept, aliases } = request;\n const startedAt = context.diagnostics.now();\n const items: IrPropertySignature[] = [];\n for (const [name, item] of documentEntries(components[kind] ?? {}, context.options, isKept)) {\n items.push(componentMember(kind, name, item, context));\n if (hasRootType(kind, item, context)) {\n addRootAlias(request, rootTypeAlias(rootTypeName(kind, name, aliases, context), kind, name));\n }\n }\n const type = items.length > 0 ? irObject(items) : irKeyword(\"never\");\n context.diagnostics.debug(\n `Transformed components → ${kind}`,\n context.diagnostics.now() - startedAt,\n );\n return irProperty(toPropertyName(kind), type);\n}\n\n/**\n * The `components` interface body (OpenAPI 3.1 §4.8.7), one member per component kind. With\n * `--exclude-deprecated`, `kept` holds the deprecated components that kept output references\n * (`keptDeprecatedComponents`); they stay, so no reference names a missing key.\n */\nexport function componentsType(\n components: ComponentsObject,\n context: TransformContext,\n kept: ReadonlySet<object> = new Set(),\n): ComponentsResult {\n // A plain object, as in the original: its key order (integer-like names first) is the\n // output order.\n const aliases: Record<string, IrTypeAliasDeclaration> = {};\n const displaced = context.options.fixes.has(OutputFix.ROOT_TYPE_NUMBERING) ? [] : null;\n const isKept = (item: unknown) => kept.has(item as object);\n const request = { components, isKept, aliases, displaced };\n const declaredKinds = DECLARED_COMPONENT_KINDS.filter((kind) => components[kind] !== undefined);\n const members = [...COMPONENT_KINDS, ...declaredKinds].map((kind) =>\n kindMember(kind, request, context),\n );\n const rootTypes = Object.values(aliases);\n return {\n type: irObject(members),\n rootTypes: [...rootTypes, ...numberDisplacedAliases(displaced ?? [], rootTypes)],\n };\n}\n"],"names":["transformSchema","responseType","parameterType","requestBodyType","headerType","pathItemType","contentEntryType","createRef","irProperty","toPropertyName","withSchemaComment","singularizeComponentKind","withIdentifierParts","alias","hasIdentifierStart","isReservedTypeName","isEnumSchema","documentEntries","rootTypeAlias","irObject","irKeyword","OutputFix","DECLARED_COMPONENT_KINDS","COMPONENT_KINDS","numberDisplacedAliases"],"mappings":";;;;;;;;;;;;;;;;;;;AAyCA,MAAM,oBAAA,GAA4E;AAAA,EAChF,OAAA,EAASA,+BAAA;AAAA,EACT,SAAA,EAAWC,qBAAA;AAAA,EACX,UAAA,EAAYC,uBAAA;AAAA,EACZ,aAAA,EAAeC,2BAAA;AAAA,EACf,OAAA,EAASC,iBAAA;AAAA,EACT,SAAA,EAAWC,qBAAA;AAAA,EACX,UAAA,EAAYC;AACd,CAAA;AASA,SAAS,eAAA,CACP,IAAA,EACA,IAAA,EACA,IAAA,EACA,OAAA,EACqB;AACrB,EAAA,MAAM,QAAA,GAAW,EAAE,IAAA,EAAMC,qBAAA,CAAU,CAAC,YAAA,EAAc,IAAA,EAAM,IAAI,CAAC,CAAA,EAAG,MAAA,EAAQ,IAAA,EAAK;AAC7E,EAAA,MAAM,OAAO,oBAAA,CAAqB,IAAI,CAAA,CAAE,IAAA,EAAe,UAAU,OAAO,CAAA;AACxE,EAA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AAO;AAAA,GACnC;AACA,EAAA,MAAM,SAAA,GAAY,MAAA,CAAO,MAAA,CAAO,OAAO,CAAA;AACvC,EAAA,OAAO;AAAA,IACL,IAAA,EAAMJ,sBAAS,OAAO,CAAA;AAAA,IACtB,SAAA,EAAW,CAAC,GAAG,SAAA,EAAW,GAAGK,uCAAuB,SAAA,IAAa,EAAC,EAAG,SAAS,CAAC;AAAA,GACjF;AACF;;"}
1
+ {"version":3,"file":"components.cjs","sources":["../../../../src/application/transform/document/components.ts"],"sourcesContent":["import { irKeyword, irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport {\n hasIdentifierStart,\n isReservedTypeName,\n withIdentifierParts,\n} from \"../../../domain/ir/identifier-text.js\";\nimport type {\n IrPropertySignature,\n IrType,\n IrTypeAliasDeclaration,\n} from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport {\n COMPONENT_KINDS,\n type ComponentKind,\n type ComponentsObject,\n DECLARED_COMPONENT_KINDS,\n isEnumSchema,\n singularizeComponentKind,\n} from \"../../../domain/openapi/components-object.js\";\nimport { createRef } from \"../../../domain/openapi/json-pointer.js\";\nimport { OutputFix } from \"../../../domain/output-fixes.js\";\nimport { type DeprecatedEntryFilter, documentEntries } from \"../document-entries.js\";\nimport type { SchemaLocation } from \"../schema/schema-context.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport { schemaCommentOptionsOf, withSchemaComment } from \"../schema-comment.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { headerType } from \"./header.js\";\nimport { contentEntryType } from \"./media-type.js\";\nimport { parameterType } from \"./parameter.js\";\nimport { pathItemType } from \"./path-item.js\";\nimport { requestBodyType } from \"./request-body.js\";\nimport { responseType } from \"./response.js\";\nimport { rootTypeAlias } from \"./root-type-aliases.js\";\n\ntype ComponentTransform = (\n item: never,\n location: SchemaLocation,\n context: TransformContext,\n) => IrType;\n\nconst COMPONENT_TRANSFORMS: Readonly<Record<ComponentKind, ComponentTransform>> = {\n schemas: transformSchema,\n responses: responseType,\n parameters: parameterType,\n requestBodies: requestBodyType,\n headers: headerType,\n pathItems: pathItemType,\n mediaTypes: contentEntryType,\n};\n\n/** The `components` type and the `--root-types` aliases. */\nexport interface ComponentsResult {\n readonly type: IrType;\n readonly rootTypes: readonly IrTypeAliasDeclaration[];\n}\n\n/** One component; the `transform` callback may replace its type, as for nested schemas. */\nfunction componentMember(\n kind: ComponentKind,\n name: string,\n item: unknown,\n context: TransformContext,\n): IrPropertySignature {\n const location = { path: createRef([\"components\", kind, name]), schema: item };\n const type = COMPONENT_TRANSFORMS[kind](item as never, location, context);\n const custom = context.callbacks.transform(item, location);\n const property = irProperty(toPropertyName(name), custom?.type ?? type, {\n isOptional: custom?.isOptional ?? false,\n isReadonly: context.options.immutable,\n });\n return withSchemaComment(property, item, schemaCommentOptionsOf(context.options.fixes));\n}\n\n/**\n * The root alias name: `SchemaPet`, `ResponseNotFound`, … A taken name gets `_2`, `_3`, … The\n * original checks for conflicts before it removes the schema prefix, and so does this; for a clash\n * of exported names see `addRootAlias`.\n *\n * The original could build a name that is no identifier, so the generated file did not parse\n * (research/legacy-bugs.md, item 16): a kept casing keeps spaces and symbols, which become `_`;\n * and a name without the prefix can start with a digit, so it keeps the prefix (`Schema1`). A\n * kept casing without the prefix can also give a reserved name (`void`, `class`), which keeps the\n * prefix too (`Schemavoid`).\n */\nfunction rootTypeName(\n kind: ComponentKind,\n name: string,\n aliases: Readonly<Record<string, IrTypeAliasDeclaration>>,\n context: TransformContext,\n): string {\n const { options, casing } = context;\n const prefix = casing.pascalCase(singularizeComponentKind(kind));\n const isSchema = kind === \"schemas\";\n const base = withIdentifierParts(\n options.rootTypesKeepCasing && isSchema ? name : casing.pascalCase(name),\n );\n const exportedName = (alias: string): string => {\n const unprefixed = alias.replace(prefix, \"\");\n const isUnprefixed = options.rootTypesNoSchemaPrefix && isSchema;\n const isTypeName = hasIdentifierStart(unprefixed) && !isReservedTypeName(unprefixed);\n return isUnprefixed && isTypeName ? unprefixed : alias;\n };\n let alias = `${prefix}${base}`;\n for (let counter = 2; aliases[alias] !== undefined; counter++) {\n alias = `${prefix}${base}_${counter}`;\n }\n return exportedName(alias);\n}\n\n/**\n * Add a root alias. When its exported name is taken (two schemas of one PascalCase name without\n * the prefix), the later schema takes the name, as in the original. Without the\n * `root-type-numbering` fix the earlier one then has no alias: that output is valid, so a number\n * for it would change it (backlog 30). With the fix the earlier alias is kept aside and follows\n * the others under the same name; `renameTakenAliases` numbers it once every name is known.\n */\nfunction addRootAlias(request: ComponentsRequest, alias: IrTypeAliasDeclaration): void {\n const { aliases, displaced } = request;\n const previous = aliases[alias.name];\n if (previous !== undefined && displaced !== null) {\n displaced.push(previous);\n }\n aliases[alias.name] = alias;\n}\n\n/** `--root-types` skips enum schemas under `--enum`: the enum itself is exported. */\nfunction hasRootType(kind: ComponentKind, item: unknown, context: TransformContext): boolean {\n const { options } = context;\n return options.rootTypes && !(options.enum && kind === \"schemas\" && isEnumSchema(item));\n}\n\n/** The components of one run, and the deprecated ones that kept output still references. */\ninterface ComponentsRequest {\n readonly components: ComponentsObject;\n readonly isKept: DeprecatedEntryFilter;\n readonly aliases: Record<string, IrTypeAliasDeclaration>;\n /** With the `root-type-numbering` fix: the aliases a later schema took the name of, in order. */\n readonly displaced: IrTypeAliasDeclaration[] | null;\n}\n\nfunction kindMember(\n kind: ComponentKind,\n request: ComponentsRequest,\n context: TransformContext,\n): IrPropertySignature {\n const { components, isKept, aliases } = request;\n const startedAt = context.diagnostics.now();\n const items: IrPropertySignature[] = [];\n for (const [name, item] of documentEntries(components[kind] ?? {}, context.options, isKept)) {\n items.push(componentMember(kind, name, item, context));\n if (hasRootType(kind, item, context)) {\n addRootAlias(request, rootTypeAlias(rootTypeName(kind, name, aliases, context), kind, name));\n }\n }\n const type = items.length > 0 ? irObject(items) : irKeyword(\"never\");\n context.diagnostics.debug(\n `Transformed components → ${kind}`,\n context.diagnostics.now() - startedAt,\n );\n return irProperty(toPropertyName(kind), type);\n}\n\n/**\n * The `components` interface body (OpenAPI 3.1 §4.8.7), one member per component kind. With\n * `--exclude-deprecated`, `kept` holds the deprecated components that kept output references\n * (`keptDeprecatedComponents`); they stay, so no reference names a missing key.\n */\nexport function componentsType(\n components: ComponentsObject,\n context: TransformContext,\n kept: ReadonlySet<object> = new Set(),\n): ComponentsResult {\n // A plain object, as in the original: its key order (integer-like names first) is the\n // output order.\n const aliases: Record<string, IrTypeAliasDeclaration> = {};\n const displaced = context.options.fixes.has(OutputFix.ROOT_TYPE_NUMBERING) ? [] : null;\n const isKept = (item: unknown) => kept.has(item as object);\n const request = { components, isKept, aliases, displaced };\n const declaredKinds = DECLARED_COMPONENT_KINDS.filter((kind) => components[kind] !== undefined);\n const members = [...COMPONENT_KINDS, ...declaredKinds].map((kind) =>\n kindMember(kind, request, context),\n );\n const rootTypes = Object.values(aliases);\n return {\n type: irObject(members),\n rootTypes: [...rootTypes, ...(displaced ?? [])],\n };\n}\n"],"names":["transformSchema","responseType","parameterType","requestBodyType","headerType","pathItemType","contentEntryType","createRef","irProperty","toPropertyName","withSchemaComment","schemaCommentOptionsOf","singularizeComponentKind","withIdentifierParts","alias","hasIdentifierStart","isReservedTypeName","isEnumSchema","documentEntries","rootTypeAlias","irObject","irKeyword","OutputFix","DECLARED_COMPONENT_KINDS","COMPONENT_KINDS"],"mappings":";;;;;;;;;;;;;;;;;;;AAyCA,MAAM,oBAAA,GAA4E;AAAA,EAChF,OAAA,EAASA,+BAAA;AAAA,EACT,SAAA,EAAWC,qBAAA;AAAA,EACX,UAAA,EAAYC,uBAAA;AAAA,EACZ,aAAA,EAAeC,2BAAA;AAAA,EACf,OAAA,EAASC,iBAAA;AAAA,EACT,SAAA,EAAWC,qBAAA;AAAA,EACX,UAAA,EAAYC;AACd,CAAA;AASA,SAAS,eAAA,CACP,IAAA,EACA,IAAA,EACA,IAAA,EACA,OAAA,EACqB;AACrB,EAAA,MAAM,QAAA,GAAW,EAAE,I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A,EAAU;AACzD,EAAA,MAAM,aAAA,GAAgBC,0CAAyB,MAAA,CAAO,CAAC,SAAS,UAAA,CAAW,IAAI,MAAM,MAAS,CAAA;AAC9F,EAAA,MAAM,UAAU,CAAC,GAAGC,gCAAA,EAAiB,GAAG,aAAa,CAAA,CAAE,GAAA;AAAA,IAAI,CAAC,IAAA,KAC1D,UAAA,CAAW,IAAA,EAAM,SAAS,OAAO;AAAA,GACnC;AACA,EAAA,MAAM,SAAA,GAAY,MAAA,CAAO,MAAA,CAAO,OAAO,CAAA;AACvC,EAAA,OAAO;AAAA,IACL,IAAA,EAAMJ,sBAAS,OAAO,CAAA;AAAA,IACtB,WAAW,CAAC,GAAG,WAAW,GAAI,SAAA,IAAa,EAAG;AAAA,GAChD;AACF;;"}
@@ -6,14 +6,14 @@ import { createRef } from '../../../domain/openapi/json-pointer.mjs';
6
6
  import { OutputFix } from '../../../domain/output-fixes.mjs';
7
7
  import { documentEntries } from '../document-entries.mjs';
8
8
  import { transformSchema } from '../schema/schema-transform.mjs';
9
- import { withSchemaComment } from '../schema-comment.mjs';
9
+ import { withSchemaComment, schemaCommentOptionsOf } from '../schema-comment.mjs';
10
10
  import { headerType } from './header.mjs';
11
11
  import { contentEntryType } from './media-type.mjs';
12
12
  import { parameterType } from './parameter.mjs';
13
13
  import { pathItemType } from './path-item.mjs';
14
14
  import { requestBodyType } from './request-body.mjs';
15
15
  import { responseType } from './response.mjs';
16
- import { numberDisplacedAliases, rootTypeAlias } from './root-type-aliases.mjs';
16
+ import { rootTypeAlias } from './root-type-aliases.mjs';
17
17
 
18
18
  const COMPONENT_TRANSFORMS = {
19
19
  schemas: transformSchema,
@@ -32,7 +32,7 @@ function componentMember(kind, name, item, context) {
32
32
  isOptional: custom?.isOptional ?? false,
33
33
  isReadonly: context.options.immutable
34
34
  });
35
- return withSchemaComment(property, item);
35
+ return withSchemaComment(property, item, schemaCommentOptionsOf(context.options.fixes));
36
36
  }
37
37
  function rootTypeName(kind, name, aliases, context) {
38
38
  const { options, casing } = context;
@@ -94,7 +94,7 @@ function componentsType(components, context, kept = /* @__PURE__ */ new Set()) {
94
94
  const rootTypes = Object.values(aliases);
95
95
  return {
96
96
  type: irObject(members),
97
- rootTypes: [...rootTypes, ...numberDisplacedAliases(displaced ?? [], rootTypes)]
97
+ rootTypes: [...rootTypes, ...displaced ?? []]
98
98
  };
99
99
  }
100
100
 
@@ -1 +1 @@
1
- {"version":3,"file":"components.mjs","sources":["../../../../src/application/transform/document/components.ts"],"sourcesContent":["import { irKeyword, irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport {\n hasIdentifierStart,\n isReservedTypeName,\n withIdentifierParts,\n} from \"../../../domain/ir/identifier-text.js\";\nimport type {\n IrPropertySignature,\n IrType,\n IrTypeAliasDeclaration,\n} from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport {\n COMPONENT_KINDS,\n type ComponentKind,\n type ComponentsObject,\n DECLARED_COMPONENT_KINDS,\n isEnumSchema,\n singularizeComponentKind,\n} from \"../../../domain/openapi/components-object.js\";\nimport { createRef } from \"../../../domain/openapi/json-pointer.js\";\nimport { OutputFix } from \"../../../domain/output-fixes.js\";\nimport { type DeprecatedEntryFilter, documentEntries } from \"../document-entries.js\";\nimport type { SchemaLocation } from \"../schema/schema-context.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport { withSchemaComment } from \"../schema-comment.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { headerType } from \"./header.js\";\nimport { contentEntryType } from \"./media-type.js\";\nimport { parameterType } from \"./parameter.js\";\nimport { pathItemType } from \"./path-item.js\";\nimport { requestBodyType } from \"./request-body.js\";\nimport { responseType } from \"./response.js\";\nimport { numberDisplacedAliases, rootTypeAlias } from \"./root-type-aliases.js\";\n\ntype ComponentTransform = (\n item: never,\n location: SchemaLocation,\n context: TransformContext,\n) => IrType;\n\nconst COMPONENT_TRANSFORMS: Readonly<Record<ComponentKind, ComponentTransform>> = {\n schemas: transformSchema,\n responses: responseType,\n parameters: parameterType,\n requestBodies: requestBodyType,\n headers: headerType,\n pathItems: pathItemType,\n mediaTypes: contentEntryType,\n};\n\n/** The `components` type and the `--root-types` aliases. */\nexport interface ComponentsResult {\n readonly type: IrType;\n readonly rootTypes: readonly IrTypeAliasDeclaration[];\n}\n\n/** One component; the `transform` callback may replace its type, as for nested schemas. */\nfunction componentMember(\n kind: ComponentKind,\n name: string,\n item: unknown,\n context: TransformContext,\n): IrPropertySignature {\n const location = { path: createRef([\"components\", kind, name]), schema: item };\n const type = COMPONENT_TRANSFORMS[kind](item as never, location, context);\n const custom = context.callbacks.transform(item, location);\n const property = irProperty(toPropertyName(name), custom?.type ?? type, {\n isOptional: custom?.isOptional ?? false,\n isReadonly: context.options.immutable,\n });\n return withSchemaComment(property, item);\n}\n\n/**\n * The root alias name: `SchemaPet`, `ResponseNotFound`, … A taken name gets `_2`, `_3`, … The\n * original checks for conflicts before it removes the schema prefix, and so does this; for a clash\n * of exported names see `addRootAlias`.\n *\n * The original could build a name that is no identifier, so the generated file did not parse\n * (research/legacy-bugs.md, item 16): a kept casing keeps spaces and symbols, which become `_`;\n * and a name without the prefix can start with a digit, so it keeps the prefix (`Schema1`). A\n * kept casing without the prefix can also give a reserved name (`void`, `class`), which keeps the\n * prefix too (`Schemavoid`).\n */\nfunction rootTypeName(\n kind: ComponentKind,\n name: string,\n aliases: Readonly<Record<string, IrTypeAliasDeclaration>>,\n context: TransformContext,\n): string {\n const { options, casing } = context;\n const prefix = casing.pascalCase(singularizeComponentKind(kind));\n const isSchema = kind === \"schemas\";\n const base = withIdentifierParts(\n options.rootTypesKeepCasing && isSchema ? name : casing.pascalCase(name),\n );\n const exportedName = (alias: string): string => {\n const unprefixed = alias.replace(prefix, \"\");\n const isUnprefixed = options.rootTypesNoSchemaPrefix && isSchema;\n const isTypeName = hasIdentifierStart(unprefixed) && !isReservedTypeName(unprefixed);\n return isUnprefixed && isTypeName ? unprefixed : alias;\n };\n let alias = `${prefix}${base}`;\n for (let counter = 2; aliases[alias] !== undefined; counter++) {\n alias = `${prefix}${base}_${counter}`;\n }\n return exportedName(alias);\n}\n\n/**\n * Add a root alias. When its exported name is taken (two schemas of one PascalCase name without\n * the prefix), the later schema takes the name, as in the original. Without the\n * `root-type-numbering` fix the earlier one then has no alias: that output is valid, so a number\n * for it would change it (backlog 30). With the fix the earlier alias is kept aside and numbered\n * at the end.\n */\nfunction addRootAlias(request: ComponentsRequest, alias: IrTypeAliasDeclaration): void {\n const { aliases, displaced } = request;\n const previous = aliases[alias.name];\n if (previous !== undefined && displaced !== null) {\n displaced.push(previous);\n }\n aliases[alias.name] = alias;\n}\n\n/** `--root-types` skips enum schemas under `--enum`: the enum itself is exported. */\nfunction hasRootType(kind: ComponentKind, item: unknown, context: TransformContext): boolean {\n const { options } = context;\n return options.rootTypes && !(options.enum && kind === \"schemas\" && isEnumSchema(item));\n}\n\n/** The components of one run, and the deprecated ones that kept output still references. */\ninterface ComponentsRequest {\n readonly components: ComponentsObject;\n readonly isKept: DeprecatedEntryFilter;\n readonly aliases: Record<string, IrTypeAliasDeclaration>;\n /** With the `root-type-numbering` fix: the aliases a later schema took the name of, in order. */\n readonly displaced: IrTypeAliasDeclaration[] | null;\n}\n\nfunction kindMember(\n kind: ComponentKind,\n request: ComponentsRequest,\n context: TransformContext,\n): IrPropertySignature {\n const { components, isKept, aliases } = request;\n const startedAt = context.diagnostics.now();\n const items: IrPropertySignature[] = [];\n for (const [name, item] of documentEntries(components[kind] ?? {}, context.options, isKept)) {\n items.push(componentMember(kind, name, item, context));\n if (hasRootType(kind, item, context)) {\n addRootAlias(request, rootTypeAlias(rootTypeName(kind, name, aliases, context), kind, name));\n }\n }\n const type = items.length > 0 ? irObject(items) : irKeyword(\"never\");\n context.diagnostics.debug(\n `Transformed components → ${kind}`,\n context.diagnostics.now() - startedAt,\n );\n return irProperty(toPropertyName(kind), type);\n}\n\n/**\n * The `components` interface body (OpenAPI 3.1 §4.8.7), one member per component kind. With\n * `--exclude-deprecated`, `kept` holds the deprecated components that kept output references\n * (`keptDeprecatedComponents`); they stay, so no reference names a missing key.\n */\nexport function componentsType(\n components: ComponentsObject,\n context: TransformContext,\n kept: ReadonlySet<object> = new Set(),\n): ComponentsResult {\n // A plain object, as in the original: its key order (integer-like names first) is the\n // output order.\n const aliases: Record<string, IrTypeAliasDeclaration> = {};\n const displaced = context.options.fixes.has(OutputFix.ROOT_TYPE_NUMBERING) ? [] : null;\n const isKept = (item: unknown) => kept.has(item as object);\n const request = { components, isKept, aliases, displaced };\n const declaredKinds = DECLARED_COMPONENT_KINDS.filter((kind) => components[kind] !== undefined);\n const members = [...COMPONENT_KINDS, ...declaredKinds].map((kind) =>\n kindMember(kind, request, context),\n );\n const rootTypes = Object.values(aliases);\n return {\n type: irObject(members),\n rootTypes: [...rootTypes, ...numberDisplacedAliases(displaced ?? [], rootTypes)],\n };\n}\n"],"names":["alias"],"mappings":";;;;;;;;;;;;;;;;;AAyCA,MAAM,oBAAA,GAA4E;AAAA,EAChF,OAAA,EAAS,eAAA;AAAA,EACT,SAAA,EAAW,YAAA;AAAA,EACX,UAAA,EAAY,aAAA;AAAA,EACZ,aAAA,EAAe,eAAA;AAAA,EACf,OAAA,EAAS,UAAA;AAAA,EACT,SAAA,EAAW,YAAA;AAAA,EACX,UAAA,EAAY;AACd,CAAA;AASA,SAAS,eAAA,CACP,IAAA,EACA,IAAA,EACA,IAAA,EACA,OAAA,EACqB;AACrB,EAAA,MAAM,QAAA,GAAW,EAAE,IAAA,EAAM,SAAA,CAAU,CAAC,YAAA,EAAc,IAAA,EAAM,IAAI,CAAC,CAAA,EAAG,MAAA,EAAQ,IAAA,EAAK;AAC7E,EAAA,MAAM,OAAO,oBAAA,CAAqB,IAAI,CAAA,CAAE,IAAA,EAAe,UAAU,OAAO,CAAA;AACxE,EAAA,MAAM,MAAA,GAAS,OAAA,CAAQ,SAAA,CAAU,SAAA,CAAU,MAAM,QAAQ,CAAA;A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IAAA,EAAM,SAAS,OAAO,CAAA;AAAA,IACtB,SAAA,EAAW,CAAC,GAAG,SAAA,EAAW,GAAG,uBAAuB,SAAA,IAAa,EAAC,EAAG,SAAS,CAAC;AAAA,GACjF;AACF;;"}
1
+ {"version":3,"file":"components.mjs","sources":["../../../../src/application/transform/document/components.ts"],"sourcesContent":["import { irKeyword, irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport {\n hasIdentifierStart,\n isReservedTypeName,\n withIdentifierParts,\n} from \"../../../domain/ir/identifier-text.js\";\nimport type {\n IrPropertySignature,\n IrType,\n IrTypeAliasDeclaration,\n} from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport {\n COMPONENT_KINDS,\n type ComponentKind,\n type ComponentsObject,\n DECLARED_COMPONENT_KINDS,\n isEnumSchema,\n singularizeComponentKind,\n} from \"../../../domain/openapi/components-object.js\";\nimport { createRef } from \"../../../domain/openapi/json-pointer.js\";\nimport { OutputFix } from \"../../../domain/output-fixes.js\";\nimport { type DeprecatedEntryFilter, documentEntries } from \"../document-entries.js\";\nimport type { SchemaLocation } from \"../schema/schema-context.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport { schemaCommentOptionsOf, withSchemaComment } from \"../schema-comment.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { headerType } from \"./header.js\";\nimport { contentEntryType } from \"./media-type.js\";\nimport { parameterType } from \"./parameter.js\";\nimport { pathItemType } from \"./path-item.js\";\nimport { requestBodyType } from \"./request-body.js\";\nimport { responseType } from \"./response.js\";\nimport { rootTypeAlias } from \"./root-type-aliases.js\";\n\ntype ComponentTransform = (\n item: never,\n location: SchemaLocation,\n context: TransformContext,\n) => IrType;\n\nconst COMPONENT_TRANSFORMS: Readonly<Record<ComponentKind, ComponentTransform>> = {\n schemas: transformSchema,\n responses: responseType,\n parameters: parameterType,\n requestBodies: requestBodyType,\n headers: headerType,\n pathItems: pathItemType,\n mediaTypes: contentEntryType,\n};\n\n/** The `components` type and the `--root-types` aliases. */\nexport interface ComponentsResult {\n readonly type: IrType;\n readonly rootTypes: readonly IrTypeAliasDeclaration[];\n}\n\n/** One component; the `transform` callback may replace its type, as for nested schemas. */\nfunction componentMember(\n kind: ComponentKind,\n name: string,\n item: unknown,\n context: TransformContext,\n): IrPropertySignature {\n const location = { path: createRef([\"components\", kind, name]), schema: item };\n const type = COMPONENT_TRANSFORMS[kind](item as never, location, context);\n const custom = context.callbacks.transform(item, location);\n const property = irProperty(toPropertyName(name), custom?.type ?? type, {\n isOptional: custom?.isOptional ?? false,\n isReadonly: context.options.immutable,\n });\n return withSchemaComment(property, item, schemaCommentOptionsOf(context.options.fixes));\n}\n\n/**\n * The root alias name: `SchemaPet`, `ResponseNotFound`, … A taken name gets `_2`, `_3`, … The\n * original checks for conflicts before it removes the schema prefix, and so does this; for a clash\n * of exported names see `addRootAlias`.\n *\n * The original could build a name that is no identifier, so the generated file did not parse\n * (research/legacy-bugs.md, item 16): a kept casing keeps spaces and symbols, which become `_`;\n * and a name without the prefix can start with a digit, so it keeps the prefix (`Schema1`). A\n * kept casing without the prefix can also give a reserved name (`void`, `class`), which keeps the\n * prefix too (`Schemavoid`).\n */\nfunction rootTypeName(\n kind: ComponentKind,\n name: string,\n aliases: Readonly<Record<string, IrTypeAliasDeclaration>>,\n context: TransformContext,\n): string {\n const { options, casing } = context;\n const prefix = casing.pascalCase(singularizeComponentKind(kind));\n const isSchema = kind === \"schemas\";\n const base = withIdentifierParts(\n options.rootTypesKeepCasing && isSchema ? name : casing.pascalCase(name),\n );\n const exportedName = (alias: string): string => {\n const unprefixed = alias.replace(prefix, \"\");\n const isUnprefixed = options.rootTypesNoSchemaPrefix && isSchema;\n const isTypeName = hasIdentifierStart(unprefixed) && !isReservedTypeName(unprefixed);\n return isUnprefixed && isTypeName ? unprefixed : alias;\n };\n let alias = `${prefix}${base}`;\n for (let counter = 2; aliases[alias] !== undefined; counter++) {\n alias = `${prefix}${base}_${counter}`;\n }\n return exportedName(alias);\n}\n\n/**\n * Add a root alias. When its exported name is taken (two schemas of one PascalCase name without\n * the prefix), the later schema takes the name, as in the original. Without the\n * `root-type-numbering` fix the earlier one then has no alias: that output is valid, so a number\n * for it would change it (backlog 30). With the fix the earlier alias is kept aside and follows\n * the others under the same name; `renameTakenAliases` numbers it once every name is known.\n */\nfunction addRootAlias(request: ComponentsRequest, alias: IrTypeAliasDeclaration): void {\n const { aliases, displaced } = request;\n const previous = aliases[alias.name];\n if (previous !== undefined && displaced !== null) {\n displaced.push(previous);\n }\n aliases[alias.name] = alias;\n}\n\n/** `--root-types` skips enum schemas under `--enum`: the enum itself is exported. */\nfunction hasRootType(kind: ComponentKind, item: unknown, context: TransformContext): boolean {\n const { options } = context;\n return options.rootTypes && !(options.enum && kind === \"schemas\" && isEnumSchema(item));\n}\n\n/** The components of one run, and the deprecated ones that kept output still references. */\ninterface ComponentsRequest {\n readonly components: ComponentsObject;\n readonly isKept: DeprecatedEntryFilter;\n readonly aliases: Record<string, IrTypeAliasDeclaration>;\n /** With the `root-type-numbering` fix: the aliases a later schema took the name of, in order. */\n readonly displaced: IrTypeAliasDeclaration[] | null;\n}\n\nfunction kindMember(\n kind: ComponentKind,\n request: ComponentsRequest,\n context: TransformContext,\n): IrPropertySignature {\n const { components, isKept, aliases } = request;\n const startedAt = context.diagnostics.now();\n const items: IrPropertySignature[] = [];\n for (const [name, item] of documentEntries(components[kind] ?? {}, context.options, isKept)) {\n items.push(componentMember(kind, name, item, context));\n if (hasRootType(kind, item, context)) {\n addRootAlias(request, rootTypeAlias(rootTypeName(kind, name, aliases, context), kind, name));\n }\n }\n const type = items.length > 0 ? irObject(items) : irKeyword(\"never\");\n context.diagnostics.debug(\n `Transformed components → ${kind}`,\n context.diagnostics.now() - startedAt,\n );\n return irProperty(toPropertyName(kind), type);\n}\n\n/**\n * The `components` interface body (OpenAPI 3.1 §4.8.7), one member per component kind. With\n * `--exclude-deprecated`, `kept` holds the deprecated components that kept output references\n * (`keptDeprecatedComponents`); they stay, so no reference names a missing key.\n */\nexport function componentsType(\n components: ComponentsObject,\n context: TransformContext,\n kept: ReadonlySet<object> = new Set(),\n): ComponentsResult {\n // A plain object, as in the original: its key order (integer-like names first) is the\n // output order.\n const aliases: Record<string, IrTypeAliasDeclaration> = {};\n const displaced = context.options.fixes.has(OutputFix.ROOT_TYPE_NUMBERING) ? [] : null;\n const isKept = (item: unknown) => kept.has(item as object);\n const request = { components, isKept, aliases, displaced };\n const declaredKinds = DECLARED_COMPONENT_KINDS.filter((kind) => components[kind] !== undefined);\n const members = [...COMPONENT_KINDS, ...declaredKinds].map((kind) =>\n kindMember(kind, request, context),\n );\n const rootTypes = Object.values(aliases);\n return {\n type: irObject(members),\n rootTypes: [...rootTypes, ...(displaced ?? [])],\n };\n}\n"],"names":["alias"],"mappings":";;;;;;;;;;;;;;;;;AAyCA,MAAM,oBAAA,GAA4E;AAAA,EAChF,OAAA,EAAS,eAAA;AAAA,EACT,SAAA,EAAW,YAAA;AAAA,EACX,UAAA,EAAY,aAAA;AAAA,EACZ,aAAA,EAAe,eAAA;AAAA,EACf,OAAA,EAAS,UAAA;AAAA,EACT,SAAA,EAAW,YAAA;AAAA,EACX,UAAA,EAAY;AACd,CAAA;AASA,SAAS,eAAA,CACP,IAAA,EACA,IAAA,EACA,IAAA,EACA,OAAA,EACqB;AACrB,EAAA,MAAM,QAAA,GAAW,EAAE,IAAA,EAAM,SAAA,CAAU,CAAC,YAAA,EAAc,IAAA,EAAM,IAAI,CAAC,CAAA,EAAG,MAAA,EAAQ,IAAA,EAAK;AAC7E,EAAA,MAAM,OAAO,oBAAA,CAAqB,IAAI,CAAA,CAAE,IAAA,EAAe,UAAU,OAAO,CAAA;AACxE,EAAA,MAAM,MAAA,GAAS,OAAA,CAAQ,SAAA,CAAU,SAAA,CAAU,MAAM,QAAQ,CAAA;AACzD,EAAA,MAAM,WAAW,UAAA,CAAW,cAAA,CAAe,IAAI,CAAA,EAAG,MAAA,EA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AO,CAAA;AAAA,IACtB,WAAW,CAAC,GAAG,WAAW,GAAI,SAAA,IAAa,EAAG;AAAA,GAChD;AACF;;"}
@@ -0,0 +1,66 @@
1
+ 'use strict';
2
+
3
+ const NO_DECLARED_TYPES = () => null;
4
+ function indexedNameOf(type) {
5
+ if (type.kind === "reference") {
6
+ return type.typeArguments.length === 0 ? { name: type.name, keys: [] } : null;
7
+ }
8
+ if (type.kind !== "indexedAccess" || type.index.kind !== "stringLiteral") {
9
+ return null;
10
+ }
11
+ const object = indexedNameOf(type.object);
12
+ return object === null ? null : { ...object, keys: [...object.keys, type.index.value] };
13
+ }
14
+ function memberName(member) {
15
+ if (member.kind !== "property") {
16
+ return null;
17
+ }
18
+ return member.name.kind === "string" ? member.name.value : member.name.text;
19
+ }
20
+ function propertyType(type, key) {
21
+ if (type.kind !== "object") {
22
+ return null;
23
+ }
24
+ const member = type.members.find((candidate) => memberName(candidate) === key);
25
+ return member?.kind === "property" && !member.isOptional ? member.type : null;
26
+ }
27
+ function declarationType(declaration) {
28
+ switch (declaration.kind) {
29
+ case "interface":
30
+ return { kind: "object", members: declaration.members };
31
+ case "typeAlias":
32
+ return declaration.type;
33
+ case "enum":
34
+ case "constArray":
35
+ case "rawDeclaration":
36
+ return null;
37
+ }
38
+ }
39
+ function declaredTypeLookup(declarations) {
40
+ const byName = /* @__PURE__ */ new Map();
41
+ for (const declaration of declarations) {
42
+ if ("name" in declaration && declaration.name !== void 0) {
43
+ const isRepeated = byName.has(declaration.name);
44
+ byName.set(declaration.name, isRepeated ? null : declarationType(declaration));
45
+ }
46
+ }
47
+ const resolving = /* @__PURE__ */ new Set();
48
+ const lookup = (type) => {
49
+ const indexed = indexedNameOf(type);
50
+ if (indexed === null || indexed.keys.length === 0 || resolving.has(type)) {
51
+ return null;
52
+ }
53
+ resolving.add(type);
54
+ const declared = indexed.keys.reduce((object, key) => {
55
+ const named = object === null || object.kind === "object" ? object : lookup(object);
56
+ return named === null ? null : propertyType(named, key);
57
+ }, byName.get(indexed.name) ?? null);
58
+ resolving.delete(type);
59
+ return declared;
60
+ };
61
+ return lookup;
62
+ }
63
+
64
+ exports.NO_DECLARED_TYPES = NO_DECLARED_TYPES;
65
+ exports.declaredTypeLookup = declaredTypeLookup;
66
+ //# sourceMappingURL=declared-types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declared-types.cjs","sources":["../../../../src/application/transform/document/declared-types.ts"],"sourcesContent":["import type { IrDeclaration, IrMember, IrType } from \"../../../domain/ir/nodes.js\";\n\n/**\n * The type a reference of the generated file names, read from the file's declarations: the\n * `--path-params-as-types` overlap check compares two path items through the operations and\n * components they reference (upstream #1752).\n */\n\n/** The declared type a reference names, or null when the type is no such reference. */\nexport type DeclaredTypeLookup = (type: IrType) => IrType | null;\n\n/** Knows no declaration: every reference stays unresolved. */\nexport const NO_DECLARED_TYPES: DeclaredTypeLookup = () => null;\n\n/** A reference without type arguments and the string keys indexing it: `components[\"schemas\"]`. */\ninterface IndexedName {\n readonly name: string;\n readonly keys: readonly string[];\n}\n\nfunction indexedNameOf(type: IrType): IndexedName | null {\n if (type.kind === \"reference\") {\n return type.typeArguments.length === 0 ? { name: type.name, keys: [] } : null;\n }\n if (type.kind !== \"indexedAccess\" || type.index.kind !== \"stringLiteral\") {\n return null;\n }\n const object = indexedNameOf(type.object);\n return object === null ? null : { ...object, keys: [...object.keys, type.index.value] };\n}\n\nfunction memberName(member: IrMember): string | null {\n if (member.kind !== \"property\") {\n return null;\n }\n return member.name.kind === \"string\" ? member.name.value : member.name.text;\n}\n\n/**\n * The type of the required property `key`. An optional one is `T | undefined` when indexed, which\n * is not the declared type, so it is not followed.\n */\nfunction propertyType(type: IrType, key: string): IrType | null {\n if (type.kind !== \"object\") {\n return null;\n }\n const member = type.members.find((candidate) => memberName(candidate) === key);\n return member?.kind === \"property\" && !member.isOptional ? member.type : null;\n}\n\nfunction declarationType(declaration: IrDeclaration): IrType | null {\n switch (declaration.kind) {\n case \"interface\":\n return { kind: \"object\", members: declaration.members };\n case \"typeAlias\":\n return declaration.type;\n case \"enum\":\n case \"constArray\":\n case \"rawDeclaration\":\n return null;\n }\n}\n\n/**\n * A lookup over the declarations. Only a name declared once is read: a second declaration of an\n * interface merges with the first, which this lookup does not model.\n */\nexport function declaredTypeLookup(declarations: readonly IrDeclaration[]): DeclaredTypeLookup {\n const byName = new Map<string, IrType | null>();\n for (const declaration of declarations) {\n if (\"name\" in declaration && declaration.name !== undefined) {\n const isRepeated = byName.has(declaration.name);\n byName.set(declaration.name, isRepeated ? null : declarationType(declaration));\n }\n }\n // References being resolved: a reference that indexes into itself names no type.\n const resolving = new Set<IrType>();\n const lookup: DeclaredTypeLookup = (type) => {\n const indexed = indexedNameOf(type);\n if (indexed === null || indexed.keys.length === 0 || resolving.has(type)) {\n return null;\n }\n resolving.add(type);\n // A key may index a property whose type is a reference again (`paths[\"/a\"][\"get\"]`).\n const declared = indexed.keys.reduce<IrType | null>((object, key) => {\n const named = object === null || object.kind === \"object\" ? object : lookup(object);\n return named === null ? null : propertyType(named, key);\n }, byName.get(indexed.name) ?? null);\n resolving.delete(type);\n return declared;\n };\n return lookup;\n}\n"],"names":[],"mappings":";;AAYO,MAAM,oBAAwC,MAAM;AAQ3D,SAAS,cAAc,IAAA,EAAkC;AACvD,EAAA,IAAI,IAAA,CAAK,SAAS,WAAA,EAAa;AAC7B,IAAA,OAAO,IAAA,CAAK,aAAA,CAAc,MAAA,KAAW,CAAA,GAAI,EAAE,IAAA,EAAM,IAAA,CAAK,IAAA,EAAM,IAAA,EAAM,EAAC,EAAE,GAAI,IAAA;AAAA,EAC3E;AACA,EAAA,IAAI,KAAK,IAAA,KAAS,eAAA,IAAmB,IAAA,CAAK,KAAA,CAAM,SAAS,eAAA,EAAiB;AACxE,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,MAAA,GAAS,aAAA,CAAc,IAAA,CAAK,MAAM,CAAA;AACxC,EAAA,OAAO,MAAA,KAAW,IAAA,GAAO,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