fullstacked 0.12.0-1173 → 0.12.0-1184

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