-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #257 to infer as object when only required array set
- Loading branch information
1 parent
70fedec
commit 8c80b43
Showing
5 changed files
with
70 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"openapi-zod-client": minor | ||
--- | ||
|
||
Fix #257 by inferring as object when only required array defined |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { getZodSchema } from "../src/openApiToZod"; | ||
import { test, expect } from "vitest"; | ||
|
||
test("infer-as-object-when-only-required-set", () => { | ||
expect( | ||
getZodSchema({ | ||
schema: { | ||
required: ['name', 'email'], | ||
}, | ||
}) | ||
).toMatchInlineSnapshot('"z.object({}).and(z.object({ name: z.unknown(), email: z.unknown() })).passthrough()"'); | ||
}); |
20 changes: 20 additions & 0 deletions
20
lib/tests/required-additional-props-not-in-properties.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { getZodSchema } from "../src/openApiToZod"; | ||
import { test, expect } from "vitest"; | ||
|
||
test("required-additional-props-not-in-properties", () => { | ||
expect( | ||
getZodSchema({ | ||
schema: { | ||
properties: { | ||
name: { | ||
type: "string" | ||
}, | ||
email: { | ||
type: "string" | ||
}, | ||
}, | ||
required: ['name', 'email', 'phone'], | ||
}, | ||
}) | ||
).toMatchInlineSnapshot('"z.object({ name: z.string(), email: z.string() }).and(z.object({ phone: z.unknown() })).passthrough()"'); | ||
}); |
8c80b43
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
openapi-zod-client – ./
openapi-zod-client-git-main-astahmer.vercel.app
openapi-zod-client.vercel.app
openapi-zod-client-astahmer.vercel.app