@shuttl-io/core 0.2.0

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 (802) hide show
  1. package/CHANGELOG.md +96 -0
  2. package/README.md +3 -0
  3. package/dist/Server.d.ts +5 -0
  4. package/dist/Server.js +3 -0
  5. package/dist/Triggers.d.ts +0 -0
  6. package/dist/Triggers.js +2 -0
  7. package/dist/agent.d.ts +49 -0
  8. package/dist/agent.js +251 -0
  9. package/dist/app.d.ts +17 -0
  10. package/dist/app.js +46 -0
  11. package/dist/index.d.ts +12 -0
  12. package/dist/index.js +29 -0
  13. package/dist/model.d.ts +6 -0
  14. package/dist/model.js +16 -0
  15. package/dist/models/openAi.d.ts +40 -0
  16. package/dist/models/openAi.js +346 -0
  17. package/dist/models/types.d.ts +102 -0
  18. package/dist/models/types.js +27 -0
  19. package/dist/outcomes/CombinationOutcome.d.ts +9 -0
  20. package/dist/outcomes/CombinationOutcome.js +41 -0
  21. package/dist/outcomes/IOutcomes.d.ts +9 -0
  22. package/dist/outcomes/IOutcomes.js +19 -0
  23. package/dist/outcomes/StreamingOutcome.d.ts +6 -0
  24. package/dist/outcomes/StreamingOutcome.js +30 -0
  25. package/dist/outcomes/index.d.ts +3 -0
  26. package/dist/outcomes/index.js +20 -0
  27. package/dist/secrets.d.ts +19 -0
  28. package/dist/secrets.js +34 -0
  29. package/dist/server/http.d.ts +68 -0
  30. package/dist/server/http.js +654 -0
  31. package/dist/server/index.d.ts +1 -0
  32. package/dist/server/index.js +18 -0
  33. package/dist/src/Server.d.ts +5 -0
  34. package/dist/src/Server.js +3 -0
  35. package/dist/src/Triggers.d.ts +0 -0
  36. package/dist/src/Triggers.js +2 -0
  37. package/dist/src/agent.d.ts +49 -0
  38. package/dist/src/agent.js +251 -0
  39. package/dist/src/app.d.ts +17 -0
  40. package/dist/src/app.js +46 -0
  41. package/dist/src/index.d.ts +12 -0
  42. package/dist/src/index.js +29 -0
  43. package/dist/src/model.d.ts +6 -0
  44. package/dist/src/model.js +16 -0
  45. package/dist/src/models/openAi.d.ts +38 -0
  46. package/dist/src/models/openAi.js +344 -0
  47. package/dist/src/models/types.d.ts +101 -0
  48. package/dist/src/models/types.js +27 -0
  49. package/dist/src/outcomes/CombinationOutcome.d.ts +9 -0
  50. package/dist/src/outcomes/CombinationOutcome.js +41 -0
  51. package/dist/src/outcomes/IOutcomes.d.ts +9 -0
  52. package/dist/src/outcomes/IOutcomes.js +19 -0
  53. package/dist/src/outcomes/StreamingOutcome.d.ts +6 -0
  54. package/dist/src/outcomes/StreamingOutcome.js +30 -0
  55. package/dist/src/outcomes/index.d.ts +3 -0
  56. package/dist/src/outcomes/index.js +20 -0
  57. package/dist/src/secrets.d.ts +19 -0
  58. package/dist/src/secrets.js +34 -0
  59. package/dist/src/server/http.d.ts +68 -0
  60. package/dist/src/server/http.js +654 -0
  61. package/dist/src/server/index.d.ts +1 -0
  62. package/dist/src/server/index.js +18 -0
  63. package/dist/src/tools/tool.d.ts +33 -0
  64. package/dist/src/tools/tool.js +49 -0
  65. package/dist/src/tools/toolkit.d.ts +13 -0
  66. package/dist/src/tools/toolkit.js +19 -0
  67. package/dist/src/trigger/ApiTrigger.d.ts +37 -0
  68. package/dist/src/trigger/ApiTrigger.js +106 -0
  69. package/dist/src/trigger/EmailTrigger.d.ts +15 -0
  70. package/dist/src/trigger/EmailTrigger.js +22 -0
  71. package/dist/src/trigger/FileTrigger.d.ts +14 -0
  72. package/dist/src/trigger/FileTrigger.js +37 -0
  73. package/dist/src/trigger/ITrigger.d.ts +89 -0
  74. package/dist/src/trigger/ITrigger.js +35 -0
  75. package/dist/src/trigger/RateTrigger.d.ts +23 -0
  76. package/dist/src/trigger/RateTrigger.js +58 -0
  77. package/dist/src/trigger/index.d.ts +5 -0
  78. package/dist/src/trigger/index.js +22 -0
  79. package/dist/tests/agent.test.d.ts +1 -0
  80. package/dist/tests/agent.test.js +388 -0
  81. package/dist/tests/agentStreamer.test.d.ts +1 -0
  82. package/dist/tests/agentStreamer.test.js +530 -0
  83. package/dist/tests/app.test.d.ts +1 -0
  84. package/dist/tests/app.test.js +423 -0
  85. package/dist/tests/model.test.d.ts +1 -0
  86. package/dist/tests/model.test.js +310 -0
  87. package/dist/tests/openAi.test.d.ts +1 -0
  88. package/dist/tests/openAi.test.js +701 -0
  89. package/dist/tests/outcomes.test.d.ts +1 -0
  90. package/dist/tests/outcomes.test.js +257 -0
  91. package/dist/tests/secrets.test.d.ts +1 -0
  92. package/dist/tests/secrets.test.js +263 -0
  93. package/dist/tests/server/http.test.d.ts +1 -0
  94. package/dist/tests/server/http.test.js +553 -0
  95. package/dist/tests/tool.test.d.ts +1 -0
  96. package/dist/tests/tool.test.js +315 -0
  97. package/dist/tests/toolkit.test.d.ts +1 -0
  98. package/dist/tests/toolkit.test.js +189 -0
  99. package/dist/tests/triggers.test.d.ts +1 -0
  100. package/dist/tests/triggers.test.js +203 -0
  101. package/dist/tests/types.test.d.ts +1 -0
  102. package/dist/tests/types.test.js +429 -0
  103. package/dist/tools/tool.d.ts +33 -0
  104. package/dist/tools/tool.js +49 -0
  105. package/dist/tools/toolkit.d.ts +13 -0
  106. package/dist/tools/toolkit.js +19 -0
  107. package/dist/trigger/ApiTrigger.d.ts +37 -0
  108. package/dist/trigger/ApiTrigger.js +106 -0
  109. package/dist/trigger/EmailTrigger.d.ts +15 -0
  110. package/dist/trigger/EmailTrigger.js +22 -0
  111. package/dist/trigger/FileTrigger.d.ts +14 -0
  112. package/dist/trigger/FileTrigger.js +37 -0
  113. package/dist/trigger/ITrigger.d.ts +90 -0
  114. package/dist/trigger/ITrigger.js +38 -0
  115. package/dist/trigger/RateTrigger.d.ts +23 -0
  116. package/dist/trigger/RateTrigger.js +58 -0
  117. package/dist/trigger/index.d.ts +5 -0
  118. package/dist/trigger/index.js +22 -0
  119. package/jest.config.js +20 -0
  120. package/node_modules/zod/LICENSE +21 -0
  121. package/node_modules/zod/README.md +208 -0
  122. package/node_modules/zod/index.cjs +33 -0
  123. package/node_modules/zod/index.d.cts +4 -0
  124. package/node_modules/zod/index.d.ts +4 -0
  125. package/node_modules/zod/index.js +4 -0
  126. package/node_modules/zod/locales/index.cjs +17 -0
  127. package/node_modules/zod/locales/index.d.cts +1 -0
  128. package/node_modules/zod/locales/index.d.ts +1 -0
  129. package/node_modules/zod/locales/index.js +1 -0
  130. package/node_modules/zod/locales/package.json +6 -0
  131. package/node_modules/zod/mini/index.cjs +17 -0
  132. package/node_modules/zod/mini/index.d.cts +1 -0
  133. package/node_modules/zod/mini/index.d.ts +1 -0
  134. package/node_modules/zod/mini/index.js +1 -0
  135. package/node_modules/zod/mini/package.json +6 -0
  136. package/node_modules/zod/package.json +135 -0
  137. package/node_modules/zod/src/index.ts +4 -0
  138. package/node_modules/zod/src/locales/index.ts +1 -0
  139. package/node_modules/zod/src/mini/index.ts +1 -0
  140. package/node_modules/zod/src/v3/ZodError.ts +330 -0
  141. package/node_modules/zod/src/v3/benchmarks/datetime.ts +58 -0
  142. package/node_modules/zod/src/v3/benchmarks/discriminatedUnion.ts +80 -0
  143. package/node_modules/zod/src/v3/benchmarks/index.ts +59 -0
  144. package/node_modules/zod/src/v3/benchmarks/ipv4.ts +57 -0
  145. package/node_modules/zod/src/v3/benchmarks/object.ts +69 -0
  146. package/node_modules/zod/src/v3/benchmarks/primitives.ts +162 -0
  147. package/node_modules/zod/src/v3/benchmarks/realworld.ts +63 -0
  148. package/node_modules/zod/src/v3/benchmarks/string.ts +55 -0
  149. package/node_modules/zod/src/v3/benchmarks/union.ts +80 -0
  150. package/node_modules/zod/src/v3/errors.ts +13 -0
  151. package/node_modules/zod/src/v3/external.ts +6 -0
  152. package/node_modules/zod/src/v3/helpers/enumUtil.ts +17 -0
  153. package/node_modules/zod/src/v3/helpers/errorUtil.ts +8 -0
  154. package/node_modules/zod/src/v3/helpers/parseUtil.ts +176 -0
  155. package/node_modules/zod/src/v3/helpers/partialUtil.ts +34 -0
  156. package/node_modules/zod/src/v3/helpers/typeAliases.ts +2 -0
  157. package/node_modules/zod/src/v3/helpers/util.ts +224 -0
  158. package/node_modules/zod/src/v3/index.ts +4 -0
  159. package/node_modules/zod/src/v3/locales/en.ts +124 -0
  160. package/node_modules/zod/src/v3/standard-schema.ts +113 -0
  161. package/node_modules/zod/src/v3/tests/Mocker.ts +54 -0
  162. package/node_modules/zod/src/v3/tests/all-errors.test.ts +157 -0
  163. package/node_modules/zod/src/v3/tests/anyunknown.test.ts +28 -0
  164. package/node_modules/zod/src/v3/tests/array.test.ts +71 -0
  165. package/node_modules/zod/src/v3/tests/async-parsing.test.ts +388 -0
  166. package/node_modules/zod/src/v3/tests/async-refinements.test.ts +46 -0
  167. package/node_modules/zod/src/v3/tests/base.test.ts +29 -0
  168. package/node_modules/zod/src/v3/tests/bigint.test.ts +55 -0
  169. package/node_modules/zod/src/v3/tests/branded.test.ts +53 -0
  170. package/node_modules/zod/src/v3/tests/catch.test.ts +220 -0
  171. package/node_modules/zod/src/v3/tests/coerce.test.ts +133 -0
  172. package/node_modules/zod/src/v3/tests/complex.test.ts +70 -0
  173. package/node_modules/zod/src/v3/tests/custom.test.ts +31 -0
  174. package/node_modules/zod/src/v3/tests/date.test.ts +32 -0
  175. package/node_modules/zod/src/v3/tests/deepmasking.test.ts +186 -0
  176. package/node_modules/zod/src/v3/tests/default.test.ts +112 -0
  177. package/node_modules/zod/src/v3/tests/description.test.ts +33 -0
  178. package/node_modules/zod/src/v3/tests/discriminated-unions.test.ts +315 -0
  179. package/node_modules/zod/src/v3/tests/enum.test.ts +80 -0
  180. package/node_modules/zod/src/v3/tests/error.test.ts +551 -0
  181. package/node_modules/zod/src/v3/tests/firstparty.test.ts +87 -0
  182. package/node_modules/zod/src/v3/tests/firstpartyschematypes.test.ts +21 -0
  183. package/node_modules/zod/src/v3/tests/function.test.ts +261 -0
  184. package/node_modules/zod/src/v3/tests/generics.test.ts +48 -0
  185. package/node_modules/zod/src/v3/tests/instanceof.test.ts +37 -0
  186. package/node_modules/zod/src/v3/tests/intersection.test.ts +110 -0
  187. package/node_modules/zod/src/v3/tests/language-server.source.ts +76 -0
  188. package/node_modules/zod/src/v3/tests/language-server.test.ts +207 -0
  189. package/node_modules/zod/src/v3/tests/literal.test.ts +36 -0
  190. package/node_modules/zod/src/v3/tests/map.test.ts +110 -0
  191. package/node_modules/zod/src/v3/tests/masking.test.ts +4 -0
  192. package/node_modules/zod/src/v3/tests/mocker.test.ts +19 -0
  193. package/node_modules/zod/src/v3/tests/nan.test.ts +24 -0
  194. package/node_modules/zod/src/v3/tests/nativeEnum.test.ts +87 -0
  195. package/node_modules/zod/src/v3/tests/nullable.test.ts +42 -0
  196. package/node_modules/zod/src/v3/tests/number.test.ts +176 -0
  197. package/node_modules/zod/src/v3/tests/object-augmentation.test.ts +29 -0
  198. package/node_modules/zod/src/v3/tests/object-in-es5-env.test.ts +29 -0
  199. package/node_modules/zod/src/v3/tests/object.test.ts +434 -0
  200. package/node_modules/zod/src/v3/tests/optional.test.ts +42 -0
  201. package/node_modules/zod/src/v3/tests/parseUtil.test.ts +23 -0
  202. package/node_modules/zod/src/v3/tests/parser.test.ts +41 -0
  203. package/node_modules/zod/src/v3/tests/partials.test.ts +243 -0
  204. package/node_modules/zod/src/v3/tests/pickomit.test.ts +111 -0
  205. package/node_modules/zod/src/v3/tests/pipeline.test.ts +29 -0
  206. package/node_modules/zod/src/v3/tests/preprocess.test.ts +186 -0
  207. package/node_modules/zod/src/v3/tests/primitive.test.ts +440 -0
  208. package/node_modules/zod/src/v3/tests/promise.test.ts +90 -0
  209. package/node_modules/zod/src/v3/tests/readonly.test.ts +194 -0
  210. package/node_modules/zod/src/v3/tests/record.test.ts +171 -0
  211. package/node_modules/zod/src/v3/tests/recursive.test.ts +197 -0
  212. package/node_modules/zod/src/v3/tests/refine.test.ts +313 -0
  213. package/node_modules/zod/src/v3/tests/safeparse.test.ts +27 -0
  214. package/node_modules/zod/src/v3/tests/set.test.ts +142 -0
  215. package/node_modules/zod/src/v3/tests/standard-schema.test.ts +83 -0
  216. package/node_modules/zod/src/v3/tests/string.test.ts +916 -0
  217. package/node_modules/zod/src/v3/tests/transformer.test.ts +233 -0
  218. package/node_modules/zod/src/v3/tests/tuple.test.ts +90 -0
  219. package/node_modules/zod/src/v3/tests/unions.test.ts +57 -0
  220. package/node_modules/zod/src/v3/tests/validations.test.ts +133 -0
  221. package/node_modules/zod/src/v3/tests/void.test.ts +15 -0
  222. package/node_modules/zod/src/v3/types.ts +5138 -0
  223. package/node_modules/zod/src/v4/classic/checks.ts +32 -0
  224. package/node_modules/zod/src/v4/classic/coerce.ts +27 -0
  225. package/node_modules/zod/src/v4/classic/compat.ts +70 -0
  226. package/node_modules/zod/src/v4/classic/errors.ts +82 -0
  227. package/node_modules/zod/src/v4/classic/external.ts +51 -0
  228. package/node_modules/zod/src/v4/classic/from-json-schema.ts +536 -0
  229. package/node_modules/zod/src/v4/classic/index.ts +5 -0
  230. package/node_modules/zod/src/v4/classic/iso.ts +90 -0
  231. package/node_modules/zod/src/v4/classic/parse.ts +82 -0
  232. package/node_modules/zod/src/v4/classic/schemas.ts +2352 -0
  233. package/node_modules/zod/src/v4/classic/tests/anyunknown.test.ts +26 -0
  234. package/node_modules/zod/src/v4/classic/tests/array.test.ts +264 -0
  235. package/node_modules/zod/src/v4/classic/tests/assignability.test.ts +210 -0
  236. package/node_modules/zod/src/v4/classic/tests/async-parsing.test.ts +381 -0
  237. package/node_modules/zod/src/v4/classic/tests/async-refinements.test.ts +68 -0
  238. package/node_modules/zod/src/v4/classic/tests/base.test.ts +7 -0
  239. package/node_modules/zod/src/v4/classic/tests/bigint.test.ts +54 -0
  240. package/node_modules/zod/src/v4/classic/tests/brand.test.ts +63 -0
  241. package/node_modules/zod/src/v4/classic/tests/catch.test.ts +276 -0
  242. package/node_modules/zod/src/v4/classic/tests/coalesce.test.ts +20 -0
  243. package/node_modules/zod/src/v4/classic/tests/codec-examples.test.ts +573 -0
  244. package/node_modules/zod/src/v4/classic/tests/codec.test.ts +562 -0
  245. package/node_modules/zod/src/v4/classic/tests/coerce.test.ts +160 -0
  246. package/node_modules/zod/src/v4/classic/tests/continuability.test.ts +374 -0
  247. package/node_modules/zod/src/v4/classic/tests/custom.test.ts +40 -0
  248. package/node_modules/zod/src/v4/classic/tests/date.test.ts +31 -0
  249. package/node_modules/zod/src/v4/classic/tests/datetime.test.ts +302 -0
  250. package/node_modules/zod/src/v4/classic/tests/default.test.ts +365 -0
  251. package/node_modules/zod/src/v4/classic/tests/describe-meta-checks.test.ts +27 -0
  252. package/node_modules/zod/src/v4/classic/tests/description.test.ts +32 -0
  253. package/node_modules/zod/src/v4/classic/tests/discriminated-unions.test.ts +661 -0
  254. package/node_modules/zod/src/v4/classic/tests/enum.test.ts +285 -0
  255. package/node_modules/zod/src/v4/classic/tests/error-utils.test.ts +595 -0
  256. package/node_modules/zod/src/v4/classic/tests/error.test.ts +711 -0
  257. package/node_modules/zod/src/v4/classic/tests/file.test.ts +96 -0
  258. package/node_modules/zod/src/v4/classic/tests/firstparty.test.ts +179 -0
  259. package/node_modules/zod/src/v4/classic/tests/fix-json-issue.test.ts +26 -0
  260. package/node_modules/zod/src/v4/classic/tests/from-json-schema.test.ts +537 -0
  261. package/node_modules/zod/src/v4/classic/tests/function.test.ts +308 -0
  262. package/node_modules/zod/src/v4/classic/tests/generics.test.ts +72 -0
  263. package/node_modules/zod/src/v4/classic/tests/hash.test.ts +68 -0
  264. package/node_modules/zod/src/v4/classic/tests/index.test.ts +898 -0
  265. package/node_modules/zod/src/v4/classic/tests/instanceof.test.ts +34 -0
  266. package/node_modules/zod/src/v4/classic/tests/intersection.test.ts +171 -0
  267. package/node_modules/zod/src/v4/classic/tests/json.test.ts +109 -0
  268. package/node_modules/zod/src/v4/classic/tests/lazy.test.ts +227 -0
  269. package/node_modules/zod/src/v4/classic/tests/literal.test.ts +117 -0
  270. package/node_modules/zod/src/v4/classic/tests/map.test.ts +196 -0
  271. package/node_modules/zod/src/v4/classic/tests/nan.test.ts +21 -0
  272. package/node_modules/zod/src/v4/classic/tests/nested-refine.test.ts +168 -0
  273. package/node_modules/zod/src/v4/classic/tests/nonoptional.test.ts +101 -0
  274. package/node_modules/zod/src/v4/classic/tests/nullable.test.ts +22 -0
  275. package/node_modules/zod/src/v4/classic/tests/number.test.ts +270 -0
  276. package/node_modules/zod/src/v4/classic/tests/object.test.ts +609 -0
  277. package/node_modules/zod/src/v4/classic/tests/optional.test.ts +136 -0
  278. package/node_modules/zod/src/v4/classic/tests/partial.test.ts +340 -0
  279. package/node_modules/zod/src/v4/classic/tests/pickomit.test.ts +127 -0
  280. package/node_modules/zod/src/v4/classic/tests/pipe.test.ts +101 -0
  281. package/node_modules/zod/src/v4/classic/tests/prefault.test.ts +74 -0
  282. package/node_modules/zod/src/v4/classic/tests/preprocess.test.ts +282 -0
  283. package/node_modules/zod/src/v4/classic/tests/primitive.test.ts +175 -0
  284. package/node_modules/zod/src/v4/classic/tests/promise.test.ts +81 -0
  285. package/node_modules/zod/src/v4/classic/tests/prototypes.test.ts +23 -0
  286. package/node_modules/zod/src/v4/classic/tests/readonly.test.ts +252 -0
  287. package/node_modules/zod/src/v4/classic/tests/record.test.ts +525 -0
  288. package/node_modules/zod/src/v4/classic/tests/recursive-types.test.ts +582 -0
  289. package/node_modules/zod/src/v4/classic/tests/refine.test.ts +605 -0
  290. package/node_modules/zod/src/v4/classic/tests/registries.test.ts +208 -0
  291. package/node_modules/zod/src/v4/classic/tests/set.test.ts +181 -0
  292. package/node_modules/zod/src/v4/classic/tests/standard-schema.test.ts +134 -0
  293. package/node_modules/zod/src/v4/classic/tests/string-formats.test.ts +125 -0
  294. package/node_modules/zod/src/v4/classic/tests/string.test.ts +1152 -0
  295. package/node_modules/zod/src/v4/classic/tests/stringbool.test.ts +106 -0
  296. package/node_modules/zod/src/v4/classic/tests/template-literal.test.ts +771 -0
  297. package/node_modules/zod/src/v4/classic/tests/to-json-schema-methods.test.ts +438 -0
  298. package/node_modules/zod/src/v4/classic/tests/to-json-schema.test.ts +2755 -0
  299. package/node_modules/zod/src/v4/classic/tests/transform.test.ts +361 -0
  300. package/node_modules/zod/src/v4/classic/tests/tuple.test.ts +181 -0
  301. package/node_modules/zod/src/v4/classic/tests/union.test.ts +219 -0
  302. package/node_modules/zod/src/v4/classic/tests/url.test.ts +13 -0
  303. package/node_modules/zod/src/v4/classic/tests/validations.test.ts +283 -0
  304. package/node_modules/zod/src/v4/classic/tests/void.test.ts +12 -0
  305. package/node_modules/zod/src/v4/core/api.ts +1681 -0
  306. package/node_modules/zod/src/v4/core/checks.ts +1287 -0
  307. package/node_modules/zod/src/v4/core/config.ts +15 -0
  308. package/node_modules/zod/src/v4/core/core.ts +128 -0
  309. package/node_modules/zod/src/v4/core/doc.ts +44 -0
  310. package/node_modules/zod/src/v4/core/errors.ts +424 -0
  311. package/node_modules/zod/src/v4/core/index.ts +16 -0
  312. package/node_modules/zod/src/v4/core/json-schema-generator.ts +124 -0
  313. package/node_modules/zod/src/v4/core/json-schema-processors.ts +630 -0
  314. package/node_modules/zod/src/v4/core/json-schema.ts +147 -0
  315. package/node_modules/zod/src/v4/core/parse.ts +195 -0
  316. package/node_modules/zod/src/v4/core/regexes.ts +182 -0
  317. package/node_modules/zod/src/v4/core/registries.ts +108 -0
  318. package/node_modules/zod/src/v4/core/schemas.ts +4418 -0
  319. package/node_modules/zod/src/v4/core/standard-schema.ts +159 -0
  320. package/node_modules/zod/src/v4/core/tests/extend.test.ts +59 -0
  321. package/node_modules/zod/src/v4/core/tests/index.test.ts +46 -0
  322. package/node_modules/zod/src/v4/core/tests/locales/be.test.ts +124 -0
  323. package/node_modules/zod/src/v4/core/tests/locales/en.test.ts +22 -0
  324. package/node_modules/zod/src/v4/core/tests/locales/es.test.ts +181 -0
  325. package/node_modules/zod/src/v4/core/tests/locales/he.test.ts +379 -0
  326. package/node_modules/zod/src/v4/core/tests/locales/nl.test.ts +46 -0
  327. package/node_modules/zod/src/v4/core/tests/locales/ru.test.ts +128 -0
  328. package/node_modules/zod/src/v4/core/tests/locales/tr.test.ts +69 -0
  329. package/node_modules/zod/src/v4/core/tests/record-constructor.test.ts +67 -0
  330. package/node_modules/zod/src/v4/core/tests/recursive-tuples.test.ts +45 -0
  331. package/node_modules/zod/src/v4/core/to-json-schema.ts +554 -0
  332. package/node_modules/zod/src/v4/core/util.ts +921 -0
  333. package/node_modules/zod/src/v4/core/versions.ts +5 -0
  334. package/node_modules/zod/src/v4/core/zsf.ts +323 -0
  335. package/node_modules/zod/src/v4/index.ts +4 -0
  336. package/node_modules/zod/src/v4/locales/ar.ts +125 -0
  337. package/node_modules/zod/src/v4/locales/az.ts +121 -0
  338. package/node_modules/zod/src/v4/locales/be.ts +184 -0
  339. package/node_modules/zod/src/v4/locales/bg.ts +136 -0
  340. package/node_modules/zod/src/v4/locales/ca.ts +127 -0
  341. package/node_modules/zod/src/v4/locales/cs.ts +142 -0
  342. package/node_modules/zod/src/v4/locales/da.ts +141 -0
  343. package/node_modules/zod/src/v4/locales/de.ts +124 -0
  344. package/node_modules/zod/src/v4/locales/en.ts +128 -0
  345. package/node_modules/zod/src/v4/locales/eo.ts +125 -0
  346. package/node_modules/zod/src/v4/locales/es.ts +159 -0
  347. package/node_modules/zod/src/v4/locales/fa.ts +134 -0
  348. package/node_modules/zod/src/v4/locales/fi.ts +131 -0
  349. package/node_modules/zod/src/v4/locales/fr-CA.ts +126 -0
  350. package/node_modules/zod/src/v4/locales/fr.ts +124 -0
  351. package/node_modules/zod/src/v4/locales/he.ts +256 -0
  352. package/node_modules/zod/src/v4/locales/hu.ts +126 -0
  353. package/node_modules/zod/src/v4/locales/id.ts +125 -0
  354. package/node_modules/zod/src/v4/locales/index.ts +47 -0
  355. package/node_modules/zod/src/v4/locales/is.ts +127 -0
  356. package/node_modules/zod/src/v4/locales/it.ts +125 -0
  357. package/node_modules/zod/src/v4/locales/ja.ts +122 -0
  358. package/node_modules/zod/src/v4/locales/ka.ts +138 -0
  359. package/node_modules/zod/src/v4/locales/kh.ts +7 -0
  360. package/node_modules/zod/src/v4/locales/km.ts +126 -0
  361. package/node_modules/zod/src/v4/locales/ko.ts +131 -0
  362. package/node_modules/zod/src/v4/locales/lt.ts +265 -0
  363. package/node_modules/zod/src/v4/locales/mk.ts +127 -0
  364. package/node_modules/zod/src/v4/locales/ms.ts +124 -0
  365. package/node_modules/zod/src/v4/locales/nl.ts +126 -0
  366. package/node_modules/zod/src/v4/locales/no.ts +124 -0
  367. package/node_modules/zod/src/v4/locales/ota.ts +125 -0
  368. package/node_modules/zod/src/v4/locales/pl.ts +126 -0
  369. package/node_modules/zod/src/v4/locales/ps.ts +133 -0
  370. package/node_modules/zod/src/v4/locales/pt.ts +123 -0
  371. package/node_modules/zod/src/v4/locales/ru.ts +184 -0
  372. package/node_modules/zod/src/v4/locales/sl.ts +126 -0
  373. package/node_modules/zod/src/v4/locales/sv.ts +127 -0
  374. package/node_modules/zod/src/v4/locales/ta.ts +125 -0
  375. package/node_modules/zod/src/v4/locales/th.ts +126 -0
  376. package/node_modules/zod/src/v4/locales/tr.ts +121 -0
  377. package/node_modules/zod/src/v4/locales/ua.ts +7 -0
  378. package/node_modules/zod/src/v4/locales/uk.ts +126 -0
  379. package/node_modules/zod/src/v4/locales/ur.ts +126 -0
  380. package/node_modules/zod/src/v4/locales/vi.ts +125 -0
  381. package/node_modules/zod/src/v4/locales/yo.ts +131 -0
  382. package/node_modules/zod/src/v4/locales/zh-CN.ts +123 -0
  383. package/node_modules/zod/src/v4/locales/zh-TW.ts +125 -0
  384. package/node_modules/zod/src/v4/mini/checks.ts +32 -0
  385. package/node_modules/zod/src/v4/mini/coerce.ts +22 -0
  386. package/node_modules/zod/src/v4/mini/external.ts +40 -0
  387. package/node_modules/zod/src/v4/mini/index.ts +3 -0
  388. package/node_modules/zod/src/v4/mini/iso.ts +62 -0
  389. package/node_modules/zod/src/v4/mini/parse.ts +14 -0
  390. package/node_modules/zod/src/v4/mini/schemas.ts +1781 -0
  391. package/node_modules/zod/src/v4/mini/tests/assignability.test.ts +129 -0
  392. package/node_modules/zod/src/v4/mini/tests/brand.test.ts +51 -0
  393. package/node_modules/zod/src/v4/mini/tests/checks.test.ts +144 -0
  394. package/node_modules/zod/src/v4/mini/tests/codec.test.ts +529 -0
  395. package/node_modules/zod/src/v4/mini/tests/computed.test.ts +36 -0
  396. package/node_modules/zod/src/v4/mini/tests/error.test.ts +22 -0
  397. package/node_modules/zod/src/v4/mini/tests/functions.test.ts +5 -0
  398. package/node_modules/zod/src/v4/mini/tests/index.test.ts +922 -0
  399. package/node_modules/zod/src/v4/mini/tests/number.test.ts +95 -0
  400. package/node_modules/zod/src/v4/mini/tests/object.test.ts +200 -0
  401. package/node_modules/zod/src/v4/mini/tests/prototypes.test.ts +43 -0
  402. package/node_modules/zod/src/v4/mini/tests/recursive-types.test.ts +275 -0
  403. package/node_modules/zod/src/v4/mini/tests/standard-schema.test.ts +17 -0
  404. package/node_modules/zod/src/v4/mini/tests/string.test.ts +347 -0
  405. package/node_modules/zod/src/v4-mini/index.ts +1 -0
  406. package/node_modules/zod/v3/ZodError.cjs +138 -0
  407. package/node_modules/zod/v3/ZodError.d.cts +164 -0
  408. package/node_modules/zod/v3/ZodError.d.ts +164 -0
  409. package/node_modules/zod/v3/ZodError.js +133 -0
  410. package/node_modules/zod/v3/errors.cjs +17 -0
  411. package/node_modules/zod/v3/errors.d.cts +5 -0
  412. package/node_modules/zod/v3/errors.d.ts +5 -0
  413. package/node_modules/zod/v3/errors.js +9 -0
  414. package/node_modules/zod/v3/external.cjs +22 -0
  415. package/node_modules/zod/v3/external.d.cts +6 -0
  416. package/node_modules/zod/v3/external.d.ts +6 -0
  417. package/node_modules/zod/v3/external.js +6 -0
  418. package/node_modules/zod/v3/helpers/enumUtil.cjs +2 -0
  419. package/node_modules/zod/v3/helpers/enumUtil.d.cts +8 -0
  420. package/node_modules/zod/v3/helpers/enumUtil.d.ts +8 -0
  421. package/node_modules/zod/v3/helpers/enumUtil.js +1 -0
  422. package/node_modules/zod/v3/helpers/errorUtil.cjs +9 -0
  423. package/node_modules/zod/v3/helpers/errorUtil.d.cts +9 -0
  424. package/node_modules/zod/v3/helpers/errorUtil.d.ts +9 -0
  425. package/node_modules/zod/v3/helpers/errorUtil.js +6 -0
  426. package/node_modules/zod/v3/helpers/parseUtil.cjs +124 -0
  427. package/node_modules/zod/v3/helpers/parseUtil.d.cts +78 -0
  428. package/node_modules/zod/v3/helpers/parseUtil.d.ts +78 -0
  429. package/node_modules/zod/v3/helpers/parseUtil.js +109 -0
  430. package/node_modules/zod/v3/helpers/partialUtil.cjs +2 -0
  431. package/node_modules/zod/v3/helpers/partialUtil.d.cts +8 -0
  432. package/node_modules/zod/v3/helpers/partialUtil.d.ts +8 -0
  433. package/node_modules/zod/v3/helpers/partialUtil.js +1 -0
  434. package/node_modules/zod/v3/helpers/typeAliases.cjs +2 -0
  435. package/node_modules/zod/v3/helpers/typeAliases.d.cts +2 -0
  436. package/node_modules/zod/v3/helpers/typeAliases.d.ts +2 -0
  437. package/node_modules/zod/v3/helpers/typeAliases.js +1 -0
  438. package/node_modules/zod/v3/helpers/util.cjs +137 -0
  439. package/node_modules/zod/v3/helpers/util.d.cts +85 -0
  440. package/node_modules/zod/v3/helpers/util.d.ts +85 -0
  441. package/node_modules/zod/v3/helpers/util.js +133 -0
  442. package/node_modules/zod/v3/index.cjs +33 -0
  443. package/node_modules/zod/v3/index.d.cts +4 -0
  444. package/node_modules/zod/v3/index.d.ts +4 -0
  445. package/node_modules/zod/v3/index.js +4 -0
  446. package/node_modules/zod/v3/locales/en.cjs +112 -0
  447. package/node_modules/zod/v3/locales/en.d.cts +3 -0
  448. package/node_modules/zod/v3/locales/en.d.ts +3 -0
  449. package/node_modules/zod/v3/locales/en.js +109 -0
  450. package/node_modules/zod/v3/package.json +6 -0
  451. package/node_modules/zod/v3/standard-schema.cjs +2 -0
  452. package/node_modules/zod/v3/standard-schema.d.cts +102 -0
  453. package/node_modules/zod/v3/standard-schema.d.ts +102 -0
  454. package/node_modules/zod/v3/standard-schema.js +1 -0
  455. package/node_modules/zod/v3/types.cjs +3777 -0
  456. package/node_modules/zod/v3/types.d.cts +1034 -0
  457. package/node_modules/zod/v3/types.d.ts +1034 -0
  458. package/node_modules/zod/v3/types.js +3695 -0
  459. package/node_modules/zod/v4/classic/checks.cjs +33 -0
  460. package/node_modules/zod/v4/classic/checks.d.cts +1 -0
  461. package/node_modules/zod/v4/classic/checks.d.ts +1 -0
  462. package/node_modules/zod/v4/classic/checks.js +1 -0
  463. package/node_modules/zod/v4/classic/coerce.cjs +47 -0
  464. package/node_modules/zod/v4/classic/coerce.d.cts +17 -0
  465. package/node_modules/zod/v4/classic/coerce.d.ts +17 -0
  466. package/node_modules/zod/v4/classic/coerce.js +17 -0
  467. package/node_modules/zod/v4/classic/compat.cjs +61 -0
  468. package/node_modules/zod/v4/classic/compat.d.cts +50 -0
  469. package/node_modules/zod/v4/classic/compat.d.ts +50 -0
  470. package/node_modules/zod/v4/classic/compat.js +31 -0
  471. package/node_modules/zod/v4/classic/errors.cjs +74 -0
  472. package/node_modules/zod/v4/classic/errors.d.cts +30 -0
  473. package/node_modules/zod/v4/classic/errors.d.ts +30 -0
  474. package/node_modules/zod/v4/classic/errors.js +48 -0
  475. package/node_modules/zod/v4/classic/external.cjs +73 -0
  476. package/node_modules/zod/v4/classic/external.d.cts +15 -0
  477. package/node_modules/zod/v4/classic/external.d.ts +15 -0
  478. package/node_modules/zod/v4/classic/external.js +20 -0
  479. package/node_modules/zod/v4/classic/from-json-schema.cjs +511 -0
  480. package/node_modules/zod/v4/classic/from-json-schema.d.cts +10 -0
  481. package/node_modules/zod/v4/classic/from-json-schema.d.ts +10 -0
  482. package/node_modules/zod/v4/classic/from-json-schema.js +485 -0
  483. package/node_modules/zod/v4/classic/index.cjs +33 -0
  484. package/node_modules/zod/v4/classic/index.d.cts +4 -0
  485. package/node_modules/zod/v4/classic/index.d.ts +4 -0
  486. package/node_modules/zod/v4/classic/index.js +4 -0
  487. package/node_modules/zod/v4/classic/iso.cjs +60 -0
  488. package/node_modules/zod/v4/classic/iso.d.cts +22 -0
  489. package/node_modules/zod/v4/classic/iso.d.ts +22 -0
  490. package/node_modules/zod/v4/classic/iso.js +30 -0
  491. package/node_modules/zod/v4/classic/package.json +6 -0
  492. package/node_modules/zod/v4/classic/parse.cjs +41 -0
  493. package/node_modules/zod/v4/classic/parse.d.cts +31 -0
  494. package/node_modules/zod/v4/classic/parse.d.ts +31 -0
  495. package/node_modules/zod/v4/classic/parse.js +15 -0
  496. package/node_modules/zod/v4/classic/schemas.cjs +1240 -0
  497. package/node_modules/zod/v4/classic/schemas.d.cts +726 -0
  498. package/node_modules/zod/v4/classic/schemas.d.ts +726 -0
  499. package/node_modules/zod/v4/classic/schemas.js +1126 -0
  500. package/node_modules/zod/v4/core/api.cjs +1109 -0
  501. package/node_modules/zod/v4/core/api.d.cts +304 -0
  502. package/node_modules/zod/v4/core/api.d.ts +304 -0
  503. package/node_modules/zod/v4/core/api.js +969 -0
  504. package/node_modules/zod/v4/core/checks.cjs +595 -0
  505. package/node_modules/zod/v4/core/checks.d.cts +278 -0
  506. package/node_modules/zod/v4/core/checks.d.ts +278 -0
  507. package/node_modules/zod/v4/core/checks.js +569 -0
  508. package/node_modules/zod/v4/core/core.cjs +83 -0
  509. package/node_modules/zod/v4/core/core.d.cts +52 -0
  510. package/node_modules/zod/v4/core/core.d.ts +52 -0
  511. package/node_modules/zod/v4/core/core.js +76 -0
  512. package/node_modules/zod/v4/core/doc.cjs +39 -0
  513. package/node_modules/zod/v4/core/doc.d.cts +14 -0
  514. package/node_modules/zod/v4/core/doc.d.ts +14 -0
  515. package/node_modules/zod/v4/core/doc.js +35 -0
  516. package/node_modules/zod/v4/core/errors.cjs +213 -0
  517. package/node_modules/zod/v4/core/errors.d.cts +219 -0
  518. package/node_modules/zod/v4/core/errors.d.ts +219 -0
  519. package/node_modules/zod/v4/core/errors.js +182 -0
  520. package/node_modules/zod/v4/core/index.cjs +47 -0
  521. package/node_modules/zod/v4/core/index.d.cts +16 -0
  522. package/node_modules/zod/v4/core/index.d.ts +16 -0
  523. package/node_modules/zod/v4/core/index.js +16 -0
  524. package/node_modules/zod/v4/core/json-schema-generator.cjs +99 -0
  525. package/node_modules/zod/v4/core/json-schema-generator.d.cts +64 -0
  526. package/node_modules/zod/v4/core/json-schema-generator.d.ts +64 -0
  527. package/node_modules/zod/v4/core/json-schema-generator.js +95 -0
  528. package/node_modules/zod/v4/core/json-schema-processors.cjs +617 -0
  529. package/node_modules/zod/v4/core/json-schema-processors.d.cts +49 -0
  530. package/node_modules/zod/v4/core/json-schema-processors.d.ts +49 -0
  531. package/node_modules/zod/v4/core/json-schema-processors.js +574 -0
  532. package/node_modules/zod/v4/core/json-schema.cjs +2 -0
  533. package/node_modules/zod/v4/core/json-schema.d.cts +88 -0
  534. package/node_modules/zod/v4/core/json-schema.d.ts +88 -0
  535. package/node_modules/zod/v4/core/json-schema.js +1 -0
  536. package/node_modules/zod/v4/core/package.json +6 -0
  537. package/node_modules/zod/v4/core/parse.cjs +131 -0
  538. package/node_modules/zod/v4/core/parse.d.cts +49 -0
  539. package/node_modules/zod/v4/core/parse.d.ts +49 -0
  540. package/node_modules/zod/v4/core/parse.js +93 -0
  541. package/node_modules/zod/v4/core/regexes.cjs +165 -0
  542. package/node_modules/zod/v4/core/regexes.d.cts +79 -0
  543. package/node_modules/zod/v4/core/regexes.d.ts +79 -0
  544. package/node_modules/zod/v4/core/regexes.js +132 -0
  545. package/node_modules/zod/v4/core/registries.cjs +59 -0
  546. package/node_modules/zod/v4/core/registries.d.cts +35 -0
  547. package/node_modules/zod/v4/core/registries.d.ts +35 -0
  548. package/node_modules/zod/v4/core/registries.js +54 -0
  549. package/node_modules/zod/v4/core/schemas.cjs +2040 -0
  550. package/node_modules/zod/v4/core/schemas.d.cts +1135 -0
  551. package/node_modules/zod/v4/core/schemas.d.ts +1135 -0
  552. package/node_modules/zod/v4/core/schemas.js +2009 -0
  553. package/node_modules/zod/v4/core/standard-schema.cjs +2 -0
  554. package/node_modules/zod/v4/core/standard-schema.d.cts +126 -0
  555. package/node_modules/zod/v4/core/standard-schema.d.ts +126 -0
  556. package/node_modules/zod/v4/core/standard-schema.js +1 -0
  557. package/node_modules/zod/v4/core/to-json-schema.cjs +392 -0
  558. package/node_modules/zod/v4/core/to-json-schema.d.cts +113 -0
  559. package/node_modules/zod/v4/core/to-json-schema.d.ts +113 -0
  560. package/node_modules/zod/v4/core/to-json-schema.js +383 -0
  561. package/node_modules/zod/v4/core/util.cjs +669 -0
  562. package/node_modules/zod/v4/core/util.d.cts +198 -0
  563. package/node_modules/zod/v4/core/util.d.ts +198 -0
  564. package/node_modules/zod/v4/core/util.js +611 -0
  565. package/node_modules/zod/v4/core/versions.cjs +8 -0
  566. package/node_modules/zod/v4/core/versions.d.cts +5 -0
  567. package/node_modules/zod/v4/core/versions.d.ts +5 -0
  568. package/node_modules/zod/v4/core/versions.js +5 -0
  569. package/node_modules/zod/v4/index.cjs +22 -0
  570. package/node_modules/zod/v4/index.d.cts +3 -0
  571. package/node_modules/zod/v4/index.d.ts +3 -0
  572. package/node_modules/zod/v4/index.js +3 -0
  573. package/node_modules/zod/v4/locales/ar.cjs +143 -0
  574. package/node_modules/zod/v4/locales/ar.d.cts +5 -0
  575. package/node_modules/zod/v4/locales/ar.d.ts +4 -0
  576. package/node_modules/zod/v4/locales/ar.js +116 -0
  577. package/node_modules/zod/v4/locales/az.cjs +142 -0
  578. package/node_modules/zod/v4/locales/az.d.cts +5 -0
  579. package/node_modules/zod/v4/locales/az.d.ts +4 -0
  580. package/node_modules/zod/v4/locales/az.js +115 -0
  581. package/node_modules/zod/v4/locales/be.cjs +191 -0
  582. package/node_modules/zod/v4/locales/be.d.cts +5 -0
  583. package/node_modules/zod/v4/locales/be.d.ts +4 -0
  584. package/node_modules/zod/v4/locales/be.js +164 -0
  585. package/node_modules/zod/v4/locales/bg.cjs +156 -0
  586. package/node_modules/zod/v4/locales/bg.d.cts +5 -0
  587. package/node_modules/zod/v4/locales/bg.d.ts +5 -0
  588. package/node_modules/zod/v4/locales/bg.js +128 -0
  589. package/node_modules/zod/v4/locales/ca.cjs +145 -0
  590. package/node_modules/zod/v4/locales/ca.d.cts +5 -0
  591. package/node_modules/zod/v4/locales/ca.d.ts +4 -0
  592. package/node_modules/zod/v4/locales/ca.js +118 -0
  593. package/node_modules/zod/v4/locales/cs.cjs +162 -0
  594. package/node_modules/zod/v4/locales/cs.d.cts +5 -0
  595. package/node_modules/zod/v4/locales/cs.d.ts +4 -0
  596. package/node_modules/zod/v4/locales/cs.js +135 -0
  597. package/node_modules/zod/v4/locales/da.cjs +158 -0
  598. package/node_modules/zod/v4/locales/da.d.cts +5 -0
  599. package/node_modules/zod/v4/locales/da.d.ts +4 -0
  600. package/node_modules/zod/v4/locales/da.js +131 -0
  601. package/node_modules/zod/v4/locales/de.cjs +143 -0
  602. package/node_modules/zod/v4/locales/de.d.cts +5 -0
  603. package/node_modules/zod/v4/locales/de.d.ts +4 -0
  604. package/node_modules/zod/v4/locales/de.js +116 -0
  605. package/node_modules/zod/v4/locales/en.cjs +146 -0
  606. package/node_modules/zod/v4/locales/en.d.cts +5 -0
  607. package/node_modules/zod/v4/locales/en.d.ts +5 -0
  608. package/node_modules/zod/v4/locales/en.js +118 -0
  609. package/node_modules/zod/v4/locales/eo.cjs +144 -0
  610. package/node_modules/zod/v4/locales/eo.d.cts +5 -0
  611. package/node_modules/zod/v4/locales/eo.d.ts +5 -0
  612. package/node_modules/zod/v4/locales/eo.js +116 -0
  613. package/node_modules/zod/v4/locales/es.cjs +176 -0
  614. package/node_modules/zod/v4/locales/es.d.cts +5 -0
  615. package/node_modules/zod/v4/locales/es.d.ts +4 -0
  616. package/node_modules/zod/v4/locales/es.js +149 -0
  617. package/node_modules/zod/v4/locales/fa.cjs +149 -0
  618. package/node_modules/zod/v4/locales/fa.d.cts +5 -0
  619. package/node_modules/zod/v4/locales/fa.d.ts +4 -0
  620. package/node_modules/zod/v4/locales/fa.js +122 -0
  621. package/node_modules/zod/v4/locales/fi.cjs +149 -0
  622. package/node_modules/zod/v4/locales/fi.d.cts +5 -0
  623. package/node_modules/zod/v4/locales/fi.d.ts +4 -0
  624. package/node_modules/zod/v4/locales/fi.js +122 -0
  625. package/node_modules/zod/v4/locales/fr-CA.cjs +144 -0
  626. package/node_modules/zod/v4/locales/fr-CA.d.cts +5 -0
  627. package/node_modules/zod/v4/locales/fr-CA.d.ts +4 -0
  628. package/node_modules/zod/v4/locales/fr-CA.js +117 -0
  629. package/node_modules/zod/v4/locales/fr.cjs +143 -0
  630. package/node_modules/zod/v4/locales/fr.d.cts +5 -0
  631. package/node_modules/zod/v4/locales/fr.d.ts +4 -0
  632. package/node_modules/zod/v4/locales/fr.js +116 -0
  633. package/node_modules/zod/v4/locales/he.cjs +255 -0
  634. package/node_modules/zod/v4/locales/he.d.cts +5 -0
  635. package/node_modules/zod/v4/locales/he.d.ts +4 -0
  636. package/node_modules/zod/v4/locales/he.js +228 -0
  637. package/node_modules/zod/v4/locales/hu.cjs +144 -0
  638. package/node_modules/zod/v4/locales/hu.d.cts +5 -0
  639. package/node_modules/zod/v4/locales/hu.d.ts +4 -0
  640. package/node_modules/zod/v4/locales/hu.js +117 -0
  641. package/node_modules/zod/v4/locales/id.cjs +143 -0
  642. package/node_modules/zod/v4/locales/id.d.cts +5 -0
  643. package/node_modules/zod/v4/locales/id.d.ts +4 -0
  644. package/node_modules/zod/v4/locales/id.js +116 -0
  645. package/node_modules/zod/v4/locales/index.cjs +100 -0
  646. package/node_modules/zod/v4/locales/index.d.cts +47 -0
  647. package/node_modules/zod/v4/locales/index.d.ts +47 -0
  648. package/node_modules/zod/v4/locales/index.js +47 -0
  649. package/node_modules/zod/v4/locales/is.cjs +145 -0
  650. package/node_modules/zod/v4/locales/is.d.cts +5 -0
  651. package/node_modules/zod/v4/locales/is.d.ts +5 -0
  652. package/node_modules/zod/v4/locales/is.js +117 -0
  653. package/node_modules/zod/v4/locales/it.cjs +144 -0
  654. package/node_modules/zod/v4/locales/it.d.cts +5 -0
  655. package/node_modules/zod/v4/locales/it.d.ts +4 -0
  656. package/node_modules/zod/v4/locales/it.js +117 -0
  657. package/node_modules/zod/v4/locales/ja.cjs +142 -0
  658. package/node_modules/zod/v4/locales/ja.d.cts +5 -0
  659. package/node_modules/zod/v4/locales/ja.d.ts +4 -0
  660. package/node_modules/zod/v4/locales/ja.js +115 -0
  661. package/node_modules/zod/v4/locales/ka.cjs +153 -0
  662. package/node_modules/zod/v4/locales/ka.d.cts +5 -0
  663. package/node_modules/zod/v4/locales/ka.d.ts +5 -0
  664. package/node_modules/zod/v4/locales/ka.js +125 -0
  665. package/node_modules/zod/v4/locales/kh.cjs +12 -0
  666. package/node_modules/zod/v4/locales/kh.d.cts +5 -0
  667. package/node_modules/zod/v4/locales/kh.d.ts +5 -0
  668. package/node_modules/zod/v4/locales/kh.js +5 -0
  669. package/node_modules/zod/v4/locales/km.cjs +144 -0
  670. package/node_modules/zod/v4/locales/km.d.cts +5 -0
  671. package/node_modules/zod/v4/locales/km.d.ts +4 -0
  672. package/node_modules/zod/v4/locales/km.js +117 -0
  673. package/node_modules/zod/v4/locales/ko.cjs +148 -0
  674. package/node_modules/zod/v4/locales/ko.d.cts +5 -0
  675. package/node_modules/zod/v4/locales/ko.d.ts +4 -0
  676. package/node_modules/zod/v4/locales/ko.js +121 -0
  677. package/node_modules/zod/v4/locales/lt.cjs +258 -0
  678. package/node_modules/zod/v4/locales/lt.d.cts +5 -0
  679. package/node_modules/zod/v4/locales/lt.d.ts +5 -0
  680. package/node_modules/zod/v4/locales/lt.js +230 -0
  681. package/node_modules/zod/v4/locales/mk.cjs +145 -0
  682. package/node_modules/zod/v4/locales/mk.d.cts +5 -0
  683. package/node_modules/zod/v4/locales/mk.d.ts +4 -0
  684. package/node_modules/zod/v4/locales/mk.js +118 -0
  685. package/node_modules/zod/v4/locales/ms.cjs +143 -0
  686. package/node_modules/zod/v4/locales/ms.d.cts +5 -0
  687. package/node_modules/zod/v4/locales/ms.d.ts +4 -0
  688. package/node_modules/zod/v4/locales/ms.js +116 -0
  689. package/node_modules/zod/v4/locales/nl.cjs +144 -0
  690. package/node_modules/zod/v4/locales/nl.d.cts +5 -0
  691. package/node_modules/zod/v4/locales/nl.d.ts +4 -0
  692. package/node_modules/zod/v4/locales/nl.js +117 -0
  693. package/node_modules/zod/v4/locales/no.cjs +143 -0
  694. package/node_modules/zod/v4/locales/no.d.cts +5 -0
  695. package/node_modules/zod/v4/locales/no.d.ts +4 -0
  696. package/node_modules/zod/v4/locales/no.js +116 -0
  697. package/node_modules/zod/v4/locales/ota.cjs +144 -0
  698. package/node_modules/zod/v4/locales/ota.d.cts +5 -0
  699. package/node_modules/zod/v4/locales/ota.d.ts +4 -0
  700. package/node_modules/zod/v4/locales/ota.js +117 -0
  701. package/node_modules/zod/v4/locales/package.json +6 -0
  702. package/node_modules/zod/v4/locales/pl.cjs +144 -0
  703. package/node_modules/zod/v4/locales/pl.d.cts +5 -0
  704. package/node_modules/zod/v4/locales/pl.d.ts +4 -0
  705. package/node_modules/zod/v4/locales/pl.js +117 -0
  706. package/node_modules/zod/v4/locales/ps.cjs +149 -0
  707. package/node_modules/zod/v4/locales/ps.d.cts +5 -0
  708. package/node_modules/zod/v4/locales/ps.d.ts +4 -0
  709. package/node_modules/zod/v4/locales/ps.js +122 -0
  710. package/node_modules/zod/v4/locales/pt.cjs +143 -0
  711. package/node_modules/zod/v4/locales/pt.d.cts +5 -0
  712. package/node_modules/zod/v4/locales/pt.d.ts +4 -0
  713. package/node_modules/zod/v4/locales/pt.js +116 -0
  714. package/node_modules/zod/v4/locales/ru.cjs +191 -0
  715. package/node_modules/zod/v4/locales/ru.d.cts +5 -0
  716. package/node_modules/zod/v4/locales/ru.d.ts +4 -0
  717. package/node_modules/zod/v4/locales/ru.js +164 -0
  718. package/node_modules/zod/v4/locales/sl.cjs +144 -0
  719. package/node_modules/zod/v4/locales/sl.d.cts +5 -0
  720. package/node_modules/zod/v4/locales/sl.d.ts +4 -0
  721. package/node_modules/zod/v4/locales/sl.js +117 -0
  722. package/node_modules/zod/v4/locales/sv.cjs +145 -0
  723. package/node_modules/zod/v4/locales/sv.d.cts +5 -0
  724. package/node_modules/zod/v4/locales/sv.d.ts +4 -0
  725. package/node_modules/zod/v4/locales/sv.js +118 -0
  726. package/node_modules/zod/v4/locales/ta.cjs +144 -0
  727. package/node_modules/zod/v4/locales/ta.d.cts +5 -0
  728. package/node_modules/zod/v4/locales/ta.d.ts +4 -0
  729. package/node_modules/zod/v4/locales/ta.js +117 -0
  730. package/node_modules/zod/v4/locales/th.cjs +144 -0
  731. package/node_modules/zod/v4/locales/th.d.cts +5 -0
  732. package/node_modules/zod/v4/locales/th.d.ts +4 -0
  733. package/node_modules/zod/v4/locales/th.js +117 -0
  734. package/node_modules/zod/v4/locales/tr.cjs +143 -0
  735. package/node_modules/zod/v4/locales/tr.d.cts +5 -0
  736. package/node_modules/zod/v4/locales/tr.d.ts +5 -0
  737. package/node_modules/zod/v4/locales/tr.js +115 -0
  738. package/node_modules/zod/v4/locales/ua.cjs +12 -0
  739. package/node_modules/zod/v4/locales/ua.d.cts +5 -0
  740. package/node_modules/zod/v4/locales/ua.d.ts +5 -0
  741. package/node_modules/zod/v4/locales/ua.js +5 -0
  742. package/node_modules/zod/v4/locales/uk.cjs +144 -0
  743. package/node_modules/zod/v4/locales/uk.d.cts +5 -0
  744. package/node_modules/zod/v4/locales/uk.d.ts +4 -0
  745. package/node_modules/zod/v4/locales/uk.js +117 -0
  746. package/node_modules/zod/v4/locales/ur.cjs +144 -0
  747. package/node_modules/zod/v4/locales/ur.d.cts +5 -0
  748. package/node_modules/zod/v4/locales/ur.d.ts +4 -0
  749. package/node_modules/zod/v4/locales/ur.js +117 -0
  750. package/node_modules/zod/v4/locales/vi.cjs +143 -0
  751. package/node_modules/zod/v4/locales/vi.d.cts +5 -0
  752. package/node_modules/zod/v4/locales/vi.d.ts +4 -0
  753. package/node_modules/zod/v4/locales/vi.js +116 -0
  754. package/node_modules/zod/v4/locales/yo.cjs +142 -0
  755. package/node_modules/zod/v4/locales/yo.d.cts +5 -0
  756. package/node_modules/zod/v4/locales/yo.d.ts +4 -0
  757. package/node_modules/zod/v4/locales/yo.js +115 -0
  758. package/node_modules/zod/v4/locales/zh-CN.cjs +143 -0
  759. package/node_modules/zod/v4/locales/zh-CN.d.cts +5 -0
  760. package/node_modules/zod/v4/locales/zh-CN.d.ts +4 -0
  761. package/node_modules/zod/v4/locales/zh-CN.js +116 -0
  762. package/node_modules/zod/v4/locales/zh-TW.cjs +144 -0
  763. package/node_modules/zod/v4/locales/zh-TW.d.cts +5 -0
  764. package/node_modules/zod/v4/locales/zh-TW.d.ts +4 -0
  765. package/node_modules/zod/v4/locales/zh-TW.js +117 -0
  766. package/node_modules/zod/v4/mini/checks.cjs +34 -0
  767. package/node_modules/zod/v4/mini/checks.d.cts +1 -0
  768. package/node_modules/zod/v4/mini/checks.d.ts +1 -0
  769. package/node_modules/zod/v4/mini/checks.js +1 -0
  770. package/node_modules/zod/v4/mini/coerce.cjs +47 -0
  771. package/node_modules/zod/v4/mini/coerce.d.cts +7 -0
  772. package/node_modules/zod/v4/mini/coerce.d.ts +7 -0
  773. package/node_modules/zod/v4/mini/coerce.js +17 -0
  774. package/node_modules/zod/v4/mini/external.cjs +63 -0
  775. package/node_modules/zod/v4/mini/external.d.cts +12 -0
  776. package/node_modules/zod/v4/mini/external.d.ts +12 -0
  777. package/node_modules/zod/v4/mini/external.js +14 -0
  778. package/node_modules/zod/v4/mini/index.cjs +32 -0
  779. package/node_modules/zod/v4/mini/index.d.cts +3 -0
  780. package/node_modules/zod/v4/mini/index.d.ts +3 -0
  781. package/node_modules/zod/v4/mini/index.js +3 -0
  782. package/node_modules/zod/v4/mini/iso.cjs +60 -0
  783. package/node_modules/zod/v4/mini/iso.d.cts +22 -0
  784. package/node_modules/zod/v4/mini/iso.d.ts +22 -0
  785. package/node_modules/zod/v4/mini/iso.js +30 -0
  786. package/node_modules/zod/v4/mini/package.json +6 -0
  787. package/node_modules/zod/v4/mini/parse.cjs +16 -0
  788. package/node_modules/zod/v4/mini/parse.d.cts +1 -0
  789. package/node_modules/zod/v4/mini/parse.d.ts +1 -0
  790. package/node_modules/zod/v4/mini/parse.js +1 -0
  791. package/node_modules/zod/v4/mini/schemas.cjs +929 -0
  792. package/node_modules/zod/v4/mini/schemas.d.cts +421 -0
  793. package/node_modules/zod/v4/mini/schemas.d.ts +421 -0
  794. package/node_modules/zod/v4/mini/schemas.js +809 -0
  795. package/node_modules/zod/v4/package.json +6 -0
  796. package/node_modules/zod/v4-mini/index.cjs +17 -0
  797. package/node_modules/zod/v4-mini/index.d.cts +1 -0
  798. package/node_modules/zod/v4-mini/index.d.ts +1 -0
  799. package/node_modules/zod/v4-mini/index.js +1 -0
  800. package/node_modules/zod/v4-mini/package.json +6 -0
  801. package/package.json +93 -0
  802. package/publish.sh +449 -0
@@ -0,0 +1,2755 @@
1
+ import { Validator } from "@seriousme/openapi-schema-validator";
2
+ import { describe, expect, test } from "vitest";
3
+ import * as z from "zod";
4
+ // import * as zCore from "zod/v4/core";
5
+
6
+ const openAPI30Validator = new Validator();
7
+ /** @see https://github.com/colinhacks/zod/issues/5147 */
8
+ const validateOpenAPI30Schema = async (zodJSONSchema: Record<string, unknown>): Promise<true> => {
9
+ const res = await openAPI30Validator.validate({
10
+ openapi: "3.0.0",
11
+ info: {
12
+ title: "SampleApi",
13
+ description: "Sample backend service",
14
+ version: "1.0.0",
15
+ },
16
+ components: { schemas: { test: zodJSONSchema } },
17
+ paths: {},
18
+ });
19
+
20
+ if (!res.valid) {
21
+ // `console.error` should make `vitest` trow an unhandled error
22
+ // printing the validation messages in consoles
23
+ console.error(
24
+ `OpenAPI schema is not valid against ${openAPI30Validator.version}`,
25
+ JSON.stringify(res.errors, null, 2)
26
+ );
27
+ }
28
+
29
+ return true;
30
+ };
31
+
32
+ describe("toJSONSchema", () => {
33
+ test("primitive types", () => {
34
+ expect(z.toJSONSchema(z.string())).toMatchInlineSnapshot(`
35
+ {
36
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
37
+ "type": "string",
38
+ }
39
+ `);
40
+ expect(z.toJSONSchema(z.number())).toMatchInlineSnapshot(`
41
+ {
42
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
43
+ "type": "number",
44
+ }
45
+ `);
46
+ expect(z.toJSONSchema(z.boolean())).toMatchInlineSnapshot(`
47
+ {
48
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
49
+ "type": "boolean",
50
+ }
51
+ `);
52
+ expect(z.toJSONSchema(z.null())).toMatchInlineSnapshot(`
53
+ {
54
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
55
+ "type": "null",
56
+ }
57
+ `);
58
+ expect(z.toJSONSchema(z.undefined(), { unrepresentable: "any" })).toMatchInlineSnapshot(`
59
+ {
60
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
61
+ }
62
+ `);
63
+ expect(z.toJSONSchema(z.any())).toMatchInlineSnapshot(`
64
+ {
65
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
66
+ }
67
+ `);
68
+ expect(z.toJSONSchema(z.unknown())).toMatchInlineSnapshot(`
69
+ {
70
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
71
+ }
72
+ `);
73
+ expect(z.toJSONSchema(z.never())).toMatchInlineSnapshot(`
74
+ {
75
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
76
+ "not": {},
77
+ }
78
+ `);
79
+ expect(z.toJSONSchema(z.email())).toMatchInlineSnapshot(`
80
+ {
81
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
82
+ "format": "email",
83
+ "pattern": "^(?!\\.)(?!.*\\.\\.)([A-Za-z0-9_'+\\-\\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$",
84
+ "type": "string",
85
+ }
86
+ `);
87
+ expect(z.toJSONSchema(z.iso.datetime())).toMatchInlineSnapshot(`
88
+ {
89
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
90
+ "format": "date-time",
91
+ "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z))$",
92
+ "type": "string",
93
+ }
94
+ `);
95
+ expect(z.toJSONSchema(z.iso.date())).toMatchInlineSnapshot(`
96
+ {
97
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
98
+ "format": "date",
99
+ "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$",
100
+ "type": "string",
101
+ }
102
+ `);
103
+ expect(z.toJSONSchema(z.iso.time())).toMatchInlineSnapshot(`
104
+ {
105
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
106
+ "format": "time",
107
+ "pattern": "^(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?$",
108
+ "type": "string",
109
+ }
110
+ `);
111
+ expect(z.toJSONSchema(z.iso.duration())).toMatchInlineSnapshot(`
112
+ {
113
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
114
+ "format": "duration",
115
+ "pattern": "^P(?:(\\d+W)|(?!.*W)(?=\\d|T\\d)(\\d+Y)?(\\d+M)?(\\d+D)?(T(?=\\d)(\\d+H)?(\\d+M)?(\\d+([.,]\\d+)?S)?)?)$",
116
+ "type": "string",
117
+ }
118
+ `);
119
+ expect(z.toJSONSchema(z.ipv4())).toMatchInlineSnapshot(`
120
+ {
121
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
122
+ "format": "ipv4",
123
+ "pattern": "^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$",
124
+ "type": "string",
125
+ }
126
+ `);
127
+ expect(z.toJSONSchema(z.ipv6())).toMatchInlineSnapshot(`
128
+ {
129
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
130
+ "format": "ipv6",
131
+ "pattern": "^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$",
132
+ "type": "string",
133
+ }
134
+ `);
135
+ expect(z.toJSONSchema(z.mac())).toMatchInlineSnapshot(`
136
+ {
137
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
138
+ "format": "mac",
139
+ "pattern": "^(?:[0-9A-F]{2}:){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}:){5}[0-9a-f]{2}$",
140
+ "type": "string",
141
+ }
142
+ `);
143
+ expect(z.toJSONSchema(z.mac({ delimiter: ":" }))).toMatchInlineSnapshot(`
144
+ {
145
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
146
+ "format": "mac",
147
+ "pattern": "^(?:[0-9A-F]{2}:){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}:){5}[0-9a-f]{2}$",
148
+ "type": "string",
149
+ }
150
+ `);
151
+ expect(z.toJSONSchema(z.mac({ delimiter: "-" }))).toMatchInlineSnapshot(`
152
+ {
153
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
154
+ "format": "mac",
155
+ "pattern": "^(?:[0-9A-F]{2}-){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}-){5}[0-9a-f]{2}$",
156
+ "type": "string",
157
+ }
158
+ `);
159
+ expect(z.toJSONSchema(z.uuid())).toMatchInlineSnapshot(`
160
+ {
161
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
162
+ "format": "uuid",
163
+ "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$",
164
+ "type": "string",
165
+ }
166
+ `);
167
+ expect(z.toJSONSchema(z.guid())).toMatchInlineSnapshot(`
168
+ {
169
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
170
+ "format": "uuid",
171
+ "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$",
172
+ "type": "string",
173
+ }
174
+ `);
175
+ expect(z.toJSONSchema(z.url())).toMatchInlineSnapshot(`
176
+ {
177
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
178
+ "format": "uri",
179
+ "type": "string",
180
+ }
181
+ `);
182
+ expect(z.toJSONSchema(z.base64())).toMatchInlineSnapshot(`
183
+ {
184
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
185
+ "contentEncoding": "base64",
186
+ "format": "base64",
187
+ "pattern": "^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$",
188
+ "type": "string",
189
+ }
190
+ `);
191
+ expect(z.toJSONSchema(z.cuid())).toMatchInlineSnapshot(`
192
+ {
193
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
194
+ "format": "cuid",
195
+ "pattern": "^[cC][^\\s-]{8,}$",
196
+ "type": "string",
197
+ }
198
+ `);
199
+ // expect(z.toJSONSchema(z.regex(/asdf/))).toMatchInlineSnapshot();
200
+ expect(z.toJSONSchema(z.emoji())).toMatchInlineSnapshot(`
201
+ {
202
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
203
+ "format": "emoji",
204
+ "pattern": "^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",
205
+ "type": "string",
206
+ }
207
+ `);
208
+ expect(z.toJSONSchema(z.nanoid())).toMatchInlineSnapshot(`
209
+ {
210
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
211
+ "format": "nanoid",
212
+ "pattern": "^[a-zA-Z0-9_-]{21}$",
213
+ "type": "string",
214
+ }
215
+ `);
216
+ expect(z.toJSONSchema(z.cuid2())).toMatchInlineSnapshot(`
217
+ {
218
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
219
+ "format": "cuid2",
220
+ "pattern": "^[0-9a-z]+$",
221
+ "type": "string",
222
+ }
223
+ `);
224
+ expect(z.toJSONSchema(z.ulid())).toMatchInlineSnapshot(`
225
+ {
226
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
227
+ "format": "ulid",
228
+ "pattern": "^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$",
229
+ "type": "string",
230
+ }
231
+ `);
232
+ // expect(z.toJSONSchema(z.cidr())).toMatchInlineSnapshot();
233
+ expect(z.toJSONSchema(z.number())).toMatchInlineSnapshot(`
234
+ {
235
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
236
+ "type": "number",
237
+ }
238
+ `);
239
+ expect(z.toJSONSchema(z.int())).toMatchInlineSnapshot(`
240
+ {
241
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
242
+ "maximum": 9007199254740991,
243
+ "minimum": -9007199254740991,
244
+ "type": "integer",
245
+ }
246
+ `);
247
+ expect(z.toJSONSchema(z.int32())).toMatchInlineSnapshot(`
248
+ {
249
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
250
+ "maximum": 2147483647,
251
+ "minimum": -2147483648,
252
+ "type": "integer",
253
+ }
254
+ `);
255
+ expect(z.toJSONSchema(z.float32())).toMatchInlineSnapshot(`
256
+ {
257
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
258
+ "maximum": 3.4028234663852886e+38,
259
+ "minimum": -3.4028234663852886e+38,
260
+ "type": "number",
261
+ }
262
+ `);
263
+ expect(z.toJSONSchema(z.float64())).toMatchInlineSnapshot(`
264
+ {
265
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
266
+ "maximum": 1.7976931348623157e+308,
267
+ "minimum": -1.7976931348623157e+308,
268
+ "type": "number",
269
+ }
270
+ `);
271
+ expect(z.toJSONSchema(z.jwt())).toMatchInlineSnapshot(`
272
+ {
273
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
274
+ "format": "jwt",
275
+ "type": "string",
276
+ }
277
+ `);
278
+ });
279
+
280
+ test("unsupported schema types", () => {
281
+ expect(() => z.toJSONSchema(z.bigint())).toThrow("BigInt cannot be represented in JSON Schema");
282
+ expect(() => z.toJSONSchema(z.int64())).toThrow("BigInt cannot be represented in JSON Schema");
283
+ expect(() => z.toJSONSchema(z.symbol())).toThrow("Symbols cannot be represented in JSON Schema");
284
+ expect(() => z.toJSONSchema(z.void())).toThrow("Void cannot be represented in JSON Schema");
285
+ expect(() => z.toJSONSchema(z.undefined())).toThrow("Undefined cannot be represented in JSON Schema");
286
+ expect(() => z.toJSONSchema(z.date())).toThrow("Date cannot be represented in JSON Schema");
287
+ expect(() => z.toJSONSchema(z.map(z.string(), z.number()))).toThrow("Map cannot be represented in JSON Schema");
288
+ expect(() => z.toJSONSchema(z.set(z.string()))).toThrow("Set cannot be represented in JSON Schema");
289
+ expect(() => z.toJSONSchema(z.custom(() => true))).toThrow("Custom types cannot be represented in JSON Schema");
290
+
291
+ // Transform
292
+ const transformSchema = z.string().transform((val) => Number.parseInt(val));
293
+ expect(() => z.toJSONSchema(transformSchema)).toThrow("Transforms cannot be represented in JSON Schema");
294
+
295
+ // Static catch values
296
+ const staticCatchSchema = z.string().catch(() => "sup");
297
+ expect(z.toJSONSchema(staticCatchSchema)).toMatchInlineSnapshot(`
298
+ {
299
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
300
+ "default": "sup",
301
+ "type": "string",
302
+ }
303
+ `);
304
+
305
+ // Dynamic catch values
306
+ const dynamicCatchSchema = z.string().catch((ctx) => `${ctx.issues.length}`);
307
+ expect(() => z.toJSONSchema(dynamicCatchSchema)).toThrow("Dynamic catch values are not supported in JSON Schema");
308
+ });
309
+
310
+ test("string formats", () => {
311
+ expect(z.toJSONSchema(z.string().email())).toMatchInlineSnapshot(`
312
+ {
313
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
314
+ "format": "email",
315
+ "pattern": "^(?!\\.)(?!.*\\.\\.)([A-Za-z0-9_'+\\-\\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$",
316
+ "type": "string",
317
+ }
318
+ `);
319
+ expect(z.toJSONSchema(z.string().uuid())).toMatchInlineSnapshot(`
320
+ {
321
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
322
+ "format": "uuid",
323
+ "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$",
324
+ "type": "string",
325
+ }
326
+ `);
327
+ expect(z.toJSONSchema(z.iso.datetime())).toMatchInlineSnapshot(`
328
+ {
329
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
330
+ "format": "date-time",
331
+ "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z))$",
332
+ "type": "string",
333
+ }
334
+ `);
335
+
336
+ expect(z.toJSONSchema(z.iso.date())).toMatchInlineSnapshot(`
337
+ {
338
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
339
+ "format": "date",
340
+ "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$",
341
+ "type": "string",
342
+ }
343
+ `);
344
+ expect(z.toJSONSchema(z.iso.time())).toMatchInlineSnapshot(`
345
+ {
346
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
347
+ "format": "time",
348
+ "pattern": "^(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?$",
349
+ "type": "string",
350
+ }
351
+ `);
352
+ expect(z.toJSONSchema(z.iso.duration())).toMatchInlineSnapshot(`
353
+ {
354
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
355
+ "format": "duration",
356
+ "pattern": "^P(?:(\\d+W)|(?!.*W)(?=\\d|T\\d)(\\d+Y)?(\\d+M)?(\\d+D)?(T(?=\\d)(\\d+H)?(\\d+M)?(\\d+([.,]\\d+)?S)?)?)$",
357
+ "type": "string",
358
+ }
359
+ `);
360
+ // expect(z.toJSONSchema(z.string().ip())).toMatchInlineSnapshot(`
361
+ // {
362
+ // "pattern": /\\(\\^\\(\\?:\\(\\?:25\\[0-5\\]\\|2\\[0-4\\]\\[0-9\\]\\|1\\[0-9\\]\\[0-9\\]\\|\\[1-9\\]\\[0-9\\]\\|\\[0-9\\]\\)\\\\\\.\\)\\{3\\}\\(\\?:25\\[0-5\\]\\|2\\[0-4\\]\\[0-9\\]\\|1\\[0-9\\]\\[0-9\\]\\|\\[1-9\\]\\[0-9\\]\\|\\[0-9\\]\\)\\$\\)\\|\\(\\^\\(\\(\\[a-fA-F0-9\\]\\{1,4\\}:\\)\\{7\\}\\|::\\(\\[a-fA-F0-9\\]\\{1,4\\}:\\)\\{0,6\\}\\|\\(\\[a-fA-F0-9\\]\\{1,4\\}:\\)\\{1\\}:\\(\\[a-fA-F0-9\\]\\{1,4\\}:\\)\\{0,5\\}\\|\\(\\[a-fA-F0-9\\]\\{1,4\\}:\\)\\{2\\}:\\(\\[a-fA-F0-9\\]\\{1,4\\}:\\)\\{0,4\\}\\|\\(\\[a-fA-F0-9\\]\\{1,4\\}:\\)\\{3\\}:\\(\\[a-fA-F0-9\\]\\{1,4\\}:\\)\\{0,3\\}\\|\\(\\[a-fA-F0-9\\]\\{1,4\\}:\\)\\{4\\}:\\(\\[a-fA-F0-9\\]\\{1,4\\}:\\)\\{0,2\\}\\|\\(\\[a-fA-F0-9\\]\\{1,4\\}:\\)\\{5\\}:\\(\\[a-fA-F0-9\\]\\{1,4\\}:\\)\\{0,1\\}\\)\\(\\[a-fA-F0-9\\]\\{1,4\\}\\|\\(\\(\\(25\\[0-5\\]\\)\\|\\(2\\[0-4\\]\\[0-9\\]\\)\\|\\(1\\[0-9\\]\\{2\\}\\)\\|\\(\\[0-9\\]\\{1,2\\}\\)\\)\\\\\\.\\)\\{3\\}\\(\\(25\\[0-5\\]\\)\\|\\(2\\[0-4\\]\\[0-9\\]\\)\\|\\(1\\[0-9\\]\\{2\\}\\)\\|\\(\\[0-9\\]\\{1,2\\}\\)\\)\\)\\$\\)/,
363
+ // "type": "string",
364
+ // }
365
+ // `);
366
+ expect(z.toJSONSchema(z.ipv4())).toMatchInlineSnapshot(`
367
+ {
368
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
369
+ "format": "ipv4",
370
+ "pattern": "^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$",
371
+ "type": "string",
372
+ }
373
+ `);
374
+
375
+ expect(z.toJSONSchema(z.ipv6())).toMatchInlineSnapshot(`
376
+ {
377
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
378
+ "format": "ipv6",
379
+ "pattern": "^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$",
380
+ "type": "string",
381
+ }
382
+ `);
383
+
384
+ expect(z.toJSONSchema(z.mac())).toMatchInlineSnapshot(`
385
+ {
386
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
387
+ "format": "mac",
388
+ "pattern": "^(?:[0-9A-F]{2}:){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}:){5}[0-9a-f]{2}$",
389
+ "type": "string",
390
+ }
391
+ `);
392
+ expect(z.toJSONSchema(z.mac({ delimiter: ":" }))).toMatchInlineSnapshot(`
393
+ {
394
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
395
+ "format": "mac",
396
+ "pattern": "^(?:[0-9A-F]{2}:){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}:){5}[0-9a-f]{2}$",
397
+ "type": "string",
398
+ }
399
+ `);
400
+ expect(z.toJSONSchema(z.mac({ delimiter: "-" }))).toMatchInlineSnapshot(`
401
+ {
402
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
403
+ "format": "mac",
404
+ "pattern": "^(?:[0-9A-F]{2}-){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}-){5}[0-9a-f]{2}$",
405
+ "type": "string",
406
+ }
407
+ `);
408
+
409
+ expect(z.toJSONSchema(z.base64())).toMatchInlineSnapshot(`
410
+ {
411
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
412
+ "contentEncoding": "base64",
413
+ "format": "base64",
414
+ "pattern": "^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$",
415
+ "type": "string",
416
+ }
417
+ `);
418
+ expect(z.toJSONSchema(z.url())).toMatchInlineSnapshot(`
419
+ {
420
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
421
+ "format": "uri",
422
+ "type": "string",
423
+ }
424
+ `);
425
+ expect(z.toJSONSchema(z.guid())).toMatchInlineSnapshot(`
426
+ {
427
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
428
+ "format": "uuid",
429
+ "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$",
430
+ "type": "string",
431
+ }
432
+ `);
433
+ expect(z.toJSONSchema(z.string().regex(/asdf/))).toMatchInlineSnapshot(`
434
+ {
435
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
436
+ "pattern": "asdf",
437
+ "type": "string",
438
+ }
439
+ `);
440
+ });
441
+
442
+ test("string patterns", () => {
443
+ expect(
444
+ z.toJSONSchema(
445
+ z
446
+ .string()
447
+ .startsWith("hello")
448
+ .includes("cruel")
449
+ .includes("dark", { position: 10 })
450
+ .endsWith("world")
451
+ .regex(/stuff/)
452
+ )
453
+ ).toMatchInlineSnapshot(`
454
+ {
455
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
456
+ "allOf": [
457
+ {
458
+ "pattern": "^hello.*",
459
+ },
460
+ {
461
+ "pattern": "cruel",
462
+ },
463
+ {
464
+ "pattern": "^.{10}dark",
465
+ },
466
+ {
467
+ "pattern": ".*world$",
468
+ },
469
+ {
470
+ "pattern": "stuff",
471
+ },
472
+ ],
473
+ "type": "string",
474
+ }
475
+ `);
476
+
477
+ expect(
478
+ z.toJSONSchema(
479
+ z
480
+ .string()
481
+ .startsWith("hello")
482
+ .includes("cruel")
483
+ .includes("dark", { position: 10 })
484
+ .endsWith("world")
485
+ .regex(/stuff/),
486
+ {
487
+ target: "draft-7",
488
+ }
489
+ )
490
+ ).toMatchInlineSnapshot(`
491
+ {
492
+ "$schema": "http://json-schema.org/draft-07/schema#",
493
+ "allOf": [
494
+ {
495
+ "pattern": "^hello.*",
496
+ "type": "string",
497
+ },
498
+ {
499
+ "pattern": "cruel",
500
+ "type": "string",
501
+ },
502
+ {
503
+ "pattern": "^.{10}dark",
504
+ "type": "string",
505
+ },
506
+ {
507
+ "pattern": ".*world$",
508
+ "type": "string",
509
+ },
510
+ {
511
+ "pattern": "stuff",
512
+ "type": "string",
513
+ },
514
+ ],
515
+ "type": "string",
516
+ }
517
+ `);
518
+ });
519
+
520
+ test("number constraints", () => {
521
+ expect(z.toJSONSchema(z.number().min(5).max(10))).toMatchInlineSnapshot(
522
+ `
523
+ {
524
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
525
+ "maximum": 10,
526
+ "minimum": 5,
527
+ "type": "number",
528
+ }
529
+ `
530
+ );
531
+
532
+ expect(z.toJSONSchema(z.number().gt(5).gt(10))).toMatchInlineSnapshot(`
533
+ {
534
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
535
+ "exclusiveMinimum": 10,
536
+ "type": "number",
537
+ }
538
+ `);
539
+
540
+ expect(z.toJSONSchema(z.number().gt(5).gte(10))).toMatchInlineSnapshot(`
541
+ {
542
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
543
+ "minimum": 10,
544
+ "type": "number",
545
+ }
546
+ `);
547
+
548
+ expect(z.toJSONSchema(z.number().lt(5).lt(3))).toMatchInlineSnapshot(`
549
+ {
550
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
551
+ "exclusiveMaximum": 3,
552
+ "type": "number",
553
+ }
554
+ `);
555
+
556
+ expect(z.toJSONSchema(z.number().lt(5).lt(3).lte(2))).toMatchInlineSnapshot(`
557
+ {
558
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
559
+ "maximum": 2,
560
+ "type": "number",
561
+ }
562
+ `);
563
+
564
+ expect(z.toJSONSchema(z.number().lt(5).lte(3))).toMatchInlineSnapshot(`
565
+ {
566
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
567
+ "maximum": 3,
568
+ "type": "number",
569
+ }
570
+ `);
571
+
572
+ expect(z.toJSONSchema(z.number().gt(5).lt(10))).toMatchInlineSnapshot(`
573
+ {
574
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
575
+ "exclusiveMaximum": 10,
576
+ "exclusiveMinimum": 5,
577
+ "type": "number",
578
+ }
579
+ `);
580
+ expect(z.toJSONSchema(z.number().gte(5).lte(10))).toMatchInlineSnapshot(`
581
+ {
582
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
583
+ "maximum": 10,
584
+ "minimum": 5,
585
+ "type": "number",
586
+ }
587
+ `);
588
+ expect(z.toJSONSchema(z.number().positive())).toMatchInlineSnapshot(`
589
+ {
590
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
591
+ "exclusiveMinimum": 0,
592
+ "type": "number",
593
+ }
594
+ `);
595
+ expect(z.toJSONSchema(z.number().negative())).toMatchInlineSnapshot(`
596
+ {
597
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
598
+ "exclusiveMaximum": 0,
599
+ "type": "number",
600
+ }
601
+ `);
602
+ expect(z.toJSONSchema(z.number().nonpositive())).toMatchInlineSnapshot(`
603
+ {
604
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
605
+ "maximum": 0,
606
+ "type": "number",
607
+ }
608
+ `);
609
+ expect(z.toJSONSchema(z.number().nonnegative())).toMatchInlineSnapshot(`
610
+ {
611
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
612
+ "minimum": 0,
613
+ "type": "number",
614
+ }
615
+ `);
616
+ });
617
+
618
+ test("number constraints draft-4", () => {
619
+ expect(z.toJSONSchema(z.number().gt(5).lt(10), { target: "draft-4" })).toMatchInlineSnapshot(`
620
+ {
621
+ "$schema": "http://json-schema.org/draft-04/schema#",
622
+ "exclusiveMaximum": true,
623
+ "exclusiveMinimum": true,
624
+ "maximum": 10,
625
+ "minimum": 5,
626
+ "type": "number",
627
+ }
628
+ `);
629
+ });
630
+
631
+ test("target normalization draft-04 and draft-07", () => {
632
+ // Test that both old (draft-4, draft-7) and new (draft-04, draft-07) target formats work
633
+ // Test draft-04 / draft-4
634
+ expect(z.toJSONSchema(z.number().gt(5), { target: "draft-04" })).toMatchInlineSnapshot(`
635
+ {
636
+ "$schema": "http://json-schema.org/draft-04/schema#",
637
+ "exclusiveMinimum": true,
638
+ "minimum": 5,
639
+ "type": "number",
640
+ }
641
+ `);
642
+ expect(z.toJSONSchema(z.number().gt(5), { target: "draft-4" })).toMatchInlineSnapshot(`
643
+ {
644
+ "$schema": "http://json-schema.org/draft-04/schema#",
645
+ "exclusiveMinimum": true,
646
+ "minimum": 5,
647
+ "type": "number",
648
+ }
649
+ `);
650
+ // Test draft-07 / draft-7
651
+ expect(z.toJSONSchema(z.number().gt(5), { target: "draft-07" })).toMatchInlineSnapshot(`
652
+ {
653
+ "$schema": "http://json-schema.org/draft-07/schema#",
654
+ "exclusiveMinimum": 5,
655
+ "type": "number",
656
+ }
657
+ `);
658
+ expect(z.toJSONSchema(z.number().gt(5), { target: "draft-7" })).toMatchInlineSnapshot(`
659
+ {
660
+ "$schema": "http://json-schema.org/draft-07/schema#",
661
+ "exclusiveMinimum": 5,
662
+ "type": "number",
663
+ }
664
+ `);
665
+ });
666
+
667
+ test("nullable openapi-3.0", () => {
668
+ const schema = z.string().nullable();
669
+ const jsonSchema = z.toJSONSchema(schema, { target: "openapi-3.0" });
670
+ validateOpenAPI30Schema(jsonSchema);
671
+ expect(jsonSchema).toMatchInlineSnapshot(`
672
+ {
673
+ "nullable": true,
674
+ "type": "string",
675
+ }
676
+ `);
677
+ });
678
+
679
+ test("union with null openapi-3.0", () => {
680
+ const schema = z.union([z.string(), z.null()]);
681
+ const jsonSchema = z.toJSONSchema(schema, { target: "openapi-3.0" });
682
+ validateOpenAPI30Schema(jsonSchema);
683
+ expect(jsonSchema).toMatchInlineSnapshot(`
684
+ {
685
+ "anyOf": [
686
+ {
687
+ "type": "string",
688
+ },
689
+ {
690
+ "enum": [
691
+ null,
692
+ ],
693
+ "nullable": true,
694
+ "type": "string",
695
+ },
696
+ ],
697
+ }
698
+ `);
699
+ });
700
+
701
+ test("number with exclusive min-max openapi-3.0", () => {
702
+ const schema = z.number().lt(100).gt(1);
703
+ const jsonSchema = z.toJSONSchema(schema, { target: "openapi-3.0" });
704
+ validateOpenAPI30Schema(jsonSchema);
705
+ expect(jsonSchema).toMatchInlineSnapshot(`
706
+ {
707
+ "exclusiveMaximum": true,
708
+ "exclusiveMinimum": true,
709
+ "maximum": 100,
710
+ "minimum": 1,
711
+ "type": "number",
712
+ }
713
+ `);
714
+ });
715
+
716
+ test("arrays", () => {
717
+ expect(z.toJSONSchema(z.array(z.string()))).toMatchInlineSnapshot(`
718
+ {
719
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
720
+ "items": {
721
+ "type": "string",
722
+ },
723
+ "type": "array",
724
+ }
725
+ `);
726
+ });
727
+
728
+ test("unions", () => {
729
+ const schema = z.union([z.string(), z.number()]);
730
+ expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
731
+ {
732
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
733
+ "anyOf": [
734
+ {
735
+ "type": "string",
736
+ },
737
+ {
738
+ "type": "number",
739
+ },
740
+ ],
741
+ }
742
+ `);
743
+ });
744
+
745
+ test("discriminated unions", () => {
746
+ const schema = z.discriminatedUnion("type", [
747
+ z.object({ type: z.literal("success"), data: z.string() }),
748
+ z.object({ type: z.literal("error"), message: z.string() }),
749
+ ]);
750
+ expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
751
+ {
752
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
753
+ "oneOf": [
754
+ {
755
+ "additionalProperties": false,
756
+ "properties": {
757
+ "data": {
758
+ "type": "string",
759
+ },
760
+ "type": {
761
+ "const": "success",
762
+ "type": "string",
763
+ },
764
+ },
765
+ "required": [
766
+ "type",
767
+ "data",
768
+ ],
769
+ "type": "object",
770
+ },
771
+ {
772
+ "additionalProperties": false,
773
+ "properties": {
774
+ "message": {
775
+ "type": "string",
776
+ },
777
+ "type": {
778
+ "const": "error",
779
+ "type": "string",
780
+ },
781
+ },
782
+ "required": [
783
+ "type",
784
+ "message",
785
+ ],
786
+ "type": "object",
787
+ },
788
+ ],
789
+ }
790
+ `);
791
+ });
792
+
793
+ test("intersections", () => {
794
+ const schema = z.intersection(z.object({ name: z.string() }), z.object({ age: z.number() }));
795
+
796
+ expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
797
+ {
798
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
799
+ "allOf": [
800
+ {
801
+ "additionalProperties": false,
802
+ "properties": {
803
+ "name": {
804
+ "type": "string",
805
+ },
806
+ },
807
+ "required": [
808
+ "name",
809
+ ],
810
+ "type": "object",
811
+ },
812
+ {
813
+ "additionalProperties": false,
814
+ "properties": {
815
+ "age": {
816
+ "type": "number",
817
+ },
818
+ },
819
+ "required": [
820
+ "age",
821
+ ],
822
+ "type": "object",
823
+ },
824
+ ],
825
+ }
826
+ `);
827
+ });
828
+
829
+ test("record", () => {
830
+ const schema = z.record(z.string(), z.boolean());
831
+ expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
832
+ {
833
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
834
+ "additionalProperties": {
835
+ "type": "boolean",
836
+ },
837
+ "propertyNames": {
838
+ "type": "string",
839
+ },
840
+ "type": "object",
841
+ }
842
+ `);
843
+ });
844
+
845
+ test("record openapi-3.0", () => {
846
+ const schema = z.record(z.string(), z.boolean());
847
+ const jsonSchema = z.toJSONSchema(schema, { target: "openapi-3.0" });
848
+ validateOpenAPI30Schema(jsonSchema);
849
+ expect(jsonSchema).toMatchInlineSnapshot(`
850
+ {
851
+ "additionalProperties": {
852
+ "type": "boolean",
853
+ },
854
+ "type": "object",
855
+ }
856
+ `);
857
+ });
858
+
859
+ test("tuple", () => {
860
+ const schema = z.tuple([z.string(), z.number()]);
861
+ expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
862
+ {
863
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
864
+ "prefixItems": [
865
+ {
866
+ "type": "string",
867
+ },
868
+ {
869
+ "type": "number",
870
+ },
871
+ ],
872
+ "type": "array",
873
+ }
874
+ `);
875
+ });
876
+
877
+ test("tuple with rest", () => {
878
+ const schema = z.tuple([z.string(), z.number()]).rest(z.boolean());
879
+ expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
880
+ {
881
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
882
+ "items": {
883
+ "type": "boolean",
884
+ },
885
+ "prefixItems": [
886
+ {
887
+ "type": "string",
888
+ },
889
+ {
890
+ "type": "number",
891
+ },
892
+ ],
893
+ "type": "array",
894
+ }
895
+ `);
896
+ });
897
+
898
+ test("tuple openapi-3.0", () => {
899
+ const schema = z.tuple([z.string(), z.number()]);
900
+ const jsonSchema = z.toJSONSchema(schema, { target: "openapi-3.0" });
901
+ validateOpenAPI30Schema(jsonSchema);
902
+ expect(jsonSchema).toMatchInlineSnapshot(`
903
+ {
904
+ "items": {
905
+ "anyOf": [
906
+ {
907
+ "type": "string",
908
+ },
909
+ {
910
+ "type": "number",
911
+ },
912
+ ],
913
+ },
914
+ "maxItems": 2,
915
+ "minItems": 2,
916
+ "type": "array",
917
+ }
918
+ `);
919
+ });
920
+
921
+ test("tuple with rest openapi-3.0", () => {
922
+ const schema = z.tuple([z.string(), z.number()]).rest(z.boolean());
923
+ const jsonSchema = z.toJSONSchema(schema, { target: "openapi-3.0" });
924
+ validateOpenAPI30Schema(jsonSchema);
925
+ expect(jsonSchema).toMatchInlineSnapshot(`
926
+ {
927
+ "items": {
928
+ "anyOf": [
929
+ {
930
+ "type": "string",
931
+ },
932
+ {
933
+ "type": "number",
934
+ },
935
+ {
936
+ "type": "boolean",
937
+ },
938
+ ],
939
+ },
940
+ "minItems": 3,
941
+ "type": "array",
942
+ }
943
+ `);
944
+ });
945
+
946
+ test("tuple with null openapi-3.0", () => {
947
+ const schema = z.tuple([z.string(), z.number(), z.null()]);
948
+ const jsonSchema = z.toJSONSchema(schema, { target: "openapi-3.0" });
949
+ validateOpenAPI30Schema(jsonSchema);
950
+ expect(jsonSchema).toMatchInlineSnapshot(`
951
+ {
952
+ "items": {
953
+ "anyOf": [
954
+ {
955
+ "type": "string",
956
+ },
957
+ {
958
+ "type": "number",
959
+ },
960
+ {
961
+ "enum": [
962
+ null,
963
+ ],
964
+ "nullable": true,
965
+ "type": "string",
966
+ },
967
+ ],
968
+ },
969
+ "maxItems": 3,
970
+ "minItems": 3,
971
+ "type": "array",
972
+ }
973
+ `);
974
+ });
975
+
976
+ test("tuple draft-7", () => {
977
+ const schema = z.tuple([z.string(), z.number()]);
978
+ expect(z.toJSONSchema(schema, { target: "draft-7", io: "input" })).toMatchInlineSnapshot(`
979
+ {
980
+ "$schema": "http://json-schema.org/draft-07/schema#",
981
+ "items": [
982
+ {
983
+ "type": "string",
984
+ },
985
+ {
986
+ "type": "number",
987
+ },
988
+ ],
989
+ "type": "array",
990
+ }
991
+ `);
992
+ });
993
+
994
+ test("tuple with rest draft-7", () => {
995
+ const schema = z.tuple([z.string(), z.number()]).rest(z.boolean());
996
+ expect(z.toJSONSchema(schema, { target: "draft-7", io: "input" })).toMatchInlineSnapshot(`
997
+ {
998
+ "$schema": "http://json-schema.org/draft-07/schema#",
999
+ "additionalItems": {
1000
+ "type": "boolean",
1001
+ },
1002
+ "items": [
1003
+ {
1004
+ "type": "string",
1005
+ },
1006
+ {
1007
+ "type": "number",
1008
+ },
1009
+ ],
1010
+ "type": "array",
1011
+ }
1012
+ `);
1013
+ });
1014
+
1015
+ test("tuple with rest draft-7 - issue #5151 regression test", () => {
1016
+ // This test addresses issue #5151: tuple with rest elements and ids
1017
+ // in draft-7 had incorrect internal path handling affecting complex scenarios
1018
+ const primarySchema = z.string().meta({ id: "primary" });
1019
+ const restSchema = z.number().meta({ id: "rest" });
1020
+ const testSchema = z.tuple([primarySchema], restSchema);
1021
+
1022
+ // Test both final output structure AND internal path handling
1023
+ const capturedPaths: string[] = [];
1024
+ const result = z.toJSONSchema(testSchema, {
1025
+ target: "draft-7",
1026
+ override: (ctx) => capturedPaths.push(ctx.path.join("/")),
1027
+ });
1028
+
1029
+ // Verify correct draft-7 structure with metadata extraction
1030
+ expect(result).toMatchInlineSnapshot(`
1031
+ {
1032
+ "$schema": "http://json-schema.org/draft-07/schema#",
1033
+ "additionalItems": {
1034
+ "$ref": "#/definitions/rest",
1035
+ },
1036
+ "definitions": {
1037
+ "primary": {
1038
+ "id": "primary",
1039
+ "type": "string",
1040
+ },
1041
+ "rest": {
1042
+ "id": "rest",
1043
+ "type": "number",
1044
+ },
1045
+ },
1046
+ "items": [
1047
+ {
1048
+ "$ref": "#/definitions/primary",
1049
+ },
1050
+ ],
1051
+ "type": "array",
1052
+ }
1053
+ `);
1054
+
1055
+ // Verify internal paths are correct (this was the actual bug)
1056
+ expect(capturedPaths).toContain("items/0"); // prefix items should use "items" path
1057
+ expect(capturedPaths).toContain("additionalItems"); // rest should use "additionalItems" path
1058
+ expect(capturedPaths).not.toContain("prefixItems/0"); // should not use draft-2020-12 paths
1059
+
1060
+ // Structural validations
1061
+ expect(Array.isArray(result.items)).toBe(true);
1062
+ expect(result.additionalItems).toBeDefined();
1063
+ });
1064
+
1065
+ test("promise", () => {
1066
+ const schema = z.promise(z.string());
1067
+ expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
1068
+ {
1069
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1070
+ "type": "string",
1071
+ }
1072
+ `);
1073
+ });
1074
+
1075
+ test("lazy", () => {
1076
+ const schema = z.lazy(() => z.string());
1077
+ expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
1078
+ {
1079
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1080
+ "type": "string",
1081
+ }
1082
+ `);
1083
+ });
1084
+
1085
+ // enum
1086
+ test("enum", () => {
1087
+ const a = z.enum(["a", "b", "c"]);
1088
+ expect(z.toJSONSchema(a)).toMatchInlineSnapshot(`
1089
+ {
1090
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1091
+ "enum": [
1092
+ "a",
1093
+ "b",
1094
+ "c",
1095
+ ],
1096
+ "type": "string",
1097
+ }
1098
+ `);
1099
+
1100
+ enum B {
1101
+ A = 0,
1102
+ B = 1,
1103
+ C = 2,
1104
+ }
1105
+
1106
+ const b = z.enum(B);
1107
+ expect(z.toJSONSchema(b)).toMatchInlineSnapshot(`
1108
+ {
1109
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1110
+ "enum": [
1111
+ 0,
1112
+ 1,
1113
+ 2,
1114
+ ],
1115
+ "type": "number",
1116
+ }
1117
+ `);
1118
+ });
1119
+
1120
+ // literal
1121
+ test("literal", () => {
1122
+ const a = z.literal("hello");
1123
+ expect(z.toJSONSchema(a)).toMatchInlineSnapshot(`
1124
+ {
1125
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1126
+ "const": "hello",
1127
+ "type": "string",
1128
+ }
1129
+ `);
1130
+
1131
+ const b = z.literal(7);
1132
+ expect(z.toJSONSchema(b)).toMatchInlineSnapshot(`
1133
+ {
1134
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1135
+ "const": 7,
1136
+ "type": "number",
1137
+ }
1138
+ `);
1139
+
1140
+ const c = z.literal(["hello", undefined, null, 5, BigInt(1324)]);
1141
+ expect(() => z.toJSONSchema(c)).toThrow();
1142
+
1143
+ const d = z.literal(["hello", null, 5]);
1144
+ expect(z.toJSONSchema(d)).toMatchInlineSnapshot(`
1145
+ {
1146
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1147
+ "enum": [
1148
+ "hello",
1149
+ null,
1150
+ 5,
1151
+ ],
1152
+ }
1153
+ `);
1154
+
1155
+ const e = z.literal(["hello", "zod", "v4"]);
1156
+ expect(z.toJSONSchema(e)).toMatchInlineSnapshot(`
1157
+ {
1158
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1159
+ "enum": [
1160
+ "hello",
1161
+ "zod",
1162
+ "v4",
1163
+ ],
1164
+ "type": "string",
1165
+ }
1166
+ `);
1167
+ });
1168
+
1169
+ test("literal draft-4", () => {
1170
+ const a = z.literal("hello");
1171
+ expect(z.toJSONSchema(a, { target: "draft-4" })).toMatchInlineSnapshot(`
1172
+ {
1173
+ "$schema": "http://json-schema.org/draft-04/schema#",
1174
+ "enum": [
1175
+ "hello",
1176
+ ],
1177
+ "type": "string",
1178
+ }
1179
+ `);
1180
+ });
1181
+
1182
+ // pipe
1183
+ test("pipe", () => {
1184
+ const schema = z
1185
+ .string()
1186
+ .transform((val) => Number.parseInt(val))
1187
+ .pipe(z.number());
1188
+ expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
1189
+ {
1190
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1191
+ "type": "number",
1192
+ }
1193
+ `);
1194
+ });
1195
+
1196
+ test("simple objects", () => {
1197
+ const schema = z.object({
1198
+ name: z.string(),
1199
+ age: z.number(),
1200
+ });
1201
+
1202
+ expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(
1203
+ `
1204
+ {
1205
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1206
+ "additionalProperties": false,
1207
+ "properties": {
1208
+ "age": {
1209
+ "type": "number",
1210
+ },
1211
+ "name": {
1212
+ "type": "string",
1213
+ },
1214
+ },
1215
+ "required": [
1216
+ "name",
1217
+ "age",
1218
+ ],
1219
+ "type": "object",
1220
+ }
1221
+ `
1222
+ );
1223
+ });
1224
+
1225
+ test("additionalproperties in z.object", () => {
1226
+ const a = z.object({
1227
+ name: z.string(),
1228
+ });
1229
+ expect(z.toJSONSchema(a)).toMatchInlineSnapshot(`
1230
+ {
1231
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1232
+ "additionalProperties": false,
1233
+ "properties": {
1234
+ "name": {
1235
+ "type": "string",
1236
+ },
1237
+ },
1238
+ "required": [
1239
+ "name",
1240
+ ],
1241
+ "type": "object",
1242
+ }
1243
+ `);
1244
+ expect(z.toJSONSchema(a, { io: "input" })).toMatchInlineSnapshot(`
1245
+ {
1246
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1247
+ "properties": {
1248
+ "name": {
1249
+ "type": "string",
1250
+ },
1251
+ },
1252
+ "required": [
1253
+ "name",
1254
+ ],
1255
+ "type": "object",
1256
+ }
1257
+ `);
1258
+ expect(
1259
+ z.toJSONSchema(a, {
1260
+ io: "input",
1261
+ override(ctx) {
1262
+ const def = ctx.zodSchema._zod.def;
1263
+ if (def.type === "object" && !def.catchall) {
1264
+ (ctx.jsonSchema as z.core.JSONSchema.ObjectSchema).additionalProperties = false;
1265
+ }
1266
+ },
1267
+ })
1268
+ ).toMatchInlineSnapshot(`
1269
+ {
1270
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1271
+ "additionalProperties": false,
1272
+ "properties": {
1273
+ "name": {
1274
+ "type": "string",
1275
+ },
1276
+ },
1277
+ "required": [
1278
+ "name",
1279
+ ],
1280
+ "type": "object",
1281
+ }
1282
+ `);
1283
+ });
1284
+
1285
+ test("catchall objects", () => {
1286
+ const a = z.strictObject({
1287
+ name: z.string(),
1288
+ age: z.number(),
1289
+ });
1290
+
1291
+ expect(z.toJSONSchema(a)).toMatchInlineSnapshot(`
1292
+ {
1293
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1294
+ "additionalProperties": false,
1295
+ "properties": {
1296
+ "age": {
1297
+ "type": "number",
1298
+ },
1299
+ "name": {
1300
+ "type": "string",
1301
+ },
1302
+ },
1303
+ "required": [
1304
+ "name",
1305
+ "age",
1306
+ ],
1307
+ "type": "object",
1308
+ }
1309
+ `);
1310
+
1311
+ const b = z
1312
+ .object({
1313
+ name: z.string(),
1314
+ })
1315
+ .catchall(z.string());
1316
+
1317
+ expect(z.toJSONSchema(b)).toMatchInlineSnapshot(`
1318
+ {
1319
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1320
+ "additionalProperties": {
1321
+ "type": "string",
1322
+ },
1323
+ "properties": {
1324
+ "name": {
1325
+ "type": "string",
1326
+ },
1327
+ },
1328
+ "required": [
1329
+ "name",
1330
+ ],
1331
+ "type": "object",
1332
+ }
1333
+ `);
1334
+
1335
+ const c = z.looseObject({
1336
+ name: z.string(),
1337
+ });
1338
+
1339
+ expect(z.toJSONSchema(c)).toMatchInlineSnapshot(`
1340
+ {
1341
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1342
+ "additionalProperties": {},
1343
+ "properties": {
1344
+ "name": {
1345
+ "type": "string",
1346
+ },
1347
+ },
1348
+ "required": [
1349
+ "name",
1350
+ ],
1351
+ "type": "object",
1352
+ }
1353
+ `);
1354
+ });
1355
+
1356
+ test("optional fields - object", () => {
1357
+ const schema = z.object({
1358
+ required: z.string(),
1359
+ optional: z.string().optional(),
1360
+ nonoptional: z.string().optional().nonoptional(),
1361
+ });
1362
+
1363
+ const result = z.toJSONSchema(schema);
1364
+
1365
+ expect(result).toMatchInlineSnapshot(`
1366
+ {
1367
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1368
+ "additionalProperties": false,
1369
+ "properties": {
1370
+ "nonoptional": {
1371
+ "type": "string",
1372
+ },
1373
+ "optional": {
1374
+ "type": "string",
1375
+ },
1376
+ "required": {
1377
+ "type": "string",
1378
+ },
1379
+ },
1380
+ "required": [
1381
+ "required",
1382
+ "nonoptional",
1383
+ ],
1384
+ "type": "object",
1385
+ }
1386
+ `);
1387
+ });
1388
+
1389
+ test("recursive object", () => {
1390
+ interface Category {
1391
+ name: string;
1392
+ subcategories: Category[];
1393
+ }
1394
+
1395
+ const categorySchema: z.ZodType<Category> = z.object({
1396
+ name: z.string(),
1397
+ subcategories: z.array(z.lazy(() => categorySchema)),
1398
+ });
1399
+
1400
+ const result = z.toJSONSchema(categorySchema);
1401
+ expect(result).toMatchInlineSnapshot(`
1402
+ {
1403
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1404
+ "additionalProperties": false,
1405
+ "properties": {
1406
+ "name": {
1407
+ "type": "string",
1408
+ },
1409
+ "subcategories": {
1410
+ "items": {
1411
+ "$ref": "#",
1412
+ },
1413
+ "type": "array",
1414
+ },
1415
+ },
1416
+ "required": [
1417
+ "name",
1418
+ "subcategories",
1419
+ ],
1420
+ "type": "object",
1421
+ }
1422
+ `);
1423
+ });
1424
+
1425
+ test("simple interface", () => {
1426
+ const userSchema = z.object({
1427
+ name: z.string(),
1428
+ age: z.number().optional(),
1429
+ });
1430
+
1431
+ const result = z.toJSONSchema(userSchema);
1432
+ expect(result).toMatchInlineSnapshot(`
1433
+ {
1434
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1435
+ "additionalProperties": false,
1436
+ "properties": {
1437
+ "age": {
1438
+ "type": "number",
1439
+ },
1440
+ "name": {
1441
+ "type": "string",
1442
+ },
1443
+ },
1444
+ "required": [
1445
+ "name",
1446
+ ],
1447
+ "type": "object",
1448
+ }
1449
+ `);
1450
+ });
1451
+
1452
+ test("catchall interface", () => {
1453
+ const a = z.strictObject({
1454
+ name: z.string(),
1455
+ age: z.number(),
1456
+ });
1457
+
1458
+ expect(z.toJSONSchema(a)).toMatchInlineSnapshot(`
1459
+ {
1460
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1461
+ "additionalProperties": false,
1462
+ "properties": {
1463
+ "age": {
1464
+ "type": "number",
1465
+ },
1466
+ "name": {
1467
+ "type": "string",
1468
+ },
1469
+ },
1470
+ "required": [
1471
+ "name",
1472
+ "age",
1473
+ ],
1474
+ "type": "object",
1475
+ }
1476
+ `);
1477
+
1478
+ const b = z
1479
+ .object({
1480
+ name: z.string(),
1481
+ })
1482
+ .catchall(z.string());
1483
+
1484
+ expect(z.toJSONSchema(b)).toMatchInlineSnapshot(`
1485
+ {
1486
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1487
+ "additionalProperties": {
1488
+ "type": "string",
1489
+ },
1490
+ "properties": {
1491
+ "name": {
1492
+ "type": "string",
1493
+ },
1494
+ },
1495
+ "required": [
1496
+ "name",
1497
+ ],
1498
+ "type": "object",
1499
+ }
1500
+ `);
1501
+
1502
+ const c = z.looseObject({
1503
+ name: z.string(),
1504
+ });
1505
+
1506
+ expect(z.toJSONSchema(c)).toMatchInlineSnapshot(`
1507
+ {
1508
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1509
+ "additionalProperties": {},
1510
+ "properties": {
1511
+ "name": {
1512
+ "type": "string",
1513
+ },
1514
+ },
1515
+ "required": [
1516
+ "name",
1517
+ ],
1518
+ "type": "object",
1519
+ }
1520
+ `);
1521
+ });
1522
+
1523
+ test("recursive interface schemas", () => {
1524
+ const TreeNodeSchema = z.object({
1525
+ id: z.string(),
1526
+ get children() {
1527
+ return TreeNodeSchema;
1528
+ },
1529
+ });
1530
+
1531
+ const result = z.toJSONSchema(TreeNodeSchema);
1532
+
1533
+ // Should have definitions for recursive schema
1534
+ expect(JSON.stringify(result, null, 2)).toMatchInlineSnapshot(
1535
+ `
1536
+ "{
1537
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1538
+ "type": "object",
1539
+ "properties": {
1540
+ "id": {
1541
+ "type": "string"
1542
+ },
1543
+ "children": {
1544
+ "$ref": "#"
1545
+ }
1546
+ },
1547
+ "required": [
1548
+ "id",
1549
+ "children"
1550
+ ],
1551
+ "additionalProperties": false
1552
+ }"
1553
+ `
1554
+ );
1555
+ });
1556
+
1557
+ test("mutually recursive interface schemas", () => {
1558
+ const FolderSchema = z.object({
1559
+ name: z.string(),
1560
+ get files() {
1561
+ return z.array(FileSchema);
1562
+ },
1563
+ });
1564
+
1565
+ const FileSchema = z.object({
1566
+ name: z.string(),
1567
+ get parent() {
1568
+ return FolderSchema;
1569
+ },
1570
+ });
1571
+
1572
+ const result = z.toJSONSchema(FolderSchema);
1573
+
1574
+ // Should have definitions for both schemas
1575
+ expect(JSON.stringify(result, null, 2)).toMatchInlineSnapshot(
1576
+ `
1577
+ "{
1578
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1579
+ "type": "object",
1580
+ "properties": {
1581
+ "name": {
1582
+ "type": "string"
1583
+ },
1584
+ "files": {
1585
+ "type": "array",
1586
+ "items": {
1587
+ "type": "object",
1588
+ "properties": {
1589
+ "name": {
1590
+ "type": "string"
1591
+ },
1592
+ "parent": {
1593
+ "$ref": "#"
1594
+ }
1595
+ },
1596
+ "required": [
1597
+ "name",
1598
+ "parent"
1599
+ ],
1600
+ "additionalProperties": false
1601
+ }
1602
+ }
1603
+ },
1604
+ "required": [
1605
+ "name",
1606
+ "files"
1607
+ ],
1608
+ "additionalProperties": false
1609
+ }"
1610
+ `
1611
+ );
1612
+ });
1613
+ });
1614
+
1615
+ test("override", () => {
1616
+ const schema = z.toJSONSchema(z.string(), {
1617
+ override: (ctx) => {
1618
+ ctx.zodSchema;
1619
+ ctx.jsonSchema;
1620
+ ctx.jsonSchema.whatever = "sup";
1621
+ },
1622
+ });
1623
+ expect(schema).toMatchInlineSnapshot(`
1624
+ {
1625
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1626
+ "type": "string",
1627
+ "whatever": "sup",
1628
+ }
1629
+ `);
1630
+ });
1631
+
1632
+ test("override: do not run on references", () => {
1633
+ let overrideCount = 0;
1634
+ const schema = z
1635
+ .union([z.string().date(), z.string().datetime(), z.string().datetime({ local: true })])
1636
+ .meta({ a: true })
1637
+ .transform((str) => new Date(str))
1638
+ .meta({ b: true })
1639
+ .pipe(z.date())
1640
+ .meta({ c: true })
1641
+ .brand("dateIn");
1642
+ z.toJSONSchema(schema, {
1643
+ unrepresentable: "any",
1644
+ io: "input",
1645
+ override(_) {
1646
+ overrideCount++;
1647
+ },
1648
+ });
1649
+
1650
+ expect(overrideCount).toBe(6);
1651
+ });
1652
+
1653
+ test("override with refs", () => {
1654
+ const a = z.string().optional();
1655
+ const result = z.toJSONSchema(a, {
1656
+ override(ctx) {
1657
+ if (ctx.zodSchema._zod.def.type === "string") {
1658
+ ctx.jsonSchema.type = "STRING" as "string";
1659
+ }
1660
+ },
1661
+ });
1662
+
1663
+ expect(result).toMatchInlineSnapshot(`
1664
+ {
1665
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1666
+ "type": "STRING",
1667
+ }
1668
+ `);
1669
+ });
1670
+
1671
+ test("override execution order", () => {
1672
+ const schema = z.union([z.string(), z.number()]);
1673
+ let unionSchema!: any;
1674
+ z.toJSONSchema(schema, {
1675
+ override(ctx) {
1676
+ if (ctx.zodSchema._zod.def.type === "union") {
1677
+ unionSchema = ctx.jsonSchema;
1678
+ }
1679
+ },
1680
+ });
1681
+
1682
+ expect(unionSchema).toMatchInlineSnapshot(`
1683
+ {
1684
+ "anyOf": [
1685
+ {
1686
+ "type": "string",
1687
+ },
1688
+ {
1689
+ "type": "number",
1690
+ },
1691
+ ],
1692
+ }
1693
+ `);
1694
+ });
1695
+
1696
+ test("override with path", () => {
1697
+ const userSchema = z.object({
1698
+ name: z.string(),
1699
+ age: z.number(),
1700
+ });
1701
+
1702
+ const capturedPaths: (string | number)[][] = [];
1703
+
1704
+ z.toJSONSchema(userSchema, {
1705
+ override(ctx) {
1706
+ capturedPaths.push(ctx.path);
1707
+ },
1708
+ });
1709
+
1710
+ expect(capturedPaths).toMatchInlineSnapshot(`
1711
+ [
1712
+ [
1713
+ "properties",
1714
+ "age",
1715
+ ],
1716
+ [
1717
+ "properties",
1718
+ "name",
1719
+ ],
1720
+ [],
1721
+ ]
1722
+ `);
1723
+ });
1724
+
1725
+ test("pipe", () => {
1726
+ const mySchema = z
1727
+ .string()
1728
+ .transform((val) => val.length)
1729
+ .pipe(z.number());
1730
+ // ZodPipe
1731
+
1732
+ const a = z.toJSONSchema(mySchema);
1733
+ expect(a).toMatchInlineSnapshot(`
1734
+ {
1735
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1736
+ "type": "number",
1737
+ }
1738
+ `);
1739
+ // => { type: "number" }
1740
+
1741
+ const b = z.toJSONSchema(mySchema, { io: "input" });
1742
+ expect(b).toMatchInlineSnapshot(`
1743
+ {
1744
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1745
+ "type": "string",
1746
+ }
1747
+ `);
1748
+ // => { type: "string" }
1749
+ });
1750
+
1751
+ test("passthrough schemas", () => {
1752
+ const Internal = z.object({
1753
+ num: z.number(),
1754
+ str: z.string(),
1755
+ });
1756
+ //.meta({ id: "Internal" });
1757
+
1758
+ const External = z.object({
1759
+ a: Internal,
1760
+ b: Internal.optional(),
1761
+ c: z.lazy(() => Internal),
1762
+ d: z.promise(Internal),
1763
+ e: z.pipe(Internal, Internal),
1764
+ });
1765
+
1766
+ const result = z.toJSONSchema(External, {
1767
+ reused: "ref",
1768
+ });
1769
+ expect(result).toMatchInlineSnapshot(`
1770
+ {
1771
+ "$defs": {
1772
+ "__schema0": {
1773
+ "additionalProperties": false,
1774
+ "properties": {
1775
+ "num": {
1776
+ "type": "number",
1777
+ },
1778
+ "str": {
1779
+ "type": "string",
1780
+ },
1781
+ },
1782
+ "required": [
1783
+ "num",
1784
+ "str",
1785
+ ],
1786
+ "type": "object",
1787
+ },
1788
+ },
1789
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1790
+ "additionalProperties": false,
1791
+ "properties": {
1792
+ "a": {
1793
+ "$ref": "#/$defs/__schema0",
1794
+ },
1795
+ "b": {
1796
+ "$ref": "#/$defs/__schema0",
1797
+ },
1798
+ "c": {
1799
+ "$ref": "#/$defs/__schema0",
1800
+ },
1801
+ "d": {
1802
+ "$ref": "#/$defs/__schema0",
1803
+ },
1804
+ "e": {
1805
+ "$ref": "#/$defs/__schema0",
1806
+ },
1807
+ },
1808
+ "required": [
1809
+ "a",
1810
+ "c",
1811
+ "d",
1812
+ "e",
1813
+ ],
1814
+ "type": "object",
1815
+ }
1816
+ `);
1817
+ });
1818
+
1819
+ test("extract schemas with id", () => {
1820
+ const name = z.string().meta({ id: "name" });
1821
+ const result = z.toJSONSchema(
1822
+ z.object({
1823
+ first_name: name,
1824
+ last_name: name.nullable(),
1825
+ middle_name: name.optional(),
1826
+ age: z.number().meta({ id: "age" }),
1827
+ })
1828
+ );
1829
+ expect(result).toMatchInlineSnapshot(`
1830
+ {
1831
+ "$defs": {
1832
+ "age": {
1833
+ "id": "age",
1834
+ "type": "number",
1835
+ },
1836
+ "name": {
1837
+ "id": "name",
1838
+ "type": "string",
1839
+ },
1840
+ },
1841
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1842
+ "additionalProperties": false,
1843
+ "properties": {
1844
+ "age": {
1845
+ "$ref": "#/$defs/age",
1846
+ },
1847
+ "first_name": {
1848
+ "$ref": "#/$defs/name",
1849
+ },
1850
+ "last_name": {
1851
+ "anyOf": [
1852
+ {
1853
+ "$ref": "#/$defs/name",
1854
+ },
1855
+ {
1856
+ "type": "null",
1857
+ },
1858
+ ],
1859
+ },
1860
+ "middle_name": {
1861
+ "$ref": "#/$defs/name",
1862
+ },
1863
+ },
1864
+ "required": [
1865
+ "first_name",
1866
+ "last_name",
1867
+ "age",
1868
+ ],
1869
+ "type": "object",
1870
+ }
1871
+ `);
1872
+ });
1873
+
1874
+ test("unrepresentable literal values are ignored", () => {
1875
+ const a = z.toJSONSchema(z.literal(["hello", null, 5, BigInt(1324), undefined]), { unrepresentable: "any" });
1876
+ expect(a).toMatchInlineSnapshot(`
1877
+ {
1878
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1879
+ "enum": [
1880
+ "hello",
1881
+ null,
1882
+ 5,
1883
+ 1324,
1884
+ ],
1885
+ }
1886
+ `);
1887
+
1888
+ const b = z.toJSONSchema(z.literal([undefined, null, 5, BigInt(1324)]), {
1889
+ unrepresentable: "any",
1890
+ });
1891
+ expect(b).toMatchInlineSnapshot(`
1892
+ {
1893
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1894
+ "enum": [
1895
+ null,
1896
+ 5,
1897
+ 1324,
1898
+ ],
1899
+ }
1900
+ `);
1901
+
1902
+ const c = z.toJSONSchema(z.literal([undefined]), {
1903
+ unrepresentable: "any",
1904
+ });
1905
+ expect(c).toMatchInlineSnapshot(`
1906
+ {
1907
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1908
+ }
1909
+ `);
1910
+ });
1911
+
1912
+ test("describe with id", () => {
1913
+ const jobId = z.string().meta({ id: "jobId" });
1914
+
1915
+ const a = z.toJSONSchema(
1916
+ z.object({
1917
+ current: jobId.describe("Current job"),
1918
+ previous: jobId.describe("Previous job"),
1919
+ })
1920
+ );
1921
+ expect(a).toMatchInlineSnapshot(`
1922
+ {
1923
+ "$defs": {
1924
+ "jobId": {
1925
+ "id": "jobId",
1926
+ "type": "string",
1927
+ },
1928
+ },
1929
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1930
+ "additionalProperties": false,
1931
+ "properties": {
1932
+ "current": {
1933
+ "$ref": "#/$defs/jobId",
1934
+ "description": "Current job",
1935
+ },
1936
+ "previous": {
1937
+ "$ref": "#/$defs/jobId",
1938
+ "description": "Previous job",
1939
+ },
1940
+ },
1941
+ "required": [
1942
+ "current",
1943
+ "previous",
1944
+ ],
1945
+ "type": "object",
1946
+ }
1947
+ `);
1948
+ });
1949
+
1950
+ test("overwrite id", () => {
1951
+ const jobId = z.string().meta({ id: "aaa" });
1952
+
1953
+ const a = z.toJSONSchema(
1954
+ z.object({
1955
+ current: jobId,
1956
+ previous: jobId.meta({ id: "bbb" }),
1957
+ })
1958
+ );
1959
+ expect(a).toMatchInlineSnapshot(`
1960
+ {
1961
+ "$defs": {
1962
+ "aaa": {
1963
+ "id": "aaa",
1964
+ "type": "string",
1965
+ },
1966
+ "bbb": {
1967
+ "$ref": "#/$defs/aaa",
1968
+ "id": "bbb",
1969
+ },
1970
+ },
1971
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1972
+ "additionalProperties": false,
1973
+ "properties": {
1974
+ "current": {
1975
+ "$ref": "#/$defs/aaa",
1976
+ },
1977
+ "previous": {
1978
+ "$ref": "#/$defs/bbb",
1979
+ },
1980
+ },
1981
+ "required": [
1982
+ "current",
1983
+ "previous",
1984
+ ],
1985
+ "type": "object",
1986
+ }
1987
+ `);
1988
+
1989
+ const b = z.toJSONSchema(
1990
+ z.object({
1991
+ current: jobId,
1992
+ previous: jobId.meta({ id: "ccc" }),
1993
+ }),
1994
+ {
1995
+ reused: "ref",
1996
+ }
1997
+ );
1998
+ expect(b).toMatchInlineSnapshot(`
1999
+ {
2000
+ "$defs": {
2001
+ "aaa": {
2002
+ "id": "aaa",
2003
+ "type": "string",
2004
+ },
2005
+ "ccc": {
2006
+ "$ref": "#/$defs/aaa",
2007
+ "id": "ccc",
2008
+ },
2009
+ },
2010
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2011
+ "additionalProperties": false,
2012
+ "properties": {
2013
+ "current": {
2014
+ "$ref": "#/$defs/aaa",
2015
+ },
2016
+ "previous": {
2017
+ "$ref": "#/$defs/ccc",
2018
+ },
2019
+ },
2020
+ "required": [
2021
+ "current",
2022
+ "previous",
2023
+ ],
2024
+ "type": "object",
2025
+ }
2026
+ `);
2027
+ });
2028
+
2029
+ test("overwrite descriptions", () => {
2030
+ const field = z.string().describe("a").describe("b").describe("c");
2031
+
2032
+ const a = z.toJSONSchema(
2033
+ z.object({
2034
+ d: field.describe("d"),
2035
+ e: field.describe("e"),
2036
+ })
2037
+ );
2038
+ expect(a).toMatchInlineSnapshot(`
2039
+ {
2040
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2041
+ "additionalProperties": false,
2042
+ "properties": {
2043
+ "d": {
2044
+ "description": "d",
2045
+ "type": "string",
2046
+ },
2047
+ "e": {
2048
+ "description": "e",
2049
+ "type": "string",
2050
+ },
2051
+ },
2052
+ "required": [
2053
+ "d",
2054
+ "e",
2055
+ ],
2056
+ "type": "object",
2057
+ }
2058
+ `);
2059
+
2060
+ const b = z.toJSONSchema(
2061
+ z.object({
2062
+ d: field.describe("d"),
2063
+ e: field.describe("e"),
2064
+ }),
2065
+ {
2066
+ reused: "ref",
2067
+ }
2068
+ );
2069
+ expect(b).toMatchInlineSnapshot(`
2070
+ {
2071
+ "$defs": {
2072
+ "__schema0": {
2073
+ "description": "c",
2074
+ "type": "string",
2075
+ },
2076
+ },
2077
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2078
+ "additionalProperties": false,
2079
+ "properties": {
2080
+ "d": {
2081
+ "$ref": "#/$defs/__schema0",
2082
+ "description": "d",
2083
+ },
2084
+ "e": {
2085
+ "$ref": "#/$defs/__schema0",
2086
+ "description": "e",
2087
+ },
2088
+ },
2089
+ "required": [
2090
+ "d",
2091
+ "e",
2092
+ ],
2093
+ "type": "object",
2094
+ }
2095
+ `);
2096
+ });
2097
+
2098
+ test("top-level readonly", () => {
2099
+ const A = z
2100
+ .object({
2101
+ name: z.string(),
2102
+ get b() {
2103
+ return B;
2104
+ },
2105
+ })
2106
+ .readonly()
2107
+ .meta({ id: "A" });
2108
+ // z.globalRegistry.add(A, { id: "A" });
2109
+ // .meta({ id: "A" });
2110
+
2111
+ const B = z
2112
+ .object({
2113
+ name: z.string(),
2114
+ get a() {
2115
+ return A;
2116
+ },
2117
+ })
2118
+ .readonly()
2119
+ .meta({ id: "B" });
2120
+ // z.globalRegistry.add(B, { id: "B" });
2121
+ // .meta({ id: "B" });
2122
+
2123
+ const result = z.toJSONSchema(A);
2124
+ expect(result).toMatchInlineSnapshot(`
2125
+ {
2126
+ "$defs": {
2127
+ "B": {
2128
+ "additionalProperties": false,
2129
+ "id": "B",
2130
+ "properties": {
2131
+ "a": {
2132
+ "$ref": "#",
2133
+ },
2134
+ "name": {
2135
+ "type": "string",
2136
+ },
2137
+ },
2138
+ "readOnly": true,
2139
+ "required": [
2140
+ "name",
2141
+ "a",
2142
+ ],
2143
+ "type": "object",
2144
+ },
2145
+ },
2146
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2147
+ "additionalProperties": false,
2148
+ "id": "A",
2149
+ "properties": {
2150
+ "b": {
2151
+ "$ref": "#/$defs/B",
2152
+ },
2153
+ "name": {
2154
+ "type": "string",
2155
+ },
2156
+ },
2157
+ "readOnly": true,
2158
+ "required": [
2159
+ "name",
2160
+ "b",
2161
+ ],
2162
+ "type": "object",
2163
+ }
2164
+ `);
2165
+ });
2166
+
2167
+ test("basic registry", () => {
2168
+ const myRegistry = z.registry<{ id: string }>();
2169
+ const User = z.object({
2170
+ name: z.string(),
2171
+ get posts() {
2172
+ return z.array(Post);
2173
+ },
2174
+ });
2175
+
2176
+ const Post = z.object({
2177
+ title: z.string(),
2178
+ content: z.string(),
2179
+ get author() {
2180
+ return User;
2181
+ },
2182
+ });
2183
+
2184
+ myRegistry.add(User, { id: "User" });
2185
+ myRegistry.add(Post, { id: "Post" });
2186
+
2187
+ const result = z.toJSONSchema(myRegistry, {
2188
+ uri: (id) => `https://example.com/${id}.json`,
2189
+ });
2190
+ expect(result).toMatchInlineSnapshot(`
2191
+ {
2192
+ "schemas": {
2193
+ "Post": {
2194
+ "$id": "https://example.com/Post.json",
2195
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2196
+ "additionalProperties": false,
2197
+ "properties": {
2198
+ "author": {
2199
+ "$ref": "https://example.com/User.json",
2200
+ },
2201
+ "content": {
2202
+ "type": "string",
2203
+ },
2204
+ "title": {
2205
+ "type": "string",
2206
+ },
2207
+ },
2208
+ "required": [
2209
+ "title",
2210
+ "content",
2211
+ "author",
2212
+ ],
2213
+ "type": "object",
2214
+ },
2215
+ "User": {
2216
+ "$id": "https://example.com/User.json",
2217
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2218
+ "additionalProperties": false,
2219
+ "properties": {
2220
+ "name": {
2221
+ "type": "string",
2222
+ },
2223
+ "posts": {
2224
+ "items": {
2225
+ "$ref": "https://example.com/Post.json",
2226
+ },
2227
+ "type": "array",
2228
+ },
2229
+ },
2230
+ "required": [
2231
+ "name",
2232
+ "posts",
2233
+ ],
2234
+ "type": "object",
2235
+ },
2236
+ },
2237
+ }
2238
+ `);
2239
+ });
2240
+
2241
+ test("_ref", () => {
2242
+ // const a = z.promise(z.string().describe("a"));
2243
+ const a = z.toJSONSchema(z.promise(z.string().describe("a")));
2244
+ expect(a).toMatchInlineSnapshot(`
2245
+ {
2246
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2247
+ "description": "a",
2248
+ "type": "string",
2249
+ }
2250
+ `);
2251
+
2252
+ const b = z.toJSONSchema(z.lazy(() => z.string().describe("a")));
2253
+ expect(b).toMatchInlineSnapshot(`
2254
+ {
2255
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2256
+ "description": "a",
2257
+ "type": "string",
2258
+ }
2259
+ `);
2260
+
2261
+ const c = z.toJSONSchema(z.optional(z.string().describe("a")));
2262
+ expect(c).toMatchInlineSnapshot(`
2263
+ {
2264
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2265
+ "description": "a",
2266
+ "type": "string",
2267
+ }
2268
+ `);
2269
+ });
2270
+
2271
+ test("defaults/prefaults", () => {
2272
+ const a = z
2273
+ .string()
2274
+ .transform((val) => val.length)
2275
+ .pipe(z.number());
2276
+ const b = a.prefault("hello");
2277
+ const c = a.default(1234);
2278
+
2279
+ // a
2280
+ expect(z.toJSONSchema(a)).toMatchInlineSnapshot(`
2281
+ {
2282
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2283
+ "type": "number",
2284
+ }
2285
+ `);
2286
+ expect(z.toJSONSchema(a, { io: "input" })).toMatchInlineSnapshot(`
2287
+ {
2288
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2289
+ "type": "string",
2290
+ }
2291
+ `);
2292
+
2293
+ // b
2294
+ expect(z.toJSONSchema(b)).toMatchInlineSnapshot(`
2295
+ {
2296
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2297
+ "type": "number",
2298
+ }
2299
+ `);
2300
+ expect(z.toJSONSchema(b, { io: "input" })).toMatchInlineSnapshot(`
2301
+ {
2302
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2303
+ "default": "hello",
2304
+ "type": "string",
2305
+ }
2306
+ `);
2307
+ // c
2308
+ expect(z.toJSONSchema(c)).toMatchInlineSnapshot(`
2309
+ {
2310
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2311
+ "default": 1234,
2312
+ "type": "number",
2313
+ }
2314
+ `);
2315
+ expect(z.toJSONSchema(c, { io: "input" })).toMatchInlineSnapshot(`
2316
+ {
2317
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2318
+ "type": "string",
2319
+ }
2320
+ `);
2321
+ });
2322
+
2323
+ test("input type", () => {
2324
+ const schema = z.object({
2325
+ a: z.string(),
2326
+ b: z.string().optional(),
2327
+ c: z.string().default("hello"),
2328
+ d: z.string().nullable(),
2329
+ e: z.string().prefault("hello"),
2330
+ f: z.string().catch("hello"),
2331
+ g: z.never(),
2332
+ h: z.union([z.string(), z.number().default(2)]),
2333
+ i: z.union([z.string(), z.string().optional()]),
2334
+ });
2335
+ expect(z.toJSONSchema(schema, { io: "input" })).toMatchInlineSnapshot(`
2336
+ {
2337
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2338
+ "properties": {
2339
+ "a": {
2340
+ "type": "string",
2341
+ },
2342
+ "b": {
2343
+ "type": "string",
2344
+ },
2345
+ "c": {
2346
+ "default": "hello",
2347
+ "type": "string",
2348
+ },
2349
+ "d": {
2350
+ "anyOf": [
2351
+ {
2352
+ "type": "string",
2353
+ },
2354
+ {
2355
+ "type": "null",
2356
+ },
2357
+ ],
2358
+ },
2359
+ "e": {
2360
+ "default": "hello",
2361
+ "type": "string",
2362
+ },
2363
+ "f": {
2364
+ "default": "hello",
2365
+ "type": "string",
2366
+ },
2367
+ "g": {
2368
+ "not": {},
2369
+ },
2370
+ "h": {
2371
+ "anyOf": [
2372
+ {
2373
+ "type": "string",
2374
+ },
2375
+ {
2376
+ "default": 2,
2377
+ "type": "number",
2378
+ },
2379
+ ],
2380
+ },
2381
+ "i": {
2382
+ "anyOf": [
2383
+ {
2384
+ "type": "string",
2385
+ },
2386
+ {
2387
+ "type": "string",
2388
+ },
2389
+ ],
2390
+ },
2391
+ },
2392
+ "required": [
2393
+ "a",
2394
+ "d",
2395
+ "f",
2396
+ "g",
2397
+ ],
2398
+ "type": "object",
2399
+ }
2400
+ `);
2401
+ expect(z.toJSONSchema(schema, { io: "output" })).toMatchInlineSnapshot(`
2402
+ {
2403
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2404
+ "additionalProperties": false,
2405
+ "properties": {
2406
+ "a": {
2407
+ "type": "string",
2408
+ },
2409
+ "b": {
2410
+ "type": "string",
2411
+ },
2412
+ "c": {
2413
+ "default": "hello",
2414
+ "type": "string",
2415
+ },
2416
+ "d": {
2417
+ "anyOf": [
2418
+ {
2419
+ "type": "string",
2420
+ },
2421
+ {
2422
+ "type": "null",
2423
+ },
2424
+ ],
2425
+ },
2426
+ "e": {
2427
+ "type": "string",
2428
+ },
2429
+ "f": {
2430
+ "default": "hello",
2431
+ "type": "string",
2432
+ },
2433
+ "g": {
2434
+ "not": {},
2435
+ },
2436
+ "h": {
2437
+ "anyOf": [
2438
+ {
2439
+ "type": "string",
2440
+ },
2441
+ {
2442
+ "default": 2,
2443
+ "type": "number",
2444
+ },
2445
+ ],
2446
+ },
2447
+ "i": {
2448
+ "anyOf": [
2449
+ {
2450
+ "type": "string",
2451
+ },
2452
+ {
2453
+ "type": "string",
2454
+ },
2455
+ ],
2456
+ },
2457
+ },
2458
+ "required": [
2459
+ "a",
2460
+ "c",
2461
+ "d",
2462
+ "e",
2463
+ "f",
2464
+ "g",
2465
+ "h",
2466
+ ],
2467
+ "type": "object",
2468
+ }
2469
+ `);
2470
+ });
2471
+
2472
+ test("examples on pipe", () => {
2473
+ const schema = z
2474
+ .string()
2475
+ .meta({ examples: ["test"] })
2476
+ .transform(Number)
2477
+ // .pipe(z.transform(Number).meta({ examples: [4] }))
2478
+ .meta({ examples: [4] });
2479
+
2480
+ const i = z.toJSONSchema(schema, { io: "input", unrepresentable: "any" });
2481
+ expect(i).toMatchInlineSnapshot(`
2482
+ {
2483
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2484
+ "examples": [
2485
+ "test",
2486
+ ],
2487
+ "type": "string",
2488
+ }
2489
+ `);
2490
+ const o = z.toJSONSchema(schema, { io: "output", unrepresentable: "any" });
2491
+ expect(o).toMatchInlineSnapshot(`
2492
+ {
2493
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2494
+ "examples": [
2495
+ 4,
2496
+ ],
2497
+ }
2498
+ `);
2499
+ });
2500
+
2501
+ // test("number checks", () => {
2502
+ // expect(z.toJSONSchema(z.number().int())).toMatchInlineSnapshot(`
2503
+ // {
2504
+ // "maximum": 9007199254740991,
2505
+ // "minimum": -9007199254740991,
2506
+ // "type": "integer",
2507
+ // }
2508
+ // `);
2509
+ // expect(z.toJSONSchema(z.int())).toMatchInlineSnapshot(`
2510
+ // {
2511
+ // "maximum": 9007199254740991,
2512
+ // "minimum": -9007199254740991,
2513
+ // "type": "integer",
2514
+ // }
2515
+ // `);
2516
+ // expect(z.toJSONSchema(z.int().positive())).toMatchInlineSnapshot(`
2517
+ // {
2518
+ // "exclusiveMinimum": 0,
2519
+ // "maximum": 9007199254740991,
2520
+ // "minimum": -9007199254740991,
2521
+ // "type": "integer",
2522
+ // }
2523
+ // `);
2524
+ // expect(z.toJSONSchema(z.int().nonnegative())).toMatchInlineSnapshot(`
2525
+ // {
2526
+ // "maximum": 9007199254740991,
2527
+ // "minimum": 0,
2528
+ // "type": "integer",
2529
+ // }
2530
+ // `);
2531
+ // expect(z.toJSONSchema(z.int().gt(0))).toMatchInlineSnapshot(`
2532
+ // {
2533
+ // "exclusiveMinimum": 0,
2534
+ // "maximum": 9007199254740991,
2535
+ // "minimum": -9007199254740991,
2536
+ // "type": "integer",
2537
+ // }
2538
+ // `);
2539
+ // expect(z.toJSONSchema(z.int().gte(0))).toMatchInlineSnapshot(`
2540
+ // {
2541
+ // "maximum": 9007199254740991,
2542
+ // "minimum": 0,
2543
+ // "type": "integer",
2544
+ // }
2545
+ // `);
2546
+
2547
+ // });
2548
+
2549
+ test("use output type for preprocess", () => {
2550
+ const a = z.preprocess((val) => String(val), z.string());
2551
+
2552
+ expect(z.toJSONSchema(a, { io: "input" })).toMatchInlineSnapshot(`
2553
+ {
2554
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2555
+ "type": "string",
2556
+ }
2557
+ `);
2558
+ });
2559
+
2560
+ // test("isTransforming", () => {
2561
+ // const tx = z.core.isTransforming;
2562
+ // expect(tx(z.string())).toEqual(false);
2563
+ // expect(tx(z.string().transform((val) => val))).toEqual(true);
2564
+ // expect(tx(z.string().pipe(z.string()))).toEqual(false);
2565
+ // expect(
2566
+ // tx(
2567
+ // z
2568
+ // .string()
2569
+ // .transform((val) => val)
2570
+ // .pipe(z.string())
2571
+ // )
2572
+ // ).toEqual(true);
2573
+
2574
+ // const a = z.transform((val) => val);
2575
+ // expect(tx(z.transform((val) => val))).toEqual(true);
2576
+ // expect(tx(a.optional())).toEqual(true);
2577
+
2578
+ // const b = z.string().optional();
2579
+ // expect(tx(b)).toEqual(false);
2580
+
2581
+ // const c = z.string().prefault("hello");
2582
+ // expect(tx(c)).toEqual(false);
2583
+
2584
+ // const d = z.string().default("hello");
2585
+ // expect(tx(d)).toEqual(false);
2586
+ // });
2587
+
2588
+ test("flatten simple intersections", () => {
2589
+ const FirstSchema = z.object({
2590
+ testNum: z.number(),
2591
+ });
2592
+
2593
+ const SecondSchema = z.object({
2594
+ testStr: z.string(),
2595
+ });
2596
+
2597
+ const ThirdSchema = z.object({
2598
+ testBool: z.boolean(),
2599
+ });
2600
+
2601
+ const HelloSchema = FirstSchema.and(SecondSchema).and(ThirdSchema).describe("123");
2602
+
2603
+ // Zod 3
2604
+ // console.log(JSON.stringify(zodToJsonSchema(HelloSchema), null, 2));
2605
+
2606
+ // Zod 4
2607
+ const result = z.toJSONSchema(HelloSchema, { target: "draft-7" });
2608
+ expect(result).toMatchInlineSnapshot(`
2609
+ {
2610
+ "$schema": "http://json-schema.org/draft-07/schema#",
2611
+ "allOf": [
2612
+ {
2613
+ "additionalProperties": false,
2614
+ "properties": {
2615
+ "testNum": {
2616
+ "type": "number",
2617
+ },
2618
+ },
2619
+ "required": [
2620
+ "testNum",
2621
+ ],
2622
+ "type": "object",
2623
+ },
2624
+ {
2625
+ "additionalProperties": false,
2626
+ "properties": {
2627
+ "testStr": {
2628
+ "type": "string",
2629
+ },
2630
+ },
2631
+ "required": [
2632
+ "testStr",
2633
+ ],
2634
+ "type": "object",
2635
+ },
2636
+ {
2637
+ "additionalProperties": false,
2638
+ "properties": {
2639
+ "testBool": {
2640
+ "type": "boolean",
2641
+ },
2642
+ },
2643
+ "required": [
2644
+ "testBool",
2645
+ ],
2646
+ "type": "object",
2647
+ },
2648
+ ],
2649
+ "description": "123",
2650
+ }
2651
+ `);
2652
+ });
2653
+
2654
+ test("z.file()", () => {
2655
+ const a = z.file();
2656
+ expect(z.toJSONSchema(a)).toMatchInlineSnapshot(`
2657
+ {
2658
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2659
+ "contentEncoding": "binary",
2660
+ "format": "binary",
2661
+ "type": "string",
2662
+ }
2663
+ `);
2664
+
2665
+ const b = z.file().mime("image/png").min(1000).max(10000);
2666
+ expect(z.toJSONSchema(b)).toMatchInlineSnapshot(`
2667
+ {
2668
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2669
+ "contentEncoding": "binary",
2670
+ "contentMediaType": "image/png",
2671
+ "format": "binary",
2672
+ "maxLength": 10000,
2673
+ "minLength": 1000,
2674
+ "type": "string",
2675
+ }
2676
+ `);
2677
+
2678
+ const c = z.file().mime(["image/png", "image/jpg"]).min(1000).max(10000);
2679
+ expect(z.toJSONSchema(c)).toMatchInlineSnapshot(`
2680
+ {
2681
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2682
+ "anyOf": [
2683
+ {
2684
+ "contentEncoding": "binary",
2685
+ "contentMediaType": "image/png",
2686
+ "format": "binary",
2687
+ "maxLength": 10000,
2688
+ "minLength": 1000,
2689
+ "type": "string",
2690
+ },
2691
+ {
2692
+ "contentEncoding": "binary",
2693
+ "contentMediaType": "image/jpg",
2694
+ "format": "binary",
2695
+ "maxLength": 10000,
2696
+ "minLength": 1000,
2697
+ "type": "string",
2698
+ },
2699
+ ],
2700
+ }
2701
+ `);
2702
+ });
2703
+
2704
+ test("custom toJSONSchema", () => {
2705
+ const schema = z.instanceof(Date);
2706
+ schema._zod.toJSONSchema = () => ({
2707
+ type: "string",
2708
+ format: "date-time",
2709
+ });
2710
+
2711
+ expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
2712
+ {
2713
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
2714
+ "format": "date-time",
2715
+ "type": "string",
2716
+ }
2717
+ `);
2718
+ });
2719
+
2720
+ test("cycle detection - root", () => {
2721
+ const schema = z.object({
2722
+ name: z.string(),
2723
+ get subcategories() {
2724
+ return z.array(schema);
2725
+ },
2726
+ });
2727
+
2728
+ expect(() => z.toJSONSchema(schema, { cycles: "throw" })).toThrowErrorMatchingInlineSnapshot(`
2729
+ [Error: Cycle detected: #/properties/subcategories/items/<root>
2730
+
2731
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.]
2732
+ `);
2733
+ });
2734
+
2735
+ test("cycle detection - mutual recursion", () => {
2736
+ const A = z.object({
2737
+ name: z.string(),
2738
+ get subcategories() {
2739
+ return z.array(B);
2740
+ },
2741
+ });
2742
+
2743
+ const B = z.object({
2744
+ name: z.string(),
2745
+ get subcategories() {
2746
+ return z.array(A);
2747
+ },
2748
+ });
2749
+
2750
+ expect(() => z.toJSONSchema(A, { cycles: "throw" })).toThrowErrorMatchingInlineSnapshot(`
2751
+ [Error: Cycle detected: #/properties/subcategories/items/properties/subcategories/items/<root>
2752
+
2753
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.]
2754
+ `);
2755
+ });