-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow to append or override schema via jsdoc tag (#266)
implementation taken from #125
- Loading branch information
1 parent
1346781
commit dc7eea8
Showing
4 changed files
with
100 additions
and
19 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
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 |
---|---|---|
|
@@ -964,6 +964,48 @@ describe("generateZodSchema", () => { | |
`); | ||
}); | ||
|
||
it("should append schema based on `schema` tag", () => { | ||
const source = `export interface HeroContact { | ||
/** | ||
* The email of the hero. | ||
* | ||
* @schema .trim().catch('[email protected]') | ||
*/ | ||
email: string; | ||
}`; | ||
expect(generate(source)).toMatchInlineSnapshot(` | ||
"export const heroContactSchema = z.object({ | ||
/** | ||
* The email of the hero. | ||
* | ||
* @schema .trim().catch('[email protected]') | ||
*/ | ||
email: z.string().trim().catch('[email protected]') | ||
});" | ||
`); | ||
}); | ||
|
||
it("should overrride schema based on `schema` tag", () => { | ||
const source = `export interface HeroContact { | ||
/** | ||
* The email of the hero. | ||
* | ||
* @schema coerce.int() | ||
*/ | ||
age: number; | ||
}`; | ||
expect(generate(source)).toMatchInlineSnapshot(` | ||
"export const heroContactSchema = z.object({ | ||
/** | ||
* The email of the hero. | ||
* | ||
* @schema coerce.int() | ||
*/ | ||
age: z.coerce.int() | ||
});" | ||
`); | ||
}); | ||
|
||
it("should generate custom error message for `format` tag", () => { | ||
const source = `export interface HeroContact { | ||
/** | ||
|
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