generated from stijnvanhulle/template
-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Use of
toZod
util to create schema based on a type
- Loading branch information
1 parent
97e6d07
commit 9399093
Showing
88 changed files
with
466 additions
and
411 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 @@ | ||
--- | ||
"@kubb/plugin-zod": patch | ||
--- | ||
|
||
Use of `toZod` util to create schema based on a type |
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
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 |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import type { Address } from '../models/ts/Address.ts' | ||
import type { ToZod } from '@kubb/plugin-zod/utils' | ||
import { z } from 'zod' | ||
|
||
export const addressSchema = z.object({ | ||
street: z.string().optional(), | ||
city: z.string().optional(), | ||
state: z.string().optional(), | ||
zip: z.string().optional(), | ||
}) | ||
} satisfies ToZod<Address>) | ||
|
||
export type AddressSchema = z.infer<typeof addressSchema> | ||
export type AddressSchema = Address |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import type { ApiResponse } from '../models/ts/ApiResponse.ts' | ||
import type { ToZod } from '@kubb/plugin-zod/utils' | ||
import { z } from 'zod' | ||
|
||
export const apiResponseSchema = z.object({ | ||
code: z.number().int().optional(), | ||
type: z.string().optional(), | ||
message: z.string().optional(), | ||
}) | ||
} satisfies ToZod<ApiResponse>) | ||
|
||
export type ApiResponseSchema = z.infer<typeof apiResponseSchema> | ||
export type ApiResponseSchema = ApiResponse |
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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import type { Category } from '../models/ts/Category.ts' | ||
import type { ToZod } from '@kubb/plugin-zod/utils' | ||
import { z } from 'zod' | ||
|
||
export const categorySchema = z.object({ | ||
id: z.number().int().optional(), | ||
name: z.string().optional(), | ||
}) | ||
} satisfies ToZod<Category>) | ||
|
||
export type CategorySchema = z.infer<typeof categorySchema> | ||
export type CategorySchema = Category |
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 |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import type { Customer } from '../models/ts/Customer.ts' | ||
import type { ToZod } from '@kubb/plugin-zod/utils' | ||
import { addressSchema } from './addressSchema.ts' | ||
import { z } from 'zod' | ||
|
||
export const customerSchema = z.object({ | ||
id: z.number().int().optional(), | ||
username: z.string().optional(), | ||
address: z.array(z.lazy(() => addressSchema)).optional(), | ||
}) | ||
} satisfies ToZod<Customer>) | ||
|
||
export type CustomerSchema = z.infer<typeof customerSchema> | ||
export type CustomerSchema = Customer |
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
14 changes: 8 additions & 6 deletions
14
examples/advanced/src/gen/zod/petController/deletePetSchema.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 |
---|---|---|
@@ -1,26 +1,28 @@ | ||
import type { DeletePetPathParams, DeletePetHeaderParams, DeletePet400, DeletePetMutationResponse } from '../../models/ts/petController/DeletePet.ts' | ||
import type { ToZod } from '@kubb/plugin-zod/utils' | ||
import { z } from 'zod' | ||
|
||
export const deletePetPathParamsSchema = z.object({ | ||
petId: z.number().int().describe('Pet id to delete'), | ||
}) | ||
} satisfies ToZod<DeletePetPathParams>) | ||
|
||
export type DeletePetPathParamsSchema = z.infer<typeof deletePetPathParamsSchema> | ||
export type DeletePetPathParamsSchema = DeletePetPathParams | ||
|
||
export const deletePetHeaderParamsSchema = z | ||
.object({ | ||
api_key: z.string().optional(), | ||
}) | ||
} satisfies ToZod<DeletePetHeaderParams>) | ||
.optional() | ||
|
||
export type DeletePetHeaderParamsSchema = z.infer<typeof deletePetHeaderParamsSchema> | ||
export type DeletePetHeaderParamsSchema = DeletePetHeaderParams | ||
|
||
/** | ||
* @description Invalid pet value | ||
*/ | ||
export const deletePet400Schema = z.any() | ||
|
||
export type DeletePet400Schema = z.infer<typeof deletePet400Schema> | ||
export type DeletePet400Schema = DeletePet400 | ||
|
||
export const deletePetMutationResponseSchema = z.any() | ||
|
||
export type DeletePetMutationResponseSchema = z.infer<typeof deletePetMutationResponseSchema> | ||
export type DeletePetMutationResponseSchema = DeletePetMutationResponse |
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
14 changes: 8 additions & 6 deletions
14
examples/advanced/src/gen/zod/petController/getPetByIdSchema.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 |
---|---|---|
@@ -1,33 +1,35 @@ | ||
import type { GetPetByIdPathParams, GetPetById200, GetPetById400, GetPetById404, GetPetByIdQueryResponse } from '../../models/ts/petController/GetPetById.ts' | ||
import type { ToZod } from '@kubb/plugin-zod/utils' | ||
import { petSchema } from '../petSchema.ts' | ||
import { z } from 'zod' | ||
|
||
export const getPetByIdPathParamsSchema = z.object({ | ||
petId: z.number().int().describe('ID of pet to return'), | ||
}) | ||
} satisfies ToZod<GetPetByIdPathParams>) | ||
|
||
export type GetPetByIdPathParamsSchema = z.infer<typeof getPetByIdPathParamsSchema> | ||
export type GetPetByIdPathParamsSchema = GetPetByIdPathParams | ||
|
||
/** | ||
* @description successful operation | ||
*/ | ||
export const getPetById200Schema = z.lazy(() => petSchema).and(z.object({ name: z.never() })) | ||
|
||
export type GetPetById200Schema = z.infer<typeof getPetById200Schema> | ||
export type GetPetById200Schema = GetPetById200 | ||
|
||
/** | ||
* @description Invalid ID supplied | ||
*/ | ||
export const getPetById400Schema = z.any() | ||
|
||
export type GetPetById400Schema = z.infer<typeof getPetById400Schema> | ||
export type GetPetById400Schema = GetPetById400 | ||
|
||
/** | ||
* @description Pet not found | ||
*/ | ||
export const getPetById404Schema = z.any() | ||
|
||
export type GetPetById404Schema = z.infer<typeof getPetById404Schema> | ||
export type GetPetById404Schema = GetPetById404 | ||
|
||
export const getPetByIdQueryResponseSchema = z.lazy(() => getPetById200Schema) | ||
|
||
export type GetPetByIdQueryResponseSchema = z.infer<typeof getPetByIdQueryResponseSchema> | ||
export type GetPetByIdQueryResponseSchema = GetPetByIdQueryResponse |
Oops, something went wrong.