hono-takibi 0.8.0 → 0.8.1

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 (288) hide show
  1. package/dist/cli/index.d.ts +9 -1
  2. package/dist/cli/index.js +24 -1
  3. package/dist/cli/parse.d.ts +16 -0
  4. package/dist/cli/parse.js +25 -0
  5. package/dist/cli/takibi.d.ts +16 -0
  6. package/dist/cli/takibi.js +28 -0
  7. package/dist/cli/template-code.d.ts +12 -0
  8. package/dist/cli/template-code.js +22 -0
  9. package/dist/format/index.d.ts +4 -3
  10. package/dist/format/index.js +4 -3
  11. package/dist/fsp/index.d.ts +13 -7
  12. package/dist/fsp/index.js +14 -8
  13. package/dist/generator/zod/helper/array-reference-schema.d.ts +31 -0
  14. package/dist/generator/zod/helper/array-reference-schema.js +40 -0
  15. package/dist/generator/zod/helper/index.d.ts +5 -0
  16. package/dist/generator/zod/helper/index.js +5 -0
  17. package/dist/generator/zod/helper/properties-schema.d.ts +46 -0
  18. package/dist/generator/zod/helper/properties-schema.js +60 -0
  19. package/dist/generator/zod/helper/property-schema.d.ts +27 -0
  20. package/dist/generator/zod/helper/property-schema.js +39 -0
  21. package/dist/generator/zod/helper/reference-schema.d.ts +26 -0
  22. package/dist/generator/zod/helper/reference-schema.js +35 -0
  23. package/dist/generator/zod/helper/zod-schema-from-sub-schema.d.ts +22 -0
  24. package/dist/generator/zod/helper/zod-schema-from-sub-schema.js +25 -0
  25. package/dist/generator/zod/index.d.ts +50 -4
  26. package/dist/generator/zod/index.js +63 -61
  27. package/dist/generator/zod/z/array.d.ts +2 -6
  28. package/dist/generator/zod/z/array.js +26 -7
  29. package/dist/generator/zod/z/enum.d.ts +12 -4
  30. package/dist/generator/zod/z/enum.js +11 -3
  31. package/dist/generator/zod/z/index.d.ts +0 -14
  32. package/dist/generator/zod/z/index.js +0 -14
  33. package/dist/generator/zod/z/integer.d.ts +6 -4
  34. package/dist/generator/zod/z/integer.js +51 -33
  35. package/dist/generator/zod/z/number.d.ts +1 -6
  36. package/dist/generator/zod/z/number.js +38 -55
  37. package/dist/generator/zod/z/object.d.ts +5 -4
  38. package/dist/generator/zod/z/object.js +9 -8
  39. package/dist/generator/zod/z/record.d.ts +5 -6
  40. package/dist/generator/zod/z/record.js +7 -7
  41. package/dist/generator/zod/z/string.d.ts +2 -6
  42. package/dist/generator/zod/z/string.js +23 -24
  43. package/dist/generator/zod-openapi-hono/app/helper/docs.d.ts +14 -0
  44. package/dist/generator/zod-openapi-hono/app/{generator → helper}/docs.js +6 -0
  45. package/dist/generator/zod-openapi-hono/app/helper/get-route-maps.d.ts +4 -3
  46. package/dist/generator/zod-openapi-hono/app/helper/get-route-maps.js +6 -6
  47. package/dist/generator/zod-openapi-hono/app/index.d.ts +5 -6
  48. package/dist/generator/zod-openapi-hono/app/index.js +15 -27
  49. package/dist/generator/zod-openapi-hono/handler/zod-openapi-hono-handler.d.ts +6 -5
  50. package/dist/generator/zod-openapi-hono/handler/zod-openapi-hono-handler.js +10 -12
  51. package/dist/generator/zod-openapi-hono/openapi/components/index.d.ts +15 -0
  52. package/dist/generator/zod-openapi-hono/openapi/components/index.js +43 -0
  53. package/dist/generator/zod-openapi-hono/openapi/index.d.ts +10 -0
  54. package/dist/generator/zod-openapi-hono/openapi/index.js +16 -0
  55. package/dist/generator/zod-openapi-hono/openapi/route/index.d.ts +14 -4
  56. package/dist/generator/zod-openapi-hono/openapi/route/index.js +43 -4
  57. package/dist/generator/zod-openapi-hono/openapi/route/params/index.d.ts +1 -2
  58. package/dist/generator/zod-openapi-hono/openapi/route/params/index.js +1 -2
  59. package/dist/generator/zod-openapi-hono/openapi/route/params/params-object.d.ts +14 -9
  60. package/dist/generator/zod-openapi-hono/openapi/route/params/params-object.js +16 -11
  61. package/dist/generator/zod-openapi-hono/openapi/route/params/query-parameter.d.ts +10 -5
  62. package/dist/generator/zod-openapi-hono/openapi/route/params/query-parameter.js +11 -6
  63. package/dist/generator/zod-openapi-hono/openapi/route/params/request-parameter.d.ts +9 -13
  64. package/dist/generator/zod-openapi-hono/openapi/route/params/request-parameter.js +13 -18
  65. package/dist/generator/zod-openapi-hono/openapi/route/params/request-params-array.d.ts +11 -5
  66. package/dist/generator/zod-openapi-hono/openapi/route/params/request-params-array.js +9 -4
  67. package/dist/generator/zod-openapi-hono/openapi/route/request/body/index.d.ts +10 -0
  68. package/dist/generator/zod-openapi-hono/openapi/route/request/body/{request-body.js → index.js} +7 -7
  69. package/dist/generator/zod-openapi-hono/openapi/route/response/index.d.ts +9 -14
  70. package/dist/generator/zod-openapi-hono/openapi/route/response/index.js +11 -17
  71. package/dist/generator/zod-openapi-hono/openapi/route/route.d.ts +10 -16
  72. package/dist/generator/zod-openapi-hono/openapi/route/route.js +11 -19
  73. package/dist/helper/allof.d.ts +14 -0
  74. package/dist/helper/allof.js +36 -0
  75. package/dist/helper/anyof.d.ts +14 -0
  76. package/dist/helper/anyof.js +26 -0
  77. package/dist/helper/index.d.ts +9 -0
  78. package/dist/helper/index.js +9 -0
  79. package/dist/helper/maybe-apply-nullability.d.ts +26 -0
  80. package/dist/helper/maybe-apply-nullability.js +28 -0
  81. package/dist/helper/not.d.ts +13 -0
  82. package/dist/helper/not.js +18 -0
  83. package/dist/helper/oneof.d.ts +12 -0
  84. package/dist/helper/oneof.js +24 -0
  85. package/dist/helper/pick-types.d.ts +22 -0
  86. package/dist/helper/pick-types.js +23 -0
  87. package/dist/helper/resolve-schemas-dependencies.d.ts +13 -0
  88. package/dist/helper/resolve-schemas-dependencies.js +57 -0
  89. package/dist/helper/zod-to-openapi-schema.d.ts +14 -0
  90. package/dist/helper/zod-to-openapi-schema.js +30 -0
  91. package/dist/helper/zod-to-openapi.d.ts +21 -0
  92. package/dist/helper/zod-to-openapi.js +39 -0
  93. package/dist/openapi/index.d.ts +1 -13
  94. package/dist/openapi/parse-openapi.d.ts +5 -4
  95. package/dist/openapi/parse-openapi.js +5 -4
  96. package/dist/openapi/types.d.ts +19 -59
  97. package/dist/result/index.d.ts +32 -12
  98. package/dist/result/index.js +26 -12
  99. package/dist/typespec/index.d.ts +4 -3
  100. package/dist/typespec/index.js +5 -4
  101. package/dist/utils/index.d.ts +532 -0
  102. package/dist/utils/index.js +731 -0
  103. package/dist/vite-plugin/index.js +1 -1
  104. package/dist/vite-plugin/vite-tsp.d.ts +7 -6
  105. package/dist/vite-plugin/vite-tsp.js +10 -9
  106. package/dist/vite-plugin/vite.d.ts +7 -6
  107. package/dist/vite-plugin/vite.js +10 -9
  108. package/package.json +12 -11
  109. package/dist/cli/hono-takibi/index.d.ts +0 -4
  110. package/dist/cli/hono-takibi/index.js +0 -20
  111. package/dist/cli/hono-takibi/takibi.d.ts +0 -15
  112. package/dist/cli/hono-takibi/takibi.js +0 -25
  113. package/dist/cli/hono-takibi/template-code.d.ts +0 -12
  114. package/dist/cli/hono-takibi/template-code.js +0 -24
  115. package/dist/cli/parse/index.d.ts +0 -2
  116. package/dist/cli/parse/index.js +0 -2
  117. package/dist/cli/parse/parse-cli.d.ts +0 -21
  118. package/dist/cli/parse/parse-cli.js +0 -25
  119. package/dist/cli/parse/parse-io.d.ts +0 -10
  120. package/dist/cli/parse/parse-io.js +0 -18
  121. package/dist/cli/utils/index.d.ts +0 -26
  122. package/dist/cli/utils/index.js +0 -37
  123. package/dist/cli/validator/index.d.ts +0 -2
  124. package/dist/cli/validator/index.js +0 -2
  125. package/dist/cli/validator/is-ts.d.ts +0 -1
  126. package/dist/cli/validator/is-ts.js +0 -3
  127. package/dist/cli/validator/is-yaml-or-json-tsp.d.ts +0 -1
  128. package/dist/cli/validator/is-yaml-or-json-tsp.js +0 -3
  129. package/dist/core/schema/references/extract-refs.d.ts +0 -7
  130. package/dist/core/schema/references/extract-refs.js +0 -28
  131. package/dist/core/schema/references/find-references.d.ts +0 -25
  132. package/dist/core/schema/references/find-references.js +0 -29
  133. package/dist/core/schema/references/get-ref-name.d.ts +0 -33
  134. package/dist/core/schema/references/get-ref-name.js +0 -39
  135. package/dist/core/schema/references/get-ref-schema-name.d.ts +0 -7
  136. package/dist/core/schema/references/get-ref-schema-name.js +0 -14
  137. package/dist/core/schema/references/index.d.ts +0 -7
  138. package/dist/core/schema/references/index.js +0 -7
  139. package/dist/core/schema/references/resolve-schemas-dependencies.d.ts +0 -59
  140. package/dist/core/schema/references/resolve-schemas-dependencies.js +0 -69
  141. package/dist/core/schema/references/traverse-schema-dependencies.d.ts +0 -10
  142. package/dist/core/schema/references/traverse-schema-dependencies.js +0 -31
  143. package/dist/core/schema/references/traverse-schema.d.ts +0 -45
  144. package/dist/core/schema/references/traverse-schema.js +0 -64
  145. package/dist/core/utils/capitalize.d.ts +0 -16
  146. package/dist/core/utils/capitalize.js +0 -18
  147. package/dist/core/utils/escape-string-literal.d.ts +0 -6
  148. package/dist/core/utils/escape-string-literal.js +0 -20
  149. package/dist/core/utils/exclusive.d.ts +0 -2
  150. package/dist/core/utils/exclusive.js +0 -6
  151. package/dist/core/utils/get-to-safe-identifier.d.ts +0 -6
  152. package/dist/core/utils/get-to-safe-identifier.js +0 -8
  153. package/dist/core/utils/index.d.ts +0 -12
  154. package/dist/core/utils/index.js +0 -12
  155. package/dist/core/utils/maybe-apply-nullability.d.ts +0 -2
  156. package/dist/core/utils/maybe-apply-nullability.js +0 -4
  157. package/dist/core/utils/pick-types.d.ts +0 -2
  158. package/dist/core/utils/pick-types.js +0 -4
  159. package/dist/core/utils/regex-pattern.d.ts +0 -6
  160. package/dist/core/utils/regex-pattern.js +0 -9
  161. package/dist/core/utils/remove-zod-prefix.d.ts +0 -6
  162. package/dist/core/utils/remove-zod-prefix.js +0 -8
  163. package/dist/core/utils/sanitizeIdentifier.d.ts +0 -23
  164. package/dist/core/utils/sanitizeIdentifier.js +0 -25
  165. package/dist/core/utils/strip-max-if-lt-exist.d.ts +0 -7
  166. package/dist/core/utils/strip-max-if-lt-exist.js +0 -9
  167. package/dist/core/utils/strip-min-if-gt-exist.d.ts +0 -7
  168. package/dist/core/utils/strip-min-if-gt-exist.js +0 -9
  169. package/dist/core/utils/strip-min-max-exist.d.ts +0 -8
  170. package/dist/core/utils/strip-min-max-exist.js +0 -10
  171. package/dist/core/validator/index.d.ts +0 -7
  172. package/dist/core/validator/index.js +0 -7
  173. package/dist/core/validator/is-all-optional.d.ts +0 -6
  174. package/dist/core/validator/is-all-optional.js +0 -8
  175. package/dist/core/validator/is-array-with-schema-reference.d.ts +0 -7
  176. package/dist/core/validator/is-array-with-schema-reference.js +0 -8
  177. package/dist/core/validator/is-http-method.d.ts +0 -6
  178. package/dist/core/validator/is-http-method.js +0 -15
  179. package/dist/core/validator/is-nullable-schema.d.ts +0 -7
  180. package/dist/core/validator/is-nullable-schema.js +0 -8
  181. package/dist/core/validator/is-operation.d.ts +0 -13
  182. package/dist/core/validator/is-operation.js +0 -14
  183. package/dist/core/validator/is-ref-object.d.ts +0 -11
  184. package/dist/core/validator/is-ref-object.js +0 -8
  185. package/dist/core/validator/is-unique-content-schema.d.ts +0 -8
  186. package/dist/core/validator/is-unique-content-schema.js +0 -10
  187. package/dist/generator/zod/property/index.d.ts +0 -2
  188. package/dist/generator/zod/property/index.js +0 -2
  189. package/dist/generator/zod/property/properties-schema.d.ts +0 -44
  190. package/dist/generator/zod/property/properties-schema.js +0 -60
  191. package/dist/generator/zod/property/property-schema.d.ts +0 -8
  192. package/dist/generator/zod/property/property-schema.js +0 -18
  193. package/dist/generator/zod/reference/array-reference-schema.d.ts +0 -7
  194. package/dist/generator/zod/reference/array-reference-schema.js +0 -17
  195. package/dist/generator/zod/reference/index.d.ts +0 -2
  196. package/dist/generator/zod/reference/index.js +0 -2
  197. package/dist/generator/zod/reference/reference-schema.d.ts +0 -7
  198. package/dist/generator/zod/reference/reference-schema.js +0 -16
  199. package/dist/generator/zod/sub/index.d.ts +0 -1
  200. package/dist/generator/zod/sub/index.js +0 -1
  201. package/dist/generator/zod/sub/zod-schema-from-sub-schema.d.ts +0 -7
  202. package/dist/generator/zod/sub/zod-schema-from-sub-schema.js +0 -10
  203. package/dist/generator/zod/z/coerce.d.ts +0 -6
  204. package/dist/generator/zod/z/coerce.js +0 -10
  205. package/dist/generator/zod/z/default.d.ts +0 -7
  206. package/dist/generator/zod/z/default.js +0 -8
  207. package/dist/generator/zod/z/gt.d.ts +0 -6
  208. package/dist/generator/zod/z/gt.js +0 -8
  209. package/dist/generator/zod/z/infer.d.ts +0 -7
  210. package/dist/generator/zod/z/infer.js +0 -9
  211. package/dist/generator/zod/z/intersection.d.ts +0 -6
  212. package/dist/generator/zod/z/intersection.js +0 -8
  213. package/dist/generator/zod/z/length.d.ts +0 -6
  214. package/dist/generator/zod/z/length.js +0 -8
  215. package/dist/generator/zod/z/lt.d.ts +0 -6
  216. package/dist/generator/zod/z/lt.js +0 -8
  217. package/dist/generator/zod/z/max.d.ts +0 -6
  218. package/dist/generator/zod/z/max.js +0 -8
  219. package/dist/generator/zod/z/min.d.ts +0 -9
  220. package/dist/generator/zod/z/min.js +0 -11
  221. package/dist/generator/zod/z/partial.d.ts +0 -6
  222. package/dist/generator/zod/z/partial.js +0 -9
  223. package/dist/generator/zod/z/regex.d.ts +0 -6
  224. package/dist/generator/zod/z/regex.js +0 -14
  225. package/dist/generator/zod/z/schema.d.ts +0 -6
  226. package/dist/generator/zod/z/schema.js +0 -10
  227. package/dist/generator/zod/z/stringbool.d.ts +0 -7
  228. package/dist/generator/zod/z/stringbool.js +0 -9
  229. package/dist/generator/zod/z/union.d.ts +0 -7
  230. package/dist/generator/zod/z/union.js +0 -9
  231. package/dist/generator/zod-openapi-hono/app/generator/app-route-handler.d.ts +0 -6
  232. package/dist/generator/zod-openapi-hono/app/generator/app-route-handler.js +0 -8
  233. package/dist/generator/zod-openapi-hono/app/generator/apply-openapi-routes.d.ts +0 -12
  234. package/dist/generator/zod-openapi-hono/app/generator/apply-openapi-routes.js +0 -15
  235. package/dist/generator/zod-openapi-hono/app/generator/docs.d.ts +0 -8
  236. package/dist/generator/zod-openapi-hono/app/generator/import-routes.d.ts +0 -10
  237. package/dist/generator/zod-openapi-hono/app/generator/import-routes.js +0 -21
  238. package/dist/generator/zod-openapi-hono/app/generator/index.d.ts +0 -5
  239. package/dist/generator/zod-openapi-hono/app/generator/index.js +0 -5
  240. package/dist/generator/zod-openapi-hono/app/generator/register-component.d.ts +0 -7
  241. package/dist/generator/zod-openapi-hono/app/generator/register-component.js +0 -12
  242. package/dist/generator/zod-openapi-hono/app/helper/process-import-map.d.ts +0 -12
  243. package/dist/generator/zod-openapi-hono/app/helper/process-import-map.js +0 -17
  244. package/dist/generator/zod-openapi-hono/handler/generator/handler-name.d.ts +0 -7
  245. package/dist/generator/zod-openapi-hono/handler/generator/handler-name.js +0 -10
  246. package/dist/generator/zod-openapi-hono/handler/generator/handler.d.ts +0 -7
  247. package/dist/generator/zod-openapi-hono/handler/generator/handler.js +0 -9
  248. package/dist/generator/zod-openapi-hono/handler/generator/import-handlers.d.ts +0 -9
  249. package/dist/generator/zod-openapi-hono/handler/generator/import-handlers.js +0 -22
  250. package/dist/generator/zod-openapi-hono/handler/generator/index.d.ts +0 -3
  251. package/dist/generator/zod-openapi-hono/handler/generator/index.js +0 -3
  252. package/dist/generator/zod-openapi-hono/handler/helper/group-handlers-by-file-name.d.ts +0 -11
  253. package/dist/generator/zod-openapi-hono/handler/helper/group-handlers-by-file-name.js +0 -18
  254. package/dist/generator/zod-openapi-hono/handler/import/get-handler-imports.d.ts +0 -12
  255. package/dist/generator/zod-openapi-hono/handler/import/get-handler-imports.js +0 -23
  256. package/dist/generator/zod-openapi-hono/openapi/components/allof/index.d.ts +0 -7
  257. package/dist/generator/zod-openapi-hono/openapi/components/allof/index.js +0 -21
  258. package/dist/generator/zod-openapi-hono/openapi/components/allof/process/process-alllof.d.ts +0 -12
  259. package/dist/generator/zod-openapi-hono/openapi/components/allof/process/process-alllof.js +0 -18
  260. package/dist/generator/zod-openapi-hono/openapi/components/anyof/index.d.ts +0 -7
  261. package/dist/generator/zod-openapi-hono/openapi/components/anyof/index.js +0 -19
  262. package/dist/generator/zod-openapi-hono/openapi/components/components-code.d.ts +0 -17
  263. package/dist/generator/zod-openapi-hono/openapi/components/components-code.js +0 -43
  264. package/dist/generator/zod-openapi-hono/openapi/components/not/index.d.ts +0 -7
  265. package/dist/generator/zod-openapi-hono/openapi/components/not/index.js +0 -12
  266. package/dist/generator/zod-openapi-hono/openapi/components/oneof/index.d.ts +0 -7
  267. package/dist/generator/zod-openapi-hono/openapi/components/oneof/index.js +0 -19
  268. package/dist/generator/zod-openapi-hono/openapi/route/create-route.d.ts +0 -56
  269. package/dist/generator/zod-openapi-hono/openapi/route/create-route.js +0 -56
  270. package/dist/generator/zod-openapi-hono/openapi/route/params/request-params.d.ts +0 -6
  271. package/dist/generator/zod-openapi-hono/openapi/route/params/request-params.js +0 -8
  272. package/dist/generator/zod-openapi-hono/openapi/route/request/body/insert-request-body.d.ts +0 -7
  273. package/dist/generator/zod-openapi-hono/openapi/route/request/body/insert-request-body.js +0 -9
  274. package/dist/generator/zod-openapi-hono/openapi/route/request/body/request-body.d.ts +0 -9
  275. package/dist/generator/zod-openapi-hono/openapi/route/request/object/format-request-object.d.ts +0 -25
  276. package/dist/generator/zod-openapi-hono/openapi/route/request/object/format-request-object.js +0 -27
  277. package/dist/generator/zod-openapi-hono/openapi/route/route-code.d.ts +0 -18
  278. package/dist/generator/zod-openapi-hono/openapi/route/route-code.js +0 -46
  279. package/dist/generator/zod-openapi-hono/openapi/route/route-name.d.ts +0 -15
  280. package/dist/generator/zod-openapi-hono/openapi/route/route-name.js +0 -30
  281. package/dist/generator/zod-openapi-hono/openapi/zod-openapi-hono.d.ts +0 -9
  282. package/dist/generator/zod-openapi-hono/openapi/zod-openapi-hono.js +0 -19
  283. package/dist/generator/zod-to-openapi/index.d.ts +0 -2
  284. package/dist/generator/zod-to-openapi/index.js +0 -2
  285. package/dist/generator/zod-to-openapi/zod-to-openapi-schema.d.ts +0 -9
  286. package/dist/generator/zod-to-openapi/zod-to-openapi-schema.js +0 -25
  287. package/dist/generator/zod-to-openapi/zod-to-openapi.d.ts +0 -9
  288. package/dist/generator/zod-to-openapi/zod-to-openapi.js +0 -29
@@ -1 +1,9 @@
1
- export { honoTakibi } from './hono-takibi/index.js';
1
+ import { type Result } from '../result/index.js';
2
+ /**
3
+ * CLI entry point for `hono-takibi`.
4
+ *
5
+ * @returns A `Result` containing help text or CLI execution result.
6
+ */
7
+ export declare function honoTakibi(): Promise<Result<{
8
+ message: string;
9
+ }, string>>;
package/dist/cli/index.js CHANGED
@@ -1 +1,24 @@
1
- export { honoTakibi } from './hono-takibi/index.js';
1
+ import { asyncAndThen, ok } from '../result/index.js';
2
+ import { isHelpRequested, sliceArgv } from '../utils/index.js';
3
+ import { parseCli } from './parse.js';
4
+ import { takibi } from './takibi.js';
5
+ const HELP_TEXT = `Usage: hono-takibi <input.{yaml,json,tsp}> -o <routes.ts> [options]
6
+
7
+ Options:
8
+ --export-type export TypeScript type aliases
9
+ --export-schema export Zod schema objects
10
+ --template generate app file and handler stubs
11
+ --test generate empty *.test.ts files
12
+ --base-path <path> api prefix (default: /)
13
+ -h, --help display help for command`;
14
+ /**
15
+ * CLI entry point for `hono-takibi`.
16
+ *
17
+ * @returns A `Result` containing help text or CLI execution result.
18
+ */
19
+ export async function honoTakibi() {
20
+ const args = sliceArgv(process.argv);
21
+ return isHelpRequested(sliceArgv(process.argv))
22
+ ? ok({ message: HELP_TEXT })
23
+ : await asyncAndThen(parseCli(args), async (cli) => asyncAndThen(await takibi(cli.input, cli.output, cli.exportSchema ?? false, cli.exportType ?? false, cli.template ?? false, cli.test ?? false, cli.basePath), async (result) => ok(result)));
24
+ }
@@ -0,0 +1,16 @@
1
+ import type { Result } from '../result/index.js';
2
+ /**
3
+ * Parses CLI arguments into structured options.
4
+ *
5
+ * @param args - Raw CLI arguments.
6
+ * @returns A `Result` containing parsed CLI options or an error message.
7
+ */
8
+ export declare function parseCli(args: readonly string[]): Result<{
9
+ input: `${string}.yaml` | `${string}.json` | `${string}.tsp`;
10
+ output: `${string}.ts`;
11
+ exportType?: boolean;
12
+ exportSchema?: boolean;
13
+ template: boolean;
14
+ test: boolean;
15
+ basePath?: string;
16
+ }, string>;
@@ -0,0 +1,25 @@
1
+ import { err, ok } from '../result/index.js';
2
+ import { getFlagValue, hasFlag, isTs, isYamlOrJsonOrTsp } from '../utils/index.js';
3
+ /**
4
+ * Parses CLI arguments into structured options.
5
+ *
6
+ * @param args - Raw CLI arguments.
7
+ * @returns A `Result` containing parsed CLI options or an error message.
8
+ */
9
+ export function parseCli(args) {
10
+ const input = args[0];
11
+ const oIdx = args.indexOf('-o');
12
+ const output = oIdx !== -1 ? args[oIdx + 1] : undefined;
13
+ if (!(input && output && isYamlOrJsonOrTsp(input) && isTs(output))) {
14
+ return err('Usage: hono-takibi <input.{yaml,json,tsp}> -o <routes.ts> [options]');
15
+ }
16
+ return ok({
17
+ input,
18
+ output,
19
+ exportType: hasFlag(args, '--export-type'),
20
+ exportSchema: hasFlag(args, '--export-schema'),
21
+ template: hasFlag(args, '--template'),
22
+ test: hasFlag(args, '--test'),
23
+ basePath: getFlagValue(args, '--base-path'),
24
+ });
25
+ }
@@ -0,0 +1,16 @@
1
+ import type { Result } from '../result/index.js';
2
+ /**
3
+ * Generates TypeScript code from an OpenAPI spec and optional templates.
4
+ *
5
+ * @param input - Input OpenAPI file (`.yaml`, `.json`, or `.tsp`).
6
+ * @param output - Output `.ts` file path.
7
+ * @param exportSchema - Whether to export schemas.
8
+ * @param exportType - Whether to export types.
9
+ * @param template - Whether to generate templates.
10
+ * @param test - Whether to generate test files.
11
+ * @param basePath - Optional base path for template output.
12
+ * @returns A `Result` containing a success message or an error string.
13
+ */
14
+ export declare function takibi(input: `${string}.yaml` | `${string}.json` | `${string}.tsp`, output: `${string}.ts`, exportSchema: boolean, exportType: boolean, template: boolean, test: boolean, basePath?: string): Promise<Result<{
15
+ message: string;
16
+ }, string>>;
@@ -0,0 +1,28 @@
1
+ import path from 'node:path';
2
+ import { fmt } from '../format/index.js';
3
+ import { mkdir, writeFile } from '../fsp/index.js';
4
+ import { zodOpenAPIHono } from '../generator/zod-openapi-hono/openapi/index.js';
5
+ import { parseOpenAPI } from '../openapi/parse-openapi.js';
6
+ import { asyncAndThen, ok } from '../result/index.js';
7
+ import { templateCode } from './template-code.js';
8
+ /**
9
+ * Generates TypeScript code from an OpenAPI spec and optional templates.
10
+ *
11
+ * @param input - Input OpenAPI file (`.yaml`, `.json`, or `.tsp`).
12
+ * @param output - Output `.ts` file path.
13
+ * @param exportSchema - Whether to export schemas.
14
+ * @param exportType - Whether to export types.
15
+ * @param template - Whether to generate templates.
16
+ * @param test - Whether to generate test files.
17
+ * @param basePath - Optional base path for template output.
18
+ * @returns A `Result` containing a success message or an error string.
19
+ */
20
+ export async function takibi(input, output, exportSchema, exportType, template, test, basePath) {
21
+ return await asyncAndThen(await parseOpenAPI(input), async (openAPI) => asyncAndThen(await fmt(zodOpenAPIHono(openAPI, exportSchema, exportType)), async (code) => asyncAndThen(await mkdir(path.dirname(output)), async () => asyncAndThen(await writeFile(output, code), async () => template && output.includes('/')
22
+ ? asyncAndThen(await templateCode(openAPI, output, test, basePath), async () => ok({
23
+ message: 'Generated code and template files written',
24
+ }))
25
+ : ok({
26
+ message: `Generated code written to ${output}`,
27
+ })))));
28
+ }
@@ -0,0 +1,12 @@
1
+ import type { OpenAPI } from '../openapi/index.js';
2
+ import type { Result } from '../result/index.js';
3
+ /**
4
+ * Generates Hono Takibi application and handler templates.
5
+ *
6
+ * @param openAPI - The OpenAPI document to generate from.
7
+ * @param output - Path to the main `.ts` output file.
8
+ * @param test - Whether to include test code.
9
+ * @param basePath - Optional base path for the generated app.
10
+ * @returns A `Result` indicating success or an error message.
11
+ */
12
+ export declare function templateCode(openAPI: OpenAPI, output: `${string}.ts`, test: boolean, basePath?: string): Promise<Result<void, string>>;
@@ -0,0 +1,22 @@
1
+ import path from 'node:path';
2
+ import { fmt } from '../format/index.js';
3
+ import { readdir, writeFile } from '../fsp/index.js';
4
+ import { app } from '../generator/zod-openapi-hono/app/index.js';
5
+ import { zodOpenapiHonoHandler } from '../generator/zod-openapi-hono/handler/zod-openapi-hono-handler.js';
6
+ import { asyncAndThen, ok } from '../result/index.js';
7
+ /**
8
+ * Generates Hono Takibi application and handler templates.
9
+ *
10
+ * @param openAPI - The OpenAPI document to generate from.
11
+ * @param output - Path to the main `.ts` output file.
12
+ * @param test - Whether to include test code.
13
+ * @param basePath - Optional base path for the generated app.
14
+ * @returns A `Result` indicating success or an error message.
15
+ */
16
+ export async function templateCode(openAPI, output, test, basePath) {
17
+ const dir = path.dirname(output);
18
+ return await asyncAndThen(await fmt(app(openAPI, output, basePath)), async (appCode) => asyncAndThen(await readdir(dir), async (files) => {
19
+ const target = path.join(dir, files.includes('index.ts') ? 'main.ts' : 'index.ts');
20
+ return await asyncAndThen(await writeFile(target, appCode), async () => asyncAndThen(await zodOpenapiHonoHandler(openAPI, output, test), async () => ok(undefined)));
21
+ }));
22
+ }
@@ -1,7 +1,8 @@
1
1
  import type { Result } from '../result/index.js';
2
2
  /**
3
- * Formats TypeScript code using Prettier
4
- * @param { string } code - The TypeScript code to format
5
- * @returns { Promise<Result<string, string>> } - A promise that resolves to a Result containing the formatted code or an error message
3
+ * Formats TypeScript source with Prettier.
4
+ *
5
+ * @param code - Source code to format.
6
+ * @returns A `Result` containing the formatted code or an error message.
6
7
  */
7
8
  export declare function fmt(code: string): Promise<Result<string, string>>;
@@ -1,8 +1,9 @@
1
1
  import { format } from 'prettier';
2
2
  /**
3
- * Formats TypeScript code using Prettier
4
- * @param { string } code - The TypeScript code to format
5
- * @returns { Promise<Result<string, string>> } - A promise that resolves to a Result containing the formatted code or an error message
3
+ * Formats TypeScript source with Prettier.
4
+ *
5
+ * @param code - Source code to format.
6
+ * @returns A `Result` containing the formatted code or an error message.
6
7
  */
7
8
  export async function fmt(code) {
8
9
  try {
@@ -1,17 +1,23 @@
1
1
  import type { Result } from '../result/index.js';
2
2
  /**
3
- * @param { string } dir - The directory to create.
4
- * @returns { Promise<Result<void, string>> } - A promise that resolves to a Result indicating success or an error message.
3
+ * Creates a directory if it does not already exist.
4
+ *
5
+ * @param dir - Directory path to create.
6
+ * @returns A `Result` that is `ok` on success, otherwise an error message.
5
7
  */
6
8
  export declare function mkdir(dir: string): Promise<Result<void, string>>;
7
9
  /**
8
- * @param { string } dir - The directory to read.
9
- * @returns { Promise<Result<string[], string>> } - A promise that resolves to a Result containing an array of file names or an error message.
10
+ * Reads the contents of a directory.
11
+ *
12
+ * @param dir - Directory to read.
13
+ * @returns A `Result` with the file list on success, otherwise an error message.
10
14
  */
11
15
  export declare function readdir(dir: string): Promise<Result<string[], string>>;
12
16
  /**
13
- * @param {string} path - The path to the file.
14
- * @param {string} data - The data to write to the file.
15
- * @returns {Promise<Result<void, string>>} - A promise that resolves to a Result indicating success or an error message.
17
+ * Writes UTF-8 text to a file, creating it if necessary.
18
+ *
19
+ * @param path - File path to write.
20
+ * @param data - Text data to write.
21
+ * @returns A `Result` that is `ok` on success, otherwise an error message.
16
22
  */
17
23
  export declare function writeFile(path: string, data: string): Promise<Result<void, string>>;
package/dist/fsp/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  import fsp from 'node:fs/promises';
2
- import { ok, err } from '../result/index.js';
2
+ import { err, ok } from '../result/index.js';
3
3
  /**
4
- * @param { string } dir - The directory to create.
5
- * @returns { Promise<Result<void, string>> } - A promise that resolves to a Result indicating success or an error message.
4
+ * Creates a directory if it does not already exist.
5
+ *
6
+ * @param dir - Directory path to create.
7
+ * @returns A `Result` that is `ok` on success, otherwise an error message.
6
8
  */
7
9
  export async function mkdir(dir) {
8
10
  try {
@@ -14,8 +16,10 @@ export async function mkdir(dir) {
14
16
  }
15
17
  }
16
18
  /**
17
- * @param { string } dir - The directory to read.
18
- * @returns { Promise<Result<string[], string>> } - A promise that resolves to a Result containing an array of file names or an error message.
19
+ * Reads the contents of a directory.
20
+ *
21
+ * @param dir - Directory to read.
22
+ * @returns A `Result` with the file list on success, otherwise an error message.
19
23
  */
20
24
  export async function readdir(dir) {
21
25
  try {
@@ -27,9 +31,11 @@ export async function readdir(dir) {
27
31
  }
28
32
  }
29
33
  /**
30
- * @param {string} path - The path to the file.
31
- * @param {string} data - The data to write to the file.
32
- * @returns {Promise<Result<void, string>>} - A promise that resolves to a Result indicating success or an error message.
34
+ * Writes UTF-8 text to a file, creating it if necessary.
35
+ *
36
+ * @param path - File path to write.
37
+ * @param data - Text data to write.
38
+ * @returns A `Result` that is `ok` on success, otherwise an error message.
33
39
  */
34
40
  export async function writeFile(path, data) {
35
41
  try {
@@ -0,0 +1,31 @@
1
+ import type { Schema } from '../../../openapi/index.js';
2
+ /**
3
+ * Generates a Zod schema string for an array of referenced schemas.
4
+ *
5
+ * If the schema's `items` contains a `$ref`, it generates:
6
+ * `z.array(<ref>Schema)`
7
+ *
8
+ * Falls back to `z.array(z.any())` if the `$ref` is missing or invalid.
9
+ *
10
+ * @param schema - The OpenAPI schema object with array type
11
+ * @returns The Zod schema string for the array
12
+ *
13
+ * @example
14
+ * // Array of Tag references
15
+ * arrayReferenceSchema({
16
+ * type: 'array',
17
+ * items: { $ref: '#/components/schemas/Tag' }
18
+ * })
19
+ * // → 'z.array(tagSchema)'
20
+ *
21
+ * @example
22
+ * // Invalid items reference
23
+ * arrayReferenceSchema({ type: 'array', items: {} })
24
+ * // → 'z.array(z.any())'
25
+ *
26
+ * @example
27
+ * // Missing items
28
+ * arrayReferenceSchema({ type: 'array' })
29
+ * // → 'z.array(z.any())'
30
+ */
31
+ export declare function arrayReferenceSchema(schema: Schema): string;
@@ -0,0 +1,40 @@
1
+ import { array, refName } from '../../../utils/index.js';
2
+ /**
3
+ * Generates a Zod schema string for an array of referenced schemas.
4
+ *
5
+ * If the schema's `items` contains a `$ref`, it generates:
6
+ * `z.array(<ref>Schema)`
7
+ *
8
+ * Falls back to `z.array(z.any())` if the `$ref` is missing or invalid.
9
+ *
10
+ * @param schema - The OpenAPI schema object with array type
11
+ * @returns The Zod schema string for the array
12
+ *
13
+ * @example
14
+ * // Array of Tag references
15
+ * arrayReferenceSchema({
16
+ * type: 'array',
17
+ * items: { $ref: '#/components/schemas/Tag' }
18
+ * })
19
+ * // → 'z.array(tagSchema)'
20
+ *
21
+ * @example
22
+ * // Invalid items reference
23
+ * arrayReferenceSchema({ type: 'array', items: {} })
24
+ * // → 'z.array(z.any())'
25
+ *
26
+ * @example
27
+ * // Missing items
28
+ * arrayReferenceSchema({ type: 'array' })
29
+ * // → 'z.array(z.any())'
30
+ */
31
+ export function arrayReferenceSchema(schema) {
32
+ if (!schema.items?.$ref) {
33
+ return 'z.array(z.any())';
34
+ }
35
+ const ref = refName(schema.items?.$ref);
36
+ if (!ref) {
37
+ return 'z.array(z.any())';
38
+ }
39
+ return array(`${ref}Schema`);
40
+ }
@@ -0,0 +1,5 @@
1
+ export { arrayReferenceSchema } from './array-reference-schema.js';
2
+ export { propertiesSchema } from './properties-schema.js';
3
+ export { propertySchema } from './property-schema.js';
4
+ export { referenceSchema } from './reference-schema.js';
5
+ export { zodSchemaFromSubSchema } from './zod-schema-from-sub-schema.js';
@@ -0,0 +1,5 @@
1
+ export { arrayReferenceSchema } from './array-reference-schema.js';
2
+ export { propertiesSchema } from './properties-schema.js';
3
+ export { propertySchema } from './property-schema.js';
4
+ export { referenceSchema } from './reference-schema.js';
5
+ export { zodSchemaFromSubSchema } from './zod-schema-from-sub-schema.js';
@@ -0,0 +1,46 @@
1
+ import type { Schema } from '../../../openapi/index.js';
2
+ /**
3
+ * Generates a Zod object schema string from a set of OpenAPI properties.
4
+ *
5
+ * - Handles required and optional fields
6
+ * - Supports primitive types, arrays, and `$ref`-based references
7
+ * - Automatically wraps in `.partial()` if all properties are optional
8
+ *
9
+ * @param properties - Object mapping property names to their schema definitions
10
+ * @param required - List of required property names
11
+ * @returns A Zod schema string representing the object
12
+ *
13
+ * @example
14
+ * // 1. All fields optional
15
+ * propertiesSchema(
16
+ * {
17
+ * id: { type: 'integer' },
18
+ * status: { type: 'string', enum: ['active', 'inactive'] },
19
+ * },
20
+ * []
21
+ * )
22
+ * // → 'z.object({id:z.number().int().optional(),status:z.enum(["active","inactive"]).optional()}).partial()'
23
+ *
24
+ * @example
25
+ * // 2. All fields required
26
+ * propertiesSchema(
27
+ * {
28
+ * name: { type: 'string' },
29
+ * items: { type: 'array', items: { type: 'string' } },
30
+ * },
31
+ * ['name', 'items']
32
+ * )
33
+ * // → 'z.object({name:z.string(),items:z.array(z.string())})'
34
+ *
35
+ * @example
36
+ * // 3. With schema references
37
+ * propertiesSchema(
38
+ * {
39
+ * user: { $ref: '#/components/schemas/User' },
40
+ * tags: { type: 'array', items: { $ref: '#/components/schemas/Tag' } },
41
+ * },
42
+ * []
43
+ * )
44
+ * // → 'z.object({user:userSchema.optional(),tags:z.array(tagSchema).optional()}).partial()'
45
+ */
46
+ export declare function propertiesSchema(properties: Record<string, Schema>, required: string[]): string;
@@ -0,0 +1,60 @@
1
+ import { getToSafeIdentifier, isAllOptional, partial } from '../../../utils/index.js';
2
+ import { propertySchema } from './property-schema.js';
3
+ /**
4
+ * Generates a Zod object schema string from a set of OpenAPI properties.
5
+ *
6
+ * - Handles required and optional fields
7
+ * - Supports primitive types, arrays, and `$ref`-based references
8
+ * - Automatically wraps in `.partial()` if all properties are optional
9
+ *
10
+ * @param properties - Object mapping property names to their schema definitions
11
+ * @param required - List of required property names
12
+ * @returns A Zod schema string representing the object
13
+ *
14
+ * @example
15
+ * // 1. All fields optional
16
+ * propertiesSchema(
17
+ * {
18
+ * id: { type: 'integer' },
19
+ * status: { type: 'string', enum: ['active', 'inactive'] },
20
+ * },
21
+ * []
22
+ * )
23
+ * // → 'z.object({id:z.number().int().optional(),status:z.enum(["active","inactive"]).optional()}).partial()'
24
+ *
25
+ * @example
26
+ * // 2. All fields required
27
+ * propertiesSchema(
28
+ * {
29
+ * name: { type: 'string' },
30
+ * items: { type: 'array', items: { type: 'string' } },
31
+ * },
32
+ * ['name', 'items']
33
+ * )
34
+ * // → 'z.object({name:z.string(),items:z.array(z.string())})'
35
+ *
36
+ * @example
37
+ * // 3. With schema references
38
+ * propertiesSchema(
39
+ * {
40
+ * user: { $ref: '#/components/schemas/User' },
41
+ * tags: { type: 'array', items: { $ref: '#/components/schemas/Tag' } },
42
+ * },
43
+ * []
44
+ * )
45
+ * // → 'z.object({user:userSchema.optional(),tags:z.array(tagSchema).optional()}).partial()'
46
+ */
47
+ export function propertiesSchema(properties, required) {
48
+ const objectProperties = Object.entries(properties).map(([key, schema]) => {
49
+ const isRequired = required.includes(key);
50
+ const safeKey = getToSafeIdentifier(key);
51
+ return `${safeKey}:${propertySchema(schema)}${isRequired ? '' : '.optional()'}`;
52
+ });
53
+ // Check if all properties are optional
54
+ const allOptional = isAllOptional(objectProperties);
55
+ // If all properties are optional and no required properties, return partial schema
56
+ if (required.length === 0 && allOptional) {
57
+ return partial(objectProperties);
58
+ }
59
+ return `z.object({${objectProperties}})`;
60
+ }
@@ -0,0 +1,27 @@
1
+ import type { Schema } from '../../../openapi/index.js';
2
+ /**
3
+ * Generates a Zod-compatible schema string for a given property.
4
+ *
5
+ * - Delegates `$ref` schemas to `referenceSchema`
6
+ * - Handles arrays with referenced items via `arrayReferenceSchema`
7
+ * - Falls back to `zodToOpenAPI` for primitives or complex inline schemas
8
+ *
9
+ * @param schema - The OpenAPI schema object for the property
10
+ * @returns The corresponding Zod schema string
11
+ *
12
+ * @example
13
+ * // Primitive string type
14
+ * propertySchema({ type: 'string' })
15
+ * // → 'z.string()'
16
+ *
17
+ * @example
18
+ * // Reference to another schema
19
+ * propertySchema({ $ref: '#/components/schemas/User' })
20
+ * // → 'userSchema'
21
+ *
22
+ * @example
23
+ * // Array of referenced items
24
+ * propertySchema({ type: 'array', items: { $ref: '#/components/schemas/Tag' } })
25
+ * // → 'z.array(tagSchema)'
26
+ */
27
+ export declare function propertySchema(schema: Schema): string;
@@ -0,0 +1,39 @@
1
+ import { zodToOpenAPI } from '../../../helper/zod-to-openapi.js';
2
+ import { isArrayWithSchemaReference } from '../../../utils/index.js';
3
+ import { zod } from '../index.js';
4
+ import { arrayReferenceSchema } from './array-reference-schema.js';
5
+ import { referenceSchema } from './reference-schema.js';
6
+ /**
7
+ * Generates a Zod-compatible schema string for a given property.
8
+ *
9
+ * - Delegates `$ref` schemas to `referenceSchema`
10
+ * - Handles arrays with referenced items via `arrayReferenceSchema`
11
+ * - Falls back to `zodToOpenAPI` for primitives or complex inline schemas
12
+ *
13
+ * @param schema - The OpenAPI schema object for the property
14
+ * @returns The corresponding Zod schema string
15
+ *
16
+ * @example
17
+ * // Primitive string type
18
+ * propertySchema({ type: 'string' })
19
+ * // → 'z.string()'
20
+ *
21
+ * @example
22
+ * // Reference to another schema
23
+ * propertySchema({ $ref: '#/components/schemas/User' })
24
+ * // → 'userSchema'
25
+ *
26
+ * @example
27
+ * // Array of referenced items
28
+ * propertySchema({ type: 'array', items: { $ref: '#/components/schemas/Tag' } })
29
+ * // → 'z.array(tagSchema)'
30
+ */
31
+ export function propertySchema(schema) {
32
+ if (Boolean(schema.$ref) === true) {
33
+ return referenceSchema(schema);
34
+ }
35
+ if (isArrayWithSchemaReference(schema)) {
36
+ return arrayReferenceSchema(schema);
37
+ }
38
+ return zodToOpenAPI(zod(schema), schema);
39
+ }
@@ -0,0 +1,26 @@
1
+ import type { Schema } from '../../../openapi/index.js';
2
+ /**
3
+ * Generates a Zod schema string for a referenced schema.
4
+ *
5
+ * If the schema contains a `$ref`, it extracts the reference name and appends `Schema`.
6
+ * Falls back to `'z.any()'` if the `$ref` is missing or invalid.
7
+ *
8
+ * @param schema - The OpenAPI schema object containing a `$ref`
9
+ * @returns The Zod schema string referencing another schema
10
+ *
11
+ * @example
12
+ * // Reference to Category schema
13
+ * referenceSchema({ $ref: '#/components/schemas/Category' })
14
+ * // → 'CategorySchema'
15
+ *
16
+ * @example
17
+ * // Invalid reference
18
+ * referenceSchema({})
19
+ * // → 'z.any()'
20
+ *
21
+ * @example
22
+ * // Malformed $ref
23
+ * referenceSchema({ $ref: '#/components/schemas/' })
24
+ * // → 'z.any()'
25
+ */
26
+ export declare function referenceSchema(schema: Schema): string;
@@ -0,0 +1,35 @@
1
+ import { refName } from '../../../utils/index.js';
2
+ /**
3
+ * Generates a Zod schema string for a referenced schema.
4
+ *
5
+ * If the schema contains a `$ref`, it extracts the reference name and appends `Schema`.
6
+ * Falls back to `'z.any()'` if the `$ref` is missing or invalid.
7
+ *
8
+ * @param schema - The OpenAPI schema object containing a `$ref`
9
+ * @returns The Zod schema string referencing another schema
10
+ *
11
+ * @example
12
+ * // Reference to Category schema
13
+ * referenceSchema({ $ref: '#/components/schemas/Category' })
14
+ * // → 'CategorySchema'
15
+ *
16
+ * @example
17
+ * // Invalid reference
18
+ * referenceSchema({})
19
+ * // → 'z.any()'
20
+ *
21
+ * @example
22
+ * // Malformed $ref
23
+ * referenceSchema({ $ref: '#/components/schemas/' })
24
+ * // → 'z.any()'
25
+ */
26
+ export function referenceSchema(schema) {
27
+ if (!schema.$ref) {
28
+ return 'z.any()';
29
+ }
30
+ const ref = refName(schema.$ref);
31
+ if (!ref) {
32
+ return 'z.any()';
33
+ }
34
+ return `${ref}Schema` || 'z.any()';
35
+ }
@@ -0,0 +1,22 @@
1
+ import type { Schema } from '../../../openapi/index.js';
2
+ /**
3
+ * Generates a Zod schema string from a given OpenAPI sub-schema.
4
+ *
5
+ * If the schema contains a `$ref`, it resolves to the corresponding schema name;
6
+ * otherwise, it generates an inline Zod schema using the `zod()` converter.
7
+ *
8
+ * @param subSchema - The OpenAPI sub-schema object.
9
+ * @returns The Zod schema string (e.g., `'UserSchema'` or `'z.string()'`).
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * // With $ref
14
+ * zodSchemaFromSubSchema({ $ref: '#/components/schemas/User' })
15
+ * // → 'UserSchema'
16
+ *
17
+ * // Without $ref
18
+ * zodSchemaFromSubSchema({ type: 'string', minLength: 3 })
19
+ * // → 'z.string().min(3)'
20
+ * ```
21
+ */
22
+ export declare function zodSchemaFromSubSchema(subSchema: Schema): string;
@@ -0,0 +1,25 @@
1
+ import { refName } from '../../../utils/index.js';
2
+ import { zod } from '../index.js';
3
+ /**
4
+ * Generates a Zod schema string from a given OpenAPI sub-schema.
5
+ *
6
+ * If the schema contains a `$ref`, it resolves to the corresponding schema name;
7
+ * otherwise, it generates an inline Zod schema using the `zod()` converter.
8
+ *
9
+ * @param subSchema - The OpenAPI sub-schema object.
10
+ * @returns The Zod schema string (e.g., `'UserSchema'` or `'z.string()'`).
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * // With $ref
15
+ * zodSchemaFromSubSchema({ $ref: '#/components/schemas/User' })
16
+ * // → 'UserSchema'
17
+ *
18
+ * // Without $ref
19
+ * zodSchemaFromSubSchema({ type: 'string', minLength: 3 })
20
+ * // → 'z.string().min(3)'
21
+ * ```
22
+ */
23
+ export function zodSchemaFromSubSchema(subSchema) {
24
+ return subSchema.$ref ? `${refName(subSchema.$ref)}Schema` : zod(subSchema);
25
+ }