Skip to content

Commit

Permalink
feat: Add Date support (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabien0102 committed May 31, 2021
1 parent ce06ede commit 46d769a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/core/generateZodSchema.test.ts
Expand Up @@ -60,6 +60,13 @@ describe("generateZodSchema", () => {
);
});

it("should generate a date schema", () => {
const source = `export type lastIncidentInMetropolis = Date;`;
expect(generate(source)).toMatchInlineSnapshot(
`"export const lastIncidentInMetropolisSchema = z.date();"`
);
});

it("should generate a literal schema (string)", () => {
const source = `export type Kryptonite = "kryptonite";`;
expect(generate(source)).toMatchInlineSnapshot(
Expand Down
5 changes: 5 additions & 0 deletions src/core/generateZodSchema.ts
Expand Up @@ -292,6 +292,11 @@ function buildZodPrimitive({
);
}

// Deal with `Date`
if (identifierName === "Date") {
return buildZodSchema(z, "date", [], zodProperties);
}

// Deal with `Promise<>` syntax
if (identifierName === "Promise" && typeNode.typeArguments) {
return buildZodSchema(
Expand Down

0 comments on commit 46d769a

Please sign in to comment.