Skip to content

Commit

Permalink
Add vitest serializer for ZodDiscriminatedUnion.
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinTail committed Dec 9, 2024
1 parent 6eb9c34 commit 30e35ef
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 113 deletions.
151 changes: 38 additions & 113 deletions tests/unit/__snapshots__/sse.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -33,134 +33,59 @@ exports[`SSE > makeResultHandler() > should create ResultHandler describing poss
"mimeTypes": [
"text/event-stream",
],
"schema": ZodDiscriminatedUnion {
"_def": {
"discriminator": "event",
"options": [
{
"_type": "ZodObject",
"shape": {
"data": {
"schema": {
"_type": "ZodDiscriminatedUnion",
"discriminator": "event",
"options": [
{
"_type": "ZodObject",
"shape": {
"data": {
"_type": "ZodString",
},
"event": {
"_type": "ZodLiteral",
"value": "test",
},
"id": {
"_type": "ZodOptional",
"value": {
"_type": "ZodString",
},
"event": {
"_type": "ZodLiteral",
"value": "test",
},
"id": {
"_type": "ZodOptional",
"value": {
"_type": "ZodString",
},
},
"retry": {
"_type": "ZodOptional",
"value": {
"_type": "ZodNumber",
},
},
},
},
{
"_type": "ZodObject",
"shape": {
"data": {
"retry": {
"_type": "ZodOptional",
"value": {
"_type": "ZodNumber",
},
"event": {
"_type": "ZodLiteral",
"value": "another",
},
"id": {
"_type": "ZodOptional",
"value": {
"_type": "ZodString",
},
},
"retry": {
"_type": "ZodOptional",
"value": {
"_type": "ZodNumber",
},
},
},
},
],
"optionsMap": Map {
"test" => {
"_type": "ZodObject",
"shape": {
"data": {
},
{
"_type": "ZodObject",
"shape": {
"data": {
"_type": "ZodNumber",
},
"event": {
"_type": "ZodLiteral",
"value": "another",
},
"id": {
"_type": "ZodOptional",
"value": {
"_type": "ZodString",
},
"event": {
"_type": "ZodLiteral",
"value": "test",
},
"id": {
"_type": "ZodOptional",
"value": {
"_type": "ZodString",
},
},
"retry": {
"_type": "ZodOptional",
"value": {
"_type": "ZodNumber",
},
},
},
},
"another" => {
"_type": "ZodObject",
"shape": {
"data": {
"retry": {
"_type": "ZodOptional",
"value": {
"_type": "ZodNumber",
},
"event": {
"_type": "ZodLiteral",
"value": "another",
},
"id": {
"_type": "ZodOptional",
"value": {
"_type": "ZodString",
},
},
"retry": {
"_type": "ZodOptional",
"value": {
"_type": "ZodNumber",
},
},
},
},
},
"typeName": "ZodDiscriminatedUnion",
},
"and": [Function],
"array": [Function],
"catch": [Function],
"default": [Function],
"describe": [Function],
"isNullable": [Function],
"isOptional": [Function],
"nullable": [Function],
"nullish": [Function],
"optional": [Function],
"or": [Function],
"parse": [Function],
"parseAsync": [Function],
"pipe": [Function],
"promise": [Function],
"readonly": [Function],
"refine": [Function],
"refinement": [Function],
"safeParse": [Function],
"safeParseAsync": [Function],
"spa": [Function],
"superRefine": [Function],
"transform": [Function],
],
},
"statusCodes": [
200,
Expand Down
4 changes: 4 additions & 0 deletions vitest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ const serializers = [
right,
})),
makeSchemaSerializer(z.ZodUnion, ({ options }) => ({ options })),
makeSchemaSerializer(
z.ZodDiscriminatedUnion,
({ options, discriminator }) => ({ discriminator, options }),
),
makeSchemaSerializer(z.ZodEffects, ({ _def: { schema: value } }) => ({
value,
})),
Expand Down

0 comments on commit 30e35ef

Please sign in to comment.