Test case
1 generated file · +7 −1test/inputs/json/misc/00ec5.json
Mtypescript-zoddefault / TopLevel.ts+7 −1
| @@ -1,5 +1,11 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const TypeSchema = z.enum([ |
| 5 | 11 | "string", |
| @@ -35,7 +41,7 @@ export const SchemaSchema = z.object({ | ||
| 35 | 41 | export type Schema = z.infer<typeof SchemaSchema>; |
| 36 | 42 | |
| 37 | 43 | export const ProviderSchema = z.object({ |
| 38 | - "properties": z.record(z.string(), PropertySchema), | |
| 44 | + "properties": mapSchema(PropertySchema), | |
| 39 | 45 | }); |
| 40 | 46 | export type Provider = z.infer<typeof ProviderSchema>; |
Test case
1 generated file · +7 −1test/inputs/json/misc/033b1.json
Mtypescript-zoddefault / TopLevel.ts+7 −1
| @@ -1,9 +1,15 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const TopLevelSchema = z.object({ |
| 5 | 11 | "base": z.string(), |
| 6 | 12 | "date": z.string(), |
| 7 | - "rates": z.record(z.string(), z.number()), | |
| 13 | + "rates": mapSchema(z.number()), | |
| 8 | 14 | }); |
| 9 | 15 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +7 −1test/inputs/json/misc/09f54.json
Mtypescript-zoddefault / TopLevel.ts+7 −1
| @@ -1,5 +1,11 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const DatumSchema = z.object({ |
| 5 | 11 | "anomaly": z.string(), |
| @@ -16,7 +22,7 @@ export const DescriptionSchema = z.object({ | ||
| 16 | 22 | export type Description = z.infer<typeof DescriptionSchema>; |
| 17 | 23 | |
| 18 | 24 | export const TopLevelSchema = z.object({ |
| 19 | - "data": z.record(z.string(), DatumSchema), | |
| 25 | + "data": mapSchema(DatumSchema), | |
| 20 | 26 | "description": DescriptionSchema, |
| 21 | 27 | }); |
| 22 | 28 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +7 −1test/inputs/json/misc/167d6.json
Mtypescript-zoddefault / TopLevel.ts+7 −1
| @@ -1,9 +1,15 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const TopLevelSchema = z.object({ |
| 5 | 11 | "base": z.string(), |
| 6 | 12 | "date": z.string(), |
| 7 | - "rates": z.record(z.string(), z.number()), | |
| 13 | + "rates": mapSchema(z.number()), | |
| 8 | 14 | }); |
| 9 | 15 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +7 −1test/inputs/json/misc/43eaf.json
Mtypescript-zoddefault / TopLevel.ts+7 −1
| @@ -1,9 +1,15 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const TopLevelSchema = z.object({ |
| 5 | 11 | "base": z.string(), |
| 6 | 12 | "date": z.string(), |
| 7 | - "rates": z.record(z.string(), z.number()), | |
| 13 | + "rates": mapSchema(z.number()), | |
| 8 | 14 | }); |
| 9 | 15 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +7 −1test/inputs/json/misc/5f3a1.json
Mtypescript-zoddefault / TopLevel.ts+7 −1
| @@ -1,9 +1,15 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const TopLevelSchema = z.object({ |
| 5 | 11 | "base": z.string(), |
| 6 | 12 | "date": z.string(), |
| 7 | - "rates": z.record(z.string(), z.number()), | |
| 13 | + "rates": mapSchema(z.number()), | |
| 8 | 14 | }); |
| 9 | 15 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +7 −1test/inputs/json/misc/6260a.json
Mtypescript-zoddefault / TopLevel.ts+7 −1
| @@ -1,9 +1,15 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const TopLevelSchema = z.object({ |
| 5 | 11 | "base": z.string(), |
| 6 | 12 | "date": z.string(), |
| 7 | - "rates": z.record(z.string(), z.number()), | |
| 13 | + "rates": mapSchema(z.number()), | |
| 8 | 14 | }); |
| 9 | 15 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +7 −1test/inputs/json/misc/70c77.json
Mtypescript-zoddefault / TopLevel.ts+7 −1
| @@ -1,9 +1,15 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const TopLevelSchema = z.object({ |
| 5 | 11 | "base": z.string(), |
| 6 | 12 | "date": z.string(), |
| 7 | - "rates": z.record(z.string(), z.number()), | |
| 13 | + "rates": mapSchema(z.number()), | |
| 8 | 14 | }); |
| 9 | 15 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +7 −1test/inputs/json/misc/75912.json
Mtypescript-zoddefault / TopLevel.ts+7 −1
| @@ -1,9 +1,15 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const TopLevelSchema = z.object({ |
| 5 | 11 | "base": z.string(), |
| 6 | 12 | "date": z.string(), |
| 7 | - "rates": z.record(z.string(), z.number()), | |
| 13 | + "rates": mapSchema(z.number()), | |
| 8 | 14 | }); |
| 9 | 15 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +7 −1test/inputs/json/misc/76ae1.json
Mtypescript-zoddefault / TopLevel.ts+7 −1
| @@ -1,5 +1,11 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const FormatEnumSchema = z.enum([ |
| 5 | 11 | "string", |
| @@ -102,7 +108,7 @@ export const PurpleSchemaSchema = z.object({ | ||
| 102 | 108 | export type PurpleSchema = z.infer<typeof PurpleSchemaSchema>; |
| 103 | 109 | |
| 104 | 110 | export const ArticleSchema = z.object({ |
| 105 | - "properties": z.record(z.string(), PropertySchema), | |
| 111 | + "properties": mapSchema(PropertySchema), | |
| 106 | 112 | }); |
| 107 | 113 | export type Article = z.infer<typeof ArticleSchema>; |
Test case
1 generated file · +7 −1test/inputs/json/misc/7d397.json
Mtypescript-zoddefault / TopLevel.ts+7 −1
| @@ -1,5 +1,11 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const TypeSchema = z.enum([ |
| 5 | 11 | "string", |
| @@ -41,7 +47,7 @@ export const ItemsSchema = z.object({ | ||
| 41 | 47 | export type Items = z.infer<typeof ItemsSchema>; |
| 42 | 48 | |
| 43 | 49 | export const ListSchema = z.object({ |
| 44 | - "properties": z.record(z.string(), PropertySchema), | |
| 50 | + "properties": mapSchema(PropertySchema), | |
| 45 | 51 | }); |
| 46 | 52 | export type List = z.infer<typeof ListSchema>; |
Test case
1 generated file · +7 −1test/inputs/json/misc/7f568.json
Mtypescript-zoddefault / TopLevel.ts+7 −1
| @@ -1,5 +1,11 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const LanguageSchema = z.enum([ |
| 5 | 11 | "Markdown", |
| @@ -27,7 +33,7 @@ export const TopLevelElementSchema = z.object({ | ||
| 27 | 33 | "commits_url": z.string(), |
| 28 | 34 | "created_at": z.string().pipe(z.coerce.date()), |
| 29 | 35 | "description": z.union([z.null(), z.string()]), |
| 30 | - "files": z.record(z.string(), FileSchema), | |
| 36 | + "files": mapSchema(FileSchema), | |
| 31 | 37 | "forks_url": z.string(), |
| 32 | 38 | "git_pull_url": z.string(), |
| 33 | 39 | "git_push_url": z.string(), |
Test case
1 generated file · +7 −1test/inputs/json/misc/9617f.json
Mtypescript-zoddefault / TopLevel.ts+7 −1
| @@ -1,9 +1,15 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const TopLevelSchema = z.object({ |
| 5 | 11 | "base": z.string(), |
| 6 | 12 | "date": z.string(), |
| 7 | - "rates": z.record(z.string(), z.number()), | |
| 13 | + "rates": mapSchema(z.number()), | |
| 8 | 14 | }); |
| 9 | 15 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +7 −1test/inputs/json/misc/a9691.json
Mtypescript-zoddefault / TopLevel.ts+7 −1
| @@ -1,9 +1,15 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const TopLevelSchema = z.object({ |
| 5 | 11 | "base": z.string(), |
| 6 | 12 | "date": z.string(), |
| 7 | - "rates": z.record(z.string(), z.number()), | |
| 13 | + "rates": mapSchema(z.number()), | |
| 8 | 14 | }); |
| 9 | 15 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +7 −1test/inputs/json/misc/ac944.json
Mtypescript-zoddefault / TopLevel.ts+7 −1
| @@ -1,9 +1,15 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const TopLevelSchema = z.object({ |
| 5 | 11 | "base": z.string(), |
| 6 | 12 | "date": z.string(), |
| 7 | - "rates": z.record(z.string(), z.number()), | |
| 13 | + "rates": mapSchema(z.number()), | |
| 8 | 14 | }); |
| 9 | 15 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +7 −1test/inputs/json/misc/c0356.json
Mtypescript-zoddefault / TopLevel.ts+7 −1
| @@ -1,5 +1,11 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const DatumSchema = z.object({ |
| 5 | 11 | "anomaly": z.string(), |
| @@ -15,7 +21,7 @@ export const DescriptionSchema = z.object({ | ||
| 15 | 21 | export type Description = z.infer<typeof DescriptionSchema>; |
| 16 | 22 | |
| 17 | 23 | export const TopLevelSchema = z.object({ |
| 18 | - "data": z.record(z.string(), DatumSchema), | |
| 24 | + "data": mapSchema(DatumSchema), | |
| 19 | 25 | "description": DescriptionSchema, |
| 20 | 26 | }); |
| 21 | 27 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +7 −1test/inputs/json/misc/cb81e.json
Mtypescript-zoddefault / TopLevel.ts+7 −1
| @@ -1,5 +1,11 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const DescriptionSchema = z.object({ |
| 5 | 11 | "base_period": z.string(), |
| @@ -10,7 +16,7 @@ export const DescriptionSchema = z.object({ | ||
| 10 | 16 | export type Description = z.infer<typeof DescriptionSchema>; |
| 11 | 17 | |
| 12 | 18 | export const TopLevelSchema = z.object({ |
| 13 | - "data": z.record(z.string(), z.string()), | |
| 19 | + "data": mapSchema(z.string()), | |
| 14 | 20 | "description": DescriptionSchema, |
| 15 | 21 | }); |
| 16 | 22 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +7 −1test/inputs/json/misc/cd463.json
Mtypescript-zoddefault / TopLevel.ts+7 −1
| @@ -1,9 +1,15 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const TopLevelSchema = z.object({ |
| 5 | 11 | "base": z.string(), |
| 6 | 12 | "date": z.string(), |
| 7 | - "rates": z.record(z.string(), z.number()), | |
| 13 | + "rates": mapSchema(z.number()), | |
| 8 | 14 | }); |
| 9 | 15 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +7 −1test/inputs/json/misc/cfbce.json
Mtypescript-zoddefault / TopLevel.ts+7 −1
| @@ -1,9 +1,15 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const TopLevelSchema = z.object({ |
| 5 | 11 | "base": z.string(), |
| 6 | 12 | "date": z.string(), |
| 7 | - "rates": z.record(z.string(), z.number()), | |
| 13 | + "rates": mapSchema(z.number()), | |
| 8 | 14 | }); |
| 9 | 15 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +7 −1test/inputs/json/misc/e324e.json
Mtypescript-zoddefault / TopLevel.ts+7 −1
| @@ -1,5 +1,11 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const TypeSchema = z.enum([ |
| 5 | 11 | "string", |
| @@ -35,7 +41,7 @@ export const ItemsSchema = z.object({ | ||
| 35 | 41 | export type Items = z.infer<typeof ItemsSchema>; |
| 36 | 42 | |
| 37 | 43 | export const RateSchema = z.object({ |
| 38 | - "properties": z.record(z.string(), PropertySchema), | |
| 44 | + "properties": mapSchema(PropertySchema), | |
| 39 | 45 | }); |
| 40 | 46 | export type Rate = z.infer<typeof RateSchema>; |
Test case
1 generated file · +7 −1test/inputs/json/misc/ed095.json
Mtypescript-zoddefault / TopLevel.ts+7 −1
| @@ -1,4 +1,10 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | -export const TopLevelSchema = z.record(z.string(), z.string()); | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 9 | +export const TopLevelSchema = mapSchema(z.string()); | |
| 4 | 10 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +7 −1test/inputs/json/misc/fd329.json
Mtypescript-zoddefault / TopLevel.ts+7 −1
| @@ -1,5 +1,11 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const DatumSchema = z.object({ |
| 5 | 11 | "anomaly": z.string(), |
| @@ -16,7 +22,7 @@ export const DescriptionSchema = z.object({ | ||
| 16 | 22 | export type Description = z.infer<typeof DescriptionSchema>; |
| 17 | 23 | |
| 18 | 24 | export const TopLevelSchema = z.object({ |
| 19 | - "data": z.record(z.string(), DatumSchema), | |
| 25 | + "data": mapSchema(DatumSchema), | |
| 20 | 26 | "description": DescriptionSchema, |
| 21 | 27 | }); |
| 22 | 28 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +9 −3test/inputs/json/priority/bug2037.json
Mtypescript-zoddefault / TopLevel.ts+9 −3
| @@ -1,21 +1,27 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const RewardSchema = z.object({ |
| 5 | 11 | }); |
| 6 | 12 | export type Reward = z.infer<typeof RewardSchema>; |
| 7 | 13 | |
| 8 | 14 | export const ObjectiveSchema = z.object({ |
| 9 | - "rewards": z.record(z.string(), RewardSchema), | |
| 15 | + "rewards": mapSchema(RewardSchema), | |
| 10 | 16 | }); |
| 11 | 17 | export type Objective = z.infer<typeof ObjectiveSchema>; |
| 12 | 18 | |
| 13 | 19 | export const MissionSpecSchema = z.object({ |
| 14 | - "objectives": z.record(z.string(), ObjectiveSchema), | |
| 20 | + "objectives": mapSchema(ObjectiveSchema), | |
| 15 | 21 | }); |
| 16 | 22 | export type MissionSpec = z.infer<typeof MissionSpecSchema>; |
| 17 | 23 | |
| 18 | 24 | export const TopLevelSchema = z.object({ |
| 19 | - "mission_specs": z.record(z.string(), MissionSpecSchema), | |
| 25 | + "mission_specs": mapSchema(MissionSpecSchema), | |
| 20 | 26 | }); |
| 21 | 27 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +7 −1test/inputs/json/priority/bug855-short.json
Mtypescript-zoddefault / TopLevel.ts+7 −1
| @@ -1,5 +1,11 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const TopLevelValueSchema = z.object({ |
| 5 | 11 | "channel_id": z.string().regex(/^-?\d+$/), |
| @@ -10,5 +16,5 @@ export const TopLevelValueSchema = z.object({ | ||
| 10 | 16 | }); |
| 11 | 17 | export type TopLevelValue = z.infer<typeof TopLevelValueSchema>; |
| 12 | 18 | |
| 13 | -export const TopLevelSchema = z.record(z.string(), TopLevelValueSchema); | |
| 19 | +export const TopLevelSchema = mapSchema(TopLevelValueSchema); | |
| 14 | 20 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +7 −1test/inputs/json/priority/coin-pairs.json
Mtypescript-zoddefault / TopLevel.ts+7 −1
| @@ -1,5 +1,11 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const PairSchema = z.object({ |
| 5 | 11 | "decimal_places": z.number().int(), |
| @@ -14,7 +20,7 @@ export const PairSchema = z.object({ | ||
| 14 | 20 | export type Pair = z.infer<typeof PairSchema>; |
| 15 | 21 | |
| 16 | 22 | export const TopLevelSchema = z.object({ |
| 17 | - "pairs": z.record(z.string(), PairSchema), | |
| 23 | + "pairs": mapSchema(PairSchema), | |
| 18 | 24 | "server_time": z.number().int(), |
| 19 | 25 | }); |
| 20 | 26 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
2 generated files · +30 −18test/inputs/json/priority/combinations1.json
Mtypescript-zoddefault / TopLevel.ts+15 −9
| @@ -1,5 +1,11 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const CerographClassSchema = z.object({ |
| 5 | 11 | "apotropaion": z.null(), |
| @@ -306,18 +312,18 @@ export const TopLevelSchema = z.object({ | ||
| 306 | 312 | "citrated": z.number().int(), |
| 307 | 313 | "clinodome": z.array(z.union([z.number(), z.string()])), |
| 308 | 314 | "coadjust": z.array(z.union([CoadjustClassSchema, z.number()])), |
| 309 | - "consilience": z.array(z.union([z.number(), z.record(z.string(), z.number().int())])), | |
| 310 | - "constructor": z.array(z.union([z.boolean(), z.record(z.string(), z.union([z.null(), z.number().int()]))])), | |
| 311 | - "continuative": z.array(z.union([z.record(z.string(), z.number().int()), z.string()])), | |
| 315 | + "consilience": z.array(z.union([z.number(), mapSchema(z.number().int())])), | |
| 316 | + "constructor": z.array(z.union([z.boolean(), mapSchema(z.union([z.null(), z.number().int()]))])), | |
| 317 | + "continuative": z.array(z.union([mapSchema(z.number().int()), z.string()])), | |
| 312 | 318 | "credulity": z.array(z.union([CredulityClassSchema, z.number().int(), z.string()])), |
| 313 | - "creviced": z.array(z.union([z.boolean(), z.record(z.string(), z.number().int()), z.string()])), | |
| 319 | + "creviced": z.array(z.union([z.boolean(), mapSchema(z.number().int()), z.string()])), | |
| 314 | 320 | "cubiculum": z.array(z.array(z.union([z.null(), z.number().int()]))), |
| 315 | 321 | "deruralize": z.array(z.union([z.array(z.null()), z.boolean(), DeruralizeClassSchema])), |
| 316 | 322 | "diaereses": z.array(z.union([z.array(z.number().int()), z.boolean(), DiaereseClassSchema])), |
| 317 | 323 | "dissolution": z.array(z.union([z.null(), z.array(z.null())])), |
| 318 | 324 | "downstroke": z.array(z.union([z.array(z.null()), z.boolean(), z.string()])), |
| 319 | 325 | "electrotautomerism": z.array(z.union([z.null(), z.number()])), |
| 320 | - "eleutheromania": z.array(z.union([z.number(), z.record(z.string(), z.number().int()), z.string()])), | |
| 326 | + "eleutheromania": z.array(z.union([z.number(), mapSchema(z.number().int()), z.string()])), | |
| 321 | 327 | "encrust": EncrustSchema, |
| 322 | 328 | "entomoid": z.array(z.union([CimeliaClassSchema, z.number().int()])), |
| 323 | 329 | "epipaleolithic": z.array(z.union([z.array(z.number().int()), z.number()])), |
| @@ -327,10 +333,10 @@ export const TopLevelSchema = z.object({ | ||
| 327 | 333 | "flagmaking": z.array(z.union([z.boolean(), FlagmakingClassSchema, z.number()])), |
| 328 | 334 | "fluorometer": z.array(z.union([z.null(), z.number().int(), z.string()])), |
| 329 | 335 | "fulsome": z.array(z.union([z.null(), z.number().int()])), |
| 330 | - "fuzzy": z.array(z.union([z.number().int(), z.record(z.string(), z.union([z.null(), z.number().int()]))])), | |
| 336 | + "fuzzy": z.array(z.union([z.number().int(), mapSchema(z.union([z.null(), z.number().int()]))])), | |
| 331 | 337 | "gardenwards": z.array(z.union([z.array(z.number().int()), z.boolean(), z.string()])), |
| 332 | - "generalissimo": z.array(z.union([z.null(), z.boolean(), z.record(z.string(), z.number().int())])), | |
| 333 | - "habeas": z.array(z.union([z.null(), z.record(z.string(), z.number().int())])), | |
| 338 | + "generalissimo": z.array(z.union([z.null(), z.boolean(), mapSchema(z.number().int())])), | |
| 339 | + "habeas": z.array(z.union([z.null(), mapSchema(z.number().int())])), | |
| 334 | 340 | "hemicrystalline": z.array(z.union([CimeliaClassSchema, z.string()])), |
| 335 | 341 | "hemocoele": z.array(z.union([z.array(z.number().int()), HemocoeleClassSchema])), |
| 336 | 342 | "hoister": z.array(z.union([z.null(), CimeliaClassSchema, z.string()])), |
| @@ -341,6 +347,6 @@ export const TopLevelSchema = z.object({ | ||
| 341 | 347 | "intentiveness": z.array(z.union([CimeliaClassSchema, z.number(), z.string()])), |
| 342 | 348 | "interacinar": InteracinarSchema, |
| 343 | 349 | "intercorrelation": z.array(z.union([z.null(), z.array(z.number().int())])), |
| 344 | - "jacutinga": z.array(z.union([z.array(z.number().int()), z.record(z.string(), z.union([z.null(), z.number().int()]))])), | |
| 350 | + "jacutinga": z.array(z.union([z.array(z.number().int()), mapSchema(z.union([z.null(), z.number().int()]))])), | |
| 345 | 351 | }); |
| 346 | 352 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Mtypescript-zodjust-schema-true--8c4ca457bcba / TopLevel.ts+15 −9
| @@ -1,5 +1,11 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const CerographClassSchema = z.object({ |
| 5 | 11 | "apotropaion": z.null(), |
| @@ -293,18 +299,18 @@ export const TopLevelSchema = z.object({ | ||
| 293 | 299 | "citrated": z.number().int(), |
| 294 | 300 | "clinodome": z.array(z.union([z.number(), z.string()])), |
| 295 | 301 | "coadjust": z.array(z.union([CoadjustClassSchema, z.number()])), |
| 296 | - "consilience": z.array(z.union([z.number(), z.record(z.string(), z.number().int())])), | |
| 297 | - "constructor": z.array(z.union([z.boolean(), z.record(z.string(), z.union([z.null(), z.number().int()]))])), | |
| 298 | - "continuative": z.array(z.union([z.record(z.string(), z.number().int()), z.string()])), | |
| 302 | + "consilience": z.array(z.union([z.number(), mapSchema(z.number().int())])), | |
| 303 | + "constructor": z.array(z.union([z.boolean(), mapSchema(z.union([z.null(), z.number().int()]))])), | |
| 304 | + "continuative": z.array(z.union([mapSchema(z.number().int()), z.string()])), | |
| 299 | 305 | "credulity": z.array(z.union([CredulityClassSchema, z.number().int(), z.string()])), |
| 300 | - "creviced": z.array(z.union([z.boolean(), z.record(z.string(), z.number().int()), z.string()])), | |
| 306 | + "creviced": z.array(z.union([z.boolean(), mapSchema(z.number().int()), z.string()])), | |
| 301 | 307 | "cubiculum": z.array(z.array(z.union([z.null(), z.number().int()]))), |
| 302 | 308 | "deruralize": z.array(z.union([z.array(z.null()), z.boolean(), DeruralizeClassSchema])), |
| 303 | 309 | "diaereses": z.array(z.union([z.array(z.number().int()), z.boolean(), DiaereseClassSchema])), |
| 304 | 310 | "dissolution": z.array(z.union([z.null(), z.array(z.null())])), |
| 305 | 311 | "downstroke": z.array(z.union([z.array(z.null()), z.boolean(), z.string()])), |
| 306 | 312 | "electrotautomerism": z.array(z.union([z.null(), z.number()])), |
| 307 | - "eleutheromania": z.array(z.union([z.number(), z.record(z.string(), z.number().int()), z.string()])), | |
| 313 | + "eleutheromania": z.array(z.union([z.number(), mapSchema(z.number().int()), z.string()])), | |
| 308 | 314 | "encrust": EncrustSchema, |
| 309 | 315 | "entomoid": z.array(z.union([CimeliaClassSchema, z.number().int()])), |
| 310 | 316 | "epipaleolithic": z.array(z.union([z.array(z.number().int()), z.number()])), |
| @@ -314,10 +320,10 @@ export const TopLevelSchema = z.object({ | ||
| 314 | 320 | "flagmaking": z.array(z.union([z.boolean(), FlagmakingClassSchema, z.number()])), |
| 315 | 321 | "fluorometer": z.array(z.union([z.null(), z.number().int(), z.string()])), |
| 316 | 322 | "fulsome": z.array(z.union([z.null(), z.number().int()])), |
| 317 | - "fuzzy": z.array(z.union([z.number().int(), z.record(z.string(), z.union([z.null(), z.number().int()]))])), | |
| 323 | + "fuzzy": z.array(z.union([z.number().int(), mapSchema(z.union([z.null(), z.number().int()]))])), | |
| 318 | 324 | "gardenwards": z.array(z.union([z.array(z.number().int()), z.boolean(), z.string()])), |
| 319 | - "generalissimo": z.array(z.union([z.null(), z.boolean(), z.record(z.string(), z.number().int())])), | |
| 320 | - "habeas": z.array(z.union([z.null(), z.record(z.string(), z.number().int())])), | |
| 325 | + "generalissimo": z.array(z.union([z.null(), z.boolean(), mapSchema(z.number().int())])), | |
| 326 | + "habeas": z.array(z.union([z.null(), mapSchema(z.number().int())])), | |
| 321 | 327 | "hemicrystalline": z.array(z.union([CimeliaClassSchema, z.string()])), |
| 322 | 328 | "hemocoele": z.array(z.union([z.array(z.number().int()), HemocoeleClassSchema])), |
| 323 | 329 | "hoister": z.array(z.union([z.null(), CimeliaClassSchema, z.string()])), |
| @@ -328,5 +334,5 @@ export const TopLevelSchema = z.object({ | ||
| 328 | 334 | "intentiveness": z.array(z.union([CimeliaClassSchema, z.number(), z.string()])), |
| 329 | 335 | "interacinar": InteracinarSchema, |
| 330 | 336 | "intercorrelation": z.array(z.union([z.null(), z.array(z.number().int())])), |
| 331 | - "jacutinga": z.array(z.union([z.array(z.number().int()), z.record(z.string(), z.union([z.null(), z.number().int()]))])), | |
| 337 | + "jacutinga": z.array(z.union([z.array(z.number().int()), mapSchema(z.union([z.null(), z.number().int()]))])), | |
| 332 | 338 | }); |
Test case
2 generated files · +36 −24test/inputs/json/priority/combinations2.json
Mtypescript-zoddefault / TopLevel.ts+18 −12
| @@ -1,5 +1,11 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const AlleviateClassSchema = z.object({ |
| 5 | 11 | "apriori": z.null(), |
| @@ -243,8 +249,8 @@ export type OskarClass = z.infer<typeof OskarClassSchema>; | ||
| 243 | 249 | |
| 244 | 250 | export const TopLevelSchema = z.object({ |
| 245 | 251 | "Abranchiata": z.array(z.union([z.null(), z.array(z.number().int()), z.number().int()])), |
| 246 | - "academe": z.array(z.union([z.array(z.number().int()), z.number().int(), z.record(z.string(), z.number().int())])), | |
| 247 | - "acquirable": z.array(z.union([z.array(z.union([z.null(), z.number().int()])), z.record(z.string(), z.number().int())])), | |
| 252 | + "academe": z.array(z.union([z.array(z.number().int()), z.number().int(), mapSchema(z.number().int())])), | |
| 253 | + "acquirable": z.array(z.union([z.array(z.union([z.null(), z.number().int()])), mapSchema(z.number().int())])), | |
| 248 | 254 | "aerometry": z.array(z.union([z.boolean(), z.number()])), |
| 249 | 255 | "alexin": z.array(z.union([z.array(z.number().int()), z.boolean()])), |
| 250 | 256 | "alleviate": z.array(z.union([z.array(z.union([z.null(), z.number().int()])), AlleviateClassSchema])), |
| @@ -253,39 +259,39 @@ export const TopLevelSchema = z.object({ | ||
| 253 | 259 | "amphithyron": z.array(z.union([z.null(), AmphithyronSchema])), |
| 254 | 260 | "Andriana": z.array(z.union([z.null(), z.string()])), |
| 255 | 261 | "ankee": z.array(z.union([z.array(z.number().int()), AnkeeClassSchema, z.number().int()])), |
| 256 | - "annihilator": z.array(z.union([z.null(), z.record(z.string(), z.union([z.null(), z.number().int()]))])), | |
| 262 | + "annihilator": z.array(z.union([z.null(), mapSchema(z.union([z.null(), z.number().int()]))])), | |
| 257 | 263 | "annulose": z.null(), |
| 258 | 264 | "Ansarie": z.array(z.union([z.null(), z.array(z.number().int()), AnsarieClassSchema])), |
| 259 | 265 | "aphasia": z.array(z.union([z.array(z.number().int()), z.number().int()])), |
| 260 | 266 | "asprawl": z.array(z.union([z.number(), z.string()])), |
| 261 | 267 | "attractive": z.array(z.union([z.null(), z.boolean()])), |
| 262 | - "barksome": z.record(z.string(), z.number().int()), | |
| 268 | + "barksome": mapSchema(z.number().int()), | |
| 263 | 269 | "bedesman": z.array(z.union([z.boolean(), z.number(), z.string()])), |
| 264 | 270 | "belard": z.array(z.union([z.array(z.number().int()), RebeccaSchema, z.number()])), |
| 265 | - "bocking": z.array(z.union([z.array(z.number().int()), z.boolean(), z.record(z.string(), z.number().int())])), | |
| 266 | - "brawlingly": z.array(z.union([z.array(z.null()), z.record(z.string(), z.union([z.null(), z.number().int()]))])), | |
| 271 | + "bocking": z.array(z.union([z.array(z.number().int()), z.boolean(), mapSchema(z.number().int())])), | |
| 272 | + "brawlingly": z.array(z.union([z.array(z.null()), mapSchema(z.union([z.null(), z.number().int()]))])), | |
| 267 | 273 | "brookie": z.array(z.union([z.array(z.number().int()), RebeccaSchema])), |
| 268 | 274 | "bumboatman": z.array(z.union([z.null(), z.array(z.null()), z.string()])), |
| 269 | 275 | "bystreet": z.array(z.null()), |
| 270 | 276 | "calaverite": z.array(z.union([z.array(z.number().int()), z.string()])), |
| 271 | - "catallactic": z.array(z.union([z.array(z.null()), z.boolean(), z.record(z.string(), z.number().int())])), | |
| 272 | - "cemental": z.array(z.union([z.array(z.number().int()), z.number(), z.record(z.string(), z.number().int())])), | |
| 277 | + "catallactic": z.array(z.union([z.array(z.null()), z.boolean(), mapSchema(z.number().int())])), | |
| 278 | + "cemental": z.array(z.union([z.array(z.number().int()), z.number(), mapSchema(z.number().int())])), | |
| 273 | 279 | "Chytridiaceae": z.array(z.union([z.null(), z.boolean(), ChytridiaceaeClassSchema])), |
| 274 | 280 | "Discordia": z.array(z.union([z.array(z.number().int()), DiscordiaClassSchema])), |
| 275 | 281 | "Endomyces": z.array(z.union([z.number().int(), z.string()])), |
| 276 | 282 | "Epinephelidae": z.array(z.union([z.boolean(), z.number().int(), z.string()])), |
| 277 | - "Eupatorium": z.array(z.union([z.array(z.null()), z.record(z.string(), z.number().int())])), | |
| 283 | + "Eupatorium": z.array(z.union([z.array(z.null()), mapSchema(z.number().int())])), | |
| 278 | 284 | "Gryphosaurus": z.array(z.union([z.array(z.number().int()), GryphosaurusClassSchema, z.string()])), |
| 279 | - "Koryak": z.array(z.union([z.record(z.string(), z.union([z.null(), z.number().int()])), z.string()])), | |
| 285 | + "Koryak": z.array(z.union([mapSchema(z.union([z.null(), z.number().int()])), z.string()])), | |
| 280 | 286 | "Lavinia": z.array(z.union([LaviniaClassSchema, z.string()])), |
| 281 | 287 | "Oskar": z.array(z.union([z.array(z.number().int()), OskarClassSchema])), |
| 282 | 288 | "Rebecca": z.array(z.union([RebeccaSchema, z.number().int(), z.string()])), |
| 283 | 289 | "Rhomboganoidei": z.array(z.union([z.array(z.number().int()), RebeccaSchema, z.string()])), |
| 284 | 290 | "Rigsmal": z.boolean(), |
| 285 | 291 | "Ruellia": z.array(z.union([z.boolean(), RebeccaSchema, z.string()])), |
| 286 | - "School": z.array(z.union([z.null(), z.number().int(), z.record(z.string(), z.number().int())])), | |
| 292 | + "School": z.array(z.union([z.null(), z.number().int(), mapSchema(z.number().int())])), | |
| 287 | 293 | "Shakespearolater": z.array(z.union([z.array(z.number().int()), z.number(), z.string()])), |
| 288 | 294 | "Svan": z.array(z.number()), |
| 289 | - "Wayao": z.record(z.string(), z.number()), | |
| 295 | + "Wayao": mapSchema(z.number()), | |
| 290 | 296 | }); |
| 291 | 297 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Mtypescript-zodjust-schema-true--8c4ca457bcba / TopLevel.ts+18 −12
| @@ -1,5 +1,11 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const AlleviateClassSchema = z.object({ |
| 5 | 11 | "apriori": z.null(), |
| @@ -233,8 +239,8 @@ export const OskarClassSchema = z.object({ | ||
| 233 | 239 | |
| 234 | 240 | export const TopLevelSchema = z.object({ |
| 235 | 241 | "Abranchiata": z.array(z.union([z.null(), z.array(z.number().int()), z.number().int()])), |
| 236 | - "academe": z.array(z.union([z.array(z.number().int()), z.number().int(), z.record(z.string(), z.number().int())])), | |
| 237 | - "acquirable": z.array(z.union([z.array(z.union([z.null(), z.number().int()])), z.record(z.string(), z.number().int())])), | |
| 242 | + "academe": z.array(z.union([z.array(z.number().int()), z.number().int(), mapSchema(z.number().int())])), | |
| 243 | + "acquirable": z.array(z.union([z.array(z.union([z.null(), z.number().int()])), mapSchema(z.number().int())])), | |
| 238 | 244 | "aerometry": z.array(z.union([z.boolean(), z.number()])), |
| 239 | 245 | "alexin": z.array(z.union([z.array(z.number().int()), z.boolean()])), |
| 240 | 246 | "alleviate": z.array(z.union([z.array(z.union([z.null(), z.number().int()])), AlleviateClassSchema])), |
| @@ -243,38 +249,38 @@ export const TopLevelSchema = z.object({ | ||
| 243 | 249 | "amphithyron": z.array(z.union([z.null(), AmphithyronSchema])), |
| 244 | 250 | "Andriana": z.array(z.union([z.null(), z.string()])), |
| 245 | 251 | "ankee": z.array(z.union([z.array(z.number().int()), AnkeeClassSchema, z.number().int()])), |
| 246 | - "annihilator": z.array(z.union([z.null(), z.record(z.string(), z.union([z.null(), z.number().int()]))])), | |
| 252 | + "annihilator": z.array(z.union([z.null(), mapSchema(z.union([z.null(), z.number().int()]))])), | |
| 247 | 253 | "annulose": z.null(), |
| 248 | 254 | "Ansarie": z.array(z.union([z.null(), z.array(z.number().int()), AnsarieClassSchema])), |
| 249 | 255 | "aphasia": z.array(z.union([z.array(z.number().int()), z.number().int()])), |
| 250 | 256 | "asprawl": z.array(z.union([z.number(), z.string()])), |
| 251 | 257 | "attractive": z.array(z.union([z.null(), z.boolean()])), |
| 252 | - "barksome": z.record(z.string(), z.number().int()), | |
| 258 | + "barksome": mapSchema(z.number().int()), | |
| 253 | 259 | "bedesman": z.array(z.union([z.boolean(), z.number(), z.string()])), |
| 254 | 260 | "belard": z.array(z.union([z.array(z.number().int()), RebeccaSchema, z.number()])), |
| 255 | - "bocking": z.array(z.union([z.array(z.number().int()), z.boolean(), z.record(z.string(), z.number().int())])), | |
| 256 | - "brawlingly": z.array(z.union([z.array(z.null()), z.record(z.string(), z.union([z.null(), z.number().int()]))])), | |
| 261 | + "bocking": z.array(z.union([z.array(z.number().int()), z.boolean(), mapSchema(z.number().int())])), | |
| 262 | + "brawlingly": z.array(z.union([z.array(z.null()), mapSchema(z.union([z.null(), z.number().int()]))])), | |
| 257 | 263 | "brookie": z.array(z.union([z.array(z.number().int()), RebeccaSchema])), |
| 258 | 264 | "bumboatman": z.array(z.union([z.null(), z.array(z.null()), z.string()])), |
| 259 | 265 | "bystreet": z.array(z.null()), |
| 260 | 266 | "calaverite": z.array(z.union([z.array(z.number().int()), z.string()])), |
| 261 | - "catallactic": z.array(z.union([z.array(z.null()), z.boolean(), z.record(z.string(), z.number().int())])), | |
| 262 | - "cemental": z.array(z.union([z.array(z.number().int()), z.number(), z.record(z.string(), z.number().int())])), | |
| 267 | + "catallactic": z.array(z.union([z.array(z.null()), z.boolean(), mapSchema(z.number().int())])), | |
| 268 | + "cemental": z.array(z.union([z.array(z.number().int()), z.number(), mapSchema(z.number().int())])), | |
| 263 | 269 | "Chytridiaceae": z.array(z.union([z.null(), z.boolean(), ChytridiaceaeClassSchema])), |
| 264 | 270 | "Discordia": z.array(z.union([z.array(z.number().int()), DiscordiaClassSchema])), |
| 265 | 271 | "Endomyces": z.array(z.union([z.number().int(), z.string()])), |
| 266 | 272 | "Epinephelidae": z.array(z.union([z.boolean(), z.number().int(), z.string()])), |
| 267 | - "Eupatorium": z.array(z.union([z.array(z.null()), z.record(z.string(), z.number().int())])), | |
| 273 | + "Eupatorium": z.array(z.union([z.array(z.null()), mapSchema(z.number().int())])), | |
| 268 | 274 | "Gryphosaurus": z.array(z.union([z.array(z.number().int()), GryphosaurusClassSchema, z.string()])), |
| 269 | - "Koryak": z.array(z.union([z.record(z.string(), z.union([z.null(), z.number().int()])), z.string()])), | |
| 275 | + "Koryak": z.array(z.union([mapSchema(z.union([z.null(), z.number().int()])), z.string()])), | |
| 270 | 276 | "Lavinia": z.array(z.union([LaviniaClassSchema, z.string()])), |
| 271 | 277 | "Oskar": z.array(z.union([z.array(z.number().int()), OskarClassSchema])), |
| 272 | 278 | "Rebecca": z.array(z.union([RebeccaSchema, z.number().int(), z.string()])), |
| 273 | 279 | "Rhomboganoidei": z.array(z.union([z.array(z.number().int()), RebeccaSchema, z.string()])), |
| 274 | 280 | "Rigsmal": z.boolean(), |
| 275 | 281 | "Ruellia": z.array(z.union([z.boolean(), RebeccaSchema, z.string()])), |
| 276 | - "School": z.array(z.union([z.null(), z.number().int(), z.record(z.string(), z.number().int())])), | |
| 282 | + "School": z.array(z.union([z.null(), z.number().int(), mapSchema(z.number().int())])), | |
| 277 | 283 | "Shakespearolater": z.array(z.union([z.array(z.number().int()), z.number(), z.string()])), |
| 278 | 284 | "Svan": z.array(z.number()), |
| 279 | - "Wayao": z.record(z.string(), z.number()), | |
| 285 | + "Wayao": mapSchema(z.number()), | |
| 280 | 286 | }); |
Test case
2 generated files · +26 −14test/inputs/json/priority/combinations3.json
Mtypescript-zoddefault / TopLevel.ts+13 −7
| @@ -1,5 +1,11 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const JurorClassSchema = z.object({ |
| 5 | 11 | "adipsy": z.null(), |
| @@ -354,7 +360,7 @@ export type PrefreshmanClass = z.infer<typeof PrefreshmanClassSchema>; | ||
| 354 | 360 | |
| 355 | 361 | export const TopLevelSchema = z.object({ |
| 356 | 362 | "juror": z.array(z.union([z.boolean(), JurorClassSchema])), |
| 357 | - "kongoni": z.array(z.union([z.array(z.number().int()), z.record(z.string(), z.number().int())])), | |
| 363 | + "kongoni": z.array(z.union([z.array(z.number().int()), mapSchema(z.number().int())])), | |
| 358 | 364 | "ladronism": z.array(z.union([LadronismClassSchema, z.number(), z.string()])), |
| 359 | 365 | "landlubberly": z.array(z.union([z.boolean(), LandlubberlyClassSchema, z.number().int()])), |
| 360 | 366 | "listener": z.array(z.union([z.array(z.null()), z.number().int()])), |
| @@ -375,25 +381,25 @@ export const TopLevelSchema = z.object({ | ||
| 375 | 381 | "nonvaluation": z.array(z.union([z.array(z.null()), z.boolean(), z.number()])), |
| 376 | 382 | "occupationalist": z.array(z.union([z.null(), z.array(z.null()), OccupationalistClassSchema])), |
| 377 | 383 | "outrival": z.array(z.union([z.null(), OutrivalClassSchema, z.number()])), |
| 378 | - "paleographically": z.array(z.union([z.number(), z.record(z.string(), z.union([z.null(), z.number().int()]))])), | |
| 379 | - "pamphletwise": z.array(z.union([z.number().int(), z.record(z.string(), z.number().int()), z.string()])), | |
| 384 | + "paleographically": z.array(z.union([z.number(), mapSchema(z.union([z.null(), z.number().int()]))])), | |
| 385 | + "pamphletwise": z.array(z.union([z.number().int(), mapSchema(z.number().int()), z.string()])), | |
| 380 | 386 | "pediatrics": z.array(z.union([z.null(), z.boolean(), z.number()])), |
| 381 | 387 | "perceptive": z.array(z.boolean()), |
| 382 | 388 | "piaculum": z.array(z.union([PiaculumClassSchema, z.number()])), |
| 383 | 389 | "piccadilly": z.array(z.union([z.null(), z.number(), z.string()])), |
| 384 | 390 | "piffler": z.array(z.union([z.array(z.null()), MonaziteClassSchema])), |
| 385 | 391 | "pithful": z.array(z.union([z.null(), z.boolean(), z.number().int()])), |
| 386 | - "placuntitis": z.array(z.union([z.number().int(), z.record(z.string(), z.number().int())])), | |
| 387 | - "plectopterous": z.array(z.union([z.number(), z.record(z.string(), z.number().int())])), | |
| 392 | + "placuntitis": z.array(z.union([z.number().int(), mapSchema(z.number().int())])), | |
| 393 | + "plectopterous": z.array(z.union([z.number(), mapSchema(z.number().int())])), | |
| 388 | 394 | "pneumocele": z.array(z.union([z.null(), PneumoceleSchema])), |
| 389 | 395 | "poliorcetic": z.array(z.union([z.boolean(), MonaziteClassSchema])), |
| 390 | - "poormaster": z.array(z.union([z.null(), z.array(z.number().int()), z.record(z.string(), z.number().int())])), | |
| 396 | + "poormaster": z.array(z.union([z.null(), z.array(z.number().int()), mapSchema(z.number().int())])), | |
| 391 | 397 | "potwhisky": z.array(z.union([z.null(), PotwhiskyClassSchema, z.number().int()])), |
| 392 | 398 | "practicalizer": z.array(z.union([z.array(z.null()), MonaziteClassSchema, z.string()])), |
| 393 | 399 | "prefreshman": z.array(z.union([z.array(z.null()), PrefreshmanClassSchema, z.string()])), |
| 394 | 400 | "prehensility": z.array(z.union([z.array(z.null()), z.boolean(), MonaziteClassSchema])), |
| 395 | 401 | "prevoidance": z.array(z.union([z.array(z.number().int()), MonaziteClassSchema, z.number().int()])), |
| 396 | - "probant": z.array(z.record(z.string(), z.union([z.null(), z.number().int()]))), | |
| 402 | + "probant": z.array(mapSchema(z.union([z.null(), z.number().int()]))), | |
| 397 | 403 | "protext": z.array(z.union([z.array(z.number().int()), z.boolean(), MonaziteClassSchema])), |
| 398 | 404 | }); |
| 399 | 405 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Mtypescript-zodjust-schema-true--8c4ca457bcba / TopLevel.ts+13 −7
| @@ -1,5 +1,11 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const JurorClassSchema = z.object({ |
| 5 | 11 | "adipsy": z.null(), |
| @@ -340,7 +346,7 @@ export const PrefreshmanClassSchema = z.object({ | ||
| 340 | 346 | |
| 341 | 347 | export const TopLevelSchema = z.object({ |
| 342 | 348 | "juror": z.array(z.union([z.boolean(), JurorClassSchema])), |
| 343 | - "kongoni": z.array(z.union([z.array(z.number().int()), z.record(z.string(), z.number().int())])), | |
| 349 | + "kongoni": z.array(z.union([z.array(z.number().int()), mapSchema(z.number().int())])), | |
| 344 | 350 | "ladronism": z.array(z.union([LadronismClassSchema, z.number(), z.string()])), |
| 345 | 351 | "landlubberly": z.array(z.union([z.boolean(), LandlubberlyClassSchema, z.number().int()])), |
| 346 | 352 | "listener": z.array(z.union([z.array(z.null()), z.number().int()])), |
| @@ -361,24 +367,24 @@ export const TopLevelSchema = z.object({ | ||
| 361 | 367 | "nonvaluation": z.array(z.union([z.array(z.null()), z.boolean(), z.number()])), |
| 362 | 368 | "occupationalist": z.array(z.union([z.null(), z.array(z.null()), OccupationalistClassSchema])), |
| 363 | 369 | "outrival": z.array(z.union([z.null(), OutrivalClassSchema, z.number()])), |
| 364 | - "paleographically": z.array(z.union([z.number(), z.record(z.string(), z.union([z.null(), z.number().int()]))])), | |
| 365 | - "pamphletwise": z.array(z.union([z.number().int(), z.record(z.string(), z.number().int()), z.string()])), | |
| 370 | + "paleographically": z.array(z.union([z.number(), mapSchema(z.union([z.null(), z.number().int()]))])), | |
| 371 | + "pamphletwise": z.array(z.union([z.number().int(), mapSchema(z.number().int()), z.string()])), | |
| 366 | 372 | "pediatrics": z.array(z.union([z.null(), z.boolean(), z.number()])), |
| 367 | 373 | "perceptive": z.array(z.boolean()), |
| 368 | 374 | "piaculum": z.array(z.union([PiaculumClassSchema, z.number()])), |
| 369 | 375 | "piccadilly": z.array(z.union([z.null(), z.number(), z.string()])), |
| 370 | 376 | "piffler": z.array(z.union([z.array(z.null()), MonaziteClassSchema])), |
| 371 | 377 | "pithful": z.array(z.union([z.null(), z.boolean(), z.number().int()])), |
| 372 | - "placuntitis": z.array(z.union([z.number().int(), z.record(z.string(), z.number().int())])), | |
| 373 | - "plectopterous": z.array(z.union([z.number(), z.record(z.string(), z.number().int())])), | |
| 378 | + "placuntitis": z.array(z.union([z.number().int(), mapSchema(z.number().int())])), | |
| 379 | + "plectopterous": z.array(z.union([z.number(), mapSchema(z.number().int())])), | |
| 374 | 380 | "pneumocele": z.array(z.union([z.null(), PneumoceleSchema])), |
| 375 | 381 | "poliorcetic": z.array(z.union([z.boolean(), MonaziteClassSchema])), |
| 376 | - "poormaster": z.array(z.union([z.null(), z.array(z.number().int()), z.record(z.string(), z.number().int())])), | |
| 382 | + "poormaster": z.array(z.union([z.null(), z.array(z.number().int()), mapSchema(z.number().int())])), | |
| 377 | 383 | "potwhisky": z.array(z.union([z.null(), PotwhiskyClassSchema, z.number().int()])), |
| 378 | 384 | "practicalizer": z.array(z.union([z.array(z.null()), MonaziteClassSchema, z.string()])), |
| 379 | 385 | "prefreshman": z.array(z.union([z.array(z.null()), PrefreshmanClassSchema, z.string()])), |
| 380 | 386 | "prehensility": z.array(z.union([z.array(z.null()), z.boolean(), MonaziteClassSchema])), |
| 381 | 387 | "prevoidance": z.array(z.union([z.array(z.number().int()), MonaziteClassSchema, z.number().int()])), |
| 382 | - "probant": z.array(z.record(z.string(), z.union([z.null(), z.number().int()]))), | |
| 388 | + "probant": z.array(mapSchema(z.union([z.null(), z.number().int()]))), | |
| 383 | 389 | "protext": z.array(z.union([z.array(z.number().int()), z.boolean(), MonaziteClassSchema])), |
| 384 | 390 | }); |
Test case
2 generated files · +34 −22test/inputs/json/priority/combinations4.json
Mtypescript-zoddefault / TopLevel.ts+17 −11
| @@ -1,5 +1,11 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const PulpitismClassSchema = z.object({ |
| 5 | 11 | "abnet": z.null(), |
| @@ -405,7 +411,7 @@ export const TopLevelSchema = z.object({ | ||
| 405 | 411 | "pulpitism": z.array(z.union([z.array(z.number().int()), PulpitismClassSchema, z.number()])), |
| 406 | 412 | "pyodermia": z.array(z.union([PyodermiaClassSchema, z.number().int()])), |
| 407 | 413 | "quebrachine": z.array(z.union([z.null(), z.boolean(), QuebrachineClassSchema])), |
| 408 | - "querier": z.array(z.union([z.boolean(), z.record(z.string(), z.number().int())])), | |
| 414 | + "querier": z.array(z.union([z.boolean(), mapSchema(z.number().int())])), | |
| 409 | 415 | "rebarbative": z.array(z.union([z.array(z.number().int()), z.boolean(), z.number()])), |
| 410 | 416 | "reimagine": z.array(ReimagineSchema), |
| 411 | 417 | "ressaut": RessautSchema, |
| @@ -414,10 +420,10 @@ export const TopLevelSchema = z.object({ | ||
| 414 | 420 | "rewrite": z.array(z.union([z.array(z.null()), RewriteClassSchema, z.number()])), |
| 415 | 421 | "saccoderm": z.array(z.union([z.null(), z.array(z.number().int()), z.string()])), |
| 416 | 422 | "santir": z.array(z.union([SantirClassSchema, z.number()])), |
| 417 | - "saprophilous": z.array(z.union([z.null(), z.record(z.string(), z.number().int()), z.string()])), | |
| 423 | + "saprophilous": z.array(z.union([z.null(), mapSchema(z.number().int()), z.string()])), | |
| 418 | 424 | "saxten": z.array(z.union([SaxtenClassSchema, z.string()])), |
| 419 | 425 | "scatty": z.array(z.union([z.null(), ScattySchema])), |
| 420 | - "scoffer": z.array(z.union([z.null(), z.array(z.null()), z.record(z.string(), z.number().int())])), | |
| 426 | + "scoffer": z.array(z.union([z.null(), z.array(z.null()), mapSchema(z.number().int())])), | |
| 421 | 427 | "scrampum": z.array(z.union([z.null(), z.array(z.number().int()), z.boolean()])), |
| 422 | 428 | "semantic": z.number(), |
| 423 | 429 | "serpentinic": z.array(z.union([z.array(z.number().int()), z.number()])), |
| @@ -425,7 +431,7 @@ export const TopLevelSchema = z.object({ | ||
| 425 | 431 | "sistering": z.array(z.union([z.array(z.null()), SisteringClassSchema, z.number().int()])), |
| 426 | 432 | "staghunting": z.array(StaghuntingSchema), |
| 427 | 433 | "stagmometer": z.array(z.union([z.array(z.union([z.null(), z.number().int()])), z.string()])), |
| 428 | - "stimulability": z.array(z.union([z.boolean(), z.number().int(), z.record(z.string(), z.number().int())])), | |
| 434 | + "stimulability": z.array(z.union([z.boolean(), z.number().int(), mapSchema(z.number().int())])), | |
| 429 | 435 | "strangleable": z.array(z.union([z.array(z.null()), z.number()])), |
| 430 | 436 | "strenuosity": z.array(z.union([z.array(z.null()), StrenuosityClassSchema])), |
| 431 | 437 | "tabaxir": z.array(z.union([z.boolean(), z.number()])), |
| @@ -435,22 +441,22 @@ export const TopLevelSchema = z.object({ | ||
| 435 | 441 | "tortricine": z.array(z.union([z.array(z.union([z.null(), z.number().int()])), QuebrachineClassSchema])), |
| 436 | 442 | "truantcy": z.array(z.union([z.boolean(), TruantcyClassSchema])), |
| 437 | 443 | "turgesce": z.array(z.string()), |
| 438 | - "unbeginning": z.array(z.union([z.array(z.null()), z.record(z.string(), z.number().int()), z.string()])), | |
| 444 | + "unbeginning": z.array(z.union([z.array(z.null()), mapSchema(z.number().int()), z.string()])), | |
| 439 | 445 | "underdunged": z.array(z.number()), |
| 440 | - "undesirability": z.array(z.union([z.array(z.number().int()), z.record(z.string(), z.number().int()), z.string()])), | |
| 441 | - "unerasing": z.array(z.union([z.array(z.null()), z.number().int(), z.record(z.string(), z.number().int())])), | |
| 446 | + "undesirability": z.array(z.union([z.array(z.number().int()), mapSchema(z.number().int()), z.string()])), | |
| 447 | + "unerasing": z.array(z.union([z.array(z.null()), z.number().int(), mapSchema(z.number().int())])), | |
| 442 | 448 | "unguentarium": z.array(z.union([z.null(), z.array(z.null()), z.number().int()])), |
| 443 | 449 | "unimpeachably": z.array(z.union([z.boolean(), UnimpeachablyClassSchema])), |
| 444 | - "unmortgaged": z.array(z.union([z.null(), z.number(), z.record(z.string(), z.number().int())])), | |
| 450 | + "unmortgaged": z.array(z.union([z.null(), z.number(), mapSchema(z.number().int())])), | |
| 445 | 451 | "unobstructed": z.array(z.union([z.null(), QuebrachineClassSchema, z.number().int()])), |
| 446 | 452 | "unreceptivity": z.array(z.union([z.array(z.null()), z.number().int(), z.string()])), |
| 447 | 453 | "unsatisfactoriness": z.array(z.union([z.array(z.number().int()), z.boolean(), z.number().int()])), |
| 448 | 454 | "unsecurity": z.array(z.number().int()), |
| 449 | 455 | "unstressed": z.array(z.union([z.boolean(), UnstressedClassSchema, z.string()])), |
| 450 | - "untasked": z.array(z.union([z.array(z.null()), z.number(), z.record(z.string(), z.number().int())])), | |
| 451 | - "unvarying": z.array(z.union([z.boolean(), z.number(), z.record(z.string(), z.number().int())])), | |
| 456 | + "untasked": z.array(z.union([z.array(z.null()), z.number(), mapSchema(z.number().int())])), | |
| 457 | + "unvarying": z.array(z.union([z.boolean(), z.number(), mapSchema(z.number().int())])), | |
| 452 | 458 | "vehemently": z.array(z.union([z.null(), z.array(z.null()), z.boolean()])), |
| 453 | - "warriorship": z.record(z.string(), z.boolean()), | |
| 459 | + "warriorship": mapSchema(z.boolean()), | |
| 454 | 460 | "whitepot": z.array(z.union([QuebrachineClassSchema, z.number()])), |
| 455 | 461 | "wrothy": z.array(z.union([z.array(z.null()), WrothyClassSchema])), |
| 456 | 462 | }); |
Mtypescript-zodjust-schema-true--8c4ca457bcba / TopLevel.ts+17 −11
| @@ -1,5 +1,11 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const PulpitismClassSchema = z.object({ |
| 5 | 11 | "abnet": z.null(), |
| @@ -389,7 +395,7 @@ export const TopLevelSchema = z.object({ | ||
| 389 | 395 | "pulpitism": z.array(z.union([z.array(z.number().int()), PulpitismClassSchema, z.number()])), |
| 390 | 396 | "pyodermia": z.array(z.union([PyodermiaClassSchema, z.number().int()])), |
| 391 | 397 | "quebrachine": z.array(z.union([z.null(), z.boolean(), QuebrachineClassSchema])), |
| 392 | - "querier": z.array(z.union([z.boolean(), z.record(z.string(), z.number().int())])), | |
| 398 | + "querier": z.array(z.union([z.boolean(), mapSchema(z.number().int())])), | |
| 393 | 399 | "rebarbative": z.array(z.union([z.array(z.number().int()), z.boolean(), z.number()])), |
| 394 | 400 | "reimagine": z.array(ReimagineSchema), |
| 395 | 401 | "ressaut": RessautSchema, |
| @@ -398,10 +404,10 @@ export const TopLevelSchema = z.object({ | ||
| 398 | 404 | "rewrite": z.array(z.union([z.array(z.null()), RewriteClassSchema, z.number()])), |
| 399 | 405 | "saccoderm": z.array(z.union([z.null(), z.array(z.number().int()), z.string()])), |
| 400 | 406 | "santir": z.array(z.union([SantirClassSchema, z.number()])), |
| 401 | - "saprophilous": z.array(z.union([z.null(), z.record(z.string(), z.number().int()), z.string()])), | |
| 407 | + "saprophilous": z.array(z.union([z.null(), mapSchema(z.number().int()), z.string()])), | |
| 402 | 408 | "saxten": z.array(z.union([SaxtenClassSchema, z.string()])), |
| 403 | 409 | "scatty": z.array(z.union([z.null(), ScattySchema])), |
| 404 | - "scoffer": z.array(z.union([z.null(), z.array(z.null()), z.record(z.string(), z.number().int())])), | |
| 410 | + "scoffer": z.array(z.union([z.null(), z.array(z.null()), mapSchema(z.number().int())])), | |
| 405 | 411 | "scrampum": z.array(z.union([z.null(), z.array(z.number().int()), z.boolean()])), |
| 406 | 412 | "semantic": z.number(), |
| 407 | 413 | "serpentinic": z.array(z.union([z.array(z.number().int()), z.number()])), |
| @@ -409,7 +415,7 @@ export const TopLevelSchema = z.object({ | ||
| 409 | 415 | "sistering": z.array(z.union([z.array(z.null()), SisteringClassSchema, z.number().int()])), |
| 410 | 416 | "staghunting": z.array(StaghuntingSchema), |
| 411 | 417 | "stagmometer": z.array(z.union([z.array(z.union([z.null(), z.number().int()])), z.string()])), |
| 412 | - "stimulability": z.array(z.union([z.boolean(), z.number().int(), z.record(z.string(), z.number().int())])), | |
| 418 | + "stimulability": z.array(z.union([z.boolean(), z.number().int(), mapSchema(z.number().int())])), | |
| 413 | 419 | "strangleable": z.array(z.union([z.array(z.null()), z.number()])), |
| 414 | 420 | "strenuosity": z.array(z.union([z.array(z.null()), StrenuosityClassSchema])), |
| 415 | 421 | "tabaxir": z.array(z.union([z.boolean(), z.number()])), |
| @@ -419,22 +425,22 @@ export const TopLevelSchema = z.object({ | ||
| 419 | 425 | "tortricine": z.array(z.union([z.array(z.union([z.null(), z.number().int()])), QuebrachineClassSchema])), |
| 420 | 426 | "truantcy": z.array(z.union([z.boolean(), TruantcyClassSchema])), |
| 421 | 427 | "turgesce": z.array(z.string()), |
| 422 | - "unbeginning": z.array(z.union([z.array(z.null()), z.record(z.string(), z.number().int()), z.string()])), | |
| 428 | + "unbeginning": z.array(z.union([z.array(z.null()), mapSchema(z.number().int()), z.string()])), | |
| 423 | 429 | "underdunged": z.array(z.number()), |
| 424 | - "undesirability": z.array(z.union([z.array(z.number().int()), z.record(z.string(), z.number().int()), z.string()])), | |
| 425 | - "unerasing": z.array(z.union([z.array(z.null()), z.number().int(), z.record(z.string(), z.number().int())])), | |
| 430 | + "undesirability": z.array(z.union([z.array(z.number().int()), mapSchema(z.number().int()), z.string()])), | |
| 431 | + "unerasing": z.array(z.union([z.array(z.null()), z.number().int(), mapSchema(z.number().int())])), | |
| 426 | 432 | "unguentarium": z.array(z.union([z.null(), z.array(z.null()), z.number().int()])), |
| 427 | 433 | "unimpeachably": z.array(z.union([z.boolean(), UnimpeachablyClassSchema])), |
| 428 | - "unmortgaged": z.array(z.union([z.null(), z.number(), z.record(z.string(), z.number().int())])), | |
| 434 | + "unmortgaged": z.array(z.union([z.null(), z.number(), mapSchema(z.number().int())])), | |
| 429 | 435 | "unobstructed": z.array(z.union([z.null(), QuebrachineClassSchema, z.number().int()])), |
| 430 | 436 | "unreceptivity": z.array(z.union([z.array(z.null()), z.number().int(), z.string()])), |
| 431 | 437 | "unsatisfactoriness": z.array(z.union([z.array(z.number().int()), z.boolean(), z.number().int()])), |
| 432 | 438 | "unsecurity": z.array(z.number().int()), |
| 433 | 439 | "unstressed": z.array(z.union([z.boolean(), UnstressedClassSchema, z.string()])), |
| 434 | - "untasked": z.array(z.union([z.array(z.null()), z.number(), z.record(z.string(), z.number().int())])), | |
| 435 | - "unvarying": z.array(z.union([z.boolean(), z.number(), z.record(z.string(), z.number().int())])), | |
| 440 | + "untasked": z.array(z.union([z.array(z.null()), z.number(), mapSchema(z.number().int())])), | |
| 441 | + "unvarying": z.array(z.union([z.boolean(), z.number(), mapSchema(z.number().int())])), | |
| 436 | 442 | "vehemently": z.array(z.union([z.null(), z.array(z.null()), z.boolean()])), |
| 437 | - "warriorship": z.record(z.string(), z.boolean()), | |
| 443 | + "warriorship": mapSchema(z.boolean()), | |
| 438 | 444 | "whitepot": z.array(z.union([QuebrachineClassSchema, z.number()])), |
| 439 | 445 | "wrothy": z.array(z.union([z.array(z.null()), WrothyClassSchema])), |
| 440 | 446 | }); |
Test case
1 generated file · +18 −12test/inputs/json/priority/nbl-stats.json
Mtypescript-zoddefault / TopLevel.ts+18 −12
| @@ -1,5 +1,11 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const LeaddatumEnumSchema = z.enum([ |
| 5 | 11 | "", |
| @@ -256,20 +262,20 @@ export const PlSchema = z.object({ | ||
| 256 | 262 | export type Pl = z.infer<typeof PlSchema>; |
| 257 | 263 | |
| 258 | 264 | export const TotalldsSchema = z.object({ |
| 259 | - "sAssists": z.record(z.string(), ScorerSchema), | |
| 260 | - "sBlocks": z.record(z.string(), ScorerSchema), | |
| 261 | - "sPoints": z.record(z.string(), ScorerSchema), | |
| 262 | - "sReboundsTotal": z.record(z.string(), ScorerSchema), | |
| 263 | - "sSteals": z.record(z.string(), ScorerSchema), | |
| 265 | + "sAssists": mapSchema(ScorerSchema), | |
| 266 | + "sBlocks": mapSchema(ScorerSchema), | |
| 267 | + "sPoints": mapSchema(ScorerSchema), | |
| 268 | + "sReboundsTotal": mapSchema(ScorerSchema), | |
| 269 | + "sSteals": mapSchema(ScorerSchema), | |
| 264 | 270 | }); |
| 265 | 271 | export type Totallds = z.infer<typeof TotalldsSchema>; |
| 266 | 272 | |
| 267 | 273 | export const LdsSchema = z.object({ |
| 268 | - "sAssists": z.record(z.string(), ScorerSchema), | |
| 274 | + "sAssists": mapSchema(ScorerSchema), | |
| 269 | 275 | "sBlocks": SBlocksSchema, |
| 270 | - "sPoints": z.record(z.string(), ScorerSchema), | |
| 271 | - "sReboundsTotal": z.record(z.string(), ScorerSchema), | |
| 272 | - "sSteals": z.record(z.string(), ScorerSchema), | |
| 276 | + "sPoints": mapSchema(ScorerSchema), | |
| 277 | + "sReboundsTotal": mapSchema(ScorerSchema), | |
| 278 | + "sSteals": mapSchema(ScorerSchema), | |
| 273 | 279 | }); |
| 274 | 280 | export type Lds = z.infer<typeof LdsSchema>; |
| 275 | 281 | |
| @@ -286,7 +292,7 @@ export const TmSchema = z.object({ | ||
| 286 | 292 | "p2_score": z.number().int(), |
| 287 | 293 | "p3_score": z.number().int(), |
| 288 | 294 | "p4_score": z.number().int(), |
| 289 | - "pl": z.record(z.string(), PlSchema), | |
| 295 | + "pl": mapSchema(PlSchema), | |
| 290 | 296 | "score": z.number().int(), |
| 291 | 297 | "scoring": z.array(ScorerSchema), |
| 292 | 298 | "shortName": z.string(), |
| @@ -358,9 +364,9 @@ export const TopLevelSchema = z.object({ | ||
| 358 | 364 | "periodLengthREGULAR": z.number().int(), |
| 359 | 365 | "periodType": PerTypeSchema, |
| 360 | 366 | "periodsMax": z.number().int(), |
| 361 | - "scorers": z.record(z.string(), z.array(ScorerSchema)), | |
| 367 | + "scorers": mapSchema(z.array(ScorerSchema)), | |
| 362 | 368 | "timeline": z.array(z.any()), |
| 363 | - "tm": z.record(z.string(), TmSchema), | |
| 369 | + "tm": mapSchema(TmSchema), | |
| 364 | 370 | "totalTimeAdded": z.number().int(), |
| 365 | 371 | "totallds": TotalldsSchema, |
| 366 | 372 | }); |
Test case
1 generated file · +8 −2test/inputs/json/priority/nested-objects.json
Mtypescript-zoddefault / TopLevel.ts+8 −2
| @@ -1,8 +1,14 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const TopLevelSchema = z.object({ |
| 5 | - "a": z.record(z.string(), z.number().int()), | |
| 6 | - "b": z.record(z.string(), z.number().int()), | |
| 11 | + "a": mapSchema(z.number().int()), | |
| 12 | + "b": mapSchema(z.number().int()), | |
| 7 | 13 | }); |
| 8 | 14 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +7 −1test/inputs/json/priority/number-map.json
Mtypescript-zoddefault / TopLevel.ts+7 −1
| @@ -1,7 +1,13 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const TopLevelSchema = z.object({ |
| 5 | - "foo": z.record(z.string(), z.number()), | |
| 11 | + "foo": mapSchema(z.number()), | |
| 6 | 12 | }); |
| 7 | 13 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +8 −2test/inputs/json/samples/kitchen-sink.json
Mtypescript-zoddefault / TopLevel.ts+8 −2
| @@ -1,5 +1,11 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const DifferentThingClassSchema = z.object({ |
| 5 | 11 | "name": z.string(), |
| @@ -25,10 +31,10 @@ export const TopLevelSchema = z.object({ | ||
| 25 | 31 | "differentThings": z.array(z.union([DifferentThingClassSchema, z.number().int(), z.string().regex(/^-?\d+$/).transform(Number)])), |
| 26 | 32 | "doubleValue": z.number(), |
| 27 | 33 | "intValue": z.number().int(), |
| 28 | - "mapValue": z.record(z.string(), z.union([z.null(), z.number().int()])), | |
| 34 | + "mapValue": mapSchema(z.union([z.null(), z.number().int()])), | |
| 29 | 35 | "name with spaces": z.null(), |
| 30 | 36 | "nullValue": z.null(), |
| 31 | - "nullableMapValue": z.record(z.string(), z.union([z.null(), z.number().int()])), | |
| 37 | + "nullableMapValue": mapSchema(z.union([z.null(), z.number().int()])), | |
| 32 | 38 | "people": z.array(PersonElementSchema), |
| 33 | 39 | "person": PurplePersonSchema, |
| 34 | 40 | "stringValue": z.string(), |
Test case
1 generated file · +7 −1test/inputs/json/samples/us-avg-temperatures.json
Mtypescript-zoddefault / TopLevel.ts+7 −1
| @@ -1,5 +1,11 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const DatumSchema = z.object({ |
| 5 | 11 | "anomaly": z.string(), |
| @@ -16,7 +22,7 @@ export const DescriptionSchema = z.object({ | ||
| 16 | 22 | export type Description = z.infer<typeof DescriptionSchema>; |
| 17 | 23 | |
| 18 | 24 | export const TopLevelSchema = z.object({ |
| 19 | - "data": z.record(z.string(), DatumSchema), | |
| 25 | + "data": mapSchema(DatumSchema), | |
| 20 | 26 | "description": DescriptionSchema, |
| 21 | 27 | }); |
| 22 | 28 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +7 −1test/inputs/schema/any.schema
Mschema-typescript-zoddefault / TopLevel.ts+7 −1
| @@ -1,8 +1,14 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const TopLevelSchema = z.object({ |
| 5 | 11 | "foo": z.any(), |
| 6 | - "values": z.record(z.string(), z.any()), | |
| 12 | + "values": mapSchema(z.any()), | |
| 7 | 13 | }); |
| 8 | 14 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +7 −1test/inputs/schema/class-map-union.schema
Mschema-typescript-zoddefault / TopLevel.ts+7 −1
| @@ -1,5 +1,11 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const UnionClassSchema = z.object({ |
| 5 | 11 | "quux": z.number().int().optional(), |
| @@ -7,6 +13,6 @@ export const UnionClassSchema = z.object({ | ||
| 7 | 13 | export type UnionClass = z.infer<typeof UnionClassSchema>; |
| 8 | 14 | |
| 9 | 15 | export const TopLevelSchema = z.object({ |
| 10 | - "union": z.record(z.string(), z.union([z.boolean(), UnionClassSchema, z.number(), z.string()])).optional(), | |
| 16 | + "union": mapSchema(z.union([z.boolean(), UnionClassSchema, z.number(), z.string()])).optional(), | |
| 11 | 17 | }); |
| 12 | 18 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +7 −1test/inputs/schema/class-with-additional.schema
Mschema-typescript-zoddefault / TopLevel.ts+7 −1
| @@ -1,7 +1,13 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const TopLevelSchema = z.object({ |
| 5 | - "map": z.record(z.string(), z.union([z.boolean(), z.number()])).optional(), | |
| 11 | + "map": mapSchema(z.union([z.boolean(), z.number()])).optional(), | |
| 6 | 12 | }); |
| 7 | 13 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +9 −3test/inputs/schema/direct-union.schema
Mschema-typescript-zoddefault / TopLevel.ts+9 −3
| @@ -1,5 +1,11 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const ArrayNodeSchema = z.object({ |
| 5 | 11 | }); |
| @@ -30,8 +36,8 @@ export const ObjectNodeSchema = z.object({ | ||
| 30 | 36 | export type ObjectNode = z.infer<typeof ObjectNodeSchema>; |
| 31 | 37 | |
| 32 | 38 | export const ThingSchema = z.object({ |
| 33 | - "optional": z.union([z.null(), z.array(z.any()), z.boolean(), z.number(), z.number().int(), z.record(z.string(), z.any()), z.string()]).optional(), | |
| 34 | - "required": z.union([z.null(), z.array(z.any()), z.boolean(), z.number(), z.number().int(), z.record(z.string(), z.any()), z.string()]), | |
| 39 | + "optional": z.union([z.null(), z.array(z.any()), z.boolean(), z.number(), z.number().int(), mapSchema(z.any()), z.string()]).optional(), | |
| 40 | + "required": z.union([z.null(), z.array(z.any()), z.boolean(), z.number(), z.number().int(), mapSchema(z.any()), z.string()]), | |
| 35 | 41 | }); |
| 36 | 42 | export type Thing = z.infer<typeof ThingSchema>; |
| 37 | 43 | |
| @@ -47,7 +53,7 @@ export const TopLevelSchema = z.object({ | ||
| 47 | 53 | "longNode": LongNodeSchema.optional(), |
| 48 | 54 | "nullNode": NullNodeSchema.optional(), |
| 49 | 55 | "objectNode": ObjectNodeSchema.optional(), |
| 50 | - "stuff": z.record(z.string(), ThingSchema), | |
| 56 | + "stuff": mapSchema(ThingSchema), | |
| 51 | 57 | "textNode": TextNodeSchema.optional(), |
| 52 | 58 | }); |
| 53 | 59 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +7 −1test/inputs/schema/empty-object.schema
Mschema-typescript-zoddefault / TopLevel.ts+7 −1
| @@ -1,4 +1,10 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | -export const TopLevelSchema = z.record(z.string(), z.any()); | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 9 | +export const TopLevelSchema = mapSchema(z.any()); | |
| 4 | 10 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +7 −1test/inputs/schema/go-schema-pattern-properties.schema
Mschema-typescript-zoddefault / TopLevel.ts+7 −1
| @@ -1,7 +1,13 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const TopLevelSchema = z.object({ |
| 5 | - "map": z.record(z.string(), z.number().int()), | |
| 11 | + "map": mapSchema(z.number().int()), | |
| 6 | 12 | }); |
| 7 | 13 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +9 −3test/inputs/schema/recursive-union-flattening.schema
Mschema-typescript-zoddefault / TopLevel.ts+9 −3
| @@ -1,19 +1,25 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export type XClass = { |
| 5 | 11 | "x"?: Array<Array<any> | boolean | XClass | number | null | string> | boolean | number | Record<string, any> | null | string; |
| 6 | 12 | }; |
| 7 | 13 | export const XClassSchema: z.ZodType<XClass> = z.lazy(() => |
| 8 | 14 | z.object({ |
| 9 | - "x": z.union([z.null(), z.array(z.union([z.null(), z.array(z.any()), z.boolean(), XClassSchema, z.number(), z.string()])), z.boolean(), z.number(), z.record(z.string(), z.any()), z.string()]).optional(), | |
| 15 | + "x": z.union([z.null(), z.array(z.union([z.null(), z.array(z.any()), z.boolean(), XClassSchema, z.number(), z.string()])), z.boolean(), z.number(), mapSchema(z.any()), z.string()]).optional(), | |
| 10 | 16 | }) |
| 11 | 17 | ); |
| 12 | 18 | |
| 13 | 19 | export const TopLevelClassSchema = z.object({ |
| 14 | - "x": z.union([z.null(), z.array(z.union([z.null(), z.array(z.any()), z.boolean(), XClassSchema, z.number(), z.string()])), z.boolean(), z.number(), z.record(z.string(), z.any()), z.string()]).optional(), | |
| 20 | + "x": z.union([z.null(), z.array(z.union([z.null(), z.array(z.any()), z.boolean(), XClassSchema, z.number(), z.string()])), z.boolean(), z.number(), mapSchema(z.any()), z.string()]).optional(), | |
| 15 | 21 | }); |
| 16 | 22 | export type TopLevelClass = z.infer<typeof TopLevelClassSchema>; |
| 17 | 23 | |
| 18 | -export const TopLevelSchema = z.union([z.null(), z.array(z.union([z.null(), z.array(z.any()), z.boolean(), TopLevelClassSchema, z.number(), z.string()])), z.boolean(), z.number(), z.number().int(), z.record(z.string(), z.any()), z.string()]); | |
| 24 | +export const TopLevelSchema = z.union([z.null(), z.array(z.union([z.null(), z.array(z.any()), z.boolean(), TopLevelClassSchema, z.number(), z.string()])), z.boolean(), z.number(), z.number().int(), mapSchema(z.any()), z.string()]); | |
| 19 | 25 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +7 −1test/inputs/schema/unevaluated-properties.schema
Mschema-typescript-zoddefault / TopLevel.ts+7 −1
| @@ -1,5 +1,11 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | |
| 4 | 10 | export const ClosedClassSchema = z.object({ |
| 5 | 11 | }); |
| @@ -14,7 +20,7 @@ export type Item = z.infer<typeof ItemSchema>; | ||
| 14 | 20 | export const ConfigSchema = z.object({ |
| 15 | 21 | "closed": z.union([z.null(), z.array(z.any()), z.boolean(), ClosedClassSchema, z.number(), z.number().int(), z.string()]).optional(), |
| 16 | 22 | "name": z.string().optional(), |
| 17 | - "settings": z.record(z.string(), z.array(ItemSchema)).optional(), | |
| 23 | + "settings": mapSchema(z.array(ItemSchema)).optional(), | |
| 18 | 24 | }); |
| 19 | 25 | export type Config = z.infer<typeof ConfigSchema>; |
Test case
1 generated file · +17 −11test/inputs/schema/vega-lite.schema
Mschema-typescript-zoddefault / TopLevel.ts+17 −11
| @@ -1,5 +1,11 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | +const mapSchema = <T extends z.ZodTypeAny>(value: T) => | |
| 4 | + z.custom<Record<string, unknown>>(input => z.getParsedType(input) === z.ZodParsedType.object) | |
| 5 | + .transform(Object.entries) | |
| 6 | + .pipe(z.array(z.tuple([z.string(), value]))) | |
| 7 | + .transform((entries): Record<string, z.output<T>> => Object.fromEntries(entries)); | |
| 8 | + | |
| 3 | 9 | // Determines how size calculation should be performed, one of `"content"` or `"padding"`. |
| 4 | 10 | // The default setting (`"content"`) interprets the width and height settings as the data |
| 5 | 11 | // rectangle (plotting) dimensions, to which padding is then added. In contrast, the |
| @@ -659,7 +665,7 @@ export const SpecSchema: z.ZodType<Spec> = z.lazy(() => | ||
| 659 | 665 | "encoding": EncodingSchema.optional(), |
| 660 | 666 | "mark": z.union([MarkDefSchema, MarkSchema]).optional(), |
| 661 | 667 | "projection": ProjectionSchema.optional(), |
| 662 | - "selection": z.record(z.string(), SelectionDefSchema).optional(), | |
| 668 | + "selection": mapSchema(SelectionDefSchema).optional(), | |
| 663 | 669 | "facet": FacetMappingSchema.optional(), |
| 664 | 670 | "spec": SpecSchema.optional(), |
| 665 | 671 | "repeat": RepeatSchema.optional(), |
| @@ -697,7 +703,7 @@ export const LayerSpecSchema: z.ZodType<LayerSpec> = z.lazy(() => | ||
| 697 | 703 | "encoding": EncodingSchema.optional(), |
| 698 | 704 | "mark": z.union([MarkDefSchema, MarkSchema]).optional(), |
| 699 | 705 | "projection": ProjectionSchema.optional(), |
| 700 | - "selection": z.record(z.string(), SelectionDefSchema).optional(), | |
| 706 | + "selection": mapSchema(SelectionDefSchema).optional(), | |
| 701 | 707 | }) |
| 702 | 708 | ); |
| 703 | 709 | |
| @@ -921,7 +927,7 @@ export const ProjectionConfigSchema = z.object({ | ||
| 921 | 927 | "fraction": z.number().optional(), |
| 922 | 928 | "lobes": z.number().optional(), |
| 923 | 929 | "parallel": z.number().optional(), |
| 924 | - "precision": z.record(z.string(), z.union([z.number(), z.string()])).optional(), | |
| 930 | + "precision": mapSchema(z.union([z.number(), z.string()])).optional(), | |
| 925 | 931 | "radius": z.number().optional(), |
| 926 | 932 | "ratio": z.number().optional(), |
| 927 | 933 | "rotate": z.array(z.number()).optional(), |
| @@ -1126,7 +1132,7 @@ export const ViewConfigSchema = z.object({ | ||
| 1126 | 1132 | export type ViewConfig = z.infer<typeof ViewConfigSchema>; |
| 1127 | 1133 | |
| 1128 | 1134 | export const DataFormatSchema = z.object({ |
| 1129 | - "parse": z.union([ParseEnumSchema, z.record(z.string(), z.any())]).optional(), | |
| 1135 | + "parse": z.union([ParseEnumSchema, mapSchema(z.any())]).optional(), | |
| 1130 | 1136 | "type": DataFormatTypeSchema.optional(), |
| 1131 | 1137 | "property": z.string().optional(), |
| 1132 | 1138 | "feature": z.string().optional(), |
| @@ -1351,7 +1357,7 @@ export const ProjectionSchema = z.object({ | ||
| 1351 | 1357 | "fraction": z.number().optional(), |
| 1352 | 1358 | "lobes": z.number().optional(), |
| 1353 | 1359 | "parallel": z.number().optional(), |
| 1354 | - "precision": z.record(z.string(), z.union([z.number(), z.string()])).optional(), | |
| 1360 | + "precision": mapSchema(z.union([z.number(), z.string()])).optional(), | |
| 1355 | 1361 | "radius": z.number().optional(), |
| 1356 | 1362 | "ratio": z.number().optional(), |
| 1357 | 1363 | "rotate": z.array(z.number()).optional(), |
| @@ -1386,7 +1392,7 @@ export const ScaleResolveMapSchema = z.object({ | ||
| 1386 | 1392 | export type ScaleResolveMap = z.infer<typeof ScaleResolveMapSchema>; |
| 1387 | 1393 | |
| 1388 | 1394 | export const SelectionDefSchema = z.object({ |
| 1389 | - "bind": z.union([BindEnumSchema, z.record(z.string(), VgBindingSchema)]).optional(), | |
| 1395 | + "bind": z.union([BindEnumSchema, mapSchema(VgBindingSchema)]).optional(), | |
| 1390 | 1396 | "empty": EmptySchema.optional(), |
| 1391 | 1397 | "encodings": z.array(SingleDefChannelSchema).optional(), |
| 1392 | 1398 | "fields": z.array(z.string()).optional(), |
| @@ -1437,7 +1443,7 @@ export const IntervalSelectionConfigSchema = z.object({ | ||
| 1437 | 1443 | export type IntervalSelectionConfig = z.infer<typeof IntervalSelectionConfigSchema>; |
| 1438 | 1444 | |
| 1439 | 1445 | export const SingleSelectionConfigSchema = z.object({ |
| 1440 | - "bind": z.record(z.string(), VgBindingSchema).optional(), | |
| 1446 | + "bind": mapSchema(VgBindingSchema).optional(), | |
| 1441 | 1447 | "empty": EmptySchema.optional(), |
| 1442 | 1448 | "encodings": z.array(SingleDefChannelSchema).optional(), |
| 1443 | 1449 | "fields": z.array(z.string()).optional(), |
| @@ -1450,7 +1456,7 @@ export type SingleSelectionConfig = z.infer<typeof SingleSelectionConfigSchema>; | ||
| 1450 | 1456 | export const DataSchema = z.object({ |
| 1451 | 1457 | "format": DataFormatSchema.optional(), |
| 1452 | 1458 | "url": z.string().optional(), |
| 1453 | - "values": z.union([z.array(z.union([z.boolean(), z.number(), z.record(z.string(), z.any()), z.string()])), z.record(z.string(), z.any()), z.string()]).optional(), | |
| 1459 | + "values": z.union([z.array(z.union([z.boolean(), z.number(), mapSchema(z.any()), z.string()])), mapSchema(z.any()), z.string()]).optional(), | |
| 1454 | 1460 | "name": z.string().optional(), |
| 1455 | 1461 | }); |
| 1456 | 1462 | export type Data = z.infer<typeof DataSchema>; |
| @@ -1604,14 +1610,14 @@ export const ConfigSchema = z.object({ | ||
| 1604 | 1610 | "padding": z.union([PaddingClassSchema, z.number()]).optional(), |
| 1605 | 1611 | "point": MarkConfigSchema.optional(), |
| 1606 | 1612 | "projection": ProjectionConfigSchema.optional(), |
| 1607 | - "range": z.record(z.string(), z.union([z.array(z.union([z.number(), z.string()])), VgSchemeSchema])).optional(), | |
| 1613 | + "range": mapSchema(z.union([z.array(z.union([z.number(), z.string()])), VgSchemeSchema])).optional(), | |
| 1608 | 1614 | "rect": MarkConfigSchema.optional(), |
| 1609 | 1615 | "rule": MarkConfigSchema.optional(), |
| 1610 | 1616 | "scale": ScaleConfigSchema.optional(), |
| 1611 | 1617 | "selection": SelectionConfigSchema.optional(), |
| 1612 | 1618 | "square": MarkConfigSchema.optional(), |
| 1613 | 1619 | "stack": StackOffsetSchema.optional(), |
| 1614 | - "style": z.record(z.string(), VgMarkConfigSchema).optional(), | |
| 1620 | + "style": mapSchema(VgMarkConfigSchema).optional(), | |
| 1615 | 1621 | "text": TextConfigSchema.optional(), |
| 1616 | 1622 | "tick": TickConfigSchema.optional(), |
| 1617 | 1623 | "timeFormat": z.string().optional(), |
| @@ -1683,7 +1689,7 @@ export const TopLevelSchema = z.object({ | ||
| 1683 | 1689 | "name": z.string().optional(), |
| 1684 | 1690 | "padding": z.union([PaddingClassSchema, z.number()]).optional(), |
| 1685 | 1691 | "projection": ProjectionSchema.optional(), |
| 1686 | - "selection": z.record(z.string(), SelectionDefSchema).optional(), | |
| 1692 | + "selection": mapSchema(SelectionDefSchema).optional(), | |
| 1687 | 1693 | "title": z.union([TitleParamsSchema, z.string()]).optional(), |
| 1688 | 1694 | "transform": z.array(TransformSchema).optional(), |
| 1689 | 1695 | "width": z.number().optional(), |
No generated files match these filters.