Test case
1 generated file · +2 −1test/inputs/json/misc/016af.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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); | |
| 3 | 4 | |
| 4 | 5 | export const TotalPopulationSchema = z.object({ |
| 5 | - "date": z.string(), | |
| 6 | + "date": dateSchema, | |
| 6 | 7 | "population": z.number().int(), |
| 7 | 8 | }); |
| 8 | 9 | export type TotalPopulation = z.infer<typeof TotalPopulationSchema>; |
Test case
1 generated file · +2 −1test/inputs/json/misc/033b1.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,9 +1,10 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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); | |
| 3 | 4 | |
| 4 | 5 | export const TopLevelSchema = z.object({ |
| 5 | 6 | "base": z.string(), |
| 6 | - "date": z.string(), | |
| 7 | + "date": dateSchema, | |
| 7 | 8 | "rates": z.record(z.string(), z.number()), |
| 8 | 9 | }); |
| 9 | 10 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +3 −2test/inputs/json/misc/0a358.json
Mtypescript-zoddefault / TopLevel.ts+3 −2
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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()); | |
| 3 | 4 | |
| 4 | 5 | export const FacetsSchema = z.object({ |
| 5 | 6 | }); |
| @@ -7,10 +8,10 @@ export type Facets = z.infer<typeof FacetsSchema>; | ||
| 7 | 8 | |
| 8 | 9 | export const ResultSchema = z.object({ |
| 9 | 10 | "code": z.string(), |
| 10 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 11 | + "created_at": dateTimeSchema, | |
| 11 | 12 | "id": z.number().int(), |
| 12 | 13 | "name": z.string(), |
| 13 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 14 | + "updated_at": dateTimeSchema, | |
| 14 | 15 | "uri": z.string(), |
| 15 | 16 | }); |
| 16 | 17 | export type Result = z.infer<typeof ResultSchema>; |
Test case
1 generated file · +10 −8test/inputs/json/misc/0a91a.json
Mtypescript-zoddefault / TopLevel.ts+10 −8
| @@ -1,5 +1,7 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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 | + | |
| 3 | 5 | |
| 4 | 6 | export const TypeSchema = z.enum([ |
| 5 | 7 | "PushEvent", |
| @@ -80,7 +82,7 @@ export const BaseRepoSchema = z.object({ | ||
| 80 | 82 | "compare_url": z.string(), |
| 81 | 83 | "contents_url": z.string(), |
| 82 | 84 | "contributors_url": z.string(), |
| 83 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 85 | + "created_at": dateTimeSchema, | |
| 84 | 86 | "default_branch": z.string(), |
| 85 | 87 | "deployments_url": z.string(), |
| 86 | 88 | "description": z.null(), |
| @@ -121,7 +123,7 @@ export const BaseRepoSchema = z.object({ | ||
| 121 | 123 | "owner": MergedBySchema, |
| 122 | 124 | "private": z.boolean(), |
| 123 | 125 | "pulls_url": z.string(), |
| 124 | - "pushed_at": z.string().pipe(z.coerce.date()), | |
| 126 | + "pushed_at": dateTimeSchema, | |
| 125 | 127 | "releases_url": z.string(), |
| 126 | 128 | "size": z.number().int(), |
| 127 | 129 | "ssh_url": z.string(), |
| @@ -134,7 +136,7 @@ export const BaseRepoSchema = z.object({ | ||
| 134 | 136 | "tags_url": z.string(), |
| 135 | 137 | "teams_url": z.string(), |
| 136 | 138 | "trees_url": z.string(), |
| 137 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 139 | + "updated_at": dateTimeSchema, | |
| 138 | 140 | "url": z.string(), |
| 139 | 141 | "watchers": z.number().int(), |
| 140 | 142 | "watchers_count": z.number().int(), |
| @@ -169,12 +171,12 @@ export const PullRequestSchema = z.object({ | ||
| 169 | 171 | "base": BaseSchema, |
| 170 | 172 | "body": z.string(), |
| 171 | 173 | "changed_files": z.number().int(), |
| 172 | - "closed_at": z.string().pipe(z.coerce.date()), | |
| 174 | + "closed_at": dateTimeSchema, | |
| 173 | 175 | "comments": z.number().int(), |
| 174 | 176 | "comments_url": z.string(), |
| 175 | 177 | "commits": z.number().int(), |
| 176 | 178 | "commits_url": z.string(), |
| 177 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 179 | + "created_at": dateTimeSchema, | |
| 178 | 180 | "deletions": z.number().int(), |
| 179 | 181 | "diff_url": z.string(), |
| 180 | 182 | "head": BaseSchema, |
| @@ -188,7 +190,7 @@ export const PullRequestSchema = z.object({ | ||
| 188 | 190 | "mergeable": z.null(), |
| 189 | 191 | "mergeable_state": z.string(), |
| 190 | 192 | "merged": z.boolean(), |
| 191 | - "merged_at": z.string().pipe(z.coerce.date()), | |
| 193 | + "merged_at": dateTimeSchema, | |
| 192 | 194 | "merged_by": MergedBySchema, |
| 193 | 195 | "milestone": z.null(), |
| 194 | 196 | "number": z.number().int(), |
| @@ -201,7 +203,7 @@ export const PullRequestSchema = z.object({ | ||
| 201 | 203 | "state": z.string(), |
| 202 | 204 | "statuses_url": z.string(), |
| 203 | 205 | "title": z.string(), |
| 204 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 206 | + "updated_at": dateTimeSchema, | |
| 205 | 207 | "url": z.string(), |
| 206 | 208 | "user": MergedBySchema, |
| 207 | 209 | }); |
| @@ -227,7 +229,7 @@ export type Payload = z.infer<typeof PayloadSchema>; | ||
| 227 | 229 | |
| 228 | 230 | export const TopLevelElementSchema = z.object({ |
| 229 | 231 | "actor": ActorSchema, |
| 230 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 232 | + "created_at": dateTimeSchema, | |
| 231 | 233 | "id": z.string(), |
| 232 | 234 | "org": ActorSchema.optional(), |
| 233 | 235 | "payload": PayloadSchema, |
Test case
1 generated file · +3 −1test/inputs/json/misc/0e0c2.json
Mtypescript-zoddefault / TopLevel.ts+3 −1
| @@ -1,5 +1,7 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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 | + | |
| 3 | 5 | |
| 4 | 6 | export const DetailLanguageSchema = z.enum([ |
| 5 | 7 | "en", |
| @@ -80,7 +82,7 @@ export const ResultSchema = z.object({ | ||
| 80 | 82 | "id": z.number().int(), |
| 81 | 83 | "images": z.array(ImageSchema), |
| 82 | 84 | "language": ResultLanguageSchema, |
| 83 | - "release_date": z.string(), | |
| 85 | + "release_date": dateSchema, | |
| 84 | 86 | "stars": z.number().int(), |
| 85 | 87 | "tags": z.union([z.null(), z.array(z.any())]), |
| 86 | 88 | "title": z.string(), |
Test case
1 generated file · +2 −1test/inputs/json/misc/167d6.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,9 +1,10 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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); | |
| 3 | 4 | |
| 4 | 5 | export const TopLevelSchema = z.object({ |
| 5 | 6 | "base": z.string(), |
| 6 | - "date": z.string(), | |
| 7 | + "date": dateSchema, | |
| 7 | 8 | "rates": z.record(z.string(), z.number()), |
| 8 | 9 | }); |
| 9 | 10 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +2 −1test/inputs/json/misc/16bc5.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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()); | |
| 3 | 4 | |
| 4 | 5 | export const AstronomySchema = z.object({ |
| 5 | 6 | "sunrise": z.string(), |
| @@ -106,7 +107,7 @@ export type Results = z.infer<typeof ResultsSchema>; | ||
| 106 | 107 | |
| 107 | 108 | export const QuerySchema = z.object({ |
| 108 | 109 | "count": z.number().int(), |
| 109 | - "created": z.string().pipe(z.coerce.date()), | |
| 110 | + "created": dateTimeSchema, | |
| 110 | 111 | "lang": z.string(), |
| 111 | 112 | "results": ResultsSchema, |
| 112 | 113 | }); |
Test case
1 generated file · +2 −1test/inputs/json/misc/1b28c.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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); | |
| 3 | 4 | |
| 4 | 5 | export const TotalPopulationSchema = z.object({ |
| 5 | - "date": z.string(), | |
| 6 | + "date": dateSchema, | |
| 6 | 7 | "population": z.number().int(), |
| 7 | 8 | }); |
| 8 | 9 | export type TotalPopulation = z.infer<typeof TotalPopulationSchema>; |
Test case
1 generated file · +5 −3test/inputs/json/misc/1b409.json
Mtypescript-zoddefault / TopLevel.ts+5 −3
| @@ -1,5 +1,7 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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 | + | |
| 3 | 5 | |
| 4 | 6 | export const PartySchema = z.enum([ |
| 5 | 7 | "Republican", |
| @@ -70,7 +72,7 @@ export type Extra = z.infer<typeof ExtraSchema>; | ||
| 70 | 72 | |
| 71 | 73 | export const PersonSchema = z.object({ |
| 72 | 74 | "bioguideid": z.string(), |
| 73 | - "birthday": z.string(), | |
| 75 | + "birthday": dateSchema, | |
| 74 | 76 | "cspanid": z.number().int(), |
| 75 | 77 | "firstname": z.string(), |
| 76 | 78 | "gender": GenderSchema, |
| @@ -96,7 +98,7 @@ export const ObjectElementSchema = z.object({ | ||
| 96 | 98 | "current": z.boolean(), |
| 97 | 99 | "description": z.string(), |
| 98 | 100 | "district": z.number().int(), |
| 99 | - "enddate": z.string(), | |
| 101 | + "enddate": dateSchema, | |
| 100 | 102 | "extra": ExtraSchema, |
| 101 | 103 | "id": z.number().int(), |
| 102 | 104 | "leadership_title": z.union([z.null(), z.string()]), |
| @@ -107,7 +109,7 @@ export const ObjectElementSchema = z.object({ | ||
| 107 | 109 | "role_type_label": RoleTypeLabelSchema, |
| 108 | 110 | "senator_class": z.null(), |
| 109 | 111 | "senator_rank": z.null(), |
| 110 | - "startdate": z.string(), | |
| 112 | + "startdate": dateSchema, | |
| 111 | 113 | "state": z.string(), |
| 112 | 114 | "title": TitleSchema, |
| 113 | 115 | "title_long": RoleTypeLabelSchema, |
Test case
1 generated file · +3 −1test/inputs/json/misc/262f0.json
Mtypescript-zoddefault / TopLevel.ts+3 −1
| @@ -1,5 +1,7 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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 | + | |
| 3 | 5 | |
| 4 | 6 | export const TextSchema = z.enum([ |
| 5 | 7 | "Mostly Cloudy", |
| @@ -113,7 +115,7 @@ export type Results = z.infer<typeof ResultsSchema>; | ||
| 113 | 115 | |
| 114 | 116 | export const QuerySchema = z.object({ |
| 115 | 117 | "count": z.number().int(), |
| 116 | - "created": z.string().pipe(z.coerce.date()), | |
| 118 | + "created": dateTimeSchema, | |
| 117 | 119 | "lang": z.string(), |
| 118 | 120 | "results": ResultsSchema, |
| 119 | 121 | }); |
Test case
1 generated file · +5 −3test/inputs/json/misc/2d4e2.json
Mtypescript-zoddefault / TopLevel.ts+5 −3
| @@ -1,5 +1,7 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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 | + | |
| 3 | 5 | |
| 4 | 6 | export const PartySchema = z.enum([ |
| 5 | 7 | "Republican", |
| @@ -96,7 +98,7 @@ export type Extra = z.infer<typeof ExtraSchema>; | ||
| 96 | 98 | |
| 97 | 99 | export const PersonSchema = z.object({ |
| 98 | 100 | "bioguideid": z.string(), |
| 99 | - "birthday": z.string(), | |
| 101 | + "birthday": dateSchema, | |
| 100 | 102 | "cspanid": z.number().int(), |
| 101 | 103 | "firstname": z.string(), |
| 102 | 104 | "gender": GenderSchema, |
| @@ -122,7 +124,7 @@ export const ObjectElementSchema = z.object({ | ||
| 122 | 124 | "current": z.boolean(), |
| 123 | 125 | "description": z.string(), |
| 124 | 126 | "district": z.null(), |
| 125 | - "enddate": z.string(), | |
| 127 | + "enddate": dateSchema, | |
| 126 | 128 | "extra": ExtraSchema, |
| 127 | 129 | "id": z.number().int(), |
| 128 | 130 | "leadership_title": z.union([z.null(), z.string()]), |
| @@ -135,7 +137,7 @@ export const ObjectElementSchema = z.object({ | ||
| 135 | 137 | "senator_class_label": SenatorClassLabelSchema, |
| 136 | 138 | "senator_rank": SenatorRankSchema, |
| 137 | 139 | "senator_rank_label": SenatorRankLabelSchema, |
| 138 | - "startdate": z.string(), | |
| 140 | + "startdate": dateSchema, | |
| 139 | 141 | "state": z.string(), |
| 140 | 142 | "title": TitleSchema, |
| 141 | 143 | "title_long": RoleTypeLabelSchema, |
Test case
1 generated file · +8 −1test/inputs/json/misc/31189.json
Mtypescript-zoddefault / TopLevel.ts+8 −1
| @@ -1,5 +1,12 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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>; | |
| 3 | 10 | |
| 4 | 11 | export const RatesSchema = z.object({ |
| 5 | 12 | "parking": z.number().optional(), |
| @@ -12,7 +19,7 @@ export const RatesSchema = z.object({ | ||
| 12 | 19 | export type Rates = z.infer<typeof RatesSchema>; |
| 13 | 20 | |
| 14 | 21 | export const PeriodSchema = z.object({ |
| 15 | - "effective_from": z.string(), | |
| 22 | + "effective_from": z.union([dateSchema, EffectiveFromEnumSchema]), | |
| 16 | 23 | "rates": RatesSchema, |
| 17 | 24 | }); |
| 18 | 25 | export type Period = z.infer<typeof PeriodSchema>; |
Test case
1 generated file · +2 −1test/inputs/json/misc/32d5c.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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()); | |
| 3 | 4 | |
| 4 | 5 | export const TopLevelElementSchema = z.object({ |
| 5 | - "BirthDate": z.union([z.null(), z.string().pipe(z.coerce.date())]), | |
| 6 | + "BirthDate": z.union([z.null(), dateTimeSchema]), | |
| 6 | 7 | "BirthDateIsProtected": z.boolean(), |
| 7 | 8 | "GenderTypeID": z.number().int(), |
| 8 | 9 | "Notes": z.string(), |
Test case
1 generated file · +8 −6test/inputs/json/misc/337ed.json
Mtypescript-zoddefault / TopLevel.ts+8 −6
| @@ -1,5 +1,7 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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 | + | |
| 3 | 5 | |
| 4 | 6 | export const StatusSchema = z.enum([ |
| 5 | 7 | "active", |
| @@ -28,12 +30,12 @@ export type Facets = z.infer<typeof FacetsSchema>; | ||
| 28 | 30 | |
| 29 | 31 | export const CustomIncomeSchema = z.object({ |
| 30 | 32 | "amount": z.number().int(), |
| 31 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 33 | + "created_at": dateTimeSchema, | |
| 32 | 34 | "id": z.string(), |
| 33 | 35 | "name": z.string(), |
| 34 | 36 | "status": StatusSchema, |
| 35 | 37 | "type": CustomIncomeTypeSchema, |
| 36 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 38 | + "updated_at": dateTimeSchema, | |
| 37 | 39 | "uri": z.string(), |
| 38 | 40 | }); |
| 39 | 41 | export type CustomIncome = z.infer<typeof CustomIncomeSchema>; |
| @@ -42,11 +44,11 @@ export const ResultSchema = z.object({ | ||
| 42 | 44 | "cost_absolute": z.union([z.null(), z.number().int()]), |
| 43 | 45 | "cost_max": z.union([z.null(), z.number().int()]), |
| 44 | 46 | "cost_min": z.union([z.null(), z.number().int()]), |
| 45 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 47 | + "created_at": dateTimeSchema, | |
| 46 | 48 | "customIncomes": z.array(CustomIncomeSchema), |
| 47 | 49 | "direct_rep_costs_max": z.null(), |
| 48 | 50 | "direct_rep_costs_min": z.null(), |
| 49 | - "end_date": z.string().pipe(z.coerce.date()), | |
| 51 | + "end_date": dateTimeSchema, | |
| 50 | 52 | "eur_sources_grants": z.number().int(), |
| 51 | 53 | "eur_sources_grants_src": z.union([z.null(), z.string()]), |
| 52 | 54 | "eur_sources_procurement": z.number().int(), |
| @@ -62,14 +64,14 @@ export const ResultSchema = z.object({ | ||
| 62 | 64 | "public_financing_national": z.union([z.null(), z.number().int()]), |
| 63 | 65 | "public_financing_total": z.union([z.null(), z.number().int()]), |
| 64 | 66 | "representative": z.string(), |
| 65 | - "start_date": z.string().pipe(z.coerce.date()), | |
| 67 | + "start_date": dateTimeSchema, | |
| 66 | 68 | "status": StatusSchema, |
| 67 | 69 | "total_budget": z.union([z.null(), z.number().int()]), |
| 68 | 70 | "turnover_absolute": z.union([z.null(), z.number().int()]), |
| 69 | 71 | "turnover_max": z.union([z.null(), z.number().int()]), |
| 70 | 72 | "turnover_min": z.union([z.null(), z.number().int()]), |
| 71 | 73 | "type": ResultTypeSchema, |
| 72 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 74 | + "updated_at": dateTimeSchema, | |
| 73 | 75 | "uri": z.string(), |
| 74 | 76 | }); |
| 75 | 77 | export type Result = z.infer<typeof ResultSchema>; |
Test case
1 generated file · +12 −2test/inputs/json/misc/33d2e.json
Mtypescript-zoddefault / TopLevel.ts+12 −2
| @@ -1,5 +1,15 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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 | + | |
| 3 | 13 | |
| 4 | 14 | export const GenderSchema = z.enum([ |
| 5 | 15 | "male", |
| @@ -37,11 +47,11 @@ export const PrizeSchema = z.object({ | ||
| 37 | 47 | export type Prize = z.infer<typeof PrizeSchema>; |
| 38 | 48 | |
| 39 | 49 | export const LaureateSchema = z.object({ |
| 40 | - "born": z.string(), | |
| 50 | + "born": z.union([dateSchema, BornEnumSchema]), | |
| 41 | 51 | "bornCity": z.string().optional(), |
| 42 | 52 | "bornCountry": z.string().optional(), |
| 43 | 53 | "bornCountryCode": z.string().optional(), |
| 44 | - "died": z.string(), | |
| 54 | + "died": z.union([dateSchema, BornEnumSchema]), | |
| 45 | 55 | "diedCity": z.string().optional(), |
| 46 | 56 | "diedCountry": z.string().optional(), |
| 47 | 57 | "diedCountryCode": z.string().optional(), |
Test case
1 generated file · +2 −1test/inputs/json/misc/3659d.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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); | |
| 3 | 4 | |
| 4 | 5 | export const TotalPopulationSchema = z.object({ |
| 5 | - "date": z.string(), | |
| 6 | + "date": dateSchema, | |
| 6 | 7 | "population": z.number().int(), |
| 7 | 8 | }); |
| 8 | 9 | export type TotalPopulation = z.infer<typeof TotalPopulationSchema>; |
Test case
1 generated file · +3 −1test/inputs/json/misc/3f1ce.json
Mtypescript-zoddefault / TopLevel.ts+3 −1
| @@ -1,5 +1,7 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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 | + | |
| 3 | 5 | |
| 4 | 6 | export const TextSchema = z.enum([ |
| 5 | 7 | "Thunderstorms", |
| @@ -111,7 +113,7 @@ export type Results = z.infer<typeof ResultsSchema>; | ||
| 111 | 113 | |
| 112 | 114 | export const QuerySchema = z.object({ |
| 113 | 115 | "count": z.number().int(), |
| 114 | - "created": z.string().pipe(z.coerce.date()), | |
| 116 | + "created": dateTimeSchema, | |
| 115 | 117 | "lang": z.string(), |
| 116 | 118 | "results": ResultsSchema, |
| 117 | 119 | }); |
Test case
1 generated file · +2 −1test/inputs/json/misc/43eaf.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,9 +1,10 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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); | |
| 3 | 4 | |
| 4 | 5 | export const TopLevelSchema = z.object({ |
| 5 | 6 | "base": z.string(), |
| 6 | - "date": z.string(), | |
| 7 | + "date": dateSchema, | |
| 7 | 8 | "rates": z.record(z.string(), z.number()), |
| 8 | 9 | }); |
| 9 | 10 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +2 −1test/inputs/json/misc/4961a.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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); | |
| 3 | 4 | |
| 4 | 5 | export const TotalPopulationSchema = z.object({ |
| 5 | - "date": z.string(), | |
| 6 | + "date": dateSchema, | |
| 6 | 7 | "population": z.number().int(), |
| 7 | 8 | }); |
| 8 | 9 | export type TotalPopulation = z.infer<typeof TotalPopulationSchema>; |
Test case
1 generated file · +2 −1test/inputs/json/misc/4a0d7.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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); | |
| 3 | 4 | |
| 4 | 5 | export const TotalPopulationSchema = z.object({ |
| 5 | - "date": z.string(), | |
| 6 | + "date": dateSchema, | |
| 6 | 7 | "population": z.number().int(), |
| 7 | 8 | }); |
| 8 | 9 | export type TotalPopulation = z.infer<typeof TotalPopulationSchema>; |
Test case
1 generated file · +2 −1test/inputs/json/misc/4c547.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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()); | |
| 3 | 4 | |
| 4 | 5 | export const AstronomySchema = z.object({ |
| 5 | 6 | "sunrise": z.string(), |
| @@ -106,7 +107,7 @@ export type Results = z.infer<typeof ResultsSchema>; | ||
| 106 | 107 | |
| 107 | 108 | export const QuerySchema = z.object({ |
| 108 | 109 | "count": z.number().int(), |
| 109 | - "created": z.string().pipe(z.coerce.date()), | |
| 110 | + "created": dateTimeSchema, | |
| 110 | 111 | "lang": z.string(), |
| 111 | 112 | "results": ResultsSchema, |
| 112 | 113 | }); |
Test case
1 generated file · +2 −1test/inputs/json/misc/4e336.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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); | |
| 3 | 4 | |
| 4 | 5 | export const TotalPopulationSchema = z.object({ |
| 5 | - "date": z.string(), | |
| 6 | + "date": dateSchema, | |
| 6 | 7 | "population": z.number().int(), |
| 7 | 8 | }); |
| 8 | 9 | export type TotalPopulation = z.infer<typeof TotalPopulationSchema>; |
Test case
1 generated file · +4 −2test/inputs/json/misc/54d32.json
Mtypescript-zoddefault / TopLevel.ts+4 −2
| @@ -1,5 +1,7 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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 | + | |
| 3 | 5 | |
| 4 | 6 | export const StatusSchema = z.enum([ |
| 5 | 7 | "inactive", |
| @@ -12,12 +14,12 @@ export const FacetsSchema = z.object({ | ||
| 12 | 14 | export type Facets = z.infer<typeof FacetsSchema>; |
| 13 | 15 | |
| 14 | 16 | export const ResultSchema = z.object({ |
| 15 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 17 | + "created_at": dateTimeSchema, | |
| 16 | 18 | "id": z.string(), |
| 17 | 19 | "person_id": z.string(), |
| 18 | 20 | "representative_id": z.string(), |
| 19 | 21 | "status": StatusSchema, |
| 20 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 22 | + "updated_at": dateTimeSchema, | |
| 21 | 23 | }); |
| 22 | 24 | export type Result = z.infer<typeof ResultSchema>; |
Test case
1 generated file · +2 −1test/inputs/json/misc/5eae5.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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()); | |
| 3 | 4 | |
| 4 | 5 | export const TopLevelElementSchema = z.object({ |
| 5 | - "Date": z.string().pipe(z.coerce.date()), | |
| 6 | + "Date": dateTimeSchema, | |
| 6 | 7 | "ID": z.number().int(), |
| 7 | 8 | "Sponsor": z.string(), |
| 8 | 9 | "Title": z.string(), |
Test case
1 generated file · +2 −1test/inputs/json/misc/5f3a1.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,9 +1,10 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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); | |
| 3 | 4 | |
| 4 | 5 | export const TopLevelSchema = z.object({ |
| 5 | 6 | "base": z.string(), |
| 6 | - "date": z.string(), | |
| 7 | + "date": dateSchema, | |
| 7 | 8 | "rates": z.record(z.string(), z.number()), |
| 8 | 9 | }); |
| 9 | 10 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +2 −1test/inputs/json/misc/6260a.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,9 +1,10 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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); | |
| 3 | 4 | |
| 4 | 5 | export const TopLevelSchema = z.object({ |
| 5 | 6 | "base": z.string(), |
| 6 | - "date": z.string(), | |
| 7 | + "date": dateSchema, | |
| 7 | 8 | "rates": z.record(z.string(), z.number()), |
| 8 | 9 | }); |
| 9 | 10 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +4 −2test/inputs/json/misc/65dec.json
Mtypescript-zoddefault / TopLevel.ts+4 −2
| @@ -1,5 +1,7 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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 | + | |
| 3 | 5 | |
| 4 | 6 | export const ColorIdentitySchema = z.enum([ |
| 5 | 7 | "W", |
| @@ -61,7 +63,7 @@ export const LegalityElementSchema = z.object({ | ||
| 61 | 63 | export type LegalityElement = z.infer<typeof LegalityElementSchema>; |
| 62 | 64 | |
| 63 | 65 | export const RulingSchema = z.object({ |
| 64 | - "date": z.string(), | |
| 66 | + "date": dateSchema, | |
| 65 | 67 | "text": z.string(), |
| 66 | 68 | }); |
| 67 | 69 | export type Ruling = z.infer<typeof RulingSchema>; |
| @@ -108,7 +110,7 @@ export const TopLevelSchema = z.object({ | ||
| 108 | 110 | "mkm_id": z.number().int(), |
| 109 | 111 | "mkm_name": z.string(), |
| 110 | 112 | "name": z.string(), |
| 111 | - "releaseDate": z.string(), | |
| 113 | + "releaseDate": dateSchema, | |
| 112 | 114 | "type": z.string(), |
| 113 | 115 | }); |
| 114 | 116 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +3 −1test/inputs/json/misc/6dec6.json
Mtypescript-zoddefault / TopLevel.ts+3 −1
| @@ -1,5 +1,7 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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 | + | |
| 3 | 5 | |
| 4 | 6 | export const TextSchema = z.enum([ |
| 5 | 7 | "Showers", |
| @@ -113,7 +115,7 @@ export type Results = z.infer<typeof ResultsSchema>; | ||
| 113 | 115 | |
| 114 | 116 | export const QuerySchema = z.object({ |
| 115 | 117 | "count": z.number().int(), |
| 116 | - "created": z.string().pipe(z.coerce.date()), | |
| 118 | + "created": dateTimeSchema, | |
| 117 | 119 | "lang": z.string(), |
| 118 | 120 | "results": ResultsSchema, |
| 119 | 121 | }); |
Test case
1 generated file · +2 −1test/inputs/json/misc/70c77.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,9 +1,10 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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); | |
| 3 | 4 | |
| 4 | 5 | export const TopLevelSchema = z.object({ |
| 5 | 6 | "base": z.string(), |
| 6 | - "date": z.string(), | |
| 7 | + "date": dateSchema, | |
| 7 | 8 | "rates": z.record(z.string(), z.number()), |
| 8 | 9 | }); |
| 9 | 10 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +6 −4test/inputs/json/misc/734ad.json
Mtypescript-zoddefault / TopLevel.ts+6 −4
| @@ -1,5 +1,7 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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 | + | |
| 3 | 5 | |
| 4 | 6 | export const StatusSchema = z.enum([ |
| 5 | 7 | "active", |
| @@ -31,7 +33,7 @@ export const ResultSchema = z.object({ | ||
| 31 | 33 | "be_office_town": z.string().optional(), |
| 32 | 34 | "code_of_conduct": z.string(), |
| 33 | 35 | "contact_country": z.number().int(), |
| 34 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 36 | + "created_at": dateTimeSchema, | |
| 35 | 37 | "entity": z.string(), |
| 36 | 38 | "goals": z.string(), |
| 37 | 39 | "head": z.string(), |
| @@ -46,7 +48,7 @@ export const ResultSchema = z.object({ | ||
| 46 | 48 | "id": z.string(), |
| 47 | 49 | "identification_code": z.string(), |
| 48 | 50 | "info_members": z.string(), |
| 49 | - "last_update_date": z.string().pipe(z.coerce.date()), | |
| 51 | + "last_update_date": dateTimeSchema, | |
| 50 | 52 | "legal": z.string(), |
| 51 | 53 | "legal_status": z.string(), |
| 52 | 54 | "main_category": z.number().int(), |
| @@ -62,12 +64,12 @@ export const ResultSchema = z.object({ | ||
| 62 | 64 | "networking": z.union([z.null(), z.string()]), |
| 63 | 65 | "number_of_natural_persons": z.union([z.null(), z.number().int()]), |
| 64 | 66 | "other_code_of_conduct": z.union([z.null(), z.string()]), |
| 65 | - "registration_date": z.string().pipe(z.coerce.date()), | |
| 67 | + "registration_date": dateTimeSchema, | |
| 66 | 68 | "status": StatusSchema, |
| 67 | 69 | "structure_members": z.string(), |
| 68 | 70 | "sub_category": z.number().int(), |
| 69 | 71 | "sub_category_title": z.string(), |
| 70 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 72 | + "updated_at": dateTimeSchema, | |
| 71 | 73 | "uri": z.string(), |
| 72 | 74 | "web_site_url": z.union([z.null(), z.string()]), |
| 73 | 75 | }); |
Test case
1 generated file · +2 −1test/inputs/json/misc/75912.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,9 +1,10 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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); | |
| 3 | 4 | |
| 4 | 5 | export const TopLevelSchema = z.object({ |
| 5 | 6 | "base": z.string(), |
| 6 | - "date": z.string(), | |
| 7 | + "date": dateSchema, | |
| 7 | 8 | "rates": z.record(z.string(), z.number()), |
| 8 | 9 | }); |
| 9 | 10 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +3 −1test/inputs/json/misc/77392.json
Mtypescript-zoddefault / TopLevel.ts+3 −1
| @@ -1,5 +1,7 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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 | + | |
| 3 | 5 | |
| 4 | 6 | export const OrbitClassSchema = z.enum([ |
| 5 | 7 | "Apollo", |
| @@ -24,7 +26,7 @@ export type Pha = z.infer<typeof PhaSchema>; | ||
| 24 | 26 | |
| 25 | 27 | export const TopLevelElementSchema = z.object({ |
| 26 | 28 | "designation": z.string(), |
| 27 | - "discovery_date": z.string().pipe(z.coerce.date()), | |
| 29 | + "discovery_date": dateTimeSchema, | |
| 28 | 30 | "h_mag": z.string().optional(), |
| 29 | 31 | "i_deg": z.string(), |
| 30 | 32 | "moid_au": z.string(), |
Test case
1 generated file · +2 −1test/inputs/json/misc/7dfa6.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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); | |
| 3 | 4 | |
| 4 | 5 | export const TotalPopulationSchema = z.object({ |
| 5 | - "date": z.string(), | |
| 6 | + "date": dateSchema, | |
| 6 | 7 | "population": z.number().int(), |
| 7 | 8 | }); |
| 8 | 9 | export type TotalPopulation = z.infer<typeof TotalPopulationSchema>; |
Test case
1 generated file · +4 −2test/inputs/json/misc/7f568.json
Mtypescript-zoddefault / TopLevel.ts+4 −2
| @@ -1,5 +1,7 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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 | + | |
| 3 | 5 | |
| 4 | 6 | export const LanguageSchema = z.enum([ |
| 5 | 7 | "Markdown", |
| @@ -25,7 +27,7 @@ export const TopLevelElementSchema = z.object({ | ||
| 25 | 27 | "comments": z.number().int(), |
| 26 | 28 | "comments_url": z.string(), |
| 27 | 29 | "commits_url": z.string(), |
| 28 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 30 | + "created_at": dateTimeSchema, | |
| 29 | 31 | "description": z.union([z.null(), z.string()]), |
| 30 | 32 | "files": z.record(z.string(), FileSchema), |
| 31 | 33 | "forks_url": z.string(), |
| @@ -35,7 +37,7 @@ export const TopLevelElementSchema = z.object({ | ||
| 35 | 37 | "id": z.string(), |
| 36 | 38 | "public": z.boolean(), |
| 37 | 39 | "truncated": z.boolean(), |
| 38 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 40 | + "updated_at": dateTimeSchema, | |
| 39 | 41 | "url": z.string(), |
| 40 | 42 | "user": z.null(), |
| 41 | 43 | }); |
Test case
1 generated file · +3 −2test/inputs/json/misc/80aff.json
Mtypescript-zoddefault / TopLevel.ts+3 −2
| @@ -1,17 +1,18 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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()); | |
| 3 | 4 | |
| 4 | 5 | export const FacetsSchema = z.object({ |
| 5 | 6 | }); |
| 6 | 7 | export type Facets = z.infer<typeof FacetsSchema>; |
| 7 | 8 | |
| 8 | 9 | export const ResultSchema = z.object({ |
| 9 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 10 | + "created_at": dateTimeSchema, | |
| 10 | 11 | "id": z.number().int(), |
| 11 | 12 | "items": z.number().int(), |
| 12 | 13 | "name": z.string(), |
| 13 | 14 | "parent": z.union([z.null(), z.number().int()]), |
| 14 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 15 | + "updated_at": dateTimeSchema, | |
| 15 | 16 | "uri": z.string(), |
| 16 | 17 | }); |
| 17 | 18 | export type Result = z.infer<typeof ResultSchema>; |
Test case
1 generated file · +2 −1test/inputs/json/misc/88130.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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()); | |
| 3 | 4 | |
| 4 | 5 | export const AstronomySchema = z.object({ |
| 5 | 6 | "sunrise": z.string(), |
| @@ -106,7 +107,7 @@ export type Results = z.infer<typeof ResultsSchema>; | ||
| 106 | 107 | |
| 107 | 108 | export const QuerySchema = z.object({ |
| 108 | 109 | "count": z.number().int(), |
| 109 | - "created": z.string().pipe(z.coerce.date()), | |
| 110 | + "created": dateTimeSchema, | |
| 110 | 111 | "lang": z.string(), |
| 111 | 112 | "results": ResultsSchema, |
| 112 | 113 | }); |
Test case
1 generated file · +2 −1test/inputs/json/misc/8a62c.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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); | |
| 3 | 4 | |
| 4 | 5 | export const TotalPopulationSchema = z.object({ |
| 5 | - "date": z.string(), | |
| 6 | + "date": dateSchema, | |
| 6 | 7 | "population": z.number().int(), |
| 7 | 8 | }); |
| 8 | 9 | export type TotalPopulation = z.infer<typeof TotalPopulationSchema>; |
Test case
1 generated file · +2 −1test/inputs/json/misc/9617f.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,9 +1,10 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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); | |
| 3 | 4 | |
| 4 | 5 | export const TopLevelSchema = z.object({ |
| 5 | 6 | "base": z.string(), |
| 6 | - "date": z.string(), | |
| 7 | + "date": dateSchema, | |
| 7 | 8 | "rates": z.record(z.string(), z.number()), |
| 8 | 9 | }); |
| 9 | 10 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +2 −1test/inputs/json/misc/9929c.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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()); | |
| 3 | 4 | |
| 4 | 5 | export const AstronomySchema = z.object({ |
| 5 | 6 | "sunrise": z.string(), |
| @@ -106,7 +107,7 @@ export type Results = z.infer<typeof ResultsSchema>; | ||
| 106 | 107 | |
| 107 | 108 | export const QuerySchema = z.object({ |
| 108 | 109 | "count": z.number().int(), |
| 109 | - "created": z.string().pipe(z.coerce.date()), | |
| 110 | + "created": dateTimeSchema, | |
| 110 | 111 | "lang": z.string(), |
| 111 | 112 | "results": ResultsSchema, |
| 112 | 113 | }); |
Test case
1 generated file · +4 −2test/inputs/json/misc/9ac3b.json
Mtypescript-zoddefault / TopLevel.ts+4 −2
| @@ -1,5 +1,7 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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 | + | |
| 3 | 5 | |
| 4 | 6 | export const StatusSchema = z.enum([ |
| 5 | 7 | "inactive", |
| @@ -19,7 +21,7 @@ export const FacetsSchema = z.object({ | ||
| 19 | 21 | export type Facets = z.infer<typeof FacetsSchema>; |
| 20 | 22 | |
| 21 | 23 | export const ResultSchema = z.object({ |
| 22 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 24 | + "created_at": dateTimeSchema, | |
| 23 | 25 | "entity": z.string(), |
| 24 | 26 | "first_name": z.string(), |
| 25 | 27 | "id": z.string(), |
| @@ -28,7 +30,7 @@ export const ResultSchema = z.object({ | ||
| 28 | 30 | "position": z.union([z.null(), z.string()]), |
| 29 | 31 | "status": StatusSchema, |
| 30 | 32 | "title": z.union([z.null(), TitleSchema]), |
| 31 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 33 | + "updated_at": dateTimeSchema, | |
| 32 | 34 | "uri": z.string(), |
| 33 | 35 | }); |
| 34 | 36 | export type Result = z.infer<typeof ResultSchema>; |
Test case
1 generated file · +6 −4test/inputs/json/misc/a0496.json
Mtypescript-zoddefault / TopLevel.ts+6 −4
| @@ -1,5 +1,7 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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()); | |
| 3 | 5 | |
| 4 | 6 | export const ErrorsSchema = z.object({ |
| 5 | 7 | }); |
| @@ -8,20 +10,20 @@ export type Errors = z.infer<typeof ErrorsSchema>; | ||
| 8 | 10 | export const TopLevelSchema = z.object({ |
| 9 | 11 | "code": z.string(), |
| 10 | 12 | "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()]))), | |
| 12 | 14 | "description": z.string(), |
| 13 | 15 | "display_url": z.string(), |
| 14 | 16 | "errors": ErrorsSchema, |
| 15 | 17 | "frequency": z.string(), |
| 16 | - "from_date": z.string(), | |
| 18 | + "from_date": dateSchema, | |
| 17 | 19 | "id": z.number().int(), |
| 18 | 20 | "name": z.string(), |
| 19 | 21 | "premium": z.boolean(), |
| 20 | 22 | "source_code": z.string(), |
| 21 | 23 | "source_name": z.string(), |
| 22 | - "to_date": z.string(), | |
| 24 | + "to_date": dateSchema, | |
| 23 | 25 | "type": z.string(), |
| 24 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 26 | + "updated_at": dateTimeSchema, | |
| 25 | 27 | "urlize_name": z.string(), |
| 26 | 28 | }); |
| 27 | 29 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +2 −1test/inputs/json/misc/a1eca.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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()); | |
| 3 | 4 | |
| 4 | 5 | export const AstronomySchema = z.object({ |
| 5 | 6 | "sunrise": z.string(), |
| @@ -106,7 +107,7 @@ export type Results = z.infer<typeof ResultsSchema>; | ||
| 106 | 107 | |
| 107 | 108 | export const QuerySchema = z.object({ |
| 108 | 109 | "count": z.number().int(), |
| 109 | - "created": z.string().pipe(z.coerce.date()), | |
| 110 | + "created": dateTimeSchema, | |
| 110 | 111 | "lang": z.string(), |
| 111 | 112 | "results": ResultsSchema, |
| 112 | 113 | }); |
Test case
1 generated file · +2 −1test/inputs/json/misc/a9691.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,9 +1,10 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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); | |
| 3 | 4 | |
| 4 | 5 | export const TopLevelSchema = z.object({ |
| 5 | 6 | "base": z.string(), |
| 6 | - "date": z.string(), | |
| 7 | + "date": dateSchema, | |
| 7 | 8 | "rates": z.record(z.string(), z.number()), |
| 8 | 9 | }); |
| 9 | 10 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +2 −1test/inputs/json/misc/abb4b.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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); | |
| 3 | 4 | |
| 4 | 5 | export const TotalPopulationSchema = z.object({ |
| 5 | - "date": z.string(), | |
| 6 | + "date": dateSchema, | |
| 6 | 7 | "population": z.number().int(), |
| 7 | 8 | }); |
| 8 | 9 | export type TotalPopulation = z.infer<typeof TotalPopulationSchema>; |
Test case
1 generated file · +2 −1test/inputs/json/misc/ac944.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,9 +1,10 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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); | |
| 3 | 4 | |
| 4 | 5 | export const TopLevelSchema = z.object({ |
| 5 | 6 | "base": z.string(), |
| 6 | - "date": z.string(), | |
| 7 | + "date": dateSchema, | |
| 7 | 8 | "rates": z.record(z.string(), z.number()), |
| 8 | 9 | }); |
| 9 | 10 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +3 −1test/inputs/json/misc/b4865.json
Mtypescript-zoddefault / TopLevel.ts+3 −1
| @@ -1,5 +1,7 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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 | + | |
| 3 | 5 | |
| 4 | 6 | export const FallSchema = z.enum([ |
| 5 | 7 | "Fell", |
| @@ -37,7 +39,7 @@ export const TopLevelElementSchema = z.object({ | ||
| 37 | 39 | "recclass": z.string(), |
| 38 | 40 | "reclat": z.string().optional(), |
| 39 | 41 | "reclong": z.string().optional(), |
| 40 | - "year": z.string().pipe(z.coerce.date()).optional(), | |
| 42 | + "year": dateTimeSchema.optional(), | |
| 41 | 43 | }); |
| 42 | 44 | export type TopLevelElement = z.infer<typeof TopLevelElementSchema>; |
Test case
1 generated file · +2 −1test/inputs/json/misc/b6f2c.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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); | |
| 3 | 4 | |
| 4 | 5 | export const TotalPopulationSchema = z.object({ |
| 5 | - "date": z.string(), | |
| 6 | + "date": dateSchema, | |
| 6 | 7 | "population": z.number().int(), |
| 7 | 8 | }); |
| 8 | 9 | export type TotalPopulation = z.infer<typeof TotalPopulationSchema>; |
Test case
1 generated file · +2 −1test/inputs/json/misc/bb1ec.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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); | |
| 3 | 4 | |
| 4 | 5 | export const TotalPopulationSchema = z.object({ |
| 5 | - "date": z.string(), | |
| 6 | + "date": dateSchema, | |
| 6 | 7 | "population": z.number().int(), |
| 7 | 8 | }); |
| 8 | 9 | export type TotalPopulation = z.infer<typeof TotalPopulationSchema>; |
Test case
1 generated file · +2 −1test/inputs/json/misc/cd463.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,9 +1,10 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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); | |
| 3 | 4 | |
| 4 | 5 | export const TopLevelSchema = z.object({ |
| 5 | 6 | "base": z.string(), |
| 6 | - "date": z.string(), | |
| 7 | + "date": dateSchema, | |
| 7 | 8 | "rates": z.record(z.string(), z.number()), |
| 8 | 9 | }); |
| 9 | 10 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +2 −1test/inputs/json/misc/cf0d8.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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()); | |
| 3 | 4 | |
| 4 | 5 | export const AstronomySchema = z.object({ |
| 5 | 6 | "sunrise": z.string(), |
| @@ -106,7 +107,7 @@ export type Results = z.infer<typeof ResultsSchema>; | ||
| 106 | 107 | |
| 107 | 108 | export const QuerySchema = z.object({ |
| 108 | 109 | "count": z.number().int(), |
| 109 | - "created": z.string().pipe(z.coerce.date()), | |
| 110 | + "created": dateTimeSchema, | |
| 110 | 111 | "lang": z.string(), |
| 111 | 112 | "results": ResultsSchema, |
| 112 | 113 | }); |
Test case
1 generated file · +2 −1test/inputs/json/misc/cfbce.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,9 +1,10 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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); | |
| 3 | 4 | |
| 4 | 5 | export const TopLevelSchema = z.object({ |
| 5 | 6 | "base": z.string(), |
| 6 | - "date": z.string(), | |
| 7 | + "date": dateSchema, | |
| 7 | 8 | "rates": z.record(z.string(), z.number()), |
| 8 | 9 | }); |
| 9 | 10 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +2 −1test/inputs/json/misc/d0908.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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); | |
| 3 | 4 | |
| 4 | 5 | export const TotalPopulationSchema = z.object({ |
| 5 | - "date": z.string(), | |
| 6 | + "date": dateSchema, | |
| 6 | 7 | "population": z.number().int(), |
| 7 | 8 | }); |
| 8 | 9 | export type TotalPopulation = z.infer<typeof TotalPopulationSchema>; |
Test case
1 generated file · +3 −2test/inputs/json/misc/d23d5.json
Mtypescript-zoddefault / TopLevel.ts+3 −2
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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()); | |
| 3 | 4 | |
| 4 | 5 | export const FacetsSchema = z.object({ |
| 5 | 6 | }); |
| @@ -7,10 +8,10 @@ export type Facets = z.infer<typeof FacetsSchema>; | ||
| 7 | 8 | |
| 8 | 9 | export const ResultSchema = z.object({ |
| 9 | 10 | "acronym": z.union([z.null(), z.string()]), |
| 10 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 11 | + "created_at": dateTimeSchema, | |
| 11 | 12 | "id": z.string(), |
| 12 | 13 | "name": z.string(), |
| 13 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 14 | + "updated_at": dateTimeSchema, | |
| 14 | 15 | "uri": z.string(), |
| 15 | 16 | }); |
| 16 | 17 | export type Result = z.infer<typeof ResultSchema>; |
Test case
1 generated file · +3 −1test/inputs/json/misc/dbfb3.json
Mtypescript-zoddefault / TopLevel.ts+3 −1
| @@ -1,5 +1,7 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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 | + | |
| 3 | 5 | |
| 4 | 6 | export const TextSchema = z.enum([ |
| 5 | 7 | "Mostly Sunny", |
| @@ -112,7 +114,7 @@ export type Results = z.infer<typeof ResultsSchema>; | ||
| 112 | 114 | |
| 113 | 115 | export const QuerySchema = z.object({ |
| 114 | 116 | "count": z.number().int(), |
| 115 | - "created": z.string().pipe(z.coerce.date()), | |
| 117 | + "created": dateTimeSchema, | |
| 116 | 118 | "lang": z.string(), |
| 117 | 119 | "results": ResultsSchema, |
| 118 | 120 | }); |
Test case
1 generated file · +4 −2test/inputs/json/misc/dc44f.json
Mtypescript-zoddefault / TopLevel.ts+4 −2
| @@ -1,5 +1,7 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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 | + | |
| 3 | 5 | |
| 4 | 6 | export const BoosterSchema = z.enum([ |
| 5 | 7 | "rare", |
| @@ -110,7 +112,7 @@ export const LegalityElementSchema = z.object({ | ||
| 110 | 112 | export type LegalityElement = z.infer<typeof LegalityElementSchema>; |
| 111 | 113 | |
| 112 | 114 | export const RulingSchema = z.object({ |
| 113 | - "date": z.string(), | |
| 115 | + "date": dateSchema, | |
| 114 | 116 | "text": z.string(), |
| 115 | 117 | }); |
| 116 | 118 | export type Ruling = z.infer<typeof RulingSchema>; |
| @@ -156,7 +158,7 @@ export const TopLevelSchema = z.object({ | ||
| 156 | 158 | "mkm_id": z.number().int(), |
| 157 | 159 | "mkm_name": z.string(), |
| 158 | 160 | "name": z.string(), |
| 159 | - "releaseDate": z.string(), | |
| 161 | + "releaseDate": dateSchema, | |
| 160 | 162 | "type": z.string(), |
| 161 | 163 | }); |
| 162 | 164 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +4 −2test/inputs/json/misc/dd1ce.json
Mtypescript-zoddefault / TopLevel.ts+4 −2
| @@ -1,5 +1,7 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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 | + | |
| 3 | 5 | |
| 4 | 6 | export const BoosterSchema = z.enum([ |
| 5 | 7 | "rare", |
| @@ -110,7 +112,7 @@ export const LegalityElementSchema = z.object({ | ||
| 110 | 112 | export type LegalityElement = z.infer<typeof LegalityElementSchema>; |
| 111 | 113 | |
| 112 | 114 | export const RulingSchema = z.object({ |
| 113 | - "date": z.string(), | |
| 115 | + "date": dateSchema, | |
| 114 | 116 | "text": z.string(), |
| 115 | 117 | }); |
| 116 | 118 | export type Ruling = z.infer<typeof RulingSchema>; |
| @@ -156,7 +158,7 @@ export const TopLevelSchema = z.object({ | ||
| 156 | 158 | "mkm_id": z.number().int(), |
| 157 | 159 | "mkm_name": z.string(), |
| 158 | 160 | "name": z.string(), |
| 159 | - "releaseDate": z.string(), | |
| 161 | + "releaseDate": dateSchema, | |
| 160 | 162 | "type": z.string(), |
| 161 | 163 | }); |
| 162 | 164 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +2 −1test/inputs/json/misc/df957.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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()); | |
| 3 | 4 | |
| 4 | 5 | export const AstronomySchema = z.object({ |
| 5 | 6 | "sunrise": z.string(), |
| @@ -106,7 +107,7 @@ export type Results = z.infer<typeof ResultsSchema>; | ||
| 106 | 107 | |
| 107 | 108 | export const QuerySchema = z.object({ |
| 108 | 109 | "count": z.number().int(), |
| 109 | - "created": z.string().pipe(z.coerce.date()), | |
| 110 | + "created": dateTimeSchema, | |
| 110 | 111 | "lang": z.string(), |
| 111 | 112 | "results": ResultsSchema, |
| 112 | 113 | }); |
Test case
1 generated file · +3 −1test/inputs/json/misc/e2915.json
Mtypescript-zoddefault / TopLevel.ts+3 −1
| @@ -1,5 +1,7 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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 | + | |
| 3 | 5 | |
| 4 | 6 | export const TextSchema = z.enum([ |
| 5 | 7 | "Sunny", |
| @@ -111,7 +113,7 @@ export type Results = z.infer<typeof ResultsSchema>; | ||
| 111 | 113 | |
| 112 | 114 | export const QuerySchema = z.object({ |
| 113 | 115 | "count": z.number().int(), |
| 114 | - "created": z.string().pipe(z.coerce.date()), | |
| 116 | + "created": dateTimeSchema, | |
| 115 | 117 | "lang": z.string(), |
| 116 | 118 | "results": ResultsSchema, |
| 117 | 119 | }); |
Test case
1 generated file · +4 −2test/inputs/json/priority/bug2590.json
Mtypescript-zoddefault / TopLevel.ts+4 −2
| @@ -1,9 +1,11 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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()); | |
| 3 | 5 | |
| 4 | 6 | 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]), | |
| 7 | 9 | "name": z.string(), |
| 8 | 10 | }); |
| 9 | 11 | export type Invoice = z.infer<typeof InvoiceSchema>; |
Test case
1 generated file · +4 −2test/inputs/json/priority/bug2663.json
Mtypescript-zoddefault / TopLevel.ts+4 −2
| @@ -1,9 +1,11 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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()); | |
| 3 | 5 | |
| 4 | 6 | export const TopLevelSchema = z.object({ |
| 5 | - "birthday": z.string(), | |
| 6 | - "lastSeen": z.string().pipe(z.coerce.date()), | |
| 7 | + "birthday": dateSchema, | |
| 8 | + "lastSeen": dateTimeSchema, | |
| 7 | 9 | "name": z.string(), |
| 8 | 10 | }); |
| 9 | 11 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +3 −1test/inputs/json/priority/keywords.json
Mtypescript-zoddefault / TopLevel.ts+3 −1
| @@ -1,5 +1,7 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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 | + | |
| 3 | 5 | |
| 4 | 6 | export const EnumValueSchema = z.enum([ |
| 5 | 7 | "ready", |
| @@ -358,7 +360,7 @@ export const DateParseHandlingSchema = z.object({ | ||
| 358 | 360 | export type DateParseHandling = z.infer<typeof DateParseHandlingSchema>; |
| 359 | 361 | |
| 360 | 362 | export const DateTimeSchema = z.object({ |
| 361 | - "DateTime": z.string().pipe(z.coerce.date()), | |
| 363 | + "DateTime": dateTimeSchema, | |
| 362 | 364 | }); |
| 363 | 365 | export type DateTime = z.infer<typeof DateTimeSchema>; |
Test case
1 generated file · +18 −16test/inputs/json/samples/github-events.json
Mtypescript-zoddefault / TopLevel.ts+18 −16
| @@ -1,5 +1,7 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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 | + | |
| 3 | 5 | |
| 4 | 6 | export const TypeSchema = z.enum([ |
| 5 | 7 | "User", |
| @@ -56,10 +58,10 @@ export type Label = z.infer<typeof LabelSchema>; | ||
| 56 | 58 | export const MilestoneSchema = z.object({ |
| 57 | 59 | "closed_at": z.null(), |
| 58 | 60 | "closed_issues": z.number().int(), |
| 59 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 61 | + "created_at": dateTimeSchema, | |
| 60 | 62 | "creator": UserSchema, |
| 61 | 63 | "description": z.string(), |
| 62 | - "due_on": z.union([z.null(), z.string().pipe(z.coerce.date())]), | |
| 64 | + "due_on": z.union([z.null(), dateTimeSchema]), | |
| 63 | 65 | "html_url": z.string(), |
| 64 | 66 | "id": z.number().int(), |
| 65 | 67 | "labels_url": z.string(), |
| @@ -67,7 +69,7 @@ export const MilestoneSchema = z.object({ | ||
| 67 | 69 | "open_issues": z.number().int(), |
| 68 | 70 | "state": z.string(), |
| 69 | 71 | "title": z.string(), |
| 70 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 72 | + "updated_at": dateTimeSchema, | |
| 71 | 73 | "url": z.string(), |
| 72 | 74 | }); |
| 73 | 75 | export type Milestone = z.infer<typeof MilestoneSchema>; |
| @@ -92,7 +94,7 @@ export const BaseRepoSchema = z.object({ | ||
| 92 | 94 | "compare_url": z.string(), |
| 93 | 95 | "contents_url": z.string(), |
| 94 | 96 | "contributors_url": z.string(), |
| 95 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 97 | + "created_at": dateTimeSchema, | |
| 96 | 98 | "default_branch": z.string(), |
| 97 | 99 | "deployments_url": z.string(), |
| 98 | 100 | "description": z.string(), |
| @@ -133,7 +135,7 @@ export const BaseRepoSchema = z.object({ | ||
| 133 | 135 | "owner": UserSchema, |
| 134 | 136 | "private": z.boolean(), |
| 135 | 137 | "pulls_url": z.string(), |
| 136 | - "pushed_at": z.string().pipe(z.coerce.date()), | |
| 138 | + "pushed_at": dateTimeSchema, | |
| 137 | 139 | "releases_url": z.string(), |
| 138 | 140 | "size": z.number().int(), |
| 139 | 141 | "ssh_url": z.string(), |
| @@ -146,7 +148,7 @@ export const BaseRepoSchema = z.object({ | ||
| 146 | 148 | "tags_url": z.string(), |
| 147 | 149 | "teams_url": z.string(), |
| 148 | 150 | "trees_url": z.string(), |
| 149 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 151 | + "updated_at": dateTimeSchema, | |
| 150 | 152 | "url": z.string(), |
| 151 | 153 | "watchers": z.number().int(), |
| 152 | 154 | "watchers_count": z.number().int(), |
| @@ -167,11 +169,11 @@ export type TopLevelRepo = z.infer<typeof TopLevelRepoSchema>; | ||
| 167 | 169 | |
| 168 | 170 | export const CommentSchema = z.object({ |
| 169 | 171 | "body": z.string(), |
| 170 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 172 | + "created_at": dateTimeSchema, | |
| 171 | 173 | "html_url": z.string(), |
| 172 | 174 | "id": z.number().int(), |
| 173 | 175 | "issue_url": z.string(), |
| 174 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 176 | + "updated_at": dateTimeSchema, | |
| 175 | 177 | "url": z.string(), |
| 176 | 178 | "user": UserSchema, |
| 177 | 179 | }); |
| @@ -190,10 +192,10 @@ export const IssueSchema = z.object({ | ||
| 190 | 192 | "assignee": z.null(), |
| 191 | 193 | "assignees": z.array(z.any()), |
| 192 | 194 | "body": z.string(), |
| 193 | - "closed_at": z.union([z.null(), z.string().pipe(z.coerce.date())]), | |
| 195 | + "closed_at": z.union([z.null(), dateTimeSchema]), | |
| 194 | 196 | "comments": z.number().int(), |
| 195 | 197 | "comments_url": z.string(), |
| 196 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 198 | + "created_at": dateTimeSchema, | |
| 197 | 199 | "events_url": z.string(), |
| 198 | 200 | "html_url": z.string(), |
| 199 | 201 | "id": z.number().int(), |
| @@ -206,7 +208,7 @@ export const IssueSchema = z.object({ | ||
| 206 | 208 | "repository_url": z.string(), |
| 207 | 209 | "state": z.string(), |
| 208 | 210 | "title": z.string(), |
| 209 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 211 | + "updated_at": dateTimeSchema, | |
| 210 | 212 | "url": z.string(), |
| 211 | 213 | "user": UserSchema, |
| 212 | 214 | }); |
| @@ -240,12 +242,12 @@ export const PayloadPullRequestSchema = z.object({ | ||
| 240 | 242 | "base": BaseSchema, |
| 241 | 243 | "body": z.string(), |
| 242 | 244 | "changed_files": z.number().int(), |
| 243 | - "closed_at": z.string().pipe(z.coerce.date()), | |
| 245 | + "closed_at": dateTimeSchema, | |
| 244 | 246 | "comments": z.number().int(), |
| 245 | 247 | "comments_url": z.string(), |
| 246 | 248 | "commits": z.number().int(), |
| 247 | 249 | "commits_url": z.string(), |
| 248 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 250 | + "created_at": dateTimeSchema, | |
| 249 | 251 | "deletions": z.number().int(), |
| 250 | 252 | "diff_url": z.string(), |
| 251 | 253 | "head": BaseSchema, |
| @@ -259,7 +261,7 @@ export const PayloadPullRequestSchema = z.object({ | ||
| 259 | 261 | "mergeable": z.null(), |
| 260 | 262 | "mergeable_state": z.string(), |
| 261 | 263 | "merged": z.boolean(), |
| 262 | - "merged_at": z.string().pipe(z.coerce.date()), | |
| 264 | + "merged_at": dateTimeSchema, | |
| 263 | 265 | "merged_by": UserSchema, |
| 264 | 266 | "milestone": z.null(), |
| 265 | 267 | "number": z.number().int(), |
| @@ -272,7 +274,7 @@ export const PayloadPullRequestSchema = z.object({ | ||
| 272 | 274 | "state": z.string(), |
| 273 | 275 | "statuses_url": z.string(), |
| 274 | 276 | "title": z.string(), |
| 275 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 277 | + "updated_at": dateTimeSchema, | |
| 276 | 278 | "url": z.string(), |
| 277 | 279 | "user": UserSchema, |
| 278 | 280 | }); |
| @@ -300,7 +302,7 @@ export type Payload = z.infer<typeof PayloadSchema>; | ||
| 300 | 302 | |
| 301 | 303 | export const TopLevelElementSchema = z.object({ |
| 302 | 304 | "actor": ActorSchema, |
| 303 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 305 | + "created_at": dateTimeSchema, | |
| 304 | 306 | "id": z.string(), |
| 305 | 307 | "org": ActorSchema.optional(), |
| 306 | 308 | "payload": PayloadSchema, |
Test case
1 generated file · +2 −1test/inputs/json/samples/null-safe.json
Mtypescript-zoddefault / TopLevel.ts+2 −1
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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()); | |
| 3 | 4 | |
| 4 | 5 | export const AddressSchema = z.object({ |
| 5 | 6 | "city": z.string(), |
| @@ -10,7 +11,7 @@ export type Address = z.infer<typeof AddressSchema>; | ||
| 10 | 11 | |
| 11 | 12 | export const ItemSchema = z.object({ |
| 12 | 13 | "address": AddressSchema.optional(), |
| 13 | - "created_at": z.string().pipe(z.coerce.date()).optional(), | |
| 14 | + "created_at": dateTimeSchema.optional(), | |
| 14 | 15 | "name": z.string(), |
| 15 | 16 | "sex": z.union([z.null(), z.number().int()]), |
| 16 | 17 | }); |
Test case
1 generated file · +5 −3test/inputs/json/samples/us-senators.json
Mtypescript-zoddefault / TopLevel.ts+5 −3
| @@ -1,5 +1,7 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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 | + | |
| 3 | 5 | |
| 4 | 6 | export const PartySchema = z.enum([ |
| 5 | 7 | "Democrat", |
| @@ -96,7 +98,7 @@ export type Extra = z.infer<typeof ExtraSchema>; | ||
| 96 | 98 | |
| 97 | 99 | export const PersonSchema = z.object({ |
| 98 | 100 | "bioguideid": z.string(), |
| 99 | - "birthday": z.string(), | |
| 101 | + "birthday": dateSchema, | |
| 100 | 102 | "cspanid": z.number().int(), |
| 101 | 103 | "firstname": z.string(), |
| 102 | 104 | "gender": GenderSchema, |
| @@ -121,7 +123,7 @@ export const ObjectElementSchema = z.object({ | ||
| 121 | 123 | "current": z.boolean(), |
| 122 | 124 | "description": z.string(), |
| 123 | 125 | "district": z.null(), |
| 124 | - "enddate": z.string(), | |
| 126 | + "enddate": dateSchema, | |
| 125 | 127 | "extra": ExtraSchema, |
| 126 | 128 | "leadership_title": z.union([z.null(), z.string()]), |
| 127 | 129 | "party": PartySchema, |
| @@ -133,7 +135,7 @@ export const ObjectElementSchema = z.object({ | ||
| 133 | 135 | "senator_class_label": SenatorClassLabelSchema, |
| 134 | 136 | "senator_rank": SenatorRankSchema, |
| 135 | 137 | "senator_rank_label": SenatorRankLabelSchema, |
| 136 | - "startdate": z.string(), | |
| 138 | + "startdate": dateSchema, | |
| 137 | 139 | "state": z.string(), |
| 138 | 140 | "title": TitleSchema, |
| 139 | 141 | "title_long": RoleTypeLabelSchema, |
Test case
1 generated file · +3 −1test/inputs/schema/date-time-or-string.schema
Mschema-typescript-zoddefault / TopLevel.ts+3 −1
| @@ -1,5 +1,7 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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 | + | |
| 3 | 5 | |
| 4 | 6 | export const BarEnumSchema = z.enum([ |
| 5 | 7 | "quux", |
| @@ -7,7 +9,7 @@ export const BarEnumSchema = z.enum([ | ||
| 7 | 9 | export type BarEnum = z.infer<typeof BarEnumSchema>; |
| 8 | 10 | |
| 9 | 11 | export const TopLevelSchema = z.object({ |
| 10 | - "bar": z.union([BarEnumSchema, z.string().pipe(z.coerce.date())]), | |
| 12 | + "bar": z.union([BarEnumSchema, dateTimeSchema]), | |
| 11 | 13 | "foo": z.string(), |
| 12 | 14 | }); |
| 13 | 15 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +9 −5test/inputs/schema/date-time.schema
Mschema-typescript-zoddefault / TopLevel.ts+9 −5
| @@ -1,5 +1,9 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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 | + | |
| 3 | 7 | |
| 4 | 8 | export const ComplexUnionArrayEnumSchema = z.enum([ |
| 5 | 9 | "foo", |
| @@ -20,13 +24,13 @@ export const OffsetTimeSchema = z.object({ | ||
| 20 | 24 | export type OffsetTime = z.infer<typeof OffsetTimeSchema>; |
| 21 | 25 | |
| 22 | 26 | 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, | |
| 26 | 30 | "local-date-class": LocalDateSchema.optional(), |
| 27 | 31 | "offset-date-time-class": OffsetDateTimeSchema.optional(), |
| 28 | 32 | "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])), | |
| 31 | 35 | }); |
| 32 | 36 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +9 −6test/inputs/schema/optional-date-time.schema
Mschema-typescript-zoddefault / TopLevel.ts+9 −6
| @@ -1,12 +1,15 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 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()); | |
| 3 | 6 | |
| 4 | 7 | 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, | |
| 11 | 14 | }); |
| 12 | 15 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
No generated files match these filters.