claude-scope 0.1.6 → 0.1.8

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