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

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 (514) hide show
  1. package/CHANGELOG.md +1831 -0
  2. package/dist/adapters/node-deprecations/node-deprecations.cjs +14 -0
  3. package/dist/adapters/node-deprecations/node-deprecations.cjs.map +1 -0
  4. package/dist/adapters/node-deprecations/node-deprecations.mjs +12 -0
  5. package/dist/adapters/node-deprecations/node-deprecations.mjs.map +1 -0
  6. package/dist/adapters/node-file-system/file-claims.cjs +105 -0
  7. package/dist/adapters/node-file-system/file-claims.cjs.map +1 -0
  8. package/dist/adapters/node-file-system/file-claims.mjs +95 -0
  9. package/dist/adapters/node-file-system/file-claims.mjs.map +1 -0
  10. package/dist/adapters/node-file-system/file-identity.cjs +82 -0
  11. package/dist/adapters/node-file-system/file-identity.cjs.map +1 -0
  12. package/dist/adapters/node-file-system/file-identity.mjs +74 -0
  13. package/dist/adapters/node-file-system/file-identity.mjs.map +1 -0
  14. package/dist/adapters/node-file-system/node-file-system.cjs +90 -14
  15. package/dist/adapters/node-file-system/node-file-system.cjs.map +1 -1
  16. package/dist/adapters/node-file-system/node-file-system.mjs +90 -14
  17. package/dist/adapters/node-file-system/node-file-system.mjs.map +1 -1
  18. package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs +75 -0
  19. package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs.map +1 -0
  20. package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs +72 -0
  21. package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs.map +1 -0
  22. package/dist/adapters/redocly-loader/bundled-ref-repair.cjs +1 -1
  23. package/dist/adapters/redocly-loader/bundled-ref-repair.cjs.map +1 -1
  24. package/dist/adapters/redocly-loader/bundled-ref-repair.mjs +2 -2
  25. package/dist/adapters/redocly-loader/bundled-ref-repair.mjs.map +1 -1
  26. package/dist/adapters/redocly-loader/loaded-documents.cjs +28 -0
  27. package/dist/adapters/redocly-loader/loaded-documents.cjs.map +1 -0
  28. package/dist/adapters/redocly-loader/loaded-documents.mjs +21 -0
  29. package/dist/adapters/redocly-loader/loaded-documents.mjs.map +1 -0
  30. package/dist/adapters/redocly-loader/redocly-schema-loader.cjs +14 -15
  31. package/dist/adapters/redocly-loader/redocly-schema-loader.cjs.map +1 -1
  32. package/dist/adapters/redocly-loader/redocly-schema-loader.mjs +12 -13
  33. package/dist/adapters/redocly-loader/redocly-schema-loader.mjs.map +1 -1
  34. package/dist/adapters/redocly-loader/ref-access.cjs +31 -3
  35. package/dist/adapters/redocly-loader/ref-access.cjs.map +1 -1
  36. package/dist/adapters/redocly-loader/ref-access.mjs +31 -3
  37. package/dist/adapters/redocly-loader/ref-access.mjs.map +1 -1
  38. package/dist/adapters/redocly-loader/ref-holders.cjs +2 -2
  39. package/dist/adapters/redocly-loader/ref-holders.cjs.map +1 -1
  40. package/dist/adapters/redocly-loader/ref-holders.mjs +3 -3
  41. package/dist/adapters/redocly-loader/ref-holders.mjs.map +1 -1
  42. package/dist/adapters/redocly-loader/remote-body-limit.cjs +50 -0
  43. package/dist/adapters/redocly-loader/remote-body-limit.cjs.map +1 -0
  44. package/dist/adapters/redocly-loader/remote-body-limit.mjs +48 -0
  45. package/dist/adapters/redocly-loader/remote-body-limit.mjs.map +1 -0
  46. package/dist/adapters/redocly-loader/remote-fetch.cjs +35 -6
  47. package/dist/adapters/redocly-loader/remote-fetch.cjs.map +1 -1
  48. package/dist/adapters/redocly-loader/remote-fetch.mjs +35 -6
  49. package/dist/adapters/redocly-loader/remote-fetch.mjs.map +1 -1
  50. package/dist/adapters/redocly-loader/remote-node-limit.cjs +47 -0
  51. package/dist/adapters/redocly-loader/remote-node-limit.cjs.map +1 -0
  52. package/dist/adapters/redocly-loader/remote-node-limit.mjs +44 -0
  53. package/dist/adapters/redocly-loader/remote-node-limit.mjs.map +1 -0
  54. package/dist/adapters/redocly-loader/schema-load-errors.cjs +32 -8
  55. package/dist/adapters/redocly-loader/schema-load-errors.cjs.map +1 -1
  56. package/dist/adapters/redocly-loader/schema-load-errors.mjs +32 -9
  57. package/dist/adapters/redocly-loader/schema-load-errors.mjs.map +1 -1
  58. package/dist/adapters/redocly-loader/schema-source.cjs +11 -7
  59. package/dist/adapters/redocly-loader/schema-source.cjs.map +1 -1
  60. package/dist/adapters/redocly-loader/schema-source.mjs +12 -8
  61. package/dist/adapters/redocly-loader/schema-source.mjs.map +1 -1
  62. package/dist/adapters/redocly-loader/unsupported-keys.cjs +3 -5
  63. package/dist/adapters/redocly-loader/unsupported-keys.cjs.map +1 -1
  64. package/dist/adapters/redocly-loader/unsupported-keys.mjs +3 -5
  65. package/dist/adapters/redocly-loader/unsupported-keys.mjs.map +1 -1
  66. package/dist/adapters/terminal-logger/terminal-logger.cjs +6 -4
  67. package/dist/adapters/terminal-logger/terminal-logger.cjs.map +1 -1
  68. package/dist/adapters/terminal-logger/terminal-logger.mjs +6 -4
  69. package/dist/adapters/terminal-logger/terminal-logger.mjs.map +1 -1
  70. package/dist/api/default-ports.cjs +19 -2
  71. package/dist/api/default-ports.cjs.map +1 -1
  72. package/dist/api/default-ports.mjs +19 -3
  73. package/dist/api/default-ports.mjs.map +1 -1
  74. package/dist/api/discriminator-conflict-warnings.cjs +1 -1
  75. package/dist/api/discriminator-conflict-warnings.cjs.map +1 -1
  76. package/dist/api/discriminator-conflict-warnings.mjs +2 -2
  77. package/dist/api/discriminator-conflict-warnings.mjs.map +1 -1
  78. package/dist/api/discriminator-enum-parent.cjs +2 -2
  79. package/dist/api/discriminator-enum-parent.cjs.map +1 -1
  80. package/dist/api/discriminator-enum-parent.mjs +3 -3
  81. package/dist/api/discriminator-enum-parent.mjs.map +1 -1
  82. package/dist/api/discriminator-other-owners.cjs +5 -3
  83. package/dist/api/discriminator-other-owners.cjs.map +1 -1
  84. package/dist/api/discriminator-other-owners.mjs +5 -3
  85. package/dist/api/discriminator-other-owners.mjs.map +1 -1
  86. package/dist/api/discriminator-patch.cjs +8 -4
  87. package/dist/api/discriminator-patch.cjs.map +1 -1
  88. package/dist/api/discriminator-patch.mjs +9 -5
  89. package/dist/api/discriminator-patch.mjs.map +1 -1
  90. package/dist/api/discriminator-scan.cjs +17 -10
  91. package/dist/api/discriminator-scan.cjs.map +1 -1
  92. package/dist/api/discriminator-scan.mjs +18 -11
  93. package/dist/api/discriminator-scan.mjs.map +1 -1
  94. package/dist/api/document-run.cjs +4 -3
  95. package/dist/api/document-run.cjs.map +1 -1
  96. package/dist/api/document-run.mjs +4 -3
  97. package/dist/api/document-run.mjs.map +1 -1
  98. package/dist/api/legacy-callback-warning.cjs +7 -4
  99. package/dist/api/legacy-callback-warning.cjs.map +1 -1
  100. package/dist/api/legacy-callback-warning.mjs +8 -5
  101. package/dist/api/legacy-callback-warning.mjs.map +1 -1
  102. package/dist/api/legacy-utils.cjs.map +1 -1
  103. package/dist/api/legacy-utils.mjs.map +1 -1
  104. package/dist/api/openapi-ts.cjs +9 -5
  105. package/dist/api/openapi-ts.cjs.map +1 -1
  106. package/dist/api/openapi-ts.mjs +10 -7
  107. package/dist/api/openapi-ts.mjs.map +1 -1
  108. package/dist/api/schema-callbacks.cjs +36 -12
  109. package/dist/api/schema-callbacks.cjs.map +1 -1
  110. package/dist/api/schema-callbacks.mjs +36 -12
  111. package/dist/api/schema-callbacks.mjs.map +1 -1
  112. package/dist/api/string-to-ast.cjs +7 -9
  113. package/dist/api/string-to-ast.cjs.map +1 -1
  114. package/dist/api/string-to-ast.mjs +8 -9
  115. package/dist/api/string-to-ast.mjs.map +1 -1
  116. package/dist/api/transform-context.cjs +7 -3
  117. package/dist/api/transform-context.cjs.map +1 -1
  118. package/dist/api/transform-context.mjs +7 -3
  119. package/dist/api/transform-context.mjs.map +1 -1
  120. package/dist/api/transform-schema.cjs +42 -12
  121. package/dist/api/transform-schema.cjs.map +1 -1
  122. package/dist/api/transform-schema.mjs +44 -14
  123. package/dist/api/transform-schema.mjs.map +1 -1
  124. package/dist/application/print/text-writer.cjs +10 -3
  125. package/dist/application/print/text-writer.cjs.map +1 -1
  126. package/dist/application/print/text-writer.mjs +10 -3
  127. package/dist/application/print/text-writer.mjs.map +1 -1
  128. package/dist/application/stack-overflow.cjs +2 -1
  129. package/dist/application/stack-overflow.cjs.map +1 -1
  130. package/dist/application/stack-overflow.mjs +2 -1
  131. package/dist/application/stack-overflow.mjs.map +1 -1
  132. package/dist/application/transform/document/components.cjs +2 -2
  133. package/dist/application/transform/document/components.cjs.map +1 -1
  134. package/dist/application/transform/document/components.mjs +4 -4
  135. package/dist/application/transform/document/components.mjs.map +1 -1
  136. package/dist/application/transform/document/declared-type-names.cjs +23 -0
  137. package/dist/application/transform/document/declared-type-names.cjs.map +1 -0
  138. package/dist/application/transform/document/declared-type-names.mjs +20 -0
  139. package/dist/application/transform/document/declared-type-names.mjs.map +1 -0
  140. package/dist/application/transform/document/defs-root.cjs +1 -1
  141. package/dist/application/transform/document/defs-root.cjs.map +1 -1
  142. package/dist/application/transform/document/defs-root.mjs +2 -2
  143. package/dist/application/transform/document/defs-root.mjs.map +1 -1
  144. package/dist/application/transform/document/document.cjs +4 -1
  145. package/dist/application/transform/document/document.cjs.map +1 -1
  146. package/dist/application/transform/document/document.mjs +3 -2
  147. package/dist/application/transform/document/document.mjs.map +1 -1
  148. package/dist/application/transform/document/enum-names-given-back.cjs +62 -0
  149. package/dist/application/transform/document/enum-names-given-back.cjs.map +1 -0
  150. package/dist/application/transform/document/enum-names-given-back.mjs +58 -0
  151. package/dist/application/transform/document/enum-names-given-back.mjs.map +1 -0
  152. package/dist/application/transform/document/global-type-references.cjs +1 -0
  153. package/dist/application/transform/document/global-type-references.cjs.map +1 -1
  154. package/dist/application/transform/document/global-type-references.mjs +1 -1
  155. package/dist/application/transform/document/global-type-references.mjs.map +1 -1
  156. package/dist/application/transform/document/media-type.cjs +2 -2
  157. package/dist/application/transform/document/media-type.cjs.map +1 -1
  158. package/dist/application/transform/document/media-type.mjs +3 -3
  159. package/dist/application/transform/document/media-type.mjs.map +1 -1
  160. package/dist/application/transform/document/operation-keys-written.cjs +26 -0
  161. package/dist/application/transform/document/operation-keys-written.cjs.map +1 -0
  162. package/dist/application/transform/document/operation-keys-written.mjs +24 -0
  163. package/dist/application/transform/document/operation-keys-written.mjs.map +1 -0
  164. package/dist/application/transform/document/operation.cjs +1 -1
  165. package/dist/application/transform/document/operation.cjs.map +1 -1
  166. package/dist/application/transform/document/operation.mjs +2 -2
  167. package/dist/application/transform/document/operation.mjs.map +1 -1
  168. package/dist/application/transform/document/parameter-entries.cjs +34 -0
  169. package/dist/application/transform/document/parameter-entries.cjs.map +1 -0
  170. package/dist/application/transform/document/parameter-entries.mjs +30 -0
  171. package/dist/application/transform/document/parameter-entries.mjs.map +1 -0
  172. package/dist/application/transform/document/parameter.cjs +12 -4
  173. package/dist/application/transform/document/parameter.cjs.map +1 -1
  174. package/dist/application/transform/document/parameter.mjs +13 -5
  175. package/dist/application/transform/document/parameter.mjs.map +1 -1
  176. package/dist/application/transform/document/parameters.cjs +7 -30
  177. package/dist/application/transform/document/parameters.cjs.map +1 -1
  178. package/dist/application/transform/document/parameters.mjs +8 -31
  179. package/dist/application/transform/document/parameters.mjs.map +1 -1
  180. package/dist/application/transform/document/path-item.cjs +11 -14
  181. package/dist/application/transform/document/path-item.cjs.map +1 -1
  182. package/dist/application/transform/document/path-item.mjs +12 -16
  183. package/dist/application/transform/document/path-item.mjs.map +1 -1
  184. package/dist/application/transform/document/paths-enum.cjs +1 -0
  185. package/dist/application/transform/document/paths-enum.cjs.map +1 -1
  186. package/dist/application/transform/document/paths-enum.mjs +1 -1
  187. package/dist/application/transform/document/paths-enum.mjs.map +1 -1
  188. package/dist/application/transform/document/paths.cjs +6 -2
  189. package/dist/application/transform/document/paths.cjs.map +1 -1
  190. package/dist/application/transform/document/paths.mjs +8 -4
  191. package/dist/application/transform/document/paths.mjs.map +1 -1
  192. package/dist/application/transform/document/referenced-parameter.cjs +80 -0
  193. package/dist/application/transform/document/referenced-parameter.cjs.map +1 -0
  194. package/dist/application/transform/document/referenced-parameter.mjs +78 -0
  195. package/dist/application/transform/document/referenced-parameter.mjs.map +1 -0
  196. package/dist/application/transform/document/request-body.cjs +1 -1
  197. package/dist/application/transform/document/request-body.cjs.map +1 -1
  198. package/dist/application/transform/document/request-body.mjs +2 -2
  199. package/dist/application/transform/document/request-body.mjs.map +1 -1
  200. package/dist/application/transform/document/response.cjs +2 -2
  201. package/dist/application/transform/document/response.cjs.map +1 -1
  202. package/dist/application/transform/document/response.mjs +3 -3
  203. package/dist/application/transform/document/response.mjs.map +1 -1
  204. package/dist/application/transform/document/responses.cjs +1 -1
  205. package/dist/application/transform/document/responses.cjs.map +1 -1
  206. package/dist/application/transform/document/responses.mjs +2 -2
  207. package/dist/application/transform/document/responses.mjs.map +1 -1
  208. package/dist/application/transform/document/root-type-aliases.cjs +8 -23
  209. package/dist/application/transform/document/root-type-aliases.cjs.map +1 -1
  210. package/dist/application/transform/document/root-type-aliases.mjs +8 -24
  211. package/dist/application/transform/document/root-type-aliases.mjs.map +1 -1
  212. package/dist/application/transform/document/type-resolution.cjs +3 -1
  213. package/dist/application/transform/document/type-resolution.cjs.map +1 -1
  214. package/dist/application/transform/document/type-resolution.mjs +3 -1
  215. package/dist/application/transform/document/type-resolution.mjs.map +1 -1
  216. package/dist/application/transform/document/webhooks.cjs +1 -1
  217. package/dist/application/transform/document/webhooks.cjs.map +1 -1
  218. package/dist/application/transform/document/webhooks.mjs +2 -2
  219. package/dist/application/transform/document/webhooks.mjs.map +1 -1
  220. package/dist/application/transform/footer/document-footer.cjs +10 -2
  221. package/dist/application/transform/footer/document-footer.cjs.map +1 -1
  222. package/dist/application/transform/footer/document-footer.mjs +10 -2
  223. package/dist/application/transform/footer/document-footer.mjs.map +1 -1
  224. package/dist/application/transform/footer/enum-name-claims.cjs +48 -0
  225. package/dist/application/transform/footer/enum-name-claims.cjs.map +1 -0
  226. package/dist/application/transform/footer/enum-name-claims.mjs +46 -0
  227. package/dist/application/transform/footer/enum-name-claims.mjs.map +1 -0
  228. package/dist/application/transform/footer/operation-keys.cjs +23 -0
  229. package/dist/application/transform/footer/operation-keys.cjs.map +1 -0
  230. package/dist/application/transform/footer/operation-keys.mjs +21 -0
  231. package/dist/application/transform/footer/operation-keys.mjs.map +1 -0
  232. package/dist/application/transform/footer/type-evaluation.cjs +4 -4
  233. package/dist/application/transform/footer/type-evaluation.cjs.map +1 -1
  234. package/dist/application/transform/footer/type-evaluation.mjs +4 -4
  235. package/dist/application/transform/footer/type-evaluation.mjs.map +1 -1
  236. package/dist/application/transform/helper-types.cjs +1 -1
  237. package/dist/application/transform/helper-types.cjs.map +1 -1
  238. package/dist/application/transform/helper-types.mjs +1 -1
  239. package/dist/application/transform/helper-types.mjs.map +1 -1
  240. package/dist/application/transform/numbered-names.cjs +9 -0
  241. package/dist/application/transform/numbered-names.cjs.map +1 -1
  242. package/dist/application/transform/numbered-names.mjs +9 -1
  243. package/dist/application/transform/numbered-names.mjs.map +1 -1
  244. package/dist/application/transform/ref-pointer/generated-location.cjs +1 -1
  245. package/dist/application/transform/ref-pointer/generated-location.cjs.map +1 -1
  246. package/dist/application/transform/ref-pointer/generated-location.mjs +2 -2
  247. package/dist/application/transform/ref-pointer/generated-location.mjs.map +1 -1
  248. package/dist/application/transform/ref-pointer/pointer-type.cjs +1 -1
  249. package/dist/application/transform/ref-pointer/pointer-type.cjs.map +1 -1
  250. package/dist/application/transform/ref-pointer/pointer-type.mjs +2 -2
  251. package/dist/application/transform/ref-pointer/pointer-type.mjs.map +1 -1
  252. package/dist/application/transform/ref-type.cjs +2 -1
  253. package/dist/application/transform/ref-type.cjs.map +1 -1
  254. package/dist/application/transform/ref-type.mjs +2 -1
  255. package/dist/application/transform/ref-type.mjs.map +1 -1
  256. package/dist/application/transform/schema/access-flags.cjs +1 -1
  257. package/dist/application/transform/schema/access-flags.cjs.map +1 -1
  258. package/dist/application/transform/schema/access-flags.mjs +2 -2
  259. package/dist/application/transform/schema/access-flags.mjs.map +1 -1
  260. package/dist/application/transform/schema/array-type.cjs +2 -2
  261. package/dist/application/transform/schema/array-type.cjs.map +1 -1
  262. package/dist/application/transform/schema/array-type.mjs +3 -3
  263. package/dist/application/transform/schema/array-type.mjs.map +1 -1
  264. package/dist/application/transform/schema/composition-type.cjs +4 -4
  265. package/dist/application/transform/schema/composition-type.cjs.map +1 -1
  266. package/dist/application/transform/schema/composition-type.mjs +6 -6
  267. package/dist/application/transform/schema/composition-type.mjs.map +1 -1
  268. package/dist/application/transform/schema/enum-rule.cjs +4 -6
  269. package/dist/application/transform/schema/enum-rule.cjs.map +1 -1
  270. package/dist/application/transform/schema/enum-rule.mjs +6 -8
  271. package/dist/application/transform/schema/enum-rule.mjs.map +1 -1
  272. package/dist/application/transform/schema/object-type.cjs +3 -3
  273. package/dist/application/transform/schema/object-type.cjs.map +1 -1
  274. package/dist/application/transform/schema/object-type.mjs +4 -4
  275. package/dist/application/transform/schema/object-type.mjs.map +1 -1
  276. package/dist/application/transform/schema/presence-members.cjs +1 -1
  277. package/dist/application/transform/schema/presence-members.cjs.map +1 -1
  278. package/dist/application/transform/schema/presence-members.mjs +2 -2
  279. package/dist/application/transform/schema/presence-members.mjs.map +1 -1
  280. package/dist/application/transform/schema/ref-siblings.cjs +47 -0
  281. package/dist/application/transform/schema/ref-siblings.cjs.map +1 -0
  282. package/dist/application/transform/schema/ref-siblings.mjs +45 -0
  283. package/dist/application/transform/schema/ref-siblings.mjs.map +1 -0
  284. package/dist/application/transform/schema/required-variants.cjs +2 -2
  285. package/dist/application/transform/schema/required-variants.cjs.map +1 -1
  286. package/dist/application/transform/schema/required-variants.mjs +3 -3
  287. package/dist/application/transform/schema/required-variants.mjs.map +1 -1
  288. package/dist/application/transform/schema/schema-transform.cjs +4 -2
  289. package/dist/application/transform/schema/schema-transform.cjs.map +1 -1
  290. package/dist/application/transform/schema/schema-transform.mjs +4 -2
  291. package/dist/application/transform/schema/schema-transform.mjs.map +1 -1
  292. package/dist/application/transform/schema/unevaluated-properties.cjs +1 -1
  293. package/dist/application/transform/schema/unevaluated-properties.cjs.map +1 -1
  294. package/dist/application/transform/schema/unevaluated-properties.mjs +2 -2
  295. package/dist/application/transform/schema/unevaluated-properties.mjs.map +1 -1
  296. package/dist/application/transform/schema-comment.cjs +6 -2
  297. package/dist/application/transform/schema-comment.cjs.map +1 -1
  298. package/dist/application/transform/schema-comment.mjs +7 -3
  299. package/dist/application/transform/schema-comment.mjs.map +1 -1
  300. package/dist/cli/api-settings.cjs +62 -6
  301. package/dist/cli/api-settings.cjs.map +1 -1
  302. package/dist/cli/api-settings.mjs +60 -7
  303. package/dist/cli/api-settings.mjs.map +1 -1
  304. package/dist/cli/api-writes.cjs +72 -0
  305. package/dist/cli/api-writes.cjs.map +1 -0
  306. package/dist/cli/api-writes.mjs +69 -0
  307. package/dist/cli/api-writes.mjs.map +1 -0
  308. package/dist/cli/cli-errors.cjs +12 -1
  309. package/dist/cli/cli-errors.cjs.map +1 -1
  310. package/dist/cli/cli-errors.mjs +12 -1
  311. package/dist/cli/cli-errors.mjs.map +1 -1
  312. package/dist/cli/cli-output.cjs +106 -1
  313. package/dist/cli/cli-output.cjs.map +1 -1
  314. package/dist/cli/cli-output.mjs +99 -2
  315. package/dist/cli/cli-output.mjs.map +1 -1
  316. package/dist/cli/main.cjs +5 -1
  317. package/dist/cli/main.cjs.map +1 -1
  318. package/dist/cli/main.mjs +6 -2
  319. package/dist/cli/main.mjs.map +1 -1
  320. package/dist/cli/redocly-apis.cjs +82 -36
  321. package/dist/cli/redocly-apis.cjs.map +1 -1
  322. package/dist/cli/redocly-apis.mjs +85 -39
  323. package/dist/cli/redocly-apis.mjs.map +1 -1
  324. package/dist/cli/run-cli.cjs +13 -7
  325. package/dist/cli/run-cli.cjs.map +1 -1
  326. package/dist/cli/run-cli.mjs +14 -8
  327. package/dist/cli/run-cli.mjs.map +1 -1
  328. package/dist/domain/append-all.cjs +10 -0
  329. package/dist/domain/append-all.cjs.map +1 -0
  330. package/dist/domain/append-all.mjs +8 -0
  331. package/dist/domain/append-all.mjs.map +1 -0
  332. package/dist/domain/cause-secrets.cjs +37 -0
  333. package/dist/domain/cause-secrets.cjs.map +1 -0
  334. package/dist/domain/cause-secrets.mjs +35 -0
  335. package/dist/domain/cause-secrets.mjs.map +1 -0
  336. package/dist/domain/deprecations.cjs +11 -0
  337. package/dist/domain/deprecations.cjs.map +1 -0
  338. package/dist/domain/deprecations.mjs +9 -0
  339. package/dist/domain/deprecations.mjs.map +1 -0
  340. package/dist/domain/errors.cjs +9 -3
  341. package/dist/domain/errors.cjs.map +1 -1
  342. package/dist/domain/errors.mjs +9 -3
  343. package/dist/domain/errors.mjs.map +1 -1
  344. package/dist/domain/ir/identifier-text.cjs.map +1 -1
  345. package/dist/domain/ir/identifier-text.mjs +1 -1
  346. package/dist/domain/ir/identifier-text.mjs.map +1 -1
  347. package/dist/domain/ir/ir-shape.cjs +187 -0
  348. package/dist/domain/ir/ir-shape.cjs.map +1 -0
  349. package/dist/domain/ir/ir-shape.mjs +184 -0
  350. package/dist/domain/ir/ir-shape.mjs.map +1 -0
  351. package/dist/domain/ir/newer-identifier-ranges.cjs +182 -29
  352. package/dist/domain/ir/newer-identifier-ranges.cjs.map +1 -1
  353. package/dist/domain/ir/newer-identifier-ranges.mjs +182 -29
  354. package/dist/domain/ir/newer-identifier-ranges.mjs.map +1 -1
  355. package/dist/domain/openapi/alias-expansion.cjs +3 -1
  356. package/dist/domain/openapi/alias-expansion.cjs.map +1 -1
  357. package/dist/domain/openapi/alias-expansion.mjs +3 -1
  358. package/dist/domain/openapi/alias-expansion.mjs.map +1 -1
  359. package/dist/domain/openapi/discriminated-union.cjs +3 -3
  360. package/dist/domain/openapi/discriminated-union.cjs.map +1 -1
  361. package/dist/domain/openapi/discriminated-union.mjs +4 -4
  362. package/dist/domain/openapi/discriminated-union.mjs.map +1 -1
  363. package/dist/domain/openapi/discriminator-conflicts.cjs +10 -6
  364. package/dist/domain/openapi/discriminator-conflicts.cjs.map +1 -1
  365. package/dist/domain/openapi/discriminator-conflicts.mjs +11 -7
  366. package/dist/domain/openapi/discriminator-conflicts.mjs.map +1 -1
  367. package/dist/domain/openapi/json-pointer.cjs +43 -1
  368. package/dist/domain/openapi/json-pointer.cjs.map +1 -1
  369. package/dist/domain/openapi/json-pointer.mjs +40 -2
  370. package/dist/domain/openapi/json-pointer.mjs.map +1 -1
  371. package/dist/domain/openapi/schema-dialect.cjs +15 -0
  372. package/dist/domain/openapi/schema-dialect.cjs.map +1 -0
  373. package/dist/domain/openapi/schema-dialect.mjs +12 -0
  374. package/dist/domain/openapi/schema-dialect.mjs.map +1 -0
  375. package/dist/domain/openapi/unsupported-features.cjs +1 -1
  376. package/dist/domain/openapi/unsupported-features.cjs.map +1 -1
  377. package/dist/domain/openapi/unsupported-features.mjs +2 -2
  378. package/dist/domain/openapi/unsupported-features.mjs.map +1 -1
  379. package/dist/domain/output-fixes.cjs +25 -14
  380. package/dist/domain/output-fixes.cjs.map +1 -1
  381. package/dist/domain/output-fixes.mjs +25 -13
  382. package/dist/domain/output-fixes.mjs.map +1 -1
  383. package/dist/domain/url-secrets.cjs +48 -0
  384. package/dist/domain/url-secrets.cjs.map +1 -0
  385. package/dist/domain/url-secrets.mjs +45 -0
  386. package/dist/domain/url-secrets.mjs.map +1 -0
  387. package/dist/domain/warnings.cjs +0 -1
  388. package/dist/domain/warnings.cjs.map +1 -1
  389. package/dist/domain/warnings.mjs +0 -1
  390. package/dist/domain/warnings.mjs.map +1 -1
  391. package/dist/index.cjs +2 -3
  392. package/dist/index.cjs.map +1 -1
  393. package/dist/index.d.cts +57 -20
  394. package/dist/index.d.mts +57 -20
  395. package/dist/index.d.ts +57 -20
  396. package/dist/index.mjs +3 -2
  397. package/dist/index.mjs.map +1 -1
  398. package/package.json +5 -6
  399. package/src/adapters/node-deprecations/node-deprecations.ts +14 -0
  400. package/src/adapters/node-file-system/file-claims.ts +138 -0
  401. package/src/adapters/node-file-system/file-identity.ts +137 -0
  402. package/src/adapters/node-file-system/node-file-system.ts +145 -18
  403. package/src/adapters/redocly-loader/bundled-mapping-copies.ts +95 -0
  404. package/src/adapters/redocly-loader/bundled-ref-repair.ts +2 -2
  405. package/src/adapters/redocly-loader/loaded-documents.ts +46 -0
  406. package/src/adapters/redocly-loader/redocly-schema-loader.ts +18 -24
  407. package/src/adapters/redocly-loader/ref-access.ts +37 -3
  408. package/src/adapters/redocly-loader/ref-holders.ts +3 -3
  409. package/src/adapters/redocly-loader/remote-body-limit.ts +66 -0
  410. package/src/adapters/redocly-loader/remote-fetch.ts +74 -11
  411. package/src/adapters/redocly-loader/remote-node-limit.ts +62 -0
  412. package/src/adapters/redocly-loader/schema-load-errors.ts +52 -13
  413. package/src/adapters/redocly-loader/schema-source.ts +20 -8
  414. package/src/adapters/redocly-loader/unsupported-keys.ts +3 -7
  415. package/src/adapters/terminal-logger/terminal-logger.ts +10 -5
  416. package/src/api/default-ports.ts +40 -4
  417. package/src/api/discriminator-conflict-warnings.ts +2 -2
  418. package/src/api/discriminator-enum-parent.ts +3 -3
  419. package/src/api/discriminator-other-owners.ts +5 -3
  420. package/src/api/discriminator-patch.ts +9 -6
  421. package/src/api/discriminator-scan.ts +19 -11
  422. package/src/api/document-run.ts +9 -3
  423. package/src/api/legacy-callback-warning.ts +13 -6
  424. package/src/api/legacy-utils.ts +5 -1
  425. package/src/api/openapi-ts.ts +26 -7
  426. package/src/api/run-context.ts +6 -0
  427. package/src/api/schema-callbacks.ts +60 -17
  428. package/src/api/string-to-ast.ts +11 -15
  429. package/src/api/transform-context.ts +7 -3
  430. package/src/api/transform-schema.ts +67 -15
  431. package/src/application/ports/deprecation-reporter.ts +9 -0
  432. package/src/application/ports/file-system.ts +39 -0
  433. package/src/application/ports/schema-loader.ts +11 -1
  434. package/src/application/print/text-writer.ts +10 -3
  435. package/src/application/stack-overflow.ts +9 -5
  436. package/src/application/transform/document/components.ts +4 -4
  437. package/src/application/transform/document/declared-type-names.ts +36 -0
  438. package/src/application/transform/document/defs-root.ts +2 -2
  439. package/src/application/transform/document/document.ts +4 -3
  440. package/src/application/transform/document/enum-names-given-back.ts +91 -0
  441. package/src/application/transform/document/global-type-references.ts +1 -1
  442. package/src/application/transform/document/media-type.ts +4 -3
  443. package/src/application/transform/document/operation-keys-written.ts +27 -0
  444. package/src/application/transform/document/operation.ts +2 -2
  445. package/src/application/transform/document/parameter-entries.ts +70 -0
  446. package/src/application/transform/document/parameter.ts +21 -9
  447. package/src/application/transform/document/parameters.ts +13 -58
  448. package/src/application/transform/document/path-item.ts +13 -31
  449. package/src/application/transform/document/paths-enum.ts +1 -1
  450. package/src/application/transform/document/paths.ts +8 -4
  451. package/src/application/transform/document/referenced-parameter.ts +146 -0
  452. package/src/application/transform/document/request-body.ts +2 -2
  453. package/src/application/transform/document/response.ts +3 -3
  454. package/src/application/transform/document/responses.ts +2 -2
  455. package/src/application/transform/document/root-type-aliases.ts +17 -38
  456. package/src/application/transform/document/type-resolution.ts +2 -1
  457. package/src/application/transform/document/webhooks.ts +2 -2
  458. package/src/application/transform/footer/document-footer.ts +18 -1
  459. package/src/application/transform/footer/enum-name-claims.ts +62 -0
  460. package/src/application/transform/footer/operation-keys.ts +28 -0
  461. package/src/application/transform/footer/type-evaluation.ts +4 -4
  462. package/src/application/transform/helper-types.ts +6 -5
  463. package/src/application/transform/numbered-names.ts +15 -0
  464. package/src/application/transform/ref-pointer/generated-location.ts +2 -2
  465. package/src/application/transform/ref-pointer/pointer-type.ts +2 -4
  466. package/src/application/transform/ref-type.ts +2 -1
  467. package/src/application/transform/schema/access-flags.ts +2 -2
  468. package/src/application/transform/schema/array-type.ts +3 -5
  469. package/src/application/transform/schema/composition-type.ts +6 -6
  470. package/src/application/transform/schema/enum-rule.ts +10 -8
  471. package/src/application/transform/schema/object-type.ts +4 -4
  472. package/src/application/transform/schema/presence-members.ts +2 -2
  473. package/src/application/transform/schema/ref-siblings.ts +76 -0
  474. package/src/application/transform/schema/required-variants.ts +3 -3
  475. package/src/application/transform/schema/schema-context.ts +3 -0
  476. package/src/application/transform/schema/schema-transform.ts +4 -2
  477. package/src/application/transform/schema/unevaluated-properties.ts +2 -2
  478. package/src/application/transform/schema-comment.ts +7 -3
  479. package/src/application/transform/transform-context.ts +5 -0
  480. package/src/cli/api-settings.ts +82 -7
  481. package/src/cli/api-writes.ts +117 -0
  482. package/src/cli/cli-dependencies.ts +21 -4
  483. package/src/cli/cli-errors.ts +20 -1
  484. package/src/cli/cli-output.ts +186 -7
  485. package/src/cli/main.ts +6 -3
  486. package/src/cli/redocly-apis.ts +153 -48
  487. package/src/cli/run-cli.ts +37 -8
  488. package/src/domain/append-all.ts +10 -0
  489. package/src/domain/cause-secrets.ts +52 -0
  490. package/src/domain/deprecations.ts +15 -0
  491. package/src/domain/errors.ts +22 -7
  492. package/src/domain/ir/identifier-text.ts +6 -5
  493. package/src/domain/ir/ir-shape.ts +299 -0
  494. package/src/domain/ir/newer-identifier-ranges.ts +183 -30
  495. package/src/domain/openapi/alias-expansion.ts +4 -1
  496. package/src/domain/openapi/discriminated-union.ts +6 -4
  497. package/src/domain/openapi/discriminator-conflicts.ts +21 -7
  498. package/src/domain/openapi/document-object.ts +2 -0
  499. package/src/domain/openapi/json-pointer.ts +96 -7
  500. package/src/domain/openapi/schema-dialect.ts +22 -0
  501. package/src/domain/openapi/unsupported-features.ts +2 -2
  502. package/src/domain/output-fixes.ts +37 -18
  503. package/src/domain/url-secrets.ts +72 -0
  504. package/src/domain/warnings.ts +0 -1
  505. package/src/index.ts +2 -6
  506. package/src/types/generator-options.ts +1 -1
  507. package/dist/cli/main.d.cts +0 -2
  508. package/dist/cli/main.d.mts +0 -2
  509. package/dist/cli/main.d.ts +0 -2
  510. package/dist/domain/url-credentials.cjs +0 -10
  511. package/dist/domain/url-credentials.cjs.map +0 -1
  512. package/dist/domain/url-credentials.mjs +0 -8
  513. package/dist/domain/url-credentials.mjs.map +0 -1
  514. package/src/domain/url-credentials.ts +0 -18
@@ -1,5 +1,11 @@
1
1
  import type { Readable } from "node:stream";
2
- import type { FileReader, FileWriter } from "../application/ports/file-system.js";
2
+ import type {
3
+ DirectoryCheck,
4
+ FileClaims,
5
+ FileIdentity,
6
+ FileReader,
7
+ FileWriter,
8
+ } from "../application/ports/file-system.js";
3
9
  import type { Logger } from "../application/ports/logger.js";
4
10
  import type { RedoclyConfigSource } from "../application/ports/redocly-config-source.js";
5
11
  import type { GeneratorOptions, SchemaSource } from "../types.js";
@@ -19,8 +25,19 @@ export interface TextStyle {
19
25
  dim(text: string): string;
20
26
  }
21
27
 
22
- /** Generate the printed declarations, with the comment header, for one schema. */
23
- export type GenerateTypes = (source: SchemaSource, options: GeneratorOptions) => Promise<string>;
28
+ /** The printed declarations of one schema, and the local files they were generated from. */
29
+ export interface GeneratedTypes {
30
+ /** The declarations, with the comment header. */
31
+ readonly contents: string;
32
+ /** The schema, when it is a local file, and every local file its `$ref`s loaded. */
33
+ readonly localFiles: readonly URL[];
34
+ }
35
+
36
+ /** Generate the types of one schema. */
37
+ export type GenerateTypes = (
38
+ source: SchemaSource,
39
+ options: GeneratorOptions,
40
+ ) => Promise<GeneratedTypes>;
24
41
 
25
42
  export interface CliDependencies {
26
43
  /** The working directory, as a directory URL (with a trailing slash). */
@@ -38,7 +55,7 @@ export interface CliDependencies {
38
55
  * input with no prompt, which looks like a hang (upstream #1905).
39
56
  */
40
57
  readonly isStdinTerminal: () => boolean;
41
- readonly files: FileReader & FileWriter;
58
+ readonly files: FileReader & FileWriter & FileIdentity & DirectoryCheck & FileClaims;
42
59
  readonly redoclyConfigs: RedoclyConfigSource;
43
60
  readonly generate: GenerateTypes;
44
61
  /** A monotonic time in milliseconds, for the time printed after each output. */
@@ -68,9 +68,24 @@ function parseFailedMessage(error: OpenAPITypesafeError): string {
68
68
  );
69
69
  }
70
70
 
71
+ /**
72
+ * Text piped into stdin that is only a YAML string (`echo api.yaml | openapi-typesafe`) gets the
73
+ * CLI's advice, not the Node API's (`openapiTS(pathToFileURL(path))`).
74
+ */
75
+ function sourceInvalidMessage(error: OpenAPITypesafeError): string {
76
+ const { received, text } = error.details;
77
+ if (received !== "stream" || typeof text !== "string") {
78
+ return error.message;
79
+ }
80
+ return (
81
+ `stdin held only the YAML string "${text}", not an OpenAPI document. To read a file, pass ` +
82
+ "its path or URL as the first argument: openapi-typesafe ./openapi.yaml -o ./schema.ts"
83
+ );
84
+ }
85
+
71
86
  const CLI_ERROR_REPORTS: Readonly<Record<ErrorCode, CliErrorReport>> = {
72
87
  SCHEMA_SOURCE_EMPTY: { exitCode: EXIT_CODES.SCHEMA },
73
- SCHEMA_SOURCE_INVALID: { exitCode: EXIT_CODES.SCHEMA },
88
+ SCHEMA_SOURCE_INVALID: { exitCode: EXIT_CODES.SCHEMA, message: sourceInvalidMessage },
74
89
  SCHEMA_LOAD_FAILED: { exitCode: EXIT_CODES.SCHEMA, message: loadFailedMessage },
75
90
  SCHEMA_PARSE_FAILED: { exitCode: EXIT_CODES.SCHEMA, message: parseFailedMessage },
76
91
  SCHEMA_VERSION_UNSUPPORTED: { exitCode: EXIT_CODES.SCHEMA },
@@ -92,6 +107,10 @@ const CLI_ERROR_REPORTS: Readonly<Record<ErrorCode, CliErrorReport>> = {
92
107
  CLI_CONFIG_OUTPUT_MISSING: { exitCode: EXIT_CODES.USAGE },
93
108
  CLI_CHECK_OUTPUT_MISSING: { exitCode: EXIT_CODES.USAGE },
94
109
  CLI_INPUT_MISSING: { exitCode: EXIT_CODES.USAGE },
110
+ CLI_OUTPUT_IS_INPUT: { exitCode: EXIT_CODES.USAGE },
111
+ CLI_OUTPUT_DUPLICATE: { exitCode: EXIT_CODES.USAGE },
112
+ CLI_OUTPUT_INVALID: { exitCode: EXIT_CODES.USAGE },
113
+ CLI_LOCATION_INVALID: { exitCode: EXIT_CODES.USAGE },
95
114
  OUTPUT_STALE: { exitCode: EXIT_CODES.OUTPUT_STALE },
96
115
  OUTPUT_READ_FAILED: { exitCode: EXIT_CODES.OUTPUT },
97
116
  OUTPUT_WRITE_FAILED: { exitCode: EXIT_CODES.OUTPUT },
@@ -1,8 +1,10 @@
1
1
  import path from "node:path";
2
2
  import { fileURLToPath, pathToFileURL } from "node:url";
3
3
  import { formatDuration } from "../adapters/terminal-logger/terminal-logger.js";
4
+ import type { RedoclyConfig } from "../application/ports/redocly-config-source.js";
5
+ import { redactUnparsedUrl } from "../domain/url-secrets.js";
4
6
  import type { CliArguments } from "./cli-arguments.js";
5
- import type { CliDependencies } from "./cli-dependencies.js";
7
+ import type { CliDependencies, GeneratedTypes } from "./cli-dependencies.js";
6
8
  import { cliError } from "./cli-errors.js";
7
9
 
8
10
  /** Writing one generated file, or checking it with `--check`, and the line printed for it. */
@@ -14,10 +16,14 @@ export interface CliRun {
14
16
  readonly startedAt: number;
15
17
  }
16
18
 
17
- /** A generated file: `source` names the schema and `output` is the path as the user wrote it. */
18
- export interface OutputFile {
19
+ /** An output as the user wrote it: `source` names the schema, `output` is the path or URL. */
20
+ export interface NamedOutput {
19
21
  readonly source: string;
20
22
  readonly output: string;
23
+ }
24
+
25
+ /** A generated file: an output with the location of its local file. */
26
+ export interface OutputFile extends NamedOutput {
21
27
  readonly file: URL;
22
28
  }
23
29
 
@@ -28,18 +34,180 @@ export interface OutputFile {
28
34
  const URL_SCHEME = /^[a-z][a-z\d+.-]+:/i;
29
35
 
30
36
  /**
31
- * The URL of a location the user wrote: a URL as it is, else a file path, absolute or relative to
32
- * the directory of `base` (a directory or file URL). A path is not parsed as a URL, so `#`, `?` and
33
- * `%` are part of the file name.
37
+ * The URL of a location the user wrote: a URL, else a file path, absolute or relative to the
38
+ * directory of `base` (a directory or file URL). A relative `file:` URL (`file:api.yaml`) resolves
39
+ * against `base` too, as in openapi-typescript. A path is not parsed as a URL, so `#`, `?` and `%`
40
+ * are part of the file name. A location with a scheme that does not parse as a URL
41
+ * (`http://[::1/x`) fails with `CLI_LOCATION_INVALID`.
34
42
  */
35
43
  export function resolveLocationUrl(location: string, base: URL): URL {
36
44
  if (URL_SCHEME.test(location)) {
37
- return new URL(location);
45
+ const url = URL.parse(location, base.href);
46
+ if (url === null) {
47
+ const shown = redactUnparsedUrl(location);
48
+ throw cliError("CLI_LOCATION_INVALID", `The location ${shown} is not a valid URL`);
49
+ }
50
+ return url;
38
51
  }
39
52
  const baseDirectory = fileURLToPath(new URL(".", base));
40
53
  return pathToFileURL(path.resolve(baseDirectory, location));
41
54
  }
42
55
 
56
+ const FILE_PROTOCOL = "file:";
57
+
58
+ /** Segments that name a directory: the directory itself and its parent. */
59
+ const DIRECTORY_SEGMENTS: ReadonlySet<string> = new Set([".", ".."]);
60
+
61
+ /**
62
+ * Whether the location names a directory as written, before resolving drops the sign: a trailing
63
+ * `/` (or `\\` on Windows), or a last segment `.` or `..` (`-o gen/.`, `-o a/b/..`). For a URL
64
+ * the parsed path tells it too, since the URL parser drops `.`, `..` and their `%2E` forms.
65
+ */
66
+ function namesDirectory(location: string, file: URL): boolean {
67
+ const lastSegment = location
68
+ .split(path.sep)
69
+ .flatMap((part) => part.split("/"))
70
+ .at(-1);
71
+ return (
72
+ lastSegment === "" || DIRECTORY_SEGMENTS.has(lastSegment ?? "") || file.pathname.endsWith("/")
73
+ );
74
+ }
75
+
76
+ function invalidOutput(output: string, reason: string): Error {
77
+ return cliError("CLI_OUTPUT_INVALID", `The output ${output} ${reason}`);
78
+ }
79
+
80
+ /** The URL of the output, if it is a local file that can be written; it may not exist yet. */
81
+ function outputUrlOf(run: CliRun, output: string, base: URL): URL {
82
+ const file = parseLocationUrl(output, base);
83
+ if (file?.protocol !== FILE_PROTOCOL) {
84
+ throw invalidOutput(
85
+ output,
86
+ "is not a local file. Write the types to a file path or a file: URL.",
87
+ );
88
+ }
89
+ if (!isLocalFile(file)) {
90
+ throw invalidOutput(output, "names no file on this computer. Use a file path instead.");
91
+ }
92
+ if (namesDirectory(output, file) || run.deps.files.isDirectory(file)) {
93
+ throw invalidOutput(output, "is a directory. Name the file to write the types to in it.");
94
+ }
95
+ return file;
96
+ }
97
+
98
+ /** A `file:` URL with a host, or with an encoded slash, names no path on this platform. */
99
+ function isLocalFile(file: URL): boolean {
100
+ try {
101
+ fileURLToPath(file);
102
+ return true;
103
+ } catch {
104
+ return false;
105
+ }
106
+ }
107
+
108
+ /**
109
+ * The output file of `source`, as the user wrote it in `output`, relative to `base`. Fails with
110
+ * `CLI_OUTPUT_INVALID` before anything is generated when it is not a local file (a URL of
111
+ * another scheme) or is a directory (a trailing separator, a last segment `.` or `..`, or a
112
+ * directory on disk). Without this check, `-o dir/` and `-o dir/.` wrote a file named `dir`.
113
+ */
114
+ export function outputFileOf(run: CliRun, named: NamedOutput, base: URL): OutputFile {
115
+ return { ...named, file: outputUrlOf(run, named.output, base) };
116
+ }
117
+
118
+ /** A file the CLI reads or writes: `name` is how an error names it, `location` where it is. */
119
+ export interface NamedFile {
120
+ readonly name: string;
121
+ readonly location: URL;
122
+ }
123
+
124
+ /** The `files` that are the local file `output`, also through a link or in another letter case. */
125
+ function filesAtOutput(run: CliRun, output: OutputFile, files: readonly NamedFile[]): NamedFile[] {
126
+ return files.filter(
127
+ ({ location }) =>
128
+ location.protocol === FILE_PROTOCOL && run.deps.files.isSameFile(location, output.file),
129
+ );
130
+ }
131
+
132
+ /** A location as a path relative to the working directory, as error messages name files. */
133
+ function displayPathOf(run: CliRun, location: URL): string {
134
+ return path.relative(fileURLToPath(run.deps.cwd), fileURLToPath(location)) || ".";
135
+ }
136
+
137
+ /** The Redocly config file the run read, if any: no output may replace it. */
138
+ export function redoclyConfigFiles(run: CliRun, redocly: RedoclyConfig): NamedFile[] {
139
+ if (!redocly.configFile) {
140
+ return [];
141
+ }
142
+ const location = resolveLocationUrl(redocly.configFile, run.deps.cwd);
143
+ return [{ name: `Redocly config ${displayPathOf(run, location)}`, location }];
144
+ }
145
+
146
+ /** The local files that `owner` (a schema or an API) was generated from, `$ref`'d ones too. */
147
+ export function filesReadBy(run: CliRun, types: GeneratedTypes, owner: string): NamedFile[] {
148
+ return types.localFiles.map((location) => ({
149
+ name: `schema ${displayPathOf(run, location)} that ${owner} reads`,
150
+ location,
151
+ }));
152
+ }
153
+
154
+ /**
155
+ * Fail with `CLI_OUTPUT_IS_INPUT` when `output` is one of the `schemas` (or the Redocly config).
156
+ * Writing it would replace that file with the types, which upstream did without a word. The CLI
157
+ * checks the files it knows before generating, so nothing is loaded or written, and the files
158
+ * that `$ref`s loaded after generating, before anything is written.
159
+ */
160
+ export function ensureOutputIsNotSchema(
161
+ run: CliRun,
162
+ output: OutputFile,
163
+ schemas: readonly NamedFile[],
164
+ ): void {
165
+ const [schema] = filesAtOutput(run, output, schemas);
166
+ if (schema) {
167
+ throw cliError(
168
+ "CLI_OUTPUT_IS_INPUT",
169
+ `The output ${output.output} is the ${schema.name}: writing the types would ` +
170
+ "overwrite it. Choose another output file.",
171
+ );
172
+ }
173
+ }
174
+
175
+ /**
176
+ * Fail with `CLI_OUTPUT_DUPLICATE` when the output of an API is also one of `otherOutputs`.
177
+ * Whichever write came last would win, so every API with that output fails, before anything is
178
+ * generated.
179
+ */
180
+ export function ensureOutputIsOwn(
181
+ run: CliRun,
182
+ output: OutputFile,
183
+ otherOutputs: readonly NamedFile[],
184
+ ): void {
185
+ const clashes = filesAtOutput(run, output, otherOutputs);
186
+ if (clashes.length > 0) {
187
+ throw duplicateOutputError(
188
+ output,
189
+ clashes.map(({ name }) => name),
190
+ );
191
+ }
192
+ }
193
+
194
+ /** `CLI_OUTPUT_DUPLICATE` for `output`, which is also the output of the `others` (named). */
195
+ export function duplicateOutputError(output: NamedOutput, others: readonly string[]): Error {
196
+ return cliError(
197
+ "CLI_OUTPUT_DUPLICATE",
198
+ `The output ${output.output} of API ${output.source} is also the output of ` +
199
+ `${others.join(", ")}: they would overwrite each other. Give each API its own output file.`,
200
+ );
201
+ }
202
+
203
+ /** As `resolveLocationUrl`, but undefined for a URL that does not parse instead of a throw. */
204
+ export function parseLocationUrl(location: string, base: URL): URL | undefined {
205
+ if (URL_SCHEME.test(location)) {
206
+ return URL.parse(location, base.href) ?? undefined;
207
+ }
208
+ return resolveLocationUrl(location, base);
209
+ }
210
+
43
211
  function printDone(run: CliRun, output: OutputFile): void {
44
212
  const { style, now } = run.deps;
45
213
  const target = style.green(`${output.source} → ${style.bold(output.output)}`);
@@ -65,3 +233,14 @@ export function emitOutput(run: CliRun, output: OutputFile, contents: string): v
65
233
  run.deps.files.writeText(output.file, contents);
66
234
  printDone(run, output);
67
235
  }
236
+
237
+ /** Write (or `--check`) the types, unless the output is one of the files the run read. */
238
+ export function writeOutput(
239
+ run: CliRun,
240
+ output: OutputFile,
241
+ types: GeneratedTypes,
242
+ readFiles: readonly NamedFile[],
243
+ ): void {
244
+ ensureOutputIsNotSchema(run, output, readFiles);
245
+ emitOutput(run, output, types.contents);
246
+ }
package/src/cli/main.ts CHANGED
@@ -7,7 +7,7 @@ import { createRedoclyConfigSource } from "../adapters/redocly-loader/redocly-co
7
7
  import { astToString } from "../api/ast-to-string.js";
8
8
  import { COMMENT_HEADER } from "../api/comment-header.js";
9
9
  import { defaultLogger, monotonicNow, terminalSupportsColor } from "../api/default-ports.js";
10
- import openapiTS from "../api/openapi-ts.js";
10
+ import { defaultGeneratorPorts, generateDocument } from "../api/openapi-ts.js";
11
11
  import type { CliConsole, CliDependencies, GenerateTypes, TextStyle } from "./cli-dependencies.js";
12
12
  import { runCli } from "./run-cli.js";
13
13
 
@@ -36,8 +36,11 @@ function terminalStyle(): TextStyle {
36
36
 
37
37
  const STDIN_DESCRIPTOR = 0;
38
38
 
39
- const generateTypes: GenerateTypes = async (source, options) =>
40
- `${COMMENT_HEADER}${astToString(await openapiTS(source, options))}`;
39
+ const generateTypes: GenerateTypes = async (source, options) => {
40
+ const ports = await defaultGeneratorPorts(options);
41
+ const { declarations, localFiles } = await generateDocument(source, options, ports);
42
+ return { contents: `${COMMENT_HEADER}${astToString(declarations)}`, localFiles };
43
+ };
41
44
 
42
45
  function terminalConsole(): CliConsole {
43
46
  return {
@@ -1,19 +1,29 @@
1
- import { kebabCase } from "scule";
2
1
  import type { RedoclyConfig } from "../application/ports/redocly-config-source.js";
3
- import type { OutputFixName } from "../domain/output-fixes.js";
4
2
  import type { GeneratorOptions } from "../types.js";
5
3
  import {
6
4
  type ApiSettings,
5
+ apiFixNames,
6
+ apiFlags,
7
+ apiOutputOf,
7
8
  apiRefLimitOptions,
8
- FIX_SETTING,
9
9
  OUTPUT_SETTING,
10
10
  unknownSettingWarnings,
11
11
  } from "./api-settings.js";
12
- import { GENERATOR_FLAGS, type GeneratorFlags } from "./cli-arguments.js";
12
+ import { type GeneratedApi, writeGeneratedApis } from "./api-writes.js";
13
13
  import { cliError } from "./cli-errors.js";
14
- import { type CliRun, emitOutput, resolveLocationUrl } from "./cli-output.js";
14
+ import {
15
+ type CliRun,
16
+ ensureOutputIsNotSchema,
17
+ ensureOutputIsOwn,
18
+ filesReadBy,
19
+ type NamedFile,
20
+ outputFileOf,
21
+ parseLocationUrl,
22
+ redoclyConfigFiles,
23
+ resolveLocationUrl,
24
+ } from "./cli-output.js";
15
25
  import { MULTIPLE_SCHEMAS_DOCS_URL } from "./docs-links.js";
16
- import { fixNamesOf, fixOption } from "./fix-option.js";
26
+ import { fixOption } from "./fix-option.js";
17
27
  import { refLimitOptions } from "./ref-limits.js";
18
28
 
19
29
  /** The `apis` of a Redocly config: each API is generated into its `x-openapi-ts.output`. */
@@ -21,16 +31,17 @@ import { refLimitOptions } from "./ref-limits.js";
21
31
  /** The key of an API's openapi-typesafe settings in `redocly.yaml`. */
22
32
  const REDOCLY_CONFIG_KEY = "x-openapi-ts";
23
33
 
34
+ /** An API of the config as written: `root` and the settings are not checked yet. */
24
35
  interface RedoclyApi {
25
36
  readonly name: string;
26
- readonly root: string;
27
- readonly settings: ApiSettings | undefined;
37
+ readonly root: unknown;
38
+ readonly settings: unknown;
28
39
  }
29
40
 
30
41
  function redoclyApisOf(redocly: RedoclyConfig): RedoclyApi[] {
31
42
  return Object.entries(redocly.apis ?? {}).map(([name, api]) => {
32
- const settings = (api as Record<string, unknown>)[REDOCLY_CONFIG_KEY];
33
- return { name, root: api.root, settings: settings as ApiSettings | undefined };
43
+ const fields = api as Readonly<Record<string, unknown>>;
44
+ return { name, root: fields.root, settings: fields[REDOCLY_CONFIG_KEY] };
34
45
  });
35
46
  }
36
47
 
@@ -38,64 +49,158 @@ export function hasRedoclyApis(redocly: RedoclyConfig): boolean {
38
49
  return Object.keys(redocly.apis ?? {}).length > 0;
39
50
  }
40
51
 
41
- /** The boolean flags an API sets, in camelCase or kebab-case; they win over the CLI's flags. */
42
- function apiFlags(settings: ApiSettings): GeneratorFlags {
43
- const flags: Partial<Record<(typeof GENERATOR_FLAGS)[number], boolean>> = {};
44
- for (const name of GENERATOR_FLAGS) {
45
- const value = typeof settings[name] === "boolean" ? settings[name] : settings[kebabCase(name)];
46
- if (typeof value === "boolean") {
47
- flags[name] = value;
48
- }
49
- }
50
- return flags;
52
+ /** Paths in the config are relative to the config file; without a file, to the working dir. */
53
+ function configRootOf(redocly: RedoclyConfig, cwd: URL): URL {
54
+ return redocly.configFile ? resolveLocationUrl(redocly.configFile, cwd) : cwd;
51
55
  }
52
56
 
53
- /** The API's `fix` names; they replace the CLI's `--fix`, as its boolean settings win (ADR-021). */
54
- function apiFixNames(settings: ApiSettings): readonly OutputFixName[] | undefined {
55
- return fixNamesOf(settings[FIX_SETTING]);
57
+ /** An API whose root and settings are usable, and the directory its paths are relative to. */
58
+ interface ApiTarget {
59
+ readonly name: string;
60
+ readonly root: string;
61
+ readonly settings: ApiSettings;
62
+ readonly configRoot: URL;
56
63
  }
57
64
 
58
- /** Paths in the config are relative to the config file; without a file, to the working dir. */
59
- function configRootOf(redocly: RedoclyConfig, cwd: URL): URL {
60
- return redocly.configFile ? resolveLocationUrl(redocly.configFile, cwd) : cwd;
65
+ function isSettingsMap(value: unknown): value is ApiSettings {
66
+ return typeof value === "object" && value !== null && !Array.isArray(value);
61
67
  }
62
68
 
63
- async function generateApi(run: CliRun, redocly: RedoclyConfig, api: RedoclyApi): Promise<void> {
64
- if (!api.settings?.[OUTPUT_SETTING]) {
69
+ /**
70
+ * The API with its settings. Fails with `CLI_CONFIG_OUTPUT_MISSING` when they name no output, and
71
+ * with `CLI_CONFIG_INVALID` when they are no map or `root` is no path or URL; only this API then
72
+ * fails, the others are still generated.
73
+ */
74
+ function apiTarget(api: RedoclyApi, configRoot: URL): ApiTarget {
75
+ const { name, root, settings } = api;
76
+ if (settings !== undefined && !isSettingsMap(settings)) {
77
+ throw cliError("CLI_CONFIG_INVALID", `API ${name}: \`${REDOCLY_CONFIG_KEY}\` must be a map`);
78
+ }
79
+ if (!settings?.[OUTPUT_SETTING]) {
65
80
  throw cliError(
66
81
  "CLI_CONFIG_OUTPUT_MISSING",
67
- `API ${api.name} is missing an \`${REDOCLY_CONFIG_KEY}.output\` key. ` +
82
+ `API ${name} is missing an \`${REDOCLY_CONFIG_KEY}.output\` key. ` +
68
83
  `See ${MULTIPLE_SCHEMAS_DOCS_URL}`,
69
84
  );
70
85
  }
71
- for (const warning of unknownSettingWarnings(api.name, api.settings)) {
72
- run.deps.logger.warn(warning);
86
+ if (typeof root !== "string" || root === "") {
87
+ throw cliError(
88
+ "CLI_CONFIG_INVALID",
89
+ `API ${name}: \`root\` in redocly.yaml must be the path or URL of its schema`,
90
+ );
73
91
  }
74
- const output = String(api.settings[OUTPUT_SETTING]);
75
- const configRoot = configRootOf(redocly, run.deps.cwd);
76
- const options: GeneratorOptions = {
92
+ return { name, root, settings, configRoot };
93
+ }
94
+
95
+ /** The generator options of one API: its own settings win over the CLI's flags. */
96
+ function apiOptions(run: CliRun, redocly: RedoclyConfig, target: ApiTarget): GeneratorOptions {
97
+ const { name, settings, configRoot } = target;
98
+ return {
77
99
  ...run.args.generatorFlags,
78
- ...apiFlags(api.settings),
100
+ ...apiFlags(name, settings),
79
101
  ...refLimitOptions(run.args, run.deps.cwd),
80
- ...apiRefLimitOptions(api.name, api.settings, configRoot),
81
- ...fixOption(apiFixNames(api.settings) ?? run.args.fix),
102
+ ...apiRefLimitOptions(name, settings, configRoot),
103
+ ...fixOption(apiFixNames(name, settings) ?? run.args.fix),
82
104
  redocly,
83
105
  };
84
- const contents = await run.deps.generate(resolveLocationUrl(api.root, configRoot), options);
85
- emitOutput(
86
- run,
87
- { source: api.name, output, file: resolveLocationUrl(output, configRoot) },
88
- contents,
89
- );
106
+ }
107
+
108
+ /** The schemas and outputs of every API of the config, keyed by API name for the outputs. */
109
+ interface ConfigFiles {
110
+ readonly schemas: readonly NamedFile[];
111
+ readonly outputs: ReadonlyMap<string, URL>;
112
+ }
113
+
114
+ /** The outputs of the other APIs, as `ensureOutputIsOwn` names them. */
115
+ function otherOutputs(files: ConfigFiles, apiName: string): NamedFile[] {
116
+ return [...files.outputs]
117
+ .filter(([name]) => name !== apiName)
118
+ .map(([name, location]) => ({ name: `API ${name}`, location }));
119
+ }
120
+
121
+ /**
122
+ * Generate the types of one API. Its output must not be a file the run reads before any API is
123
+ * loaded (the root of any API, the Redocly config) nor another API's output.
124
+ */
125
+ async function generateApi(
126
+ run: CliRun,
127
+ redocly: RedoclyConfig,
128
+ target: ApiTarget,
129
+ files: ConfigFiles,
130
+ ): Promise<GeneratedApi> {
131
+ for (const warning of unknownSettingWarnings(target.name, target.settings)) {
132
+ run.deps.logger.warn(warning);
133
+ }
134
+ const output = apiOutputOf(target.name, target.settings);
135
+ const outputFile = outputFileOf(run, { source: target.name, output }, target.configRoot);
136
+ ensureOutputIsNotSchema(run, outputFile, files.schemas);
137
+ ensureOutputIsOwn(run, outputFile, otherOutputs(files, target.name));
138
+ const source = resolveLocationUrl(target.root, target.configRoot);
139
+ const types = await run.deps.generate(source, apiOptions(run, redocly, target));
140
+ return { name: target.name, outputFile, types };
90
141
  }
91
142
 
92
143
  /**
93
- * Generate every API of the config, concurrently. Every API is generated or checked even when
94
- * another fails, so `--check` reports a stale output wherever it is; the failures are returned
95
- * in the order of the config.
144
+ * The schema and the output of every API, and the config file itself. A location that is no
145
+ * text or no valid URL is left out: it is no file that an output could be, and its own API fails
146
+ * on it, not every API.
147
+ */
148
+ function configFilesOf(run: CliRun, redocly: RedoclyConfig, apis: readonly RedoclyApi[]) {
149
+ const configRoot = configRootOf(redocly, run.deps.cwd);
150
+ const roots = apis.flatMap(({ name, root }) => {
151
+ const location = typeof root === "string" ? parseLocationUrl(root, configRoot) : undefined;
152
+ return location ? [{ name: `schema ${root} of API ${name}`, location }] : [];
153
+ });
154
+ const outputs = new Map<string, URL>();
155
+ for (const api of apis) {
156
+ const output = isSettingsMap(api.settings) ? api.settings[OUTPUT_SETTING] : undefined;
157
+ const location = typeof output === "string" ? parseLocationUrl(output, configRoot) : undefined;
158
+ if (location) {
159
+ outputs.set(api.name, location);
160
+ }
161
+ }
162
+ const schemas = [...roots, ...redoclyConfigFiles(run, redocly)];
163
+ return { configRoot, files: { schemas, outputs } satisfies ConfigFiles };
164
+ }
165
+
166
+ /** What `task` gives for each item, run one after another: the next starts when one settles. */
167
+ async function settledInTurn<T, R>(
168
+ items: readonly T[],
169
+ task: (item: T) => Promise<R>,
170
+ ): Promise<PromiseSettledResult<R>[]> {
171
+ const results: PromiseSettledResult<R>[] = [];
172
+ for (const item of items) {
173
+ try {
174
+ results.push({ status: "fulfilled", value: await task(item) });
175
+ } catch (reason) {
176
+ results.push({ status: "rejected", reason });
177
+ }
178
+ }
179
+ return results;
180
+ }
181
+
182
+ /**
183
+ * Generate every API of the config, one after another in the order of the config, then write
184
+ * them. One at a time, so a run takes the memory of its largest API, not the sum of all of them,
185
+ * and the work of one API cannot hold up the fetches of another until their timeout ends them.
186
+ * Nothing is written until every API is read and every output is claimed, so no output can
187
+ * replace a file that another API still reads; an output that is a file any API read (a `$ref`'d
188
+ * schema) fails with `CLI_OUTPUT_IS_INPUT`. Every API is generated or checked even when another
189
+ * fails, so `--check` reports a stale output wherever it is; the failures are returned in the
190
+ * order of the config.
96
191
  */
97
192
  export async function generateRedoclyApis(run: CliRun, redocly: RedoclyConfig): Promise<unknown[]> {
98
193
  const apis = redoclyApisOf(redocly);
99
- const results = await Promise.allSettled(apis.map((api) => generateApi(run, redocly, api)));
100
- return results.flatMap((result) => (result.status === "rejected" ? [result.reason] : []));
194
+ const { configRoot, files } = configFilesOf(run, redocly, apis);
195
+ const results = await settledInTurn(apis, (api) =>
196
+ generateApi(run, redocly, apiTarget(api, configRoot), files),
197
+ );
198
+ const generated = results.flatMap((result) =>
199
+ result.status === "fulfilled" ? [result.value] : [],
200
+ );
201
+ const readFiles = generated.flatMap(({ name, types }) => filesReadBy(run, types, `API ${name}`));
202
+ const writeFailures = writeGeneratedApis(run, generated, readFiles);
203
+ return results.flatMap((result) =>
204
+ result.status === "rejected" ? [result.reason] : (writeFailures.get(result.value.name) ?? []),
205
+ );
101
206
  }
@@ -5,7 +5,16 @@ import type { SchemaSource } from "../types.js";
5
5
  import { ineffectiveFlagNotices, parseCliArguments } from "./cli-arguments.js";
6
6
  import type { CliDependencies } from "./cli-dependencies.js";
7
7
  import { cliError, describeCliFailure, EXIT_CODES, type ExitCode } from "./cli-errors.js";
8
- import { type CliRun, emitOutput, resolveLocationUrl } from "./cli-output.js";
8
+ import {
9
+ type CliRun,
10
+ ensureOutputIsNotSchema,
11
+ filesReadBy,
12
+ type OutputFile,
13
+ outputFileOf,
14
+ redoclyConfigFiles,
15
+ resolveLocationUrl,
16
+ writeOutput,
17
+ } from "./cli-output.js";
9
18
  import { MULTIPLE_SCHEMAS_DOCS_URL } from "./docs-links.js";
10
19
  import { fixOption } from "./fix-option.js";
11
20
  import { HELP_TEXT } from "./help-text.js";
@@ -43,7 +52,10 @@ function schemaSource(run: CliRun): SchemaSource {
43
52
  return run.deps.stdin();
44
53
  }
45
54
 
46
- /** One schema from a path, a URL or stdin; without `--output`, the types go to stdout only. */
55
+ /**
56
+ * One schema from a path, a URL or stdin; without `--output`, the types go to stdout. Warnings and
57
+ * errors go to stderr either way, so they never mix with the types (upstream dropped warnings).
58
+ */
47
59
  async function generateSingleSchema(run: CliRun, redocly: RedoclyConfig): Promise<void> {
48
60
  const { input, output } = run.args;
49
61
  if (input?.includes("*")) {
@@ -61,20 +73,37 @@ async function generateSingleSchema(run: CliRun, redocly: RedoclyConfig): Promis
61
73
  );
62
74
  }
63
75
  const source = schemaSource(run);
76
+ const outputFile = output ? singleOutputFile(run, output, source, redocly) : undefined;
64
77
  const options = {
65
78
  ...run.args.generatorFlags,
66
79
  ...refLimitOptions(run.args, run.deps.cwd),
67
80
  ...fixOption(run.args.fix),
68
81
  redocly,
69
- silent: !output,
70
82
  };
71
- const contents = await run.deps.generate(source, options);
72
- if (!output) {
73
- run.deps.writeStdout(contents);
83
+ const types = await run.deps.generate(source, options);
84
+ if (!outputFile) {
85
+ run.deps.writeStdout(types.contents);
74
86
  return;
75
87
  }
76
- const file = resolveLocationUrl(output, run.deps.cwd);
77
- emitOutput(run, { source: input ?? "stdin", output, file }, contents);
88
+ writeOutput(run, outputFile, types, filesReadBy(run, types, outputFile.source));
89
+ }
90
+
91
+ /**
92
+ * The `--output` file; it must not be the schema file nor the Redocly config, which writing it
93
+ * would replace.
94
+ */
95
+ function singleOutputFile(
96
+ run: CliRun,
97
+ output: string,
98
+ source: SchemaSource,
99
+ redocly: RedoclyConfig,
100
+ ): OutputFile {
101
+ const { input } = run.args;
102
+ const outputFile = outputFileOf(run, { source: input ?? "stdin", output }, run.deps.cwd);
103
+ const schemas =
104
+ input && source instanceof URL ? [{ name: `schema ${input}`, location: source }] : [];
105
+ ensureOutputIsNotSchema(run, outputFile, [...schemas, ...redoclyConfigFiles(run, redocly)]);
106
+ return outputFile;
78
107
  }
79
108
 
80
109
  async function generate(run: CliRun): Promise<unknown[]> {
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Append every item of `items` to `target`. `target.push(...items)` passes each item as an
3
+ * argument, and engines limit the arguments of a call (V8 throws a RangeError from about 125,000),
4
+ * so a list as long as a document allows (an `enum`, an `anyOf`, `examples`) must not be spread.
5
+ */
6
+ export function appendAll<T>(target: T[], items: Iterable<T>): void {
7
+ for (const item of items) {
8
+ target.push(item);
9
+ }
10
+ }