zod 3.25.21 → 3.25.22
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.
- package/package.json +2 -2
- package/dist/cjs/v3/tests/all-errors.test.js +0 -147
- package/dist/cjs/v3/tests/anyunknown.test.js +0 -47
- package/dist/cjs/v3/tests/array.test.js +0 -80
- package/dist/cjs/v3/tests/async-parsing.test.js +0 -381
- package/dist/cjs/v3/tests/async-refinements.test.js +0 -60
- package/dist/cjs/v3/tests/base.test.js +0 -47
- package/dist/cjs/v3/tests/bigint.test.js +0 -74
- package/dist/cjs/v3/tests/branded.test.js +0 -58
- package/dist/cjs/v3/tests/catch.test.js +0 -181
- package/dist/cjs/v3/tests/coerce.test.js +0 -152
- package/dist/cjs/v3/tests/complex.test.js +0 -78
- package/dist/cjs/v3/tests/custom.test.js +0 -51
- package/dist/cjs/v3/tests/date.test.js +0 -49
- package/dist/cjs/v3/tests/deepmasking.test.js +0 -187
- package/dist/cjs/v3/tests/default.test.js +0 -86
- package/dist/cjs/v3/tests/description.test.js +0 -51
- package/dist/cjs/v3/tests/discriminated-unions.test.js +0 -321
- package/dist/cjs/v3/tests/enum.test.js +0 -91
- package/dist/cjs/v3/tests/error.test.js +0 -526
- package/dist/cjs/v3/tests/firstparty.test.js +0 -109
- package/dist/cjs/v3/tests/firstpartyschematypes.test.js +0 -8
- package/dist/cjs/v3/tests/function.test.js +0 -236
- package/dist/cjs/v3/tests/generics.test.js +0 -67
- package/dist/cjs/v3/tests/instanceof.test.js +0 -60
- package/dist/cjs/v3/tests/intersection.test.js +0 -111
- package/dist/cjs/v3/tests/language-server.source.js +0 -71
- package/dist/cjs/v3/tests/language-server.test.js +0 -177
- package/dist/cjs/v3/tests/literal.test.js +0 -55
- package/dist/cjs/v3/tests/map.test.js +0 -112
- package/dist/cjs/v3/tests/masking.test.js +0 -5
- package/dist/cjs/v3/tests/mocker.test.js +0 -19
- package/dist/cjs/v3/tests/nan.test.js +0 -42
- package/dist/cjs/v3/tests/nativeEnum.test.js +0 -100
- package/dist/cjs/v3/tests/nullable.test.js +0 -65
- package/dist/cjs/v3/tests/number.test.js +0 -189
- package/dist/cjs/v3/tests/object-augmentation.test.js +0 -50
- package/dist/cjs/v3/tests/object-in-es5-env.test.js +0 -49
- package/dist/cjs/v3/tests/object.test.js +0 -352
- package/dist/cjs/v3/tests/optional.test.js +0 -65
- package/dist/cjs/v3/tests/parseUtil.test.js +0 -20
- package/dist/cjs/v3/tests/parser.test.js +0 -55
- package/dist/cjs/v3/tests/partials.test.js +0 -201
- package/dist/cjs/v3/tests/pickomit.test.js +0 -113
- package/dist/cjs/v3/tests/pipeline.test.js +0 -50
- package/dist/cjs/v3/tests/preprocess.test.js +0 -181
- package/dist/cjs/v3/tests/primitive.test.js +0 -385
- package/dist/cjs/v3/tests/promise.test.js +0 -98
- package/dist/cjs/v3/tests/readonly.test.js +0 -190
- package/dist/cjs/v3/tests/record.test.js +0 -153
- package/dist/cjs/v3/tests/recursive.test.js +0 -161
- package/dist/cjs/v3/tests/refine.test.js +0 -279
- package/dist/cjs/v3/tests/safeparse.test.js +0 -46
- package/dist/cjs/v3/tests/set.test.js +0 -144
- package/dist/cjs/v3/tests/standard-schema.test.js +0 -102
- package/dist/cjs/v3/tests/string.test.js +0 -842
- package/dist/cjs/v3/tests/transformer.test.js +0 -218
- package/dist/cjs/v3/tests/tuple.test.js +0 -97
- package/dist/cjs/v3/tests/unions.test.js +0 -75
- package/dist/cjs/v3/tests/validations.test.js +0 -155
- package/dist/cjs/v3/tests/void.test.js +0 -36
- package/dist/cjs/v4/classic/tests/anyunknown.test.js +0 -45
- package/dist/cjs/v4/classic/tests/array.test.js +0 -249
- package/dist/cjs/v4/classic/tests/assignability.test.js +0 -110
- package/dist/cjs/v4/classic/tests/async-parsing.test.js +0 -364
- package/dist/cjs/v4/classic/tests/async-refinements.test.js +0 -82
- package/dist/cjs/v4/classic/tests/base.test.js +0 -31
- package/dist/cjs/v4/classic/tests/bigint.test.js +0 -73
- package/dist/cjs/v4/classic/tests/brand.test.js +0 -60
- package/dist/cjs/v4/classic/tests/catch.test.js +0 -214
- package/dist/cjs/v4/classic/tests/coalesce.test.js +0 -18
- package/dist/cjs/v4/classic/tests/coerce.test.js +0 -175
- package/dist/cjs/v4/classic/tests/custom.test.js +0 -38
- package/dist/cjs/v4/classic/tests/date.test.js +0 -48
- package/dist/cjs/v4/classic/tests/default.test.js +0 -88
- package/dist/cjs/v4/classic/tests/description.test.js +0 -51
- package/dist/cjs/v4/classic/tests/discriminated-unions.test.js +0 -540
- package/dist/cjs/v4/classic/tests/enum.test.js +0 -260
- package/dist/cjs/v4/classic/tests/error-utils.test.js +0 -411
- package/dist/cjs/v4/classic/tests/error.test.js +0 -651
- package/dist/cjs/v4/classic/tests/file.test.js +0 -68
- package/dist/cjs/v4/classic/tests/firstparty.test.js +0 -198
- package/dist/cjs/v4/classic/tests/function.test.js +0 -219
- package/dist/cjs/v4/classic/tests/generics.test.js +0 -72
- package/dist/cjs/v4/classic/tests/index.test.js +0 -765
- package/dist/cjs/v4/classic/tests/instanceof.test.js +0 -58
- package/dist/cjs/v4/classic/tests/intersection.test.js +0 -134
- package/dist/cjs/v4/classic/tests/json-schema.test.js +0 -1707
- package/dist/cjs/v4/classic/tests/json.test.js +0 -105
- package/dist/cjs/v4/classic/tests/lazy.test.js +0 -185
- package/dist/cjs/v4/classic/tests/literal.test.js +0 -94
- package/dist/cjs/v4/classic/tests/map.test.js +0 -193
- package/dist/cjs/v4/classic/tests/nan.test.js +0 -42
- package/dist/cjs/v4/classic/tests/nested-refine.test.js +0 -180
- package/dist/cjs/v4/classic/tests/nonoptional.test.js +0 -80
- package/dist/cjs/v4/classic/tests/nullable.test.js +0 -43
- package/dist/cjs/v4/classic/tests/number.test.js +0 -241
- package/dist/cjs/v4/classic/tests/object.test.js +0 -405
- package/dist/cjs/v4/classic/tests/optional.test.js +0 -98
- package/dist/cjs/v4/classic/tests/partial.test.js +0 -137
- package/dist/cjs/v4/classic/tests/pickomit.test.js +0 -125
- package/dist/cjs/v4/classic/tests/pipe.test.js +0 -92
- package/dist/cjs/v4/classic/tests/prefault.test.js +0 -22
- package/dist/cjs/v4/classic/tests/preprocess.test.js +0 -273
- package/dist/cjs/v4/classic/tests/primitive.test.js +0 -184
- package/dist/cjs/v4/classic/tests/promise.test.js +0 -91
- package/dist/cjs/v4/classic/tests/readonly.test.js +0 -241
- package/dist/cjs/v4/classic/tests/record.test.js +0 -307
- package/dist/cjs/v4/classic/tests/recursive-types.test.js +0 -108
- package/dist/cjs/v4/classic/tests/refine.test.js +0 -402
- package/dist/cjs/v4/classic/tests/registries.test.js +0 -155
- package/dist/cjs/v4/classic/tests/set.test.js +0 -182
- package/dist/cjs/v4/classic/tests/standard-schema.test.js +0 -77
- package/dist/cjs/v4/classic/tests/string-formats.test.js +0 -49
- package/dist/cjs/v4/classic/tests/string.test.js +0 -980
- package/dist/cjs/v4/classic/tests/template-literal.test.js +0 -705
- package/dist/cjs/v4/classic/tests/transform.test.js +0 -239
- package/dist/cjs/v4/classic/tests/tuple.test.js +0 -166
- package/dist/cjs/v4/classic/tests/union.test.js +0 -107
- package/dist/cjs/v4/classic/tests/validations.test.js +0 -301
- package/dist/cjs/v4/classic/tests/void.test.js +0 -34
- package/dist/cjs/v4/core/tests/index.test.js +0 -66
- package/dist/cjs/v4/core/tests/locales/be.test.js +0 -123
- package/dist/cjs/v4/core/tests/locales/en.test.js +0 -21
- package/dist/cjs/v4/core/tests/locales/ru.test.js +0 -123
- package/dist/cjs/v4/core/tests/locales/tr.test.js +0 -79
- package/dist/cjs/v4/mini/tests/assignability.test.js +0 -104
- package/dist/cjs/v4/mini/tests/brand.test.js +0 -58
- package/dist/cjs/v4/mini/tests/checks.test.js +0 -147
- package/dist/cjs/v4/mini/tests/computed.test.js +0 -55
- package/dist/cjs/v4/mini/tests/error.test.js +0 -45
- package/dist/cjs/v4/mini/tests/functions.test.js +0 -37
- package/dist/cjs/v4/mini/tests/index.test.js +0 -763
- package/dist/cjs/v4/mini/tests/number.test.js +0 -109
- package/dist/cjs/v4/mini/tests/object.test.js +0 -122
- package/dist/cjs/v4/mini/tests/prototypes.test.js +0 -44
- package/dist/cjs/v4/mini/tests/recursive-types.test.js +0 -106
- package/dist/cjs/v4/mini/tests/string.test.js +0 -265
- package/dist/types/v3/tests/all-errors.test.d.ts +0 -1
- package/dist/types/v3/tests/anyunknown.test.d.ts +0 -1
- package/dist/types/v3/tests/array.test.d.ts +0 -1
- package/dist/types/v3/tests/async-parsing.test.d.ts +0 -1
- package/dist/types/v3/tests/async-refinements.test.d.ts +0 -1
- package/dist/types/v3/tests/base.test.d.ts +0 -1
- package/dist/types/v3/tests/bigint.test.d.ts +0 -1
- package/dist/types/v3/tests/branded.test.d.ts +0 -1
- package/dist/types/v3/tests/catch.test.d.ts +0 -1
- package/dist/types/v3/tests/coerce.test.d.ts +0 -1
- package/dist/types/v3/tests/complex.test.d.ts +0 -1
- package/dist/types/v3/tests/custom.test.d.ts +0 -1
- package/dist/types/v3/tests/date.test.d.ts +0 -1
- package/dist/types/v3/tests/deepmasking.test.d.ts +0 -1
- package/dist/types/v3/tests/default.test.d.ts +0 -1
- package/dist/types/v3/tests/description.test.d.ts +0 -1
- package/dist/types/v3/tests/discriminated-unions.test.d.ts +0 -1
- package/dist/types/v3/tests/enum.test.d.ts +0 -1
- package/dist/types/v3/tests/error.test.d.ts +0 -1
- package/dist/types/v3/tests/firstparty.test.d.ts +0 -1
- package/dist/types/v3/tests/firstpartyschematypes.test.d.ts +0 -1
- package/dist/types/v3/tests/function.test.d.ts +0 -1
- package/dist/types/v3/tests/generics.test.d.ts +0 -1
- package/dist/types/v3/tests/instanceof.test.d.ts +0 -1
- package/dist/types/v3/tests/intersection.test.d.ts +0 -1
- package/dist/types/v3/tests/language-server.source.d.ts +0 -70
- package/dist/types/v3/tests/language-server.test.d.ts +0 -1
- package/dist/types/v3/tests/literal.test.d.ts +0 -1
- package/dist/types/v3/tests/map.test.d.ts +0 -1
- package/dist/types/v3/tests/masking.test.d.ts +0 -1
- package/dist/types/v3/tests/mocker.test.d.ts +0 -1
- package/dist/types/v3/tests/nan.test.d.ts +0 -1
- package/dist/types/v3/tests/nativeEnum.test.d.ts +0 -1
- package/dist/types/v3/tests/nullable.test.d.ts +0 -1
- package/dist/types/v3/tests/number.test.d.ts +0 -1
- package/dist/types/v3/tests/object-augmentation.test.d.ts +0 -1
- package/dist/types/v3/tests/object-in-es5-env.test.d.ts +0 -1
- package/dist/types/v3/tests/object.test.d.ts +0 -1
- package/dist/types/v3/tests/optional.test.d.ts +0 -1
- package/dist/types/v3/tests/parseUtil.test.d.ts +0 -1
- package/dist/types/v3/tests/parser.test.d.ts +0 -1
- package/dist/types/v3/tests/partials.test.d.ts +0 -1
- package/dist/types/v3/tests/pickomit.test.d.ts +0 -1
- package/dist/types/v3/tests/pipeline.test.d.ts +0 -1
- package/dist/types/v3/tests/preprocess.test.d.ts +0 -1
- package/dist/types/v3/tests/primitive.test.d.ts +0 -1
- package/dist/types/v3/tests/promise.test.d.ts +0 -1
- package/dist/types/v3/tests/readonly.test.d.ts +0 -1
- package/dist/types/v3/tests/record.test.d.ts +0 -1
- package/dist/types/v3/tests/recursive.test.d.ts +0 -1
- package/dist/types/v3/tests/refine.test.d.ts +0 -1
- package/dist/types/v3/tests/safeparse.test.d.ts +0 -1
- package/dist/types/v3/tests/set.test.d.ts +0 -1
- package/dist/types/v3/tests/standard-schema.test.d.ts +0 -1
- package/dist/types/v3/tests/string.test.d.ts +0 -1
- package/dist/types/v3/tests/transformer.test.d.ts +0 -1
- package/dist/types/v3/tests/tuple.test.d.ts +0 -1
- package/dist/types/v3/tests/unions.test.d.ts +0 -1
- package/dist/types/v3/tests/validations.test.d.ts +0 -1
- package/dist/types/v3/tests/void.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/anyunknown.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/array.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/assignability.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/async-parsing.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/async-refinements.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/base.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/bigint.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/brand.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/catch.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/coalesce.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/coerce.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/custom.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/date.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/default.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/description.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/discriminated-unions.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/enum.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/error-utils.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/error.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/file.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/firstparty.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/function.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/generics.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/index.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/instanceof.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/intersection.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/json-schema.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/json.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/lazy.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/literal.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/map.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/nan.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/nested-refine.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/nonoptional.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/nullable.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/number.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/object.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/optional.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/partial.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/pickomit.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/pipe.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/prefault.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/preprocess.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/primitive.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/promise.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/readonly.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/record.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/recursive-types.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/refine.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/registries.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/set.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/standard-schema.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/string-formats.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/string.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/template-literal.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/transform.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/tuple.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/union.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/validations.test.d.ts +0 -1
- package/dist/types/v4/classic/tests/void.test.d.ts +0 -1
- package/dist/types/v4/core/tests/index.test.d.ts +0 -1
- package/dist/types/v4/core/tests/locales/be.test.d.ts +0 -1
- package/dist/types/v4/core/tests/locales/en.test.d.ts +0 -1
- package/dist/types/v4/core/tests/locales/ru.test.d.ts +0 -1
- package/dist/types/v4/core/tests/locales/tr.test.d.ts +0 -1
- package/dist/types/v4/mini/tests/assignability.test.d.ts +0 -1
- package/dist/types/v4/mini/tests/brand.test.d.ts +0 -1
- package/dist/types/v4/mini/tests/checks.test.d.ts +0 -1
- package/dist/types/v4/mini/tests/computed.test.d.ts +0 -1
- package/dist/types/v4/mini/tests/error.test.d.ts +0 -1
- package/dist/types/v4/mini/tests/functions.test.d.ts +0 -1
- package/dist/types/v4/mini/tests/index.test.d.ts +0 -1
- package/dist/types/v4/mini/tests/number.test.d.ts +0 -1
- package/dist/types/v4/mini/tests/object.test.d.ts +0 -1
- package/dist/types/v4/mini/tests/prototypes.test.d.ts +0 -1
- package/dist/types/v4/mini/tests/recursive-types.test.d.ts +0 -1
- package/dist/types/v4/mini/tests/string.test.d.ts +0 -1
- package/src/index.ts +0 -4
- package/src/v3/ZodError.ts +0 -329
- package/src/v3/benchmarks/datetime.ts +0 -58
- package/src/v3/benchmarks/discriminatedUnion.ts +0 -80
- package/src/v3/benchmarks/index.ts +0 -59
- package/src/v3/benchmarks/ipv4.ts +0 -57
- package/src/v3/benchmarks/object.ts +0 -69
- package/src/v3/benchmarks/primitives.ts +0 -162
- package/src/v3/benchmarks/realworld.ts +0 -63
- package/src/v3/benchmarks/string.ts +0 -55
- package/src/v3/benchmarks/union.ts +0 -80
- package/src/v3/errors.ts +0 -13
- package/src/v3/external.ts +0 -6
- package/src/v3/helpers/enumUtil.ts +0 -17
- package/src/v3/helpers/errorUtil.ts +0 -8
- package/src/v3/helpers/parseUtil.ts +0 -176
- package/src/v3/helpers/partialUtil.ts +0 -34
- package/src/v3/helpers/typeAliases.ts +0 -2
- package/src/v3/helpers/util.ts +0 -224
- package/src/v3/index.ts +0 -4
- package/src/v3/locales/en.ts +0 -120
- package/src/v3/standard-schema.ts +0 -113
- package/src/v3/tests/Mocker.ts +0 -54
- package/src/v3/tests/all-errors.test.ts +0 -157
- package/src/v3/tests/anyunknown.test.ts +0 -28
- package/src/v3/tests/array.test.ts +0 -71
- package/src/v3/tests/async-parsing.test.ts +0 -388
- package/src/v3/tests/async-refinements.test.ts +0 -46
- package/src/v3/tests/base.test.ts +0 -29
- package/src/v3/tests/bigint.test.ts +0 -55
- package/src/v3/tests/branded.test.ts +0 -53
- package/src/v3/tests/catch.test.ts +0 -220
- package/src/v3/tests/coerce.test.ts +0 -133
- package/src/v3/tests/complex.test.ts +0 -56
- package/src/v3/tests/custom.test.ts +0 -31
- package/src/v3/tests/date.test.ts +0 -32
- package/src/v3/tests/deepmasking.test.ts +0 -186
- package/src/v3/tests/default.test.ts +0 -112
- package/src/v3/tests/description.test.ts +0 -33
- package/src/v3/tests/discriminated-unions.test.ts +0 -315
- package/src/v3/tests/enum.test.ts +0 -80
- package/src/v3/tests/error.test.ts +0 -551
- package/src/v3/tests/firstparty.test.ts +0 -87
- package/src/v3/tests/firstpartyschematypes.test.ts +0 -21
- package/src/v3/tests/function.test.ts +0 -257
- package/src/v3/tests/generics.test.ts +0 -48
- package/src/v3/tests/instanceof.test.ts +0 -37
- package/src/v3/tests/intersection.test.ts +0 -110
- package/src/v3/tests/language-server.source.ts +0 -76
- package/src/v3/tests/language-server.test.ts +0 -207
- package/src/v3/tests/literal.test.ts +0 -36
- package/src/v3/tests/map.test.ts +0 -110
- package/src/v3/tests/masking.test.ts +0 -4
- package/src/v3/tests/mocker.test.ts +0 -19
- package/src/v3/tests/nan.test.ts +0 -21
- package/src/v3/tests/nativeEnum.test.ts +0 -87
- package/src/v3/tests/nullable.test.ts +0 -42
- package/src/v3/tests/number.test.ts +0 -176
- package/src/v3/tests/object-augmentation.test.ts +0 -29
- package/src/v3/tests/object-in-es5-env.test.ts +0 -29
- package/src/v3/tests/object.test.ts +0 -434
- package/src/v3/tests/optional.test.ts +0 -42
- package/src/v3/tests/parseUtil.test.ts +0 -23
- package/src/v3/tests/parser.test.ts +0 -41
- package/src/v3/tests/partials.test.ts +0 -243
- package/src/v3/tests/pickomit.test.ts +0 -111
- package/src/v3/tests/pipeline.test.ts +0 -29
- package/src/v3/tests/preprocess.test.ts +0 -188
- package/src/v3/tests/primitive.test.ts +0 -440
- package/src/v3/tests/promise.test.ts +0 -90
- package/src/v3/tests/readonly.test.ts +0 -194
- package/src/v3/tests/record.test.ts +0 -171
- package/src/v3/tests/recursive.test.ts +0 -197
- package/src/v3/tests/refine.test.ts +0 -297
- package/src/v3/tests/safeparse.test.ts +0 -27
- package/src/v3/tests/set.test.ts +0 -142
- package/src/v3/tests/standard-schema.test.ts +0 -83
- package/src/v3/tests/string.test.ts +0 -916
- package/src/v3/tests/transformer.test.ts +0 -233
- package/src/v3/tests/tuple.test.ts +0 -90
- package/src/v3/tests/unions.test.ts +0 -57
- package/src/v3/tests/validations.test.ts +0 -133
- package/src/v3/tests/void.test.ts +0 -15
- package/src/v3/types.ts +0 -5135
- package/src/v4/classic/checks.ts +0 -30
- package/src/v4/classic/coerce.ts +0 -27
- package/src/v4/classic/compat.ts +0 -76
- package/src/v4/classic/errors.ts +0 -75
- package/src/v4/classic/external.ts +0 -31
- package/src/v4/classic/index.ts +0 -5
- package/src/v4/classic/iso.ts +0 -90
- package/src/v4/classic/parse.ts +0 -33
- package/src/v4/classic/schemas.ts +0 -2062
- package/src/v4/classic/tests/anyunknown.test.ts +0 -26
- package/src/v4/classic/tests/array.test.ts +0 -257
- package/src/v4/classic/tests/assignability.test.ts +0 -124
- package/src/v4/classic/tests/async-parsing.test.ts +0 -381
- package/src/v4/classic/tests/async-refinements.test.ts +0 -68
- package/src/v4/classic/tests/base.test.ts +0 -7
- package/src/v4/classic/tests/bigint.test.ts +0 -54
- package/src/v4/classic/tests/brand.test.ts +0 -57
- package/src/v4/classic/tests/catch.test.ts +0 -252
- package/src/v4/classic/tests/coalesce.test.ts +0 -20
- package/src/v4/classic/tests/coerce.test.ts +0 -160
- package/src/v4/classic/tests/custom.test.ts +0 -16
- package/src/v4/classic/tests/date.test.ts +0 -31
- package/src/v4/classic/tests/default.test.ts +0 -114
- package/src/v4/classic/tests/description.test.ts +0 -32
- package/src/v4/classic/tests/discriminated-unions.test.ts +0 -566
- package/src/v4/classic/tests/enum.test.ts +0 -285
- package/src/v4/classic/tests/error-utils.test.ts +0 -480
- package/src/v4/classic/tests/error.test.ts +0 -698
- package/src/v4/classic/tests/file.test.ts +0 -52
- package/src/v4/classic/tests/firstparty.test.ts +0 -177
- package/src/v4/classic/tests/function.test.ts +0 -230
- package/src/v4/classic/tests/generics.test.ts +0 -58
- package/src/v4/classic/tests/index.test.ts +0 -909
- package/src/v4/classic/tests/instanceof.test.ts +0 -34
- package/src/v4/classic/tests/intersection.test.ts +0 -171
- package/src/v4/classic/tests/json-schema.test.ts +0 -1810
- package/src/v4/classic/tests/json.test.ts +0 -108
- package/src/v4/classic/tests/lazy.test.ts +0 -227
- package/src/v4/classic/tests/literal.test.ts +0 -82
- package/src/v4/classic/tests/map.test.ts +0 -196
- package/src/v4/classic/tests/nan.test.ts +0 -21
- package/src/v4/classic/tests/nested-refine.test.ts +0 -165
- package/src/v4/classic/tests/nonoptional.test.ts +0 -86
- package/src/v4/classic/tests/nullable.test.ts +0 -22
- package/src/v4/classic/tests/number.test.ts +0 -242
- package/src/v4/classic/tests/object.test.ts +0 -493
- package/src/v4/classic/tests/optional.test.ts +0 -103
- package/src/v4/classic/tests/partial.test.ts +0 -147
- package/src/v4/classic/tests/pickomit.test.ts +0 -125
- package/src/v4/classic/tests/pipe.test.ts +0 -81
- package/src/v4/classic/tests/prefault.test.ts +0 -37
- package/src/v4/classic/tests/preprocess.test.ts +0 -272
- package/src/v4/classic/tests/primitive.test.ts +0 -175
- package/src/v4/classic/tests/promise.test.ts +0 -81
- package/src/v4/classic/tests/readonly.test.ts +0 -252
- package/src/v4/classic/tests/record.test.ts +0 -332
- package/src/v4/classic/tests/recursive-types.test.ts +0 -126
- package/src/v4/classic/tests/refine.test.ts +0 -423
- package/src/v4/classic/tests/registries.test.ts +0 -159
- package/src/v4/classic/tests/set.test.ts +0 -179
- package/src/v4/classic/tests/standard-schema.test.ts +0 -57
- package/src/v4/classic/tests/string-formats.test.ts +0 -31
- package/src/v4/classic/tests/string.test.ts +0 -1081
- package/src/v4/classic/tests/template-literal.test.ts +0 -758
- package/src/v4/classic/tests/transform.test.ts +0 -250
- package/src/v4/classic/tests/tuple.test.ts +0 -163
- package/src/v4/classic/tests/union.test.ts +0 -94
- package/src/v4/classic/tests/validations.test.ts +0 -277
- package/src/v4/classic/tests/void.test.ts +0 -12
- package/src/v4/core/api.ts +0 -1533
- package/src/v4/core/checks.ts +0 -1282
- package/src/v4/core/config.ts +0 -15
- package/src/v4/core/core.ts +0 -98
- package/src/v4/core/doc.ts +0 -45
- package/src/v4/core/errors.ts +0 -433
- package/src/v4/core/function.ts +0 -143
- package/src/v4/core/index.ts +0 -15
- package/src/v4/core/json-schema.ts +0 -106
- package/src/v4/core/parse.ts +0 -94
- package/src/v4/core/regexes.ts +0 -133
- package/src/v4/core/registries.ts +0 -89
- package/src/v4/core/schemas.ts +0 -3802
- package/src/v4/core/standard-schema.ts +0 -64
- package/src/v4/core/tests/index.test.ts +0 -46
- package/src/v4/core/tests/locales/be.test.ts +0 -124
- package/src/v4/core/tests/locales/en.test.ts +0 -22
- package/src/v4/core/tests/locales/ru.test.ts +0 -128
- package/src/v4/core/tests/locales/tr.test.ts +0 -69
- package/src/v4/core/to-json-schema.ts +0 -790
- package/src/v4/core/util.ts +0 -750
- package/src/v4/core/versions.ts +0 -5
- package/src/v4/core/zsf.ts +0 -323
- package/src/v4/index.ts +0 -4
- package/src/v4/locales/ar.ts +0 -125
- package/src/v4/locales/az.ts +0 -121
- package/src/v4/locales/be.ts +0 -185
- package/src/v4/locales/ca.ts +0 -127
- package/src/v4/locales/cs.ts +0 -142
- package/src/v4/locales/de.ts +0 -124
- package/src/v4/locales/en.ts +0 -127
- package/src/v4/locales/es.ts +0 -124
- package/src/v4/locales/fa.ts +0 -134
- package/src/v4/locales/fi.ts +0 -131
- package/src/v4/locales/fr.ts +0 -124
- package/src/v4/locales/frCA.ts +0 -126
- package/src/v4/locales/he.ts +0 -125
- package/src/v4/locales/hu.ts +0 -126
- package/src/v4/locales/id.ts +0 -124
- package/src/v4/locales/index.ts +0 -34
- package/src/v4/locales/it.ts +0 -125
- package/src/v4/locales/ja.ts +0 -122
- package/src/v4/locales/ko.ts +0 -131
- package/src/v4/locales/mk.ts +0 -127
- package/src/v4/locales/ms.ts +0 -124
- package/src/v4/locales/no.ts +0 -124
- package/src/v4/locales/ota.ts +0 -125
- package/src/v4/locales/pl.ts +0 -125
- package/src/v4/locales/pt.ts +0 -123
- package/src/v4/locales/ru.ts +0 -185
- package/src/v4/locales/sl.ts +0 -125
- package/src/v4/locales/ta.ts +0 -125
- package/src/v4/locales/th.ts +0 -126
- package/src/v4/locales/tr.ts +0 -121
- package/src/v4/locales/ua.ts +0 -126
- package/src/v4/locales/ur.ts +0 -126
- package/src/v4/locales/vi.ts +0 -125
- package/src/v4/locales/zh-CN.ts +0 -123
- package/src/v4/locales/zh-tw.ts +0 -125
- package/src/v4/mini/checks.ts +0 -32
- package/src/v4/mini/coerce.ts +0 -22
- package/src/v4/mini/external.ts +0 -26
- package/src/v4/mini/index.ts +0 -3
- package/src/v4/mini/iso.ts +0 -62
- package/src/v4/mini/parse.ts +0 -1
- package/src/v4/mini/schemas.ts +0 -1556
- package/src/v4/mini/tests/assignability.test.ts +0 -117
- package/src/v4/mini/tests/brand.test.ts +0 -51
- package/src/v4/mini/tests/checks.test.ts +0 -144
- package/src/v4/mini/tests/computed.test.ts +0 -36
- package/src/v4/mini/tests/error.test.ts +0 -22
- package/src/v4/mini/tests/functions.test.ts +0 -43
- package/src/v4/mini/tests/index.test.ts +0 -914
- package/src/v4/mini/tests/number.test.ts +0 -95
- package/src/v4/mini/tests/object.test.ts +0 -139
- package/src/v4/mini/tests/prototypes.test.ts +0 -23
- package/src/v4/mini/tests/recursive-types.test.ts +0 -124
- package/src/v4/mini/tests/string.test.ts +0 -284
|
@@ -1,1707 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const vitest_1 = require("vitest");
|
|
27
|
-
const z = __importStar(require("zod/v4"));
|
|
28
|
-
const core_1 = require("zod/v4/core");
|
|
29
|
-
(0, vitest_1.describe)("toJSONSchema", () => {
|
|
30
|
-
(0, vitest_1.test)("primitive types", () => {
|
|
31
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.string())).toMatchInlineSnapshot(`
|
|
32
|
-
{
|
|
33
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
34
|
-
"type": "string",
|
|
35
|
-
}
|
|
36
|
-
`);
|
|
37
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.number())).toMatchInlineSnapshot(`
|
|
38
|
-
{
|
|
39
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
40
|
-
"type": "number",
|
|
41
|
-
}
|
|
42
|
-
`);
|
|
43
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.boolean())).toMatchInlineSnapshot(`
|
|
44
|
-
{
|
|
45
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
46
|
-
"type": "boolean",
|
|
47
|
-
}
|
|
48
|
-
`);
|
|
49
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.null())).toMatchInlineSnapshot(`
|
|
50
|
-
{
|
|
51
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
52
|
-
"type": "null",
|
|
53
|
-
}
|
|
54
|
-
`);
|
|
55
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.undefined())).toMatchInlineSnapshot(`
|
|
56
|
-
{
|
|
57
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
58
|
-
"type": "null",
|
|
59
|
-
}
|
|
60
|
-
`);
|
|
61
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.any())).toMatchInlineSnapshot(`
|
|
62
|
-
{
|
|
63
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
64
|
-
}
|
|
65
|
-
`);
|
|
66
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.unknown())).toMatchInlineSnapshot(`
|
|
67
|
-
{
|
|
68
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
69
|
-
}
|
|
70
|
-
`);
|
|
71
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.never())).toMatchInlineSnapshot(`
|
|
72
|
-
{
|
|
73
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
74
|
-
"not": {},
|
|
75
|
-
}
|
|
76
|
-
`);
|
|
77
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.email())).toMatchInlineSnapshot(`
|
|
78
|
-
{
|
|
79
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
80
|
-
"format": "email",
|
|
81
|
-
"pattern": "^(?!\\.)(?!.*\\.\\.)([A-Za-z0-9_'+\\-\\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$",
|
|
82
|
-
"type": "string",
|
|
83
|
-
}
|
|
84
|
-
`);
|
|
85
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.iso.datetime())).toMatchInlineSnapshot(`
|
|
86
|
-
{
|
|
87
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
88
|
-
"format": "date-time",
|
|
89
|
-
"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)$",
|
|
90
|
-
"type": "string",
|
|
91
|
-
}
|
|
92
|
-
`);
|
|
93
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.iso.date())).toMatchInlineSnapshot(`
|
|
94
|
-
{
|
|
95
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
96
|
-
"format": "date",
|
|
97
|
-
"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])))$",
|
|
98
|
-
"type": "string",
|
|
99
|
-
}
|
|
100
|
-
`);
|
|
101
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.iso.time())).toMatchInlineSnapshot(`
|
|
102
|
-
{
|
|
103
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
104
|
-
"format": "time",
|
|
105
|
-
"pattern": "^([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(\\.\\d+)?$",
|
|
106
|
-
"type": "string",
|
|
107
|
-
}
|
|
108
|
-
`);
|
|
109
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.iso.duration())).toMatchInlineSnapshot(`
|
|
110
|
-
{
|
|
111
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
112
|
-
"format": "duration",
|
|
113
|
-
"pattern": "^P(?:(\\d+W)|(?!.*W)(?=\\d|T\\d)(\\d+Y)?(\\d+M)?(\\d+D)?(T(?=\\d)(\\d+H)?(\\d+M)?(\\d+([.,]\\d+)?S)?)?)$",
|
|
114
|
-
"type": "string",
|
|
115
|
-
}
|
|
116
|
-
`);
|
|
117
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.ipv4())).toMatchInlineSnapshot(`
|
|
118
|
-
{
|
|
119
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
120
|
-
"format": "ipv4",
|
|
121
|
-
"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])$",
|
|
122
|
-
"type": "string",
|
|
123
|
-
}
|
|
124
|
-
`);
|
|
125
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.ipv6())).toMatchInlineSnapshot(`
|
|
126
|
-
{
|
|
127
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
128
|
-
"format": "ipv6",
|
|
129
|
-
"pattern": "^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})$",
|
|
130
|
-
"type": "string",
|
|
131
|
-
}
|
|
132
|
-
`);
|
|
133
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.uuid())).toMatchInlineSnapshot(`
|
|
134
|
-
{
|
|
135
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
136
|
-
"format": "uuid",
|
|
137
|
-
"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)$",
|
|
138
|
-
"type": "string",
|
|
139
|
-
}
|
|
140
|
-
`);
|
|
141
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.guid())).toMatchInlineSnapshot(`
|
|
142
|
-
{
|
|
143
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
144
|
-
"format": "uuid",
|
|
145
|
-
"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})$",
|
|
146
|
-
"type": "string",
|
|
147
|
-
}
|
|
148
|
-
`);
|
|
149
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.url())).toMatchInlineSnapshot(`
|
|
150
|
-
{
|
|
151
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
152
|
-
"format": "uri",
|
|
153
|
-
"type": "string",
|
|
154
|
-
}
|
|
155
|
-
`);
|
|
156
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.base64())).toMatchInlineSnapshot(`
|
|
157
|
-
{
|
|
158
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
159
|
-
"contentEncoding": "base64",
|
|
160
|
-
"format": "base64",
|
|
161
|
-
"pattern": "^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$",
|
|
162
|
-
"type": "string",
|
|
163
|
-
}
|
|
164
|
-
`);
|
|
165
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.cuid())).toMatchInlineSnapshot(`
|
|
166
|
-
{
|
|
167
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
168
|
-
"format": "cuid",
|
|
169
|
-
"pattern": "^[cC][^\\s-]{8,}$",
|
|
170
|
-
"type": "string",
|
|
171
|
-
}
|
|
172
|
-
`);
|
|
173
|
-
// expect(toJSONSchema(z.regex(/asdf/))).toMatchInlineSnapshot();
|
|
174
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.emoji())).toMatchInlineSnapshot(`
|
|
175
|
-
{
|
|
176
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
177
|
-
"format": "emoji",
|
|
178
|
-
"pattern": "^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",
|
|
179
|
-
"type": "string",
|
|
180
|
-
}
|
|
181
|
-
`);
|
|
182
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.nanoid())).toMatchInlineSnapshot(`
|
|
183
|
-
{
|
|
184
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
185
|
-
"format": "nanoid",
|
|
186
|
-
"pattern": "^[a-zA-Z0-9_-]{21}$",
|
|
187
|
-
"type": "string",
|
|
188
|
-
}
|
|
189
|
-
`);
|
|
190
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.cuid2())).toMatchInlineSnapshot(`
|
|
191
|
-
{
|
|
192
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
193
|
-
"format": "cuid2",
|
|
194
|
-
"pattern": "^[0-9a-z]+$",
|
|
195
|
-
"type": "string",
|
|
196
|
-
}
|
|
197
|
-
`);
|
|
198
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.ulid())).toMatchInlineSnapshot(`
|
|
199
|
-
{
|
|
200
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
201
|
-
"format": "ulid",
|
|
202
|
-
"pattern": "^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$",
|
|
203
|
-
"type": "string",
|
|
204
|
-
}
|
|
205
|
-
`);
|
|
206
|
-
// expect(toJSONSchema(z.cidr())).toMatchInlineSnapshot();
|
|
207
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.number())).toMatchInlineSnapshot(`
|
|
208
|
-
{
|
|
209
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
210
|
-
"type": "number",
|
|
211
|
-
}
|
|
212
|
-
`);
|
|
213
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.int())).toMatchInlineSnapshot(`
|
|
214
|
-
{
|
|
215
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
216
|
-
"maximum": 9007199254740991,
|
|
217
|
-
"minimum": -9007199254740991,
|
|
218
|
-
"type": "integer",
|
|
219
|
-
}
|
|
220
|
-
`);
|
|
221
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.int32())).toMatchInlineSnapshot(`
|
|
222
|
-
{
|
|
223
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
224
|
-
"maximum": 2147483647,
|
|
225
|
-
"minimum": -2147483648,
|
|
226
|
-
"type": "integer",
|
|
227
|
-
}
|
|
228
|
-
`);
|
|
229
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.float32())).toMatchInlineSnapshot(`
|
|
230
|
-
{
|
|
231
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
232
|
-
"maximum": 3.4028234663852886e+38,
|
|
233
|
-
"minimum": -3.4028234663852886e+38,
|
|
234
|
-
"type": "number",
|
|
235
|
-
}
|
|
236
|
-
`);
|
|
237
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.float64())).toMatchInlineSnapshot(`
|
|
238
|
-
{
|
|
239
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
240
|
-
"maximum": 1.7976931348623157e+308,
|
|
241
|
-
"minimum": -1.7976931348623157e+308,
|
|
242
|
-
"type": "number",
|
|
243
|
-
}
|
|
244
|
-
`);
|
|
245
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.jwt())).toMatchInlineSnapshot(`
|
|
246
|
-
{
|
|
247
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
248
|
-
"format": "jwt",
|
|
249
|
-
"type": "string",
|
|
250
|
-
}
|
|
251
|
-
`);
|
|
252
|
-
});
|
|
253
|
-
(0, vitest_1.test)("unsupported schema types", () => {
|
|
254
|
-
(0, vitest_1.expect)(() => (0, core_1.toJSONSchema)(z.bigint())).toThrow("BigInt cannot be represented in JSON Schema");
|
|
255
|
-
(0, vitest_1.expect)(() => (0, core_1.toJSONSchema)(z.int64())).toThrow("BigInt cannot be represented in JSON Schema");
|
|
256
|
-
(0, vitest_1.expect)(() => (0, core_1.toJSONSchema)(z.symbol())).toThrow("Symbols cannot be represented in JSON Schema");
|
|
257
|
-
(0, vitest_1.expect)(() => (0, core_1.toJSONSchema)(z.void())).toThrow("Void cannot be represented in JSON Schema");
|
|
258
|
-
(0, vitest_1.expect)(() => (0, core_1.toJSONSchema)(z.date())).toThrow("Date cannot be represented in JSON Schema");
|
|
259
|
-
(0, vitest_1.expect)(() => (0, core_1.toJSONSchema)(z.map(z.string(), z.number()))).toThrow("Map cannot be represented in JSON Schema");
|
|
260
|
-
(0, vitest_1.expect)(() => (0, core_1.toJSONSchema)(z.set(z.string()))).toThrow("Set cannot be represented in JSON Schema");
|
|
261
|
-
(0, vitest_1.expect)(() => (0, core_1.toJSONSchema)(z.custom(() => true))).toThrow("Custom types cannot be represented in JSON Schema");
|
|
262
|
-
// File type
|
|
263
|
-
const fileSchema = z.file();
|
|
264
|
-
(0, vitest_1.expect)(() => (0, core_1.toJSONSchema)(fileSchema)).toThrow("File cannot be represented in JSON Schema");
|
|
265
|
-
// Transform
|
|
266
|
-
const transformSchema = z.string().transform((val) => Number.parseInt(val));
|
|
267
|
-
(0, vitest_1.expect)(() => (0, core_1.toJSONSchema)(transformSchema)).toThrow("Transforms cannot be represented in JSON Schema");
|
|
268
|
-
// Static catch values
|
|
269
|
-
const staticCatchSchema = z.string().catch(() => "sup");
|
|
270
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(staticCatchSchema)).toMatchInlineSnapshot(`
|
|
271
|
-
{
|
|
272
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
273
|
-
"default": "sup",
|
|
274
|
-
"type": "string",
|
|
275
|
-
}
|
|
276
|
-
`);
|
|
277
|
-
// Dynamic catch values
|
|
278
|
-
const dynamicCatchSchema = z.string().catch((ctx) => `${ctx.issues.length}`);
|
|
279
|
-
(0, vitest_1.expect)(() => (0, core_1.toJSONSchema)(dynamicCatchSchema)).toThrow("Dynamic catch values are not supported in JSON Schema");
|
|
280
|
-
});
|
|
281
|
-
(0, vitest_1.test)("string formats", () => {
|
|
282
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.string().email())).toMatchInlineSnapshot(`
|
|
283
|
-
{
|
|
284
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
285
|
-
"format": "email",
|
|
286
|
-
"pattern": "^(?!\\.)(?!.*\\.\\.)([A-Za-z0-9_'+\\-\\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$",
|
|
287
|
-
"type": "string",
|
|
288
|
-
}
|
|
289
|
-
`);
|
|
290
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.string().uuid())).toMatchInlineSnapshot(`
|
|
291
|
-
{
|
|
292
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
293
|
-
"format": "uuid",
|
|
294
|
-
"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)$",
|
|
295
|
-
"type": "string",
|
|
296
|
-
}
|
|
297
|
-
`);
|
|
298
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.iso.datetime())).toMatchInlineSnapshot(`
|
|
299
|
-
{
|
|
300
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
301
|
-
"format": "date-time",
|
|
302
|
-
"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)$",
|
|
303
|
-
"type": "string",
|
|
304
|
-
}
|
|
305
|
-
`);
|
|
306
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.iso.date())).toMatchInlineSnapshot(`
|
|
307
|
-
{
|
|
308
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
309
|
-
"format": "date",
|
|
310
|
-
"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])))$",
|
|
311
|
-
"type": "string",
|
|
312
|
-
}
|
|
313
|
-
`);
|
|
314
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.iso.time())).toMatchInlineSnapshot(`
|
|
315
|
-
{
|
|
316
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
317
|
-
"format": "time",
|
|
318
|
-
"pattern": "^([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(\\.\\d+)?$",
|
|
319
|
-
"type": "string",
|
|
320
|
-
}
|
|
321
|
-
`);
|
|
322
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.iso.duration())).toMatchInlineSnapshot(`
|
|
323
|
-
{
|
|
324
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
325
|
-
"format": "duration",
|
|
326
|
-
"pattern": "^P(?:(\\d+W)|(?!.*W)(?=\\d|T\\d)(\\d+Y)?(\\d+M)?(\\d+D)?(T(?=\\d)(\\d+H)?(\\d+M)?(\\d+([.,]\\d+)?S)?)?)$",
|
|
327
|
-
"type": "string",
|
|
328
|
-
}
|
|
329
|
-
`);
|
|
330
|
-
// expect(toJSONSchema(z.string().ip())).toMatchInlineSnapshot(`
|
|
331
|
-
// {
|
|
332
|
-
// "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\\}\\)\\)\\)\\$\\)/,
|
|
333
|
-
// "type": "string",
|
|
334
|
-
// }
|
|
335
|
-
// `);
|
|
336
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.ipv4())).toMatchInlineSnapshot(`
|
|
337
|
-
{
|
|
338
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
339
|
-
"format": "ipv4",
|
|
340
|
-
"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])$",
|
|
341
|
-
"type": "string",
|
|
342
|
-
}
|
|
343
|
-
`);
|
|
344
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.ipv6())).toMatchInlineSnapshot(`
|
|
345
|
-
{
|
|
346
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
347
|
-
"format": "ipv6",
|
|
348
|
-
"pattern": "^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})$",
|
|
349
|
-
"type": "string",
|
|
350
|
-
}
|
|
351
|
-
`);
|
|
352
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.base64())).toMatchInlineSnapshot(`
|
|
353
|
-
{
|
|
354
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
355
|
-
"contentEncoding": "base64",
|
|
356
|
-
"format": "base64",
|
|
357
|
-
"pattern": "^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$",
|
|
358
|
-
"type": "string",
|
|
359
|
-
}
|
|
360
|
-
`);
|
|
361
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.url())).toMatchInlineSnapshot(`
|
|
362
|
-
{
|
|
363
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
364
|
-
"format": "uri",
|
|
365
|
-
"type": "string",
|
|
366
|
-
}
|
|
367
|
-
`);
|
|
368
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.guid())).toMatchInlineSnapshot(`
|
|
369
|
-
{
|
|
370
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
371
|
-
"format": "uuid",
|
|
372
|
-
"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})$",
|
|
373
|
-
"type": "string",
|
|
374
|
-
}
|
|
375
|
-
`);
|
|
376
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.string().regex(/asdf/))).toMatchInlineSnapshot(`
|
|
377
|
-
{
|
|
378
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
379
|
-
"format": "regex",
|
|
380
|
-
"pattern": "asdf",
|
|
381
|
-
"type": "string",
|
|
382
|
-
}
|
|
383
|
-
`);
|
|
384
|
-
});
|
|
385
|
-
(0, vitest_1.test)("number constraints", () => {
|
|
386
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.number().min(5).max(10))).toMatchInlineSnapshot(`
|
|
387
|
-
{
|
|
388
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
389
|
-
"maximum": 10,
|
|
390
|
-
"minimum": 5,
|
|
391
|
-
"type": "number",
|
|
392
|
-
}
|
|
393
|
-
`);
|
|
394
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.number().gt(5).gt(10))).toMatchInlineSnapshot(`
|
|
395
|
-
{
|
|
396
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
397
|
-
"exclusiveMinimum": 10,
|
|
398
|
-
"type": "number",
|
|
399
|
-
}
|
|
400
|
-
`);
|
|
401
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.number().gt(5).gte(10))).toMatchInlineSnapshot(`
|
|
402
|
-
{
|
|
403
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
404
|
-
"minimum": 10,
|
|
405
|
-
"type": "number",
|
|
406
|
-
}
|
|
407
|
-
`);
|
|
408
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.number().lt(5).lt(3))).toMatchInlineSnapshot(`
|
|
409
|
-
{
|
|
410
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
411
|
-
"exclusiveMaximum": 3,
|
|
412
|
-
"type": "number",
|
|
413
|
-
}
|
|
414
|
-
`);
|
|
415
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.number().lt(5).lt(3).lte(2))).toMatchInlineSnapshot(`
|
|
416
|
-
{
|
|
417
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
418
|
-
"maximum": 2,
|
|
419
|
-
"type": "number",
|
|
420
|
-
}
|
|
421
|
-
`);
|
|
422
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.number().lt(5).lte(3))).toMatchInlineSnapshot(`
|
|
423
|
-
{
|
|
424
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
425
|
-
"maximum": 3,
|
|
426
|
-
"type": "number",
|
|
427
|
-
}
|
|
428
|
-
`);
|
|
429
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.number().gt(5).lt(10))).toMatchInlineSnapshot(`
|
|
430
|
-
{
|
|
431
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
432
|
-
"exclusiveMaximum": 10,
|
|
433
|
-
"exclusiveMinimum": 5,
|
|
434
|
-
"type": "number",
|
|
435
|
-
}
|
|
436
|
-
`);
|
|
437
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.number().gte(5).lte(10))).toMatchInlineSnapshot(`
|
|
438
|
-
{
|
|
439
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
440
|
-
"maximum": 10,
|
|
441
|
-
"minimum": 5,
|
|
442
|
-
"type": "number",
|
|
443
|
-
}
|
|
444
|
-
`);
|
|
445
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.number().positive())).toMatchInlineSnapshot(`
|
|
446
|
-
{
|
|
447
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
448
|
-
"exclusiveMinimum": 0,
|
|
449
|
-
"type": "number",
|
|
450
|
-
}
|
|
451
|
-
`);
|
|
452
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.number().negative())).toMatchInlineSnapshot(`
|
|
453
|
-
{
|
|
454
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
455
|
-
"exclusiveMaximum": 0,
|
|
456
|
-
"type": "number",
|
|
457
|
-
}
|
|
458
|
-
`);
|
|
459
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.number().nonpositive())).toMatchInlineSnapshot(`
|
|
460
|
-
{
|
|
461
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
462
|
-
"maximum": 0,
|
|
463
|
-
"type": "number",
|
|
464
|
-
}
|
|
465
|
-
`);
|
|
466
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.number().nonnegative())).toMatchInlineSnapshot(`
|
|
467
|
-
{
|
|
468
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
469
|
-
"minimum": 0,
|
|
470
|
-
"type": "number",
|
|
471
|
-
}
|
|
472
|
-
`);
|
|
473
|
-
});
|
|
474
|
-
(0, vitest_1.test)("arrays", () => {
|
|
475
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(z.array(z.string()))).toMatchInlineSnapshot(`
|
|
476
|
-
{
|
|
477
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
478
|
-
"items": {
|
|
479
|
-
"type": "string",
|
|
480
|
-
},
|
|
481
|
-
"type": "array",
|
|
482
|
-
}
|
|
483
|
-
`);
|
|
484
|
-
});
|
|
485
|
-
(0, vitest_1.test)("unions", () => {
|
|
486
|
-
const schema = z.union([z.string(), z.number()]);
|
|
487
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(schema)).toMatchInlineSnapshot(`
|
|
488
|
-
{
|
|
489
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
490
|
-
"anyOf": [
|
|
491
|
-
{
|
|
492
|
-
"type": "string",
|
|
493
|
-
},
|
|
494
|
-
{
|
|
495
|
-
"type": "number",
|
|
496
|
-
},
|
|
497
|
-
],
|
|
498
|
-
}
|
|
499
|
-
`);
|
|
500
|
-
});
|
|
501
|
-
(0, vitest_1.test)("intersections", () => {
|
|
502
|
-
const schema = z.intersection(z.object({ name: z.string() }), z.object({ age: z.number() }));
|
|
503
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(schema)).toMatchInlineSnapshot(`
|
|
504
|
-
{
|
|
505
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
506
|
-
"allOf": [
|
|
507
|
-
{
|
|
508
|
-
"properties": {
|
|
509
|
-
"name": {
|
|
510
|
-
"type": "string",
|
|
511
|
-
},
|
|
512
|
-
},
|
|
513
|
-
"required": [
|
|
514
|
-
"name",
|
|
515
|
-
],
|
|
516
|
-
"type": "object",
|
|
517
|
-
},
|
|
518
|
-
{
|
|
519
|
-
"properties": {
|
|
520
|
-
"age": {
|
|
521
|
-
"type": "number",
|
|
522
|
-
},
|
|
523
|
-
},
|
|
524
|
-
"required": [
|
|
525
|
-
"age",
|
|
526
|
-
],
|
|
527
|
-
"type": "object",
|
|
528
|
-
},
|
|
529
|
-
],
|
|
530
|
-
}
|
|
531
|
-
`);
|
|
532
|
-
});
|
|
533
|
-
(0, vitest_1.test)("record", () => {
|
|
534
|
-
const schema = z.record(z.string(), z.boolean());
|
|
535
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(schema)).toMatchInlineSnapshot(`
|
|
536
|
-
{
|
|
537
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
538
|
-
"additionalProperties": {
|
|
539
|
-
"type": "boolean",
|
|
540
|
-
},
|
|
541
|
-
"propertyNames": {
|
|
542
|
-
"type": "string",
|
|
543
|
-
},
|
|
544
|
-
"type": "object",
|
|
545
|
-
}
|
|
546
|
-
`);
|
|
547
|
-
});
|
|
548
|
-
(0, vitest_1.test)("tuple", () => {
|
|
549
|
-
const schema = z.tuple([z.string(), z.number()]).rest(z.boolean());
|
|
550
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(schema)).toMatchInlineSnapshot(`
|
|
551
|
-
{
|
|
552
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
553
|
-
"items": {
|
|
554
|
-
"type": "boolean",
|
|
555
|
-
},
|
|
556
|
-
"prefixItems": [
|
|
557
|
-
{
|
|
558
|
-
"type": "string",
|
|
559
|
-
},
|
|
560
|
-
{
|
|
561
|
-
"type": "number",
|
|
562
|
-
},
|
|
563
|
-
],
|
|
564
|
-
"type": "array",
|
|
565
|
-
}
|
|
566
|
-
`);
|
|
567
|
-
});
|
|
568
|
-
(0, vitest_1.test)("promise", () => {
|
|
569
|
-
const schema = z.promise(z.string());
|
|
570
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(schema)).toMatchInlineSnapshot(`
|
|
571
|
-
{
|
|
572
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
573
|
-
"type": "string",
|
|
574
|
-
}
|
|
575
|
-
`);
|
|
576
|
-
});
|
|
577
|
-
(0, vitest_1.test)("lazy", () => {
|
|
578
|
-
const schema = z.lazy(() => z.string());
|
|
579
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(schema)).toMatchInlineSnapshot(`
|
|
580
|
-
{
|
|
581
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
582
|
-
"type": "string",
|
|
583
|
-
}
|
|
584
|
-
`);
|
|
585
|
-
});
|
|
586
|
-
// enum
|
|
587
|
-
(0, vitest_1.test)("enum", () => {
|
|
588
|
-
const schema = z.enum(["a", "b", "c"]);
|
|
589
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(schema)).toMatchInlineSnapshot(`
|
|
590
|
-
{
|
|
591
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
592
|
-
"enum": [
|
|
593
|
-
"a",
|
|
594
|
-
"b",
|
|
595
|
-
"c",
|
|
596
|
-
],
|
|
597
|
-
}
|
|
598
|
-
`);
|
|
599
|
-
});
|
|
600
|
-
// literal
|
|
601
|
-
(0, vitest_1.test)("literal", () => {
|
|
602
|
-
const a = z.literal("hello");
|
|
603
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(a)).toMatchInlineSnapshot(`
|
|
604
|
-
{
|
|
605
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
606
|
-
"const": "hello",
|
|
607
|
-
}
|
|
608
|
-
`);
|
|
609
|
-
const b = z.literal(["hello", undefined, null, 5, BigInt(1324)]);
|
|
610
|
-
(0, vitest_1.expect)(() => (0, core_1.toJSONSchema)(b)).toThrow();
|
|
611
|
-
const c = z.literal(["hello", null, 5]);
|
|
612
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(c)).toMatchInlineSnapshot(`
|
|
613
|
-
{
|
|
614
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
615
|
-
"enum": [
|
|
616
|
-
"hello",
|
|
617
|
-
null,
|
|
618
|
-
5,
|
|
619
|
-
],
|
|
620
|
-
}
|
|
621
|
-
`);
|
|
622
|
-
});
|
|
623
|
-
// pipe
|
|
624
|
-
(0, vitest_1.test)("pipe", () => {
|
|
625
|
-
const schema = z
|
|
626
|
-
.string()
|
|
627
|
-
.transform((val) => Number.parseInt(val))
|
|
628
|
-
.pipe(z.number());
|
|
629
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(schema)).toMatchInlineSnapshot(`
|
|
630
|
-
{
|
|
631
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
632
|
-
"type": "number",
|
|
633
|
-
}
|
|
634
|
-
`);
|
|
635
|
-
});
|
|
636
|
-
(0, vitest_1.test)("simple objects", () => {
|
|
637
|
-
const schema = z.object({
|
|
638
|
-
name: z.string(),
|
|
639
|
-
age: z.number(),
|
|
640
|
-
});
|
|
641
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(schema)).toMatchInlineSnapshot(`
|
|
642
|
-
{
|
|
643
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
644
|
-
"properties": {
|
|
645
|
-
"age": {
|
|
646
|
-
"type": "number",
|
|
647
|
-
},
|
|
648
|
-
"name": {
|
|
649
|
-
"type": "string",
|
|
650
|
-
},
|
|
651
|
-
},
|
|
652
|
-
"required": [
|
|
653
|
-
"name",
|
|
654
|
-
"age",
|
|
655
|
-
],
|
|
656
|
-
"type": "object",
|
|
657
|
-
}
|
|
658
|
-
`);
|
|
659
|
-
});
|
|
660
|
-
(0, vitest_1.test)("catchall objects", () => {
|
|
661
|
-
const a = z.strictObject({
|
|
662
|
-
name: z.string(),
|
|
663
|
-
age: z.number(),
|
|
664
|
-
});
|
|
665
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(a)).toMatchInlineSnapshot(`
|
|
666
|
-
{
|
|
667
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
668
|
-
"additionalProperties": false,
|
|
669
|
-
"properties": {
|
|
670
|
-
"age": {
|
|
671
|
-
"type": "number",
|
|
672
|
-
},
|
|
673
|
-
"name": {
|
|
674
|
-
"type": "string",
|
|
675
|
-
},
|
|
676
|
-
},
|
|
677
|
-
"required": [
|
|
678
|
-
"name",
|
|
679
|
-
"age",
|
|
680
|
-
],
|
|
681
|
-
"type": "object",
|
|
682
|
-
}
|
|
683
|
-
`);
|
|
684
|
-
const b = z
|
|
685
|
-
.object({
|
|
686
|
-
name: z.string(),
|
|
687
|
-
})
|
|
688
|
-
.catchall(z.string());
|
|
689
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(b)).toMatchInlineSnapshot(`
|
|
690
|
-
{
|
|
691
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
692
|
-
"additionalProperties": {
|
|
693
|
-
"type": "string",
|
|
694
|
-
},
|
|
695
|
-
"properties": {
|
|
696
|
-
"name": {
|
|
697
|
-
"type": "string",
|
|
698
|
-
},
|
|
699
|
-
},
|
|
700
|
-
"required": [
|
|
701
|
-
"name",
|
|
702
|
-
],
|
|
703
|
-
"type": "object",
|
|
704
|
-
}
|
|
705
|
-
`);
|
|
706
|
-
const c = z.looseObject({
|
|
707
|
-
name: z.string(),
|
|
708
|
-
});
|
|
709
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(c)).toMatchInlineSnapshot(`
|
|
710
|
-
{
|
|
711
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
712
|
-
"additionalProperties": {},
|
|
713
|
-
"properties": {
|
|
714
|
-
"name": {
|
|
715
|
-
"type": "string",
|
|
716
|
-
},
|
|
717
|
-
},
|
|
718
|
-
"required": [
|
|
719
|
-
"name",
|
|
720
|
-
],
|
|
721
|
-
"type": "object",
|
|
722
|
-
}
|
|
723
|
-
`);
|
|
724
|
-
});
|
|
725
|
-
(0, vitest_1.test)("optional fields - object", () => {
|
|
726
|
-
const schema = z.object({
|
|
727
|
-
required: z.string(),
|
|
728
|
-
optional: z.string().optional(),
|
|
729
|
-
nonoptional: z.string().optional().nonoptional(),
|
|
730
|
-
});
|
|
731
|
-
const result = (0, core_1.toJSONSchema)(schema);
|
|
732
|
-
(0, vitest_1.expect)(result).toMatchInlineSnapshot(`
|
|
733
|
-
{
|
|
734
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
735
|
-
"properties": {
|
|
736
|
-
"nonoptional": {
|
|
737
|
-
"type": "string",
|
|
738
|
-
},
|
|
739
|
-
"optional": {
|
|
740
|
-
"type": "string",
|
|
741
|
-
},
|
|
742
|
-
"required": {
|
|
743
|
-
"type": "string",
|
|
744
|
-
},
|
|
745
|
-
},
|
|
746
|
-
"required": [
|
|
747
|
-
"required",
|
|
748
|
-
"nonoptional",
|
|
749
|
-
],
|
|
750
|
-
"type": "object",
|
|
751
|
-
}
|
|
752
|
-
`);
|
|
753
|
-
});
|
|
754
|
-
(0, vitest_1.test)("recursive object", () => {
|
|
755
|
-
const categorySchema = z.object({
|
|
756
|
-
name: z.string(),
|
|
757
|
-
subcategories: z.array(z.lazy(() => categorySchema)),
|
|
758
|
-
});
|
|
759
|
-
const result = (0, core_1.toJSONSchema)(categorySchema);
|
|
760
|
-
(0, vitest_1.expect)(result).toMatchInlineSnapshot(`
|
|
761
|
-
{
|
|
762
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
763
|
-
"properties": {
|
|
764
|
-
"name": {
|
|
765
|
-
"type": "string",
|
|
766
|
-
},
|
|
767
|
-
"subcategories": {
|
|
768
|
-
"items": {
|
|
769
|
-
"$ref": "#",
|
|
770
|
-
},
|
|
771
|
-
"type": "array",
|
|
772
|
-
},
|
|
773
|
-
},
|
|
774
|
-
"required": [
|
|
775
|
-
"name",
|
|
776
|
-
"subcategories",
|
|
777
|
-
],
|
|
778
|
-
"type": "object",
|
|
779
|
-
}
|
|
780
|
-
`);
|
|
781
|
-
});
|
|
782
|
-
(0, vitest_1.test)("simple interface", () => {
|
|
783
|
-
const userSchema = z.object({
|
|
784
|
-
name: z.string(),
|
|
785
|
-
age: z.number().optional(),
|
|
786
|
-
});
|
|
787
|
-
const result = (0, core_1.toJSONSchema)(userSchema);
|
|
788
|
-
(0, vitest_1.expect)(result).toMatchInlineSnapshot(`
|
|
789
|
-
{
|
|
790
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
791
|
-
"properties": {
|
|
792
|
-
"age": {
|
|
793
|
-
"type": "number",
|
|
794
|
-
},
|
|
795
|
-
"name": {
|
|
796
|
-
"type": "string",
|
|
797
|
-
},
|
|
798
|
-
},
|
|
799
|
-
"required": [
|
|
800
|
-
"name",
|
|
801
|
-
],
|
|
802
|
-
"type": "object",
|
|
803
|
-
}
|
|
804
|
-
`);
|
|
805
|
-
});
|
|
806
|
-
(0, vitest_1.test)("catchall interface", () => {
|
|
807
|
-
const a = z.strictObject({
|
|
808
|
-
name: z.string(),
|
|
809
|
-
age: z.number(),
|
|
810
|
-
});
|
|
811
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(a)).toMatchInlineSnapshot(`
|
|
812
|
-
{
|
|
813
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
814
|
-
"additionalProperties": false,
|
|
815
|
-
"properties": {
|
|
816
|
-
"age": {
|
|
817
|
-
"type": "number",
|
|
818
|
-
},
|
|
819
|
-
"name": {
|
|
820
|
-
"type": "string",
|
|
821
|
-
},
|
|
822
|
-
},
|
|
823
|
-
"required": [
|
|
824
|
-
"name",
|
|
825
|
-
"age",
|
|
826
|
-
],
|
|
827
|
-
"type": "object",
|
|
828
|
-
}
|
|
829
|
-
`);
|
|
830
|
-
const b = z
|
|
831
|
-
.object({
|
|
832
|
-
name: z.string(),
|
|
833
|
-
})
|
|
834
|
-
.catchall(z.string());
|
|
835
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(b)).toMatchInlineSnapshot(`
|
|
836
|
-
{
|
|
837
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
838
|
-
"additionalProperties": {
|
|
839
|
-
"type": "string",
|
|
840
|
-
},
|
|
841
|
-
"properties": {
|
|
842
|
-
"name": {
|
|
843
|
-
"type": "string",
|
|
844
|
-
},
|
|
845
|
-
},
|
|
846
|
-
"required": [
|
|
847
|
-
"name",
|
|
848
|
-
],
|
|
849
|
-
"type": "object",
|
|
850
|
-
}
|
|
851
|
-
`);
|
|
852
|
-
const c = z.looseObject({
|
|
853
|
-
name: z.string(),
|
|
854
|
-
});
|
|
855
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(c)).toMatchInlineSnapshot(`
|
|
856
|
-
{
|
|
857
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
858
|
-
"additionalProperties": {},
|
|
859
|
-
"properties": {
|
|
860
|
-
"name": {
|
|
861
|
-
"type": "string",
|
|
862
|
-
},
|
|
863
|
-
},
|
|
864
|
-
"required": [
|
|
865
|
-
"name",
|
|
866
|
-
],
|
|
867
|
-
"type": "object",
|
|
868
|
-
}
|
|
869
|
-
`);
|
|
870
|
-
});
|
|
871
|
-
(0, vitest_1.test)("recursive interface schemas", () => {
|
|
872
|
-
const TreeNodeSchema = z.object({
|
|
873
|
-
id: z.string(),
|
|
874
|
-
get children() {
|
|
875
|
-
return TreeNodeSchema;
|
|
876
|
-
},
|
|
877
|
-
});
|
|
878
|
-
const result = (0, core_1.toJSONSchema)(TreeNodeSchema);
|
|
879
|
-
// Should have definitions for recursive schema
|
|
880
|
-
(0, vitest_1.expect)(JSON.stringify(result, null, 2)).toMatchInlineSnapshot(`
|
|
881
|
-
"{
|
|
882
|
-
"type": "object",
|
|
883
|
-
"properties": {
|
|
884
|
-
"id": {
|
|
885
|
-
"type": "string"
|
|
886
|
-
},
|
|
887
|
-
"children": {
|
|
888
|
-
"$ref": "#"
|
|
889
|
-
}
|
|
890
|
-
},
|
|
891
|
-
"required": [
|
|
892
|
-
"id",
|
|
893
|
-
"children"
|
|
894
|
-
],
|
|
895
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema"
|
|
896
|
-
}"
|
|
897
|
-
`);
|
|
898
|
-
});
|
|
899
|
-
(0, vitest_1.test)("mutually recursive interface schemas", () => {
|
|
900
|
-
const FolderSchema = z.object({
|
|
901
|
-
name: z.string(),
|
|
902
|
-
get files() {
|
|
903
|
-
return z.array(FileSchema);
|
|
904
|
-
},
|
|
905
|
-
});
|
|
906
|
-
const FileSchema = z.object({
|
|
907
|
-
name: z.string(),
|
|
908
|
-
get parent() {
|
|
909
|
-
return FolderSchema;
|
|
910
|
-
},
|
|
911
|
-
});
|
|
912
|
-
const result = (0, core_1.toJSONSchema)(FolderSchema);
|
|
913
|
-
// Should have definitions for both schemas
|
|
914
|
-
(0, vitest_1.expect)(JSON.stringify(result, null, 2)).toMatchInlineSnapshot(`
|
|
915
|
-
"{
|
|
916
|
-
"type": "object",
|
|
917
|
-
"properties": {
|
|
918
|
-
"name": {
|
|
919
|
-
"type": "string"
|
|
920
|
-
},
|
|
921
|
-
"files": {
|
|
922
|
-
"type": "array",
|
|
923
|
-
"items": {
|
|
924
|
-
"type": "object",
|
|
925
|
-
"properties": {
|
|
926
|
-
"name": {
|
|
927
|
-
"type": "string"
|
|
928
|
-
},
|
|
929
|
-
"parent": {
|
|
930
|
-
"$ref": "#"
|
|
931
|
-
}
|
|
932
|
-
},
|
|
933
|
-
"required": [
|
|
934
|
-
"name",
|
|
935
|
-
"parent"
|
|
936
|
-
]
|
|
937
|
-
}
|
|
938
|
-
}
|
|
939
|
-
},
|
|
940
|
-
"required": [
|
|
941
|
-
"name",
|
|
942
|
-
"files"
|
|
943
|
-
],
|
|
944
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema"
|
|
945
|
-
}"
|
|
946
|
-
`);
|
|
947
|
-
});
|
|
948
|
-
});
|
|
949
|
-
(0, vitest_1.test)("override", () => {
|
|
950
|
-
const schema = z.toJSONSchema(z.string(), {
|
|
951
|
-
override: (ctx) => {
|
|
952
|
-
ctx.zodSchema;
|
|
953
|
-
ctx.jsonSchema;
|
|
954
|
-
ctx.jsonSchema.whatever = "sup";
|
|
955
|
-
},
|
|
956
|
-
});
|
|
957
|
-
(0, vitest_1.expect)(schema).toMatchInlineSnapshot(`
|
|
958
|
-
{
|
|
959
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
960
|
-
"type": "string",
|
|
961
|
-
"whatever": "sup",
|
|
962
|
-
}
|
|
963
|
-
`);
|
|
964
|
-
});
|
|
965
|
-
(0, vitest_1.test)("override: do not run on references", () => {
|
|
966
|
-
let overrideCount = 0;
|
|
967
|
-
const schema = z
|
|
968
|
-
.union([z.string().date(), z.string().datetime(), z.string().datetime({ local: true })])
|
|
969
|
-
.meta({ a: true })
|
|
970
|
-
.transform((str) => new Date(str))
|
|
971
|
-
.meta({ b: true })
|
|
972
|
-
.pipe(z.date())
|
|
973
|
-
.meta({ c: true })
|
|
974
|
-
.brand("dateIn");
|
|
975
|
-
z.toJSONSchema(schema, {
|
|
976
|
-
unrepresentable: "any",
|
|
977
|
-
io: "input",
|
|
978
|
-
override(_) {
|
|
979
|
-
overrideCount++;
|
|
980
|
-
},
|
|
981
|
-
});
|
|
982
|
-
(0, vitest_1.expect)(overrideCount).toBe(6);
|
|
983
|
-
});
|
|
984
|
-
(0, vitest_1.test)("override with refs", () => {
|
|
985
|
-
const a = z.string().optional();
|
|
986
|
-
const result = z.toJSONSchema(a, {
|
|
987
|
-
override(ctx) {
|
|
988
|
-
if (ctx.zodSchema._zod.def.type === "string") {
|
|
989
|
-
ctx.jsonSchema.type = "STRING";
|
|
990
|
-
}
|
|
991
|
-
},
|
|
992
|
-
});
|
|
993
|
-
(0, vitest_1.expect)(result).toMatchInlineSnapshot(`
|
|
994
|
-
{
|
|
995
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
996
|
-
"type": "STRING",
|
|
997
|
-
}
|
|
998
|
-
`);
|
|
999
|
-
});
|
|
1000
|
-
(0, vitest_1.test)("override execution order", () => {
|
|
1001
|
-
const schema = z.union([z.string(), z.number()]);
|
|
1002
|
-
let unionSchema;
|
|
1003
|
-
z.toJSONSchema(schema, {
|
|
1004
|
-
override(ctx) {
|
|
1005
|
-
if (ctx.zodSchema._zod.def.type === "union") {
|
|
1006
|
-
unionSchema = ctx.jsonSchema;
|
|
1007
|
-
}
|
|
1008
|
-
},
|
|
1009
|
-
});
|
|
1010
|
-
(0, vitest_1.expect)(unionSchema).toMatchInlineSnapshot(`
|
|
1011
|
-
{
|
|
1012
|
-
"anyOf": [
|
|
1013
|
-
{
|
|
1014
|
-
"type": "string",
|
|
1015
|
-
},
|
|
1016
|
-
{
|
|
1017
|
-
"type": "number",
|
|
1018
|
-
},
|
|
1019
|
-
],
|
|
1020
|
-
}
|
|
1021
|
-
`);
|
|
1022
|
-
});
|
|
1023
|
-
(0, vitest_1.test)("pipe", () => {
|
|
1024
|
-
const mySchema = z
|
|
1025
|
-
.string()
|
|
1026
|
-
.transform((val) => val.length)
|
|
1027
|
-
.pipe(z.number());
|
|
1028
|
-
// ZodPipe
|
|
1029
|
-
const a = z.toJSONSchema(mySchema);
|
|
1030
|
-
(0, vitest_1.expect)(a).toMatchInlineSnapshot(`
|
|
1031
|
-
{
|
|
1032
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
1033
|
-
"type": "number",
|
|
1034
|
-
}
|
|
1035
|
-
`);
|
|
1036
|
-
// => { type: "number" }
|
|
1037
|
-
const b = z.toJSONSchema(mySchema, { io: "input" });
|
|
1038
|
-
(0, vitest_1.expect)(b).toMatchInlineSnapshot(`
|
|
1039
|
-
{
|
|
1040
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
1041
|
-
"type": "string",
|
|
1042
|
-
}
|
|
1043
|
-
`);
|
|
1044
|
-
// => { type: "string" }
|
|
1045
|
-
});
|
|
1046
|
-
(0, vitest_1.test)("passthrough schemas", () => {
|
|
1047
|
-
const Internal = z.object({
|
|
1048
|
-
num: z.number(),
|
|
1049
|
-
str: z.string(),
|
|
1050
|
-
});
|
|
1051
|
-
//.meta({ id: "Internal" });
|
|
1052
|
-
const External = z.object({
|
|
1053
|
-
a: Internal,
|
|
1054
|
-
b: Internal.optional(),
|
|
1055
|
-
c: z.lazy(() => Internal),
|
|
1056
|
-
d: z.promise(Internal),
|
|
1057
|
-
e: z.pipe(Internal, Internal),
|
|
1058
|
-
});
|
|
1059
|
-
const result = z.toJSONSchema(External, {
|
|
1060
|
-
reused: "ref",
|
|
1061
|
-
});
|
|
1062
|
-
(0, vitest_1.expect)(result).toMatchInlineSnapshot(`
|
|
1063
|
-
{
|
|
1064
|
-
"$defs": {
|
|
1065
|
-
"__schema0": {
|
|
1066
|
-
"properties": {
|
|
1067
|
-
"num": {
|
|
1068
|
-
"type": "number",
|
|
1069
|
-
},
|
|
1070
|
-
"str": {
|
|
1071
|
-
"type": "string",
|
|
1072
|
-
},
|
|
1073
|
-
},
|
|
1074
|
-
"required": [
|
|
1075
|
-
"num",
|
|
1076
|
-
"str",
|
|
1077
|
-
],
|
|
1078
|
-
"type": "object",
|
|
1079
|
-
},
|
|
1080
|
-
},
|
|
1081
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
1082
|
-
"properties": {
|
|
1083
|
-
"a": {
|
|
1084
|
-
"$ref": "#/$defs/__schema0",
|
|
1085
|
-
},
|
|
1086
|
-
"b": {
|
|
1087
|
-
"$ref": "#/$defs/__schema0",
|
|
1088
|
-
},
|
|
1089
|
-
"c": {
|
|
1090
|
-
"$ref": "#/$defs/__schema0",
|
|
1091
|
-
},
|
|
1092
|
-
"d": {
|
|
1093
|
-
"$ref": "#/$defs/__schema0",
|
|
1094
|
-
},
|
|
1095
|
-
"e": {
|
|
1096
|
-
"$ref": "#/$defs/__schema0",
|
|
1097
|
-
},
|
|
1098
|
-
},
|
|
1099
|
-
"required": [
|
|
1100
|
-
"a",
|
|
1101
|
-
"c",
|
|
1102
|
-
"d",
|
|
1103
|
-
"e",
|
|
1104
|
-
],
|
|
1105
|
-
"type": "object",
|
|
1106
|
-
}
|
|
1107
|
-
`);
|
|
1108
|
-
});
|
|
1109
|
-
(0, vitest_1.test)("extract schemas with id", () => {
|
|
1110
|
-
const name = z.string().meta({ id: "name" });
|
|
1111
|
-
const result = z.toJSONSchema(z.object({
|
|
1112
|
-
first_name: name,
|
|
1113
|
-
last_name: name.nullable(),
|
|
1114
|
-
middle_name: name.optional(),
|
|
1115
|
-
age: z.number().meta({ id: "age" }),
|
|
1116
|
-
}));
|
|
1117
|
-
(0, vitest_1.expect)(result).toMatchInlineSnapshot(`
|
|
1118
|
-
{
|
|
1119
|
-
"$defs": {
|
|
1120
|
-
"age": {
|
|
1121
|
-
"id": "age",
|
|
1122
|
-
"type": "number",
|
|
1123
|
-
},
|
|
1124
|
-
"name": {
|
|
1125
|
-
"id": "name",
|
|
1126
|
-
"type": "string",
|
|
1127
|
-
},
|
|
1128
|
-
},
|
|
1129
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
1130
|
-
"properties": {
|
|
1131
|
-
"age": {
|
|
1132
|
-
"$ref": "#/$defs/age",
|
|
1133
|
-
},
|
|
1134
|
-
"first_name": {
|
|
1135
|
-
"$ref": "#/$defs/name",
|
|
1136
|
-
},
|
|
1137
|
-
"last_name": {
|
|
1138
|
-
"anyOf": [
|
|
1139
|
-
{
|
|
1140
|
-
"$ref": "#/$defs/name",
|
|
1141
|
-
},
|
|
1142
|
-
{
|
|
1143
|
-
"type": "null",
|
|
1144
|
-
},
|
|
1145
|
-
],
|
|
1146
|
-
},
|
|
1147
|
-
"middle_name": {
|
|
1148
|
-
"$ref": "#/$defs/name",
|
|
1149
|
-
},
|
|
1150
|
-
},
|
|
1151
|
-
"required": [
|
|
1152
|
-
"first_name",
|
|
1153
|
-
"last_name",
|
|
1154
|
-
"age",
|
|
1155
|
-
],
|
|
1156
|
-
"type": "object",
|
|
1157
|
-
}
|
|
1158
|
-
`);
|
|
1159
|
-
});
|
|
1160
|
-
(0, vitest_1.test)("unrepresentable literal values are ignored", () => {
|
|
1161
|
-
const a = z.toJSONSchema(z.literal(["hello", null, 5, BigInt(1324), undefined]), { unrepresentable: "any" });
|
|
1162
|
-
(0, vitest_1.expect)(a).toMatchInlineSnapshot(`
|
|
1163
|
-
{
|
|
1164
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
1165
|
-
"enum": [
|
|
1166
|
-
"hello",
|
|
1167
|
-
null,
|
|
1168
|
-
5,
|
|
1169
|
-
1324,
|
|
1170
|
-
],
|
|
1171
|
-
}
|
|
1172
|
-
`);
|
|
1173
|
-
const b = z.toJSONSchema(z.literal([undefined, null, 5, BigInt(1324)]), { unrepresentable: "any" });
|
|
1174
|
-
(0, vitest_1.expect)(b).toMatchInlineSnapshot(`
|
|
1175
|
-
{
|
|
1176
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
1177
|
-
"enum": [
|
|
1178
|
-
null,
|
|
1179
|
-
5,
|
|
1180
|
-
1324,
|
|
1181
|
-
],
|
|
1182
|
-
}
|
|
1183
|
-
`);
|
|
1184
|
-
const c = z.toJSONSchema(z.literal([undefined]), { unrepresentable: "any" });
|
|
1185
|
-
(0, vitest_1.expect)(c).toMatchInlineSnapshot(`
|
|
1186
|
-
{
|
|
1187
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
1188
|
-
}
|
|
1189
|
-
`);
|
|
1190
|
-
});
|
|
1191
|
-
(0, vitest_1.test)("describe with id", () => {
|
|
1192
|
-
const jobId = z.string().meta({ id: "jobId" });
|
|
1193
|
-
const a = z.toJSONSchema(z.object({
|
|
1194
|
-
current: jobId.describe("Current job"),
|
|
1195
|
-
previous: jobId.describe("Previous job"),
|
|
1196
|
-
}));
|
|
1197
|
-
(0, vitest_1.expect)(a).toMatchInlineSnapshot(`
|
|
1198
|
-
{
|
|
1199
|
-
"$defs": {
|
|
1200
|
-
"jobId": {
|
|
1201
|
-
"id": "jobId",
|
|
1202
|
-
"type": "string",
|
|
1203
|
-
},
|
|
1204
|
-
},
|
|
1205
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
1206
|
-
"properties": {
|
|
1207
|
-
"current": {
|
|
1208
|
-
"$ref": "#/$defs/jobId",
|
|
1209
|
-
"description": "Current job",
|
|
1210
|
-
},
|
|
1211
|
-
"previous": {
|
|
1212
|
-
"$ref": "#/$defs/jobId",
|
|
1213
|
-
"description": "Previous job",
|
|
1214
|
-
},
|
|
1215
|
-
},
|
|
1216
|
-
"required": [
|
|
1217
|
-
"current",
|
|
1218
|
-
"previous",
|
|
1219
|
-
],
|
|
1220
|
-
"type": "object",
|
|
1221
|
-
}
|
|
1222
|
-
`);
|
|
1223
|
-
});
|
|
1224
|
-
(0, vitest_1.test)("overwrite id", () => {
|
|
1225
|
-
const jobId = z.string().meta({ id: "aaa" });
|
|
1226
|
-
const a = z.toJSONSchema(z.object({
|
|
1227
|
-
current: jobId,
|
|
1228
|
-
previous: jobId.meta({ id: "bbb" }),
|
|
1229
|
-
}));
|
|
1230
|
-
(0, vitest_1.expect)(a).toMatchInlineSnapshot(`
|
|
1231
|
-
{
|
|
1232
|
-
"$defs": {
|
|
1233
|
-
"aaa": {
|
|
1234
|
-
"id": "aaa",
|
|
1235
|
-
"type": "string",
|
|
1236
|
-
},
|
|
1237
|
-
"bbb": {
|
|
1238
|
-
"$ref": "#/$defs/aaa",
|
|
1239
|
-
"id": "bbb",
|
|
1240
|
-
},
|
|
1241
|
-
},
|
|
1242
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
1243
|
-
"properties": {
|
|
1244
|
-
"current": {
|
|
1245
|
-
"$ref": "#/$defs/aaa",
|
|
1246
|
-
},
|
|
1247
|
-
"previous": {
|
|
1248
|
-
"$ref": "#/$defs/bbb",
|
|
1249
|
-
},
|
|
1250
|
-
},
|
|
1251
|
-
"required": [
|
|
1252
|
-
"current",
|
|
1253
|
-
"previous",
|
|
1254
|
-
],
|
|
1255
|
-
"type": "object",
|
|
1256
|
-
}
|
|
1257
|
-
`);
|
|
1258
|
-
const b = z.toJSONSchema(z.object({
|
|
1259
|
-
current: jobId,
|
|
1260
|
-
previous: jobId.meta({ id: "ccc" }),
|
|
1261
|
-
}), {
|
|
1262
|
-
reused: "ref",
|
|
1263
|
-
});
|
|
1264
|
-
(0, vitest_1.expect)(b).toMatchInlineSnapshot(`
|
|
1265
|
-
{
|
|
1266
|
-
"$defs": {
|
|
1267
|
-
"aaa": {
|
|
1268
|
-
"id": "aaa",
|
|
1269
|
-
"type": "string",
|
|
1270
|
-
},
|
|
1271
|
-
"ccc": {
|
|
1272
|
-
"$ref": "#/$defs/aaa",
|
|
1273
|
-
"id": "ccc",
|
|
1274
|
-
},
|
|
1275
|
-
},
|
|
1276
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
1277
|
-
"properties": {
|
|
1278
|
-
"current": {
|
|
1279
|
-
"$ref": "#/$defs/aaa",
|
|
1280
|
-
},
|
|
1281
|
-
"previous": {
|
|
1282
|
-
"$ref": "#/$defs/ccc",
|
|
1283
|
-
},
|
|
1284
|
-
},
|
|
1285
|
-
"required": [
|
|
1286
|
-
"current",
|
|
1287
|
-
"previous",
|
|
1288
|
-
],
|
|
1289
|
-
"type": "object",
|
|
1290
|
-
}
|
|
1291
|
-
`);
|
|
1292
|
-
});
|
|
1293
|
-
(0, vitest_1.test)("overwrite descriptions", () => {
|
|
1294
|
-
const field = z.string().describe("a").describe("b").describe("c");
|
|
1295
|
-
const a = z.toJSONSchema(z.object({
|
|
1296
|
-
d: field.describe("d"),
|
|
1297
|
-
e: field.describe("e"),
|
|
1298
|
-
}));
|
|
1299
|
-
(0, vitest_1.expect)(a).toMatchInlineSnapshot(`
|
|
1300
|
-
{
|
|
1301
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
1302
|
-
"properties": {
|
|
1303
|
-
"d": {
|
|
1304
|
-
"description": "d",
|
|
1305
|
-
"type": "string",
|
|
1306
|
-
},
|
|
1307
|
-
"e": {
|
|
1308
|
-
"description": "e",
|
|
1309
|
-
"type": "string",
|
|
1310
|
-
},
|
|
1311
|
-
},
|
|
1312
|
-
"required": [
|
|
1313
|
-
"d",
|
|
1314
|
-
"e",
|
|
1315
|
-
],
|
|
1316
|
-
"type": "object",
|
|
1317
|
-
}
|
|
1318
|
-
`);
|
|
1319
|
-
const b = z.toJSONSchema(z.object({
|
|
1320
|
-
d: field.describe("d"),
|
|
1321
|
-
e: field.describe("e"),
|
|
1322
|
-
}), {
|
|
1323
|
-
reused: "ref",
|
|
1324
|
-
});
|
|
1325
|
-
(0, vitest_1.expect)(b).toMatchInlineSnapshot(`
|
|
1326
|
-
{
|
|
1327
|
-
"$defs": {
|
|
1328
|
-
"__schema0": {
|
|
1329
|
-
"description": "c",
|
|
1330
|
-
"type": "string",
|
|
1331
|
-
},
|
|
1332
|
-
},
|
|
1333
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
1334
|
-
"properties": {
|
|
1335
|
-
"d": {
|
|
1336
|
-
"$ref": "#/$defs/__schema0",
|
|
1337
|
-
"description": "d",
|
|
1338
|
-
},
|
|
1339
|
-
"e": {
|
|
1340
|
-
"$ref": "#/$defs/__schema0",
|
|
1341
|
-
"description": "e",
|
|
1342
|
-
},
|
|
1343
|
-
},
|
|
1344
|
-
"required": [
|
|
1345
|
-
"d",
|
|
1346
|
-
"e",
|
|
1347
|
-
],
|
|
1348
|
-
"type": "object",
|
|
1349
|
-
}
|
|
1350
|
-
`);
|
|
1351
|
-
});
|
|
1352
|
-
(0, vitest_1.test)("top-level readonly", () => {
|
|
1353
|
-
const A = z
|
|
1354
|
-
.object({
|
|
1355
|
-
name: z.string(),
|
|
1356
|
-
get b() {
|
|
1357
|
-
return B;
|
|
1358
|
-
},
|
|
1359
|
-
})
|
|
1360
|
-
.readonly()
|
|
1361
|
-
.meta({ id: "A" });
|
|
1362
|
-
const B = z
|
|
1363
|
-
.object({
|
|
1364
|
-
name: z.string(),
|
|
1365
|
-
get a() {
|
|
1366
|
-
return A;
|
|
1367
|
-
},
|
|
1368
|
-
})
|
|
1369
|
-
.readonly()
|
|
1370
|
-
.meta({ id: "B" });
|
|
1371
|
-
const result = z.toJSONSchema(A);
|
|
1372
|
-
(0, vitest_1.expect)(result).toMatchInlineSnapshot(`
|
|
1373
|
-
{
|
|
1374
|
-
"$defs": {
|
|
1375
|
-
"B": {
|
|
1376
|
-
"id": "B",
|
|
1377
|
-
"properties": {
|
|
1378
|
-
"a": {
|
|
1379
|
-
"$ref": "#",
|
|
1380
|
-
},
|
|
1381
|
-
"name": {
|
|
1382
|
-
"type": "string",
|
|
1383
|
-
},
|
|
1384
|
-
},
|
|
1385
|
-
"readOnly": true,
|
|
1386
|
-
"required": [
|
|
1387
|
-
"name",
|
|
1388
|
-
"a",
|
|
1389
|
-
],
|
|
1390
|
-
"type": "object",
|
|
1391
|
-
},
|
|
1392
|
-
},
|
|
1393
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
1394
|
-
"id": "A",
|
|
1395
|
-
"properties": {
|
|
1396
|
-
"b": {
|
|
1397
|
-
"$ref": "#/$defs/B",
|
|
1398
|
-
},
|
|
1399
|
-
"name": {
|
|
1400
|
-
"type": "string",
|
|
1401
|
-
},
|
|
1402
|
-
},
|
|
1403
|
-
"readOnly": true,
|
|
1404
|
-
"required": [
|
|
1405
|
-
"name",
|
|
1406
|
-
"b",
|
|
1407
|
-
],
|
|
1408
|
-
"type": "object",
|
|
1409
|
-
}
|
|
1410
|
-
`);
|
|
1411
|
-
});
|
|
1412
|
-
(0, vitest_1.test)("basic registry", () => {
|
|
1413
|
-
const myRegistry = z.registry();
|
|
1414
|
-
const User = z.object({
|
|
1415
|
-
name: z.string(),
|
|
1416
|
-
get posts() {
|
|
1417
|
-
return z.array(Post);
|
|
1418
|
-
},
|
|
1419
|
-
});
|
|
1420
|
-
const Post = z.object({
|
|
1421
|
-
title: z.string(),
|
|
1422
|
-
content: z.string(),
|
|
1423
|
-
get author() {
|
|
1424
|
-
return User;
|
|
1425
|
-
},
|
|
1426
|
-
});
|
|
1427
|
-
myRegistry.add(User, { id: "User" });
|
|
1428
|
-
myRegistry.add(Post, { id: "Post" });
|
|
1429
|
-
const result = z.toJSONSchema(myRegistry);
|
|
1430
|
-
(0, vitest_1.expect)(result).toMatchInlineSnapshot(`
|
|
1431
|
-
{
|
|
1432
|
-
"schemas": {
|
|
1433
|
-
"Post": {
|
|
1434
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
1435
|
-
"properties": {
|
|
1436
|
-
"author": {
|
|
1437
|
-
"$ref": "User",
|
|
1438
|
-
},
|
|
1439
|
-
"content": {
|
|
1440
|
-
"type": "string",
|
|
1441
|
-
},
|
|
1442
|
-
"title": {
|
|
1443
|
-
"type": "string",
|
|
1444
|
-
},
|
|
1445
|
-
},
|
|
1446
|
-
"required": [
|
|
1447
|
-
"title",
|
|
1448
|
-
"content",
|
|
1449
|
-
"author",
|
|
1450
|
-
],
|
|
1451
|
-
"type": "object",
|
|
1452
|
-
},
|
|
1453
|
-
"User": {
|
|
1454
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
1455
|
-
"properties": {
|
|
1456
|
-
"name": {
|
|
1457
|
-
"type": "string",
|
|
1458
|
-
},
|
|
1459
|
-
"posts": {
|
|
1460
|
-
"items": {
|
|
1461
|
-
"$ref": "Post",
|
|
1462
|
-
},
|
|
1463
|
-
"type": "array",
|
|
1464
|
-
},
|
|
1465
|
-
},
|
|
1466
|
-
"required": [
|
|
1467
|
-
"name",
|
|
1468
|
-
"posts",
|
|
1469
|
-
],
|
|
1470
|
-
"type": "object",
|
|
1471
|
-
},
|
|
1472
|
-
},
|
|
1473
|
-
}
|
|
1474
|
-
`);
|
|
1475
|
-
});
|
|
1476
|
-
(0, vitest_1.test)("_ref", () => {
|
|
1477
|
-
// const a = z.promise(z.string().describe("a"));
|
|
1478
|
-
const a = z.toJSONSchema(z.promise(z.string().describe("a")));
|
|
1479
|
-
(0, vitest_1.expect)(a).toMatchInlineSnapshot(`
|
|
1480
|
-
{
|
|
1481
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
1482
|
-
"description": "a",
|
|
1483
|
-
"type": "string",
|
|
1484
|
-
}
|
|
1485
|
-
`);
|
|
1486
|
-
const b = z.toJSONSchema(z.lazy(() => z.string().describe("a")));
|
|
1487
|
-
(0, vitest_1.expect)(b).toMatchInlineSnapshot(`
|
|
1488
|
-
{
|
|
1489
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
1490
|
-
"description": "a",
|
|
1491
|
-
"type": "string",
|
|
1492
|
-
}
|
|
1493
|
-
`);
|
|
1494
|
-
const c = z.toJSONSchema(z.optional(z.string().describe("a")));
|
|
1495
|
-
(0, vitest_1.expect)(c).toMatchInlineSnapshot(`
|
|
1496
|
-
{
|
|
1497
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
1498
|
-
"description": "a",
|
|
1499
|
-
"type": "string",
|
|
1500
|
-
}
|
|
1501
|
-
`);
|
|
1502
|
-
});
|
|
1503
|
-
(0, vitest_1.test)("defaults/prefaults", () => {
|
|
1504
|
-
const a = z
|
|
1505
|
-
.string()
|
|
1506
|
-
.transform((val) => val.length)
|
|
1507
|
-
.pipe(z.number());
|
|
1508
|
-
const b = a.prefault("hello");
|
|
1509
|
-
const c = a.default(1234);
|
|
1510
|
-
// a
|
|
1511
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(a)).toMatchInlineSnapshot(`
|
|
1512
|
-
{
|
|
1513
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
1514
|
-
"type": "number",
|
|
1515
|
-
}
|
|
1516
|
-
`);
|
|
1517
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(a, { io: "input" })).toMatchInlineSnapshot(`
|
|
1518
|
-
{
|
|
1519
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
1520
|
-
"type": "string",
|
|
1521
|
-
}
|
|
1522
|
-
`);
|
|
1523
|
-
// b
|
|
1524
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(b)).toMatchInlineSnapshot(`
|
|
1525
|
-
{
|
|
1526
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
1527
|
-
"type": "number",
|
|
1528
|
-
}
|
|
1529
|
-
`);
|
|
1530
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(b, { io: "input" })).toMatchInlineSnapshot(`
|
|
1531
|
-
{
|
|
1532
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
1533
|
-
"default": "hello",
|
|
1534
|
-
"type": "string",
|
|
1535
|
-
}
|
|
1536
|
-
`);
|
|
1537
|
-
// c
|
|
1538
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(c)).toMatchInlineSnapshot(`
|
|
1539
|
-
{
|
|
1540
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
1541
|
-
"default": 1234,
|
|
1542
|
-
"type": "number",
|
|
1543
|
-
}
|
|
1544
|
-
`);
|
|
1545
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(c, { io: "input" })).toMatchInlineSnapshot(`
|
|
1546
|
-
{
|
|
1547
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
1548
|
-
"default": 1234,
|
|
1549
|
-
"type": "string",
|
|
1550
|
-
}
|
|
1551
|
-
`);
|
|
1552
|
-
});
|
|
1553
|
-
(0, vitest_1.test)("input type", () => {
|
|
1554
|
-
const schema = z.object({
|
|
1555
|
-
a: z.string(),
|
|
1556
|
-
b: z.string().optional(),
|
|
1557
|
-
c: z.string().default("hello"),
|
|
1558
|
-
d: z.string().nullable(),
|
|
1559
|
-
e: z.string().prefault("hello"),
|
|
1560
|
-
});
|
|
1561
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(schema, { io: "input" })).toMatchInlineSnapshot(`
|
|
1562
|
-
{
|
|
1563
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
1564
|
-
"properties": {
|
|
1565
|
-
"a": {
|
|
1566
|
-
"type": "string",
|
|
1567
|
-
},
|
|
1568
|
-
"b": {
|
|
1569
|
-
"type": "string",
|
|
1570
|
-
},
|
|
1571
|
-
"c": {
|
|
1572
|
-
"default": "hello",
|
|
1573
|
-
"type": "string",
|
|
1574
|
-
},
|
|
1575
|
-
"d": {
|
|
1576
|
-
"anyOf": [
|
|
1577
|
-
{
|
|
1578
|
-
"type": "string",
|
|
1579
|
-
},
|
|
1580
|
-
{
|
|
1581
|
-
"type": "null",
|
|
1582
|
-
},
|
|
1583
|
-
],
|
|
1584
|
-
},
|
|
1585
|
-
"e": {
|
|
1586
|
-
"default": "hello",
|
|
1587
|
-
"type": "string",
|
|
1588
|
-
},
|
|
1589
|
-
},
|
|
1590
|
-
"required": [
|
|
1591
|
-
"a",
|
|
1592
|
-
"d",
|
|
1593
|
-
],
|
|
1594
|
-
"type": "object",
|
|
1595
|
-
}
|
|
1596
|
-
`);
|
|
1597
|
-
(0, vitest_1.expect)((0, core_1.toJSONSchema)(schema, { io: "output" })).toMatchInlineSnapshot(`
|
|
1598
|
-
{
|
|
1599
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
1600
|
-
"properties": {
|
|
1601
|
-
"a": {
|
|
1602
|
-
"type": "string",
|
|
1603
|
-
},
|
|
1604
|
-
"b": {
|
|
1605
|
-
"type": "string",
|
|
1606
|
-
},
|
|
1607
|
-
"c": {
|
|
1608
|
-
"default": "hello",
|
|
1609
|
-
"type": "string",
|
|
1610
|
-
},
|
|
1611
|
-
"d": {
|
|
1612
|
-
"anyOf": [
|
|
1613
|
-
{
|
|
1614
|
-
"type": "string",
|
|
1615
|
-
},
|
|
1616
|
-
{
|
|
1617
|
-
"type": "null",
|
|
1618
|
-
},
|
|
1619
|
-
],
|
|
1620
|
-
},
|
|
1621
|
-
"e": {
|
|
1622
|
-
"type": "string",
|
|
1623
|
-
},
|
|
1624
|
-
},
|
|
1625
|
-
"required": [
|
|
1626
|
-
"a",
|
|
1627
|
-
"c",
|
|
1628
|
-
"d",
|
|
1629
|
-
"e",
|
|
1630
|
-
],
|
|
1631
|
-
"type": "object",
|
|
1632
|
-
}
|
|
1633
|
-
`);
|
|
1634
|
-
});
|
|
1635
|
-
(0, vitest_1.test)("examples on pipe", () => {
|
|
1636
|
-
const schema = z
|
|
1637
|
-
.string()
|
|
1638
|
-
.meta({ examples: ["test"] })
|
|
1639
|
-
.transform(Number)
|
|
1640
|
-
// .pipe(z.transform(Number).meta({ examples: [4] }))
|
|
1641
|
-
.meta({ examples: [4] });
|
|
1642
|
-
const i = z.toJSONSchema(schema, { io: "input", unrepresentable: "any" });
|
|
1643
|
-
(0, vitest_1.expect)(i).toMatchInlineSnapshot(`
|
|
1644
|
-
{
|
|
1645
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
1646
|
-
"examples": [
|
|
1647
|
-
"test",
|
|
1648
|
-
],
|
|
1649
|
-
"type": "string",
|
|
1650
|
-
}
|
|
1651
|
-
`);
|
|
1652
|
-
const o = z.toJSONSchema(schema, { io: "output", unrepresentable: "any" });
|
|
1653
|
-
(0, vitest_1.expect)(o).toMatchInlineSnapshot(`
|
|
1654
|
-
{
|
|
1655
|
-
"$schema": "https://json-schema.org/draft-2020-12/schema",
|
|
1656
|
-
"examples": [
|
|
1657
|
-
4,
|
|
1658
|
-
],
|
|
1659
|
-
}
|
|
1660
|
-
`);
|
|
1661
|
-
});
|
|
1662
|
-
// test("number checks", () => {
|
|
1663
|
-
// expect(z.toJSONSchema(z.number().int())).toMatchInlineSnapshot(`
|
|
1664
|
-
// {
|
|
1665
|
-
// "maximum": 9007199254740991,
|
|
1666
|
-
// "minimum": -9007199254740991,
|
|
1667
|
-
// "type": "integer",
|
|
1668
|
-
// }
|
|
1669
|
-
// `);
|
|
1670
|
-
// expect(z.toJSONSchema(z.int())).toMatchInlineSnapshot(`
|
|
1671
|
-
// {
|
|
1672
|
-
// "maximum": 9007199254740991,
|
|
1673
|
-
// "minimum": -9007199254740991,
|
|
1674
|
-
// "type": "integer",
|
|
1675
|
-
// }
|
|
1676
|
-
// `);
|
|
1677
|
-
// expect(z.toJSONSchema(z.int().positive())).toMatchInlineSnapshot(`
|
|
1678
|
-
// {
|
|
1679
|
-
// "exclusiveMinimum": 0,
|
|
1680
|
-
// "maximum": 9007199254740991,
|
|
1681
|
-
// "minimum": -9007199254740991,
|
|
1682
|
-
// "type": "integer",
|
|
1683
|
-
// }
|
|
1684
|
-
// `);
|
|
1685
|
-
// expect(z.toJSONSchema(z.int().nonnegative())).toMatchInlineSnapshot(`
|
|
1686
|
-
// {
|
|
1687
|
-
// "maximum": 9007199254740991,
|
|
1688
|
-
// "minimum": 0,
|
|
1689
|
-
// "type": "integer",
|
|
1690
|
-
// }
|
|
1691
|
-
// `);
|
|
1692
|
-
// expect(z.toJSONSchema(z.int().gt(0))).toMatchInlineSnapshot(`
|
|
1693
|
-
// {
|
|
1694
|
-
// "exclusiveMinimum": 0,
|
|
1695
|
-
// "maximum": 9007199254740991,
|
|
1696
|
-
// "minimum": -9007199254740991,
|
|
1697
|
-
// "type": "integer",
|
|
1698
|
-
// }
|
|
1699
|
-
// `);
|
|
1700
|
-
// expect(z.toJSONSchema(z.int().gte(0))).toMatchInlineSnapshot(`
|
|
1701
|
-
// {
|
|
1702
|
-
// "maximum": 9007199254740991,
|
|
1703
|
-
// "minimum": 0,
|
|
1704
|
-
// "type": "integer",
|
|
1705
|
-
// }
|
|
1706
|
-
// `);
|
|
1707
|
-
// });
|