-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
82853a7
commit 692f969
Showing
9 changed files
with
194 additions
and
943 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,21 @@ | ||
import * as z from 'zod'; | ||
import { JsonSchema7Type, zodToJsonSchema } from "zod-to-json-schema"; | ||
|
||
export class ZodSchemaBuilder<R extends Record<string, JsonSchema7Type>> { | ||
|
||
private constructor(private readonly schemas: R) {} | ||
|
||
static create(): ZodSchemaBuilder<{}> { | ||
return new ZodSchemaBuilder({}); | ||
} | ||
|
||
add<S extends string, T extends z.ZodType>(name: S, type: T): ZodSchemaBuilder<R & {[name in S]: JsonSchema7Type}> { | ||
this.schemas[name] = (zodToJsonSchema(type, {name, basePath: ['#','components', 'schemas'] }).definitions as any)[name]; | ||
this.schemas[name].title = name; | ||
return this as any; | ||
} | ||
|
||
build(): { components: { schemas: R } } { | ||
return { components: { schemas: this.schemas } }; | ||
} | ||
} |
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,18 @@ | ||
import * as z from 'zod'; | ||
|
||
export const Chicken = z.object({ | ||
identifier: z.string(), | ||
type: z.string(), | ||
name: z.string() | ||
}); | ||
export type Chicken = z.infer<typeof Chicken> | ||
|
||
export const ChickenCollection = z.array(Chicken); | ||
export type ChickenCollection = z.infer<typeof ChickenCollection> | ||
|
||
export const ChickenCreateRequest = z.object({ | ||
type: z.string(), | ||
name: z.string() | ||
}); | ||
|
||
export type ChickenCreateRequest = z.infer<typeof ChickenCreateRequest> |
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