Generated-output differences

quicktype output changed between the PR base and tested PR merge revisions.
← Back to the pull request
67test cases
67files differ
67modified
0new
0deleted
367changed lines
+240 −127insertions / deletions
Base c39af7d303b025280e2668a1b2d29913093593c9 · PR merge 094afbe55e8aca5c13d037ffa572aa7a45edbe66 · Head 31267acb4d610b54908bdb29496c6b578e1069e8 · raw patch
Test case

test/inputs/json/misc/016af.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,8 +1,9 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
34
45 export const TotalPopulationSchema = z.object({
5- "date": z.string(),
6+ "date": dateSchema,
67 "population": z.number().int(),
78 });
89 export type TotalPopulation = z.infer<typeof TotalPopulationSchema>;
Test case

test/inputs/json/misc/033b1.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,9 +1,10 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
34
45 export const TopLevelSchema = z.object({
56 "base": z.string(),
6- "date": z.string(),
7+ "date": dateSchema,
78 "rates": z.record(z.string(), z.number()),
89 });
910 export type TopLevel = z.infer<typeof TopLevelSchema>;
Test case

test/inputs/json/misc/0a358.json

1 generated file · +3 −2
Mtypescript-zoddefault / TopLevel.ts+3 −2
@@ -1,5 +1,6 @@
11 import * as z from "zod";
22
3+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
34
45 export const FacetsSchema = z.object({
56 });
@@ -7,10 +8,10 @@ export type Facets = z.infer<typeof FacetsSchema>;
78
89 export const ResultSchema = z.object({
910 "code": z.string(),
10- "created_at": z.string().pipe(z.coerce.date()),
11+ "created_at": dateTimeSchema,
1112 "id": z.number().int(),
1213 "name": z.string(),
13- "updated_at": z.string().pipe(z.coerce.date()),
14+ "updated_at": dateTimeSchema,
1415 "uri": z.string(),
1516 });
1617 export type Result = z.infer<typeof ResultSchema>;
Test case

test/inputs/json/misc/0a91a.json

1 generated file · +10 −8
Mtypescript-zoddefault / TopLevel.ts+10 −8
@@ -1,5 +1,7 @@
11 import * as z from "zod";
22
3+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
4+
35
46 export const TypeSchema = z.enum([
57 "PushEvent",
@@ -80,7 +82,7 @@ export const BaseRepoSchema = z.object({
8082 "compare_url": z.string(),
8183 "contents_url": z.string(),
8284 "contributors_url": z.string(),
83- "created_at": z.string().pipe(z.coerce.date()),
85+ "created_at": dateTimeSchema,
8486 "default_branch": z.string(),
8587 "deployments_url": z.string(),
8688 "description": z.null(),
@@ -121,7 +123,7 @@ export const BaseRepoSchema = z.object({
121123 "owner": MergedBySchema,
122124 "private": z.boolean(),
123125 "pulls_url": z.string(),
124- "pushed_at": z.string().pipe(z.coerce.date()),
126+ "pushed_at": dateTimeSchema,
125127 "releases_url": z.string(),
126128 "size": z.number().int(),
127129 "ssh_url": z.string(),
@@ -134,7 +136,7 @@ export const BaseRepoSchema = z.object({
134136 "tags_url": z.string(),
135137 "teams_url": z.string(),
136138 "trees_url": z.string(),
137- "updated_at": z.string().pipe(z.coerce.date()),
139+ "updated_at": dateTimeSchema,
138140 "url": z.string(),
139141 "watchers": z.number().int(),
140142 "watchers_count": z.number().int(),
@@ -169,12 +171,12 @@ export const PullRequestSchema = z.object({
169171 "base": BaseSchema,
170172 "body": z.string(),
171173 "changed_files": z.number().int(),
172- "closed_at": z.string().pipe(z.coerce.date()),
174+ "closed_at": dateTimeSchema,
173175 "comments": z.number().int(),
174176 "comments_url": z.string(),
175177 "commits": z.number().int(),
176178 "commits_url": z.string(),
177- "created_at": z.string().pipe(z.coerce.date()),
179+ "created_at": dateTimeSchema,
178180 "deletions": z.number().int(),
179181 "diff_url": z.string(),
180182 "head": BaseSchema,
@@ -188,7 +190,7 @@ export const PullRequestSchema = z.object({
188190 "mergeable": z.null(),
189191 "mergeable_state": z.string(),
190192 "merged": z.boolean(),
191- "merged_at": z.string().pipe(z.coerce.date()),
193+ "merged_at": dateTimeSchema,
192194 "merged_by": MergedBySchema,
193195 "milestone": z.null(),
194196 "number": z.number().int(),
@@ -201,7 +203,7 @@ export const PullRequestSchema = z.object({
201203 "state": z.string(),
202204 "statuses_url": z.string(),
203205 "title": z.string(),
204- "updated_at": z.string().pipe(z.coerce.date()),
206+ "updated_at": dateTimeSchema,
205207 "url": z.string(),
206208 "user": MergedBySchema,
207209 });
@@ -227,7 +229,7 @@ export type Payload = z.infer<typeof PayloadSchema>;
227229
228230 export const TopLevelElementSchema = z.object({
229231 "actor": ActorSchema,
230- "created_at": z.string().pipe(z.coerce.date()),
232+ "created_at": dateTimeSchema,
231233 "id": z.string(),
232234 "org": ActorSchema.optional(),
233235 "payload": PayloadSchema,
Test case

test/inputs/json/misc/0e0c2.json

1 generated file · +3 −1
Mtypescript-zoddefault / TopLevel.ts+3 −1
@@ -1,5 +1,7 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
4+
35
46 export const DetailLanguageSchema = z.enum([
57 "en",
@@ -80,7 +82,7 @@ export const ResultSchema = z.object({
8082 "id": z.number().int(),
8183 "images": z.array(ImageSchema),
8284 "language": ResultLanguageSchema,
83- "release_date": z.string(),
85+ "release_date": dateSchema,
8486 "stars": z.number().int(),
8587 "tags": z.union([z.null(), z.array(z.any())]),
8688 "title": z.string(),
Test case

test/inputs/json/misc/167d6.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,9 +1,10 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
34
45 export const TopLevelSchema = z.object({
56 "base": z.string(),
6- "date": z.string(),
7+ "date": dateSchema,
78 "rates": z.record(z.string(), z.number()),
89 });
910 export type TopLevel = z.infer<typeof TopLevelSchema>;
Test case

test/inputs/json/misc/16bc5.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,5 +1,6 @@
11 import * as z from "zod";
22
3+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
34
45 export const AstronomySchema = z.object({
56 "sunrise": z.string(),
@@ -106,7 +107,7 @@ export type Results = z.infer<typeof ResultsSchema>;
106107
107108 export const QuerySchema = z.object({
108109 "count": z.number().int(),
109- "created": z.string().pipe(z.coerce.date()),
110+ "created": dateTimeSchema,
110111 "lang": z.string(),
111112 "results": ResultsSchema,
112113 });
Test case

test/inputs/json/misc/1b28c.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,8 +1,9 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
34
45 export const TotalPopulationSchema = z.object({
5- "date": z.string(),
6+ "date": dateSchema,
67 "population": z.number().int(),
78 });
89 export type TotalPopulation = z.infer<typeof TotalPopulationSchema>;
Test case

test/inputs/json/misc/1b409.json

1 generated file · +5 −3
Mtypescript-zoddefault / TopLevel.ts+5 −3
@@ -1,5 +1,7 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
4+
35
46 export const PartySchema = z.enum([
57 "Republican",
@@ -70,7 +72,7 @@ export type Extra = z.infer<typeof ExtraSchema>;
7072
7173 export const PersonSchema = z.object({
7274 "bioguideid": z.string(),
73- "birthday": z.string(),
75+ "birthday": dateSchema,
7476 "cspanid": z.number().int(),
7577 "firstname": z.string(),
7678 "gender": GenderSchema,
@@ -96,7 +98,7 @@ export const ObjectElementSchema = z.object({
9698 "current": z.boolean(),
9799 "description": z.string(),
98100 "district": z.number().int(),
99- "enddate": z.string(),
101+ "enddate": dateSchema,
100102 "extra": ExtraSchema,
101103 "id": z.number().int(),
102104 "leadership_title": z.union([z.null(), z.string()]),
@@ -107,7 +109,7 @@ export const ObjectElementSchema = z.object({
107109 "role_type_label": RoleTypeLabelSchema,
108110 "senator_class": z.null(),
109111 "senator_rank": z.null(),
110- "startdate": z.string(),
112+ "startdate": dateSchema,
111113 "state": z.string(),
112114 "title": TitleSchema,
113115 "title_long": RoleTypeLabelSchema,
Test case

test/inputs/json/misc/262f0.json

1 generated file · +3 −1
Mtypescript-zoddefault / TopLevel.ts+3 −1
@@ -1,5 +1,7 @@
11 import * as z from "zod";
22
3+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
4+
35
46 export const TextSchema = z.enum([
57 "Mostly Cloudy",
@@ -113,7 +115,7 @@ export type Results = z.infer<typeof ResultsSchema>;
113115
114116 export const QuerySchema = z.object({
115117 "count": z.number().int(),
116- "created": z.string().pipe(z.coerce.date()),
118+ "created": dateTimeSchema,
117119 "lang": z.string(),
118120 "results": ResultsSchema,
119121 });
Test case

test/inputs/json/misc/2d4e2.json

1 generated file · +5 −3
Mtypescript-zoddefault / TopLevel.ts+5 −3
@@ -1,5 +1,7 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
4+
35
46 export const PartySchema = z.enum([
57 "Republican",
@@ -96,7 +98,7 @@ export type Extra = z.infer<typeof ExtraSchema>;
9698
9799 export const PersonSchema = z.object({
98100 "bioguideid": z.string(),
99- "birthday": z.string(),
101+ "birthday": dateSchema,
100102 "cspanid": z.number().int(),
101103 "firstname": z.string(),
102104 "gender": GenderSchema,
@@ -122,7 +124,7 @@ export const ObjectElementSchema = z.object({
122124 "current": z.boolean(),
123125 "description": z.string(),
124126 "district": z.null(),
125- "enddate": z.string(),
127+ "enddate": dateSchema,
126128 "extra": ExtraSchema,
127129 "id": z.number().int(),
128130 "leadership_title": z.union([z.null(), z.string()]),
@@ -135,7 +137,7 @@ export const ObjectElementSchema = z.object({
135137 "senator_class_label": SenatorClassLabelSchema,
136138 "senator_rank": SenatorRankSchema,
137139 "senator_rank_label": SenatorRankLabelSchema,
138- "startdate": z.string(),
140+ "startdate": dateSchema,
139141 "state": z.string(),
140142 "title": TitleSchema,
141143 "title_long": RoleTypeLabelSchema,
Test case

test/inputs/json/misc/31189.json

1 generated file · +8 −1
Mtypescript-zoddefault / TopLevel.ts+8 −1
@@ -1,5 +1,12 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
4+
5+
6+export const EffectiveFromEnumSchema = z.enum([
7+ "0000-01-01",
8+]);
9+export type EffectiveFromEnum = z.infer<typeof EffectiveFromEnumSchema>;
310
411 export const RatesSchema = z.object({
512 "parking": z.number().optional(),
@@ -12,7 +19,7 @@ export const RatesSchema = z.object({
1219 export type Rates = z.infer<typeof RatesSchema>;
1320
1421 export const PeriodSchema = z.object({
15- "effective_from": z.string(),
22+ "effective_from": z.union([dateSchema, EffectiveFromEnumSchema]),
1623 "rates": RatesSchema,
1724 });
1825 export type Period = z.infer<typeof PeriodSchema>;
Test case

test/inputs/json/misc/32d5c.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,8 +1,9 @@
11 import * as z from "zod";
22
3+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
34
45 export const TopLevelElementSchema = z.object({
5- "BirthDate": z.union([z.null(), z.string().pipe(z.coerce.date())]),
6+ "BirthDate": z.union([z.null(), dateTimeSchema]),
67 "BirthDateIsProtected": z.boolean(),
78 "GenderTypeID": z.number().int(),
89 "Notes": z.string(),
Test case

test/inputs/json/misc/337ed.json

1 generated file · +8 −6
Mtypescript-zoddefault / TopLevel.ts+8 −6
@@ -1,5 +1,7 @@
11 import * as z from "zod";
22
3+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
4+
35
46 export const StatusSchema = z.enum([
57 "active",
@@ -28,12 +30,12 @@ export type Facets = z.infer<typeof FacetsSchema>;
2830
2931 export const CustomIncomeSchema = z.object({
3032 "amount": z.number().int(),
31- "created_at": z.string().pipe(z.coerce.date()),
33+ "created_at": dateTimeSchema,
3234 "id": z.string(),
3335 "name": z.string(),
3436 "status": StatusSchema,
3537 "type": CustomIncomeTypeSchema,
36- "updated_at": z.string().pipe(z.coerce.date()),
38+ "updated_at": dateTimeSchema,
3739 "uri": z.string(),
3840 });
3941 export type CustomIncome = z.infer<typeof CustomIncomeSchema>;
@@ -42,11 +44,11 @@ export const ResultSchema = z.object({
4244 "cost_absolute": z.union([z.null(), z.number().int()]),
4345 "cost_max": z.union([z.null(), z.number().int()]),
4446 "cost_min": z.union([z.null(), z.number().int()]),
45- "created_at": z.string().pipe(z.coerce.date()),
47+ "created_at": dateTimeSchema,
4648 "customIncomes": z.array(CustomIncomeSchema),
4749 "direct_rep_costs_max": z.null(),
4850 "direct_rep_costs_min": z.null(),
49- "end_date": z.string().pipe(z.coerce.date()),
51+ "end_date": dateTimeSchema,
5052 "eur_sources_grants": z.number().int(),
5153 "eur_sources_grants_src": z.union([z.null(), z.string()]),
5254 "eur_sources_procurement": z.number().int(),
@@ -62,14 +64,14 @@ export const ResultSchema = z.object({
6264 "public_financing_national": z.union([z.null(), z.number().int()]),
6365 "public_financing_total": z.union([z.null(), z.number().int()]),
6466 "representative": z.string(),
65- "start_date": z.string().pipe(z.coerce.date()),
67+ "start_date": dateTimeSchema,
6668 "status": StatusSchema,
6769 "total_budget": z.union([z.null(), z.number().int()]),
6870 "turnover_absolute": z.union([z.null(), z.number().int()]),
6971 "turnover_max": z.union([z.null(), z.number().int()]),
7072 "turnover_min": z.union([z.null(), z.number().int()]),
7173 "type": ResultTypeSchema,
72- "updated_at": z.string().pipe(z.coerce.date()),
74+ "updated_at": dateTimeSchema,
7375 "uri": z.string(),
7476 });
7577 export type Result = z.infer<typeof ResultSchema>;
Test case

test/inputs/json/misc/33d2e.json

1 generated file · +12 −2
Mtypescript-zoddefault / TopLevel.ts+12 −2
@@ -1,5 +1,15 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
4+
5+
6+export const BornEnumSchema = z.enum([
7+ "0000-00-00",
8+ "1898-00-00",
9+ "1943-00-00",
10+]);
11+export type BornEnum = z.infer<typeof BornEnumSchema>;
12+
313
414 export const GenderSchema = z.enum([
515 "male",
@@ -37,11 +47,11 @@ export const PrizeSchema = z.object({
3747 export type Prize = z.infer<typeof PrizeSchema>;
3848
3949 export const LaureateSchema = z.object({
40- "born": z.string(),
50+ "born": z.union([dateSchema, BornEnumSchema]),
4151 "bornCity": z.string().optional(),
4252 "bornCountry": z.string().optional(),
4353 "bornCountryCode": z.string().optional(),
44- "died": z.string(),
54+ "died": z.union([dateSchema, BornEnumSchema]),
4555 "diedCity": z.string().optional(),
4656 "diedCountry": z.string().optional(),
4757 "diedCountryCode": z.string().optional(),
Test case

test/inputs/json/misc/3659d.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,8 +1,9 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
34
45 export const TotalPopulationSchema = z.object({
5- "date": z.string(),
6+ "date": dateSchema,
67 "population": z.number().int(),
78 });
89 export type TotalPopulation = z.infer<typeof TotalPopulationSchema>;
Test case

test/inputs/json/misc/3f1ce.json

1 generated file · +3 −1
Mtypescript-zoddefault / TopLevel.ts+3 −1
@@ -1,5 +1,7 @@
11 import * as z from "zod";
22
3+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
4+
35
46 export const TextSchema = z.enum([
57 "Thunderstorms",
@@ -111,7 +113,7 @@ export type Results = z.infer<typeof ResultsSchema>;
111113
112114 export const QuerySchema = z.object({
113115 "count": z.number().int(),
114- "created": z.string().pipe(z.coerce.date()),
116+ "created": dateTimeSchema,
115117 "lang": z.string(),
116118 "results": ResultsSchema,
117119 });
Test case

test/inputs/json/misc/43eaf.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,9 +1,10 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
34
45 export const TopLevelSchema = z.object({
56 "base": z.string(),
6- "date": z.string(),
7+ "date": dateSchema,
78 "rates": z.record(z.string(), z.number()),
89 });
910 export type TopLevel = z.infer<typeof TopLevelSchema>;
Test case

test/inputs/json/misc/4961a.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,8 +1,9 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
34
45 export const TotalPopulationSchema = z.object({
5- "date": z.string(),
6+ "date": dateSchema,
67 "population": z.number().int(),
78 });
89 export type TotalPopulation = z.infer<typeof TotalPopulationSchema>;
Test case

test/inputs/json/misc/4a0d7.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,8 +1,9 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
34
45 export const TotalPopulationSchema = z.object({
5- "date": z.string(),
6+ "date": dateSchema,
67 "population": z.number().int(),
78 });
89 export type TotalPopulation = z.infer<typeof TotalPopulationSchema>;
Test case

test/inputs/json/misc/4c547.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,5 +1,6 @@
11 import * as z from "zod";
22
3+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
34
45 export const AstronomySchema = z.object({
56 "sunrise": z.string(),
@@ -106,7 +107,7 @@ export type Results = z.infer<typeof ResultsSchema>;
106107
107108 export const QuerySchema = z.object({
108109 "count": z.number().int(),
109- "created": z.string().pipe(z.coerce.date()),
110+ "created": dateTimeSchema,
110111 "lang": z.string(),
111112 "results": ResultsSchema,
112113 });
Test case

test/inputs/json/misc/4e336.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,8 +1,9 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
34
45 export const TotalPopulationSchema = z.object({
5- "date": z.string(),
6+ "date": dateSchema,
67 "population": z.number().int(),
78 });
89 export type TotalPopulation = z.infer<typeof TotalPopulationSchema>;
Test case

test/inputs/json/misc/54d32.json

1 generated file · +4 −2
Mtypescript-zoddefault / TopLevel.ts+4 −2
@@ -1,5 +1,7 @@
11 import * as z from "zod";
22
3+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
4+
35
46 export const StatusSchema = z.enum([
57 "inactive",
@@ -12,12 +14,12 @@ export const FacetsSchema = z.object({
1214 export type Facets = z.infer<typeof FacetsSchema>;
1315
1416 export const ResultSchema = z.object({
15- "created_at": z.string().pipe(z.coerce.date()),
17+ "created_at": dateTimeSchema,
1618 "id": z.string(),
1719 "person_id": z.string(),
1820 "representative_id": z.string(),
1921 "status": StatusSchema,
20- "updated_at": z.string().pipe(z.coerce.date()),
22+ "updated_at": dateTimeSchema,
2123 });
2224 export type Result = z.infer<typeof ResultSchema>;
Test case

test/inputs/json/misc/5eae5.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,8 +1,9 @@
11 import * as z from "zod";
22
3+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
34
45 export const TopLevelElementSchema = z.object({
5- "Date": z.string().pipe(z.coerce.date()),
6+ "Date": dateTimeSchema,
67 "ID": z.number().int(),
78 "Sponsor": z.string(),
89 "Title": z.string(),
Test case

test/inputs/json/misc/5f3a1.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,9 +1,10 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
34
45 export const TopLevelSchema = z.object({
56 "base": z.string(),
6- "date": z.string(),
7+ "date": dateSchema,
78 "rates": z.record(z.string(), z.number()),
89 });
910 export type TopLevel = z.infer<typeof TopLevelSchema>;
Test case

test/inputs/json/misc/6260a.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,9 +1,10 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
34
45 export const TopLevelSchema = z.object({
56 "base": z.string(),
6- "date": z.string(),
7+ "date": dateSchema,
78 "rates": z.record(z.string(), z.number()),
89 });
910 export type TopLevel = z.infer<typeof TopLevelSchema>;
Test case

test/inputs/json/misc/65dec.json

1 generated file · +4 −2
Mtypescript-zoddefault / TopLevel.ts+4 −2
@@ -1,5 +1,7 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
4+
35
46 export const ColorIdentitySchema = z.enum([
57 "W",
@@ -61,7 +63,7 @@ export const LegalityElementSchema = z.object({
6163 export type LegalityElement = z.infer<typeof LegalityElementSchema>;
6264
6365 export const RulingSchema = z.object({
64- "date": z.string(),
66+ "date": dateSchema,
6567 "text": z.string(),
6668 });
6769 export type Ruling = z.infer<typeof RulingSchema>;
@@ -108,7 +110,7 @@ export const TopLevelSchema = z.object({
108110 "mkm_id": z.number().int(),
109111 "mkm_name": z.string(),
110112 "name": z.string(),
111- "releaseDate": z.string(),
113+ "releaseDate": dateSchema,
112114 "type": z.string(),
113115 });
114116 export type TopLevel = z.infer<typeof TopLevelSchema>;
Test case

test/inputs/json/misc/6dec6.json

1 generated file · +3 −1
Mtypescript-zoddefault / TopLevel.ts+3 −1
@@ -1,5 +1,7 @@
11 import * as z from "zod";
22
3+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
4+
35
46 export const TextSchema = z.enum([
57 "Showers",
@@ -113,7 +115,7 @@ export type Results = z.infer<typeof ResultsSchema>;
113115
114116 export const QuerySchema = z.object({
115117 "count": z.number().int(),
116- "created": z.string().pipe(z.coerce.date()),
118+ "created": dateTimeSchema,
117119 "lang": z.string(),
118120 "results": ResultsSchema,
119121 });
Test case

test/inputs/json/misc/70c77.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,9 +1,10 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
34
45 export const TopLevelSchema = z.object({
56 "base": z.string(),
6- "date": z.string(),
7+ "date": dateSchema,
78 "rates": z.record(z.string(), z.number()),
89 });
910 export type TopLevel = z.infer<typeof TopLevelSchema>;
Test case

test/inputs/json/misc/734ad.json

1 generated file · +6 −4
Mtypescript-zoddefault / TopLevel.ts+6 −4
@@ -1,5 +1,7 @@
11 import * as z from "zod";
22
3+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
4+
35
46 export const StatusSchema = z.enum([
57 "active",
@@ -31,7 +33,7 @@ export const ResultSchema = z.object({
3133 "be_office_town": z.string().optional(),
3234 "code_of_conduct": z.string(),
3335 "contact_country": z.number().int(),
34- "created_at": z.string().pipe(z.coerce.date()),
36+ "created_at": dateTimeSchema,
3537 "entity": z.string(),
3638 "goals": z.string(),
3739 "head": z.string(),
@@ -46,7 +48,7 @@ export const ResultSchema = z.object({
4648 "id": z.string(),
4749 "identification_code": z.string(),
4850 "info_members": z.string(),
49- "last_update_date": z.string().pipe(z.coerce.date()),
51+ "last_update_date": dateTimeSchema,
5052 "legal": z.string(),
5153 "legal_status": z.string(),
5254 "main_category": z.number().int(),
@@ -62,12 +64,12 @@ export const ResultSchema = z.object({
6264 "networking": z.union([z.null(), z.string()]),
6365 "number_of_natural_persons": z.union([z.null(), z.number().int()]),
6466 "other_code_of_conduct": z.union([z.null(), z.string()]),
65- "registration_date": z.string().pipe(z.coerce.date()),
67+ "registration_date": dateTimeSchema,
6668 "status": StatusSchema,
6769 "structure_members": z.string(),
6870 "sub_category": z.number().int(),
6971 "sub_category_title": z.string(),
70- "updated_at": z.string().pipe(z.coerce.date()),
72+ "updated_at": dateTimeSchema,
7173 "uri": z.string(),
7274 "web_site_url": z.union([z.null(), z.string()]),
7375 });
Test case

test/inputs/json/misc/75912.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,9 +1,10 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
34
45 export const TopLevelSchema = z.object({
56 "base": z.string(),
6- "date": z.string(),
7+ "date": dateSchema,
78 "rates": z.record(z.string(), z.number()),
89 });
910 export type TopLevel = z.infer<typeof TopLevelSchema>;
Test case

test/inputs/json/misc/77392.json

1 generated file · +3 −1
Mtypescript-zoddefault / TopLevel.ts+3 −1
@@ -1,5 +1,7 @@
11 import * as z from "zod";
22
3+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
4+
35
46 export const OrbitClassSchema = z.enum([
57 "Apollo",
@@ -24,7 +26,7 @@ export type Pha = z.infer<typeof PhaSchema>;
2426
2527 export const TopLevelElementSchema = z.object({
2628 "designation": z.string(),
27- "discovery_date": z.string().pipe(z.coerce.date()),
29+ "discovery_date": dateTimeSchema,
2830 "h_mag": z.string().optional(),
2931 "i_deg": z.string(),
3032 "moid_au": z.string(),
Test case

test/inputs/json/misc/7dfa6.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,8 +1,9 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
34
45 export const TotalPopulationSchema = z.object({
5- "date": z.string(),
6+ "date": dateSchema,
67 "population": z.number().int(),
78 });
89 export type TotalPopulation = z.infer<typeof TotalPopulationSchema>;
Test case

test/inputs/json/misc/7f568.json

1 generated file · +4 −2
Mtypescript-zoddefault / TopLevel.ts+4 −2
@@ -1,5 +1,7 @@
11 import * as z from "zod";
22
3+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
4+
35
46 export const LanguageSchema = z.enum([
57 "Markdown",
@@ -25,7 +27,7 @@ export const TopLevelElementSchema = z.object({
2527 "comments": z.number().int(),
2628 "comments_url": z.string(),
2729 "commits_url": z.string(),
28- "created_at": z.string().pipe(z.coerce.date()),
30+ "created_at": dateTimeSchema,
2931 "description": z.union([z.null(), z.string()]),
3032 "files": z.record(z.string(), FileSchema),
3133 "forks_url": z.string(),
@@ -35,7 +37,7 @@ export const TopLevelElementSchema = z.object({
3537 "id": z.string(),
3638 "public": z.boolean(),
3739 "truncated": z.boolean(),
38- "updated_at": z.string().pipe(z.coerce.date()),
40+ "updated_at": dateTimeSchema,
3941 "url": z.string(),
4042 "user": z.null(),
4143 });
Test case

test/inputs/json/misc/80aff.json

1 generated file · +3 −2
Mtypescript-zoddefault / TopLevel.ts+3 −2
@@ -1,17 +1,18 @@
11 import * as z from "zod";
22
3+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
34
45 export const FacetsSchema = z.object({
56 });
67 export type Facets = z.infer<typeof FacetsSchema>;
78
89 export const ResultSchema = z.object({
9- "created_at": z.string().pipe(z.coerce.date()),
10+ "created_at": dateTimeSchema,
1011 "id": z.number().int(),
1112 "items": z.number().int(),
1213 "name": z.string(),
1314 "parent": z.union([z.null(), z.number().int()]),
14- "updated_at": z.string().pipe(z.coerce.date()),
15+ "updated_at": dateTimeSchema,
1516 "uri": z.string(),
1617 });
1718 export type Result = z.infer<typeof ResultSchema>;
Test case

test/inputs/json/misc/88130.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,5 +1,6 @@
11 import * as z from "zod";
22
3+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
34
45 export const AstronomySchema = z.object({
56 "sunrise": z.string(),
@@ -106,7 +107,7 @@ export type Results = z.infer<typeof ResultsSchema>;
106107
107108 export const QuerySchema = z.object({
108109 "count": z.number().int(),
109- "created": z.string().pipe(z.coerce.date()),
110+ "created": dateTimeSchema,
110111 "lang": z.string(),
111112 "results": ResultsSchema,
112113 });
Test case

test/inputs/json/misc/8a62c.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,8 +1,9 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
34
45 export const TotalPopulationSchema = z.object({
5- "date": z.string(),
6+ "date": dateSchema,
67 "population": z.number().int(),
78 });
89 export type TotalPopulation = z.infer<typeof TotalPopulationSchema>;
Test case

test/inputs/json/misc/9617f.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,9 +1,10 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
34
45 export const TopLevelSchema = z.object({
56 "base": z.string(),
6- "date": z.string(),
7+ "date": dateSchema,
78 "rates": z.record(z.string(), z.number()),
89 });
910 export type TopLevel = z.infer<typeof TopLevelSchema>;
Test case

test/inputs/json/misc/9929c.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,5 +1,6 @@
11 import * as z from "zod";
22
3+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
34
45 export const AstronomySchema = z.object({
56 "sunrise": z.string(),
@@ -106,7 +107,7 @@ export type Results = z.infer<typeof ResultsSchema>;
106107
107108 export const QuerySchema = z.object({
108109 "count": z.number().int(),
109- "created": z.string().pipe(z.coerce.date()),
110+ "created": dateTimeSchema,
110111 "lang": z.string(),
111112 "results": ResultsSchema,
112113 });
Test case

test/inputs/json/misc/9ac3b.json

1 generated file · +4 −2
Mtypescript-zoddefault / TopLevel.ts+4 −2
@@ -1,5 +1,7 @@
11 import * as z from "zod";
22
3+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
4+
35
46 export const StatusSchema = z.enum([
57 "inactive",
@@ -19,7 +21,7 @@ export const FacetsSchema = z.object({
1921 export type Facets = z.infer<typeof FacetsSchema>;
2022
2123 export const ResultSchema = z.object({
22- "created_at": z.string().pipe(z.coerce.date()),
24+ "created_at": dateTimeSchema,
2325 "entity": z.string(),
2426 "first_name": z.string(),
2527 "id": z.string(),
@@ -28,7 +30,7 @@ export const ResultSchema = z.object({
2830 "position": z.union([z.null(), z.string()]),
2931 "status": StatusSchema,
3032 "title": z.union([z.null(), TitleSchema]),
31- "updated_at": z.string().pipe(z.coerce.date()),
33+ "updated_at": dateTimeSchema,
3234 "uri": z.string(),
3335 });
3436 export type Result = z.infer<typeof ResultSchema>;
Test case

test/inputs/json/misc/a0496.json

1 generated file · +6 −4
Mtypescript-zoddefault / TopLevel.ts+6 −4
@@ -1,5 +1,7 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
4+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
35
46 export const ErrorsSchema = z.object({
57 });
@@ -8,20 +10,20 @@ export type Errors = z.infer<typeof ErrorsSchema>;
810 export const TopLevelSchema = z.object({
911 "code": z.string(),
1012 "column_names": z.array(z.string()),
11- "data": z.array(z.array(z.union([z.null(), z.number(), z.string()]))),
13+ "data": z.array(z.array(z.union([z.null(), dateSchema, z.number()]))),
1214 "description": z.string(),
1315 "display_url": z.string(),
1416 "errors": ErrorsSchema,
1517 "frequency": z.string(),
16- "from_date": z.string(),
18+ "from_date": dateSchema,
1719 "id": z.number().int(),
1820 "name": z.string(),
1921 "premium": z.boolean(),
2022 "source_code": z.string(),
2123 "source_name": z.string(),
22- "to_date": z.string(),
24+ "to_date": dateSchema,
2325 "type": z.string(),
24- "updated_at": z.string().pipe(z.coerce.date()),
26+ "updated_at": dateTimeSchema,
2527 "urlize_name": z.string(),
2628 });
2729 export type TopLevel = z.infer<typeof TopLevelSchema>;
Test case

test/inputs/json/misc/a1eca.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,5 +1,6 @@
11 import * as z from "zod";
22
3+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
34
45 export const AstronomySchema = z.object({
56 "sunrise": z.string(),
@@ -106,7 +107,7 @@ export type Results = z.infer<typeof ResultsSchema>;
106107
107108 export const QuerySchema = z.object({
108109 "count": z.number().int(),
109- "created": z.string().pipe(z.coerce.date()),
110+ "created": dateTimeSchema,
110111 "lang": z.string(),
111112 "results": ResultsSchema,
112113 });
Test case

test/inputs/json/misc/a9691.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,9 +1,10 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
34
45 export const TopLevelSchema = z.object({
56 "base": z.string(),
6- "date": z.string(),
7+ "date": dateSchema,
78 "rates": z.record(z.string(), z.number()),
89 });
910 export type TopLevel = z.infer<typeof TopLevelSchema>;
Test case

test/inputs/json/misc/abb4b.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,8 +1,9 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
34
45 export const TotalPopulationSchema = z.object({
5- "date": z.string(),
6+ "date": dateSchema,
67 "population": z.number().int(),
78 });
89 export type TotalPopulation = z.infer<typeof TotalPopulationSchema>;
Test case

test/inputs/json/misc/ac944.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,9 +1,10 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
34
45 export const TopLevelSchema = z.object({
56 "base": z.string(),
6- "date": z.string(),
7+ "date": dateSchema,
78 "rates": z.record(z.string(), z.number()),
89 });
910 export type TopLevel = z.infer<typeof TopLevelSchema>;
Test case

test/inputs/json/misc/b4865.json

1 generated file · +3 −1
Mtypescript-zoddefault / TopLevel.ts+3 −1
@@ -1,5 +1,7 @@
11 import * as z from "zod";
22
3+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
4+
35
46 export const FallSchema = z.enum([
57 "Fell",
@@ -37,7 +39,7 @@ export const TopLevelElementSchema = z.object({
3739 "recclass": z.string(),
3840 "reclat": z.string().optional(),
3941 "reclong": z.string().optional(),
40- "year": z.string().pipe(z.coerce.date()).optional(),
42+ "year": dateTimeSchema.optional(),
4143 });
4244 export type TopLevelElement = z.infer<typeof TopLevelElementSchema>;
Test case

test/inputs/json/misc/b6f2c.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,8 +1,9 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
34
45 export const TotalPopulationSchema = z.object({
5- "date": z.string(),
6+ "date": dateSchema,
67 "population": z.number().int(),
78 });
89 export type TotalPopulation = z.infer<typeof TotalPopulationSchema>;
Test case

test/inputs/json/misc/bb1ec.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,8 +1,9 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
34
45 export const TotalPopulationSchema = z.object({
5- "date": z.string(),
6+ "date": dateSchema,
67 "population": z.number().int(),
78 });
89 export type TotalPopulation = z.infer<typeof TotalPopulationSchema>;
Test case

test/inputs/json/misc/cd463.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,9 +1,10 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
34
45 export const TopLevelSchema = z.object({
56 "base": z.string(),
6- "date": z.string(),
7+ "date": dateSchema,
78 "rates": z.record(z.string(), z.number()),
89 });
910 export type TopLevel = z.infer<typeof TopLevelSchema>;
Test case

test/inputs/json/misc/cf0d8.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,5 +1,6 @@
11 import * as z from "zod";
22
3+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
34
45 export const AstronomySchema = z.object({
56 "sunrise": z.string(),
@@ -106,7 +107,7 @@ export type Results = z.infer<typeof ResultsSchema>;
106107
107108 export const QuerySchema = z.object({
108109 "count": z.number().int(),
109- "created": z.string().pipe(z.coerce.date()),
110+ "created": dateTimeSchema,
110111 "lang": z.string(),
111112 "results": ResultsSchema,
112113 });
Test case

test/inputs/json/misc/cfbce.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,9 +1,10 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
34
45 export const TopLevelSchema = z.object({
56 "base": z.string(),
6- "date": z.string(),
7+ "date": dateSchema,
78 "rates": z.record(z.string(), z.number()),
89 });
910 export type TopLevel = z.infer<typeof TopLevelSchema>;
Test case

test/inputs/json/misc/d0908.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,8 +1,9 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
34
45 export const TotalPopulationSchema = z.object({
5- "date": z.string(),
6+ "date": dateSchema,
67 "population": z.number().int(),
78 });
89 export type TotalPopulation = z.infer<typeof TotalPopulationSchema>;
Test case

test/inputs/json/misc/d23d5.json

1 generated file · +3 −2
Mtypescript-zoddefault / TopLevel.ts+3 −2
@@ -1,5 +1,6 @@
11 import * as z from "zod";
22
3+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
34
45 export const FacetsSchema = z.object({
56 });
@@ -7,10 +8,10 @@ export type Facets = z.infer<typeof FacetsSchema>;
78
89 export const ResultSchema = z.object({
910 "acronym": z.union([z.null(), z.string()]),
10- "created_at": z.string().pipe(z.coerce.date()),
11+ "created_at": dateTimeSchema,
1112 "id": z.string(),
1213 "name": z.string(),
13- "updated_at": z.string().pipe(z.coerce.date()),
14+ "updated_at": dateTimeSchema,
1415 "uri": z.string(),
1516 });
1617 export type Result = z.infer<typeof ResultSchema>;
Test case

test/inputs/json/misc/dbfb3.json

1 generated file · +3 −1
Mtypescript-zoddefault / TopLevel.ts+3 −1
@@ -1,5 +1,7 @@
11 import * as z from "zod";
22
3+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
4+
35
46 export const TextSchema = z.enum([
57 "Mostly Sunny",
@@ -112,7 +114,7 @@ export type Results = z.infer<typeof ResultsSchema>;
112114
113115 export const QuerySchema = z.object({
114116 "count": z.number().int(),
115- "created": z.string().pipe(z.coerce.date()),
117+ "created": dateTimeSchema,
116118 "lang": z.string(),
117119 "results": ResultsSchema,
118120 });
Test case

test/inputs/json/misc/dc44f.json

1 generated file · +4 −2
Mtypescript-zoddefault / TopLevel.ts+4 −2
@@ -1,5 +1,7 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
4+
35
46 export const BoosterSchema = z.enum([
57 "rare",
@@ -110,7 +112,7 @@ export const LegalityElementSchema = z.object({
110112 export type LegalityElement = z.infer<typeof LegalityElementSchema>;
111113
112114 export const RulingSchema = z.object({
113- "date": z.string(),
115+ "date": dateSchema,
114116 "text": z.string(),
115117 });
116118 export type Ruling = z.infer<typeof RulingSchema>;
@@ -156,7 +158,7 @@ export const TopLevelSchema = z.object({
156158 "mkm_id": z.number().int(),
157159 "mkm_name": z.string(),
158160 "name": z.string(),
159- "releaseDate": z.string(),
161+ "releaseDate": dateSchema,
160162 "type": z.string(),
161163 });
162164 export type TopLevel = z.infer<typeof TopLevelSchema>;
Test case

test/inputs/json/misc/dd1ce.json

1 generated file · +4 −2
Mtypescript-zoddefault / TopLevel.ts+4 −2
@@ -1,5 +1,7 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
4+
35
46 export const BoosterSchema = z.enum([
57 "rare",
@@ -110,7 +112,7 @@ export const LegalityElementSchema = z.object({
110112 export type LegalityElement = z.infer<typeof LegalityElementSchema>;
111113
112114 export const RulingSchema = z.object({
113- "date": z.string(),
115+ "date": dateSchema,
114116 "text": z.string(),
115117 });
116118 export type Ruling = z.infer<typeof RulingSchema>;
@@ -156,7 +158,7 @@ export const TopLevelSchema = z.object({
156158 "mkm_id": z.number().int(),
157159 "mkm_name": z.string(),
158160 "name": z.string(),
159- "releaseDate": z.string(),
161+ "releaseDate": dateSchema,
160162 "type": z.string(),
161163 });
162164 export type TopLevel = z.infer<typeof TopLevelSchema>;
Test case

test/inputs/json/misc/df957.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,5 +1,6 @@
11 import * as z from "zod";
22
3+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
34
45 export const AstronomySchema = z.object({
56 "sunrise": z.string(),
@@ -106,7 +107,7 @@ export type Results = z.infer<typeof ResultsSchema>;
106107
107108 export const QuerySchema = z.object({
108109 "count": z.number().int(),
109- "created": z.string().pipe(z.coerce.date()),
110+ "created": dateTimeSchema,
110111 "lang": z.string(),
111112 "results": ResultsSchema,
112113 });
Test case

test/inputs/json/misc/e2915.json

1 generated file · +3 −1
Mtypescript-zoddefault / TopLevel.ts+3 −1
@@ -1,5 +1,7 @@
11 import * as z from "zod";
22
3+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
4+
35
46 export const TextSchema = z.enum([
57 "Sunny",
@@ -111,7 +113,7 @@ export type Results = z.infer<typeof ResultsSchema>;
111113
112114 export const QuerySchema = z.object({
113115 "count": z.number().int(),
114- "created": z.string().pipe(z.coerce.date()),
116+ "created": dateTimeSchema,
115117 "lang": z.string(),
116118 "results": ResultsSchema,
117119 });
Test case

test/inputs/json/priority/bug2590.json

1 generated file · +4 −2
Mtypescript-zoddefault / TopLevel.ts+4 −2
@@ -1,9 +1,11 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
4+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
35
46 export const InvoiceSchema = z.object({
5- "createdAt": z.union([z.null(), z.string().pipe(z.coerce.date())]),
6- "dueDate": z.union([z.null(), z.string()]),
7+ "createdAt": z.union([z.null(), dateTimeSchema]),
8+ "dueDate": z.union([z.null(), dateSchema]),
79 "name": z.string(),
810 });
911 export type Invoice = z.infer<typeof InvoiceSchema>;
Test case

test/inputs/json/priority/bug2663.json

1 generated file · +4 −2
Mtypescript-zoddefault / TopLevel.ts+4 −2
@@ -1,9 +1,11 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
4+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
35
46 export const TopLevelSchema = z.object({
5- "birthday": z.string(),
6- "lastSeen": z.string().pipe(z.coerce.date()),
7+ "birthday": dateSchema,
8+ "lastSeen": dateTimeSchema,
79 "name": z.string(),
810 });
911 export type TopLevel = z.infer<typeof TopLevelSchema>;
Test case

test/inputs/json/priority/keywords.json

1 generated file · +3 −1
Mtypescript-zoddefault / TopLevel.ts+3 −1
@@ -1,5 +1,7 @@
11 import * as z from "zod";
22
3+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
4+
35
46 export const EnumValueSchema = z.enum([
57 "ready",
@@ -358,7 +360,7 @@ export const DateParseHandlingSchema = z.object({
358360 export type DateParseHandling = z.infer<typeof DateParseHandlingSchema>;
359361
360362 export const DateTimeSchema = z.object({
361- "DateTime": z.string().pipe(z.coerce.date()),
363+ "DateTime": dateTimeSchema,
362364 });
363365 export type DateTime = z.infer<typeof DateTimeSchema>;
Test case

test/inputs/json/samples/github-events.json

1 generated file · +18 −16
Mtypescript-zoddefault / TopLevel.ts+18 −16
@@ -1,5 +1,7 @@
11 import * as z from "zod";
22
3+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
4+
35
46 export const TypeSchema = z.enum([
57 "User",
@@ -56,10 +58,10 @@ export type Label = z.infer<typeof LabelSchema>;
5658 export const MilestoneSchema = z.object({
5759 "closed_at": z.null(),
5860 "closed_issues": z.number().int(),
59- "created_at": z.string().pipe(z.coerce.date()),
61+ "created_at": dateTimeSchema,
6062 "creator": UserSchema,
6163 "description": z.string(),
62- "due_on": z.union([z.null(), z.string().pipe(z.coerce.date())]),
64+ "due_on": z.union([z.null(), dateTimeSchema]),
6365 "html_url": z.string(),
6466 "id": z.number().int(),
6567 "labels_url": z.string(),
@@ -67,7 +69,7 @@ export const MilestoneSchema = z.object({
6769 "open_issues": z.number().int(),
6870 "state": z.string(),
6971 "title": z.string(),
70- "updated_at": z.string().pipe(z.coerce.date()),
72+ "updated_at": dateTimeSchema,
7173 "url": z.string(),
7274 });
7375 export type Milestone = z.infer<typeof MilestoneSchema>;
@@ -92,7 +94,7 @@ export const BaseRepoSchema = z.object({
9294 "compare_url": z.string(),
9395 "contents_url": z.string(),
9496 "contributors_url": z.string(),
95- "created_at": z.string().pipe(z.coerce.date()),
97+ "created_at": dateTimeSchema,
9698 "default_branch": z.string(),
9799 "deployments_url": z.string(),
98100 "description": z.string(),
@@ -133,7 +135,7 @@ export const BaseRepoSchema = z.object({
133135 "owner": UserSchema,
134136 "private": z.boolean(),
135137 "pulls_url": z.string(),
136- "pushed_at": z.string().pipe(z.coerce.date()),
138+ "pushed_at": dateTimeSchema,
137139 "releases_url": z.string(),
138140 "size": z.number().int(),
139141 "ssh_url": z.string(),
@@ -146,7 +148,7 @@ export const BaseRepoSchema = z.object({
146148 "tags_url": z.string(),
147149 "teams_url": z.string(),
148150 "trees_url": z.string(),
149- "updated_at": z.string().pipe(z.coerce.date()),
151+ "updated_at": dateTimeSchema,
150152 "url": z.string(),
151153 "watchers": z.number().int(),
152154 "watchers_count": z.number().int(),
@@ -167,11 +169,11 @@ export type TopLevelRepo = z.infer<typeof TopLevelRepoSchema>;
167169
168170 export const CommentSchema = z.object({
169171 "body": z.string(),
170- "created_at": z.string().pipe(z.coerce.date()),
172+ "created_at": dateTimeSchema,
171173 "html_url": z.string(),
172174 "id": z.number().int(),
173175 "issue_url": z.string(),
174- "updated_at": z.string().pipe(z.coerce.date()),
176+ "updated_at": dateTimeSchema,
175177 "url": z.string(),
176178 "user": UserSchema,
177179 });
@@ -190,10 +192,10 @@ export const IssueSchema = z.object({
190192 "assignee": z.null(),
191193 "assignees": z.array(z.any()),
192194 "body": z.string(),
193- "closed_at": z.union([z.null(), z.string().pipe(z.coerce.date())]),
195+ "closed_at": z.union([z.null(), dateTimeSchema]),
194196 "comments": z.number().int(),
195197 "comments_url": z.string(),
196- "created_at": z.string().pipe(z.coerce.date()),
198+ "created_at": dateTimeSchema,
197199 "events_url": z.string(),
198200 "html_url": z.string(),
199201 "id": z.number().int(),
@@ -206,7 +208,7 @@ export const IssueSchema = z.object({
206208 "repository_url": z.string(),
207209 "state": z.string(),
208210 "title": z.string(),
209- "updated_at": z.string().pipe(z.coerce.date()),
211+ "updated_at": dateTimeSchema,
210212 "url": z.string(),
211213 "user": UserSchema,
212214 });
@@ -240,12 +242,12 @@ export const PayloadPullRequestSchema = z.object({
240242 "base": BaseSchema,
241243 "body": z.string(),
242244 "changed_files": z.number().int(),
243- "closed_at": z.string().pipe(z.coerce.date()),
245+ "closed_at": dateTimeSchema,
244246 "comments": z.number().int(),
245247 "comments_url": z.string(),
246248 "commits": z.number().int(),
247249 "commits_url": z.string(),
248- "created_at": z.string().pipe(z.coerce.date()),
250+ "created_at": dateTimeSchema,
249251 "deletions": z.number().int(),
250252 "diff_url": z.string(),
251253 "head": BaseSchema,
@@ -259,7 +261,7 @@ export const PayloadPullRequestSchema = z.object({
259261 "mergeable": z.null(),
260262 "mergeable_state": z.string(),
261263 "merged": z.boolean(),
262- "merged_at": z.string().pipe(z.coerce.date()),
264+ "merged_at": dateTimeSchema,
263265 "merged_by": UserSchema,
264266 "milestone": z.null(),
265267 "number": z.number().int(),
@@ -272,7 +274,7 @@ export const PayloadPullRequestSchema = z.object({
272274 "state": z.string(),
273275 "statuses_url": z.string(),
274276 "title": z.string(),
275- "updated_at": z.string().pipe(z.coerce.date()),
277+ "updated_at": dateTimeSchema,
276278 "url": z.string(),
277279 "user": UserSchema,
278280 });
@@ -300,7 +302,7 @@ export type Payload = z.infer<typeof PayloadSchema>;
300302
301303 export const TopLevelElementSchema = z.object({
302304 "actor": ActorSchema,
303- "created_at": z.string().pipe(z.coerce.date()),
305+ "created_at": dateTimeSchema,
304306 "id": z.string(),
305307 "org": ActorSchema.optional(),
306308 "payload": PayloadSchema,
Test case

test/inputs/json/samples/null-safe.json

1 generated file · +2 −1
Mtypescript-zoddefault / TopLevel.ts+2 −1
@@ -1,5 +1,6 @@
11 import * as z from "zod";
22
3+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
34
45 export const AddressSchema = z.object({
56 "city": z.string(),
@@ -10,7 +11,7 @@ export type Address = z.infer<typeof AddressSchema>;
1011
1112 export const ItemSchema = z.object({
1213 "address": AddressSchema.optional(),
13- "created_at": z.string().pipe(z.coerce.date()).optional(),
14+ "created_at": dateTimeSchema.optional(),
1415 "name": z.string(),
1516 "sex": z.union([z.null(), z.number().int()]),
1617 });
Test case

test/inputs/json/samples/us-senators.json

1 generated file · +5 −3
Mtypescript-zoddefault / TopLevel.ts+5 −3
@@ -1,5 +1,7 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
4+
35
46 export const PartySchema = z.enum([
57 "Democrat",
@@ -96,7 +98,7 @@ export type Extra = z.infer<typeof ExtraSchema>;
9698
9799 export const PersonSchema = z.object({
98100 "bioguideid": z.string(),
99- "birthday": z.string(),
101+ "birthday": dateSchema,
100102 "cspanid": z.number().int(),
101103 "firstname": z.string(),
102104 "gender": GenderSchema,
@@ -121,7 +123,7 @@ export const ObjectElementSchema = z.object({
121123 "current": z.boolean(),
122124 "description": z.string(),
123125 "district": z.null(),
124- "enddate": z.string(),
126+ "enddate": dateSchema,
125127 "extra": ExtraSchema,
126128 "leadership_title": z.union([z.null(), z.string()]),
127129 "party": PartySchema,
@@ -133,7 +135,7 @@ export const ObjectElementSchema = z.object({
133135 "senator_class_label": SenatorClassLabelSchema,
134136 "senator_rank": SenatorRankSchema,
135137 "senator_rank_label": SenatorRankLabelSchema,
136- "startdate": z.string(),
138+ "startdate": dateSchema,
137139 "state": z.string(),
138140 "title": TitleSchema,
139141 "title_long": RoleTypeLabelSchema,
Test case

test/inputs/schema/date-time-or-string.schema

1 generated file · +3 −1
Mschema-typescript-zoddefault / TopLevel.ts+3 −1
@@ -1,5 +1,7 @@
11 import * as z from "zod";
22
3+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
4+
35
46 export const BarEnumSchema = z.enum([
57 "quux",
@@ -7,7 +9,7 @@ export const BarEnumSchema = z.enum([
79 export type BarEnum = z.infer<typeof BarEnumSchema>;
810
911 export const TopLevelSchema = z.object({
10- "bar": z.union([BarEnumSchema, z.string().pipe(z.coerce.date())]),
12+ "bar": z.union([BarEnumSchema, dateTimeSchema]),
1113 "foo": z.string(),
1214 });
1315 export type TopLevel = z.infer<typeof TopLevelSchema>;
Test case

test/inputs/schema/date-time.schema

1 generated file · +9 −5
Mschema-typescript-zoddefault / TopLevel.ts+9 −5
@@ -1,5 +1,9 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
4+const timeSchema = z.string().regex(/^(?:[01]\d|2[0-3]):[0-5]\d:(?:[0-5]\d|60)(?:\.\d+)?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/i);
5+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
6+
37
48 export const ComplexUnionArrayEnumSchema = z.enum([
59 "foo",
@@ -20,13 +24,13 @@ export const OffsetTimeSchema = z.object({
2024 export type OffsetTime = z.infer<typeof OffsetTimeSchema>;
2125
2226 export const TopLevelSchema = z.object({
23- "complex-union-array": z.array(z.union([ComplexUnionArrayEnumSchema, z.number().int(), z.string().pipe(z.coerce.date())])),
24- "date": z.string(),
25- "date-time": z.string().pipe(z.coerce.date()),
27+ "complex-union-array": z.array(z.union([ComplexUnionArrayEnumSchema, z.number().int(), dateTimeSchema])),
28+ "date": dateSchema,
29+ "date-time": dateTimeSchema,
2630 "local-date-class": LocalDateSchema.optional(),
2731 "offset-date-time-class": OffsetDateTimeSchema.optional(),
2832 "offset-time-class": OffsetTimeSchema.optional(),
29- "time": z.string(),
30- "union-array": z.array(z.string()),
33+ "time": timeSchema,
34+ "union-array": z.array(z.union([dateSchema, timeSchema, dateTimeSchema])),
3135 });
3236 export type TopLevel = z.infer<typeof TopLevelSchema>;
Test case

test/inputs/schema/optional-date-time.schema

1 generated file · +9 −6
Mschema-typescript-zoddefault / TopLevel.ts+9 −6
@@ -1,12 +1,15 @@
11 import * as z from "zod";
22
3+const dateSchema = z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value);
4+const timeSchema = z.string().regex(/^(?:[01]\d|2[0-3]):[0-5]\d:(?:[0-5]\d|60)(?:\.\d+)?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/i);
5+const dateTimeSchema = z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success && (new Date(value.slice(0, 10) + "T00:00:00Z").toJSON() || "").slice(0, 10) === value.slice(0, 10)).pipe(z.coerce.date());
36
47 export const TopLevelSchema = z.object({
5- "optional-date": z.string().optional(),
6- "optional-date-time": z.string().pipe(z.coerce.date()).optional(),
7- "optional-time": z.string().optional(),
8- "required-date": z.string(),
9- "required-date-time": z.string().pipe(z.coerce.date()),
10- "required-time": z.string(),
8+ "optional-date": dateSchema.optional(),
9+ "optional-date-time": dateTimeSchema.optional(),
10+ "optional-time": timeSchema.optional(),
11+ "required-date": dateSchema,
12+ "required-date-time": dateTimeSchema,
13+ "required-time": timeSchema,
1114 });
1215 export type TopLevel = z.infer<typeof TopLevelSchema>;
No generated files match these filters.