diff --git a/.changeset/lazy-grapes-bake.md b/.changeset/lazy-grapes-bake.md new file mode 100644 index 000000000..05bd671b5 --- /dev/null +++ b/.changeset/lazy-grapes-bake.md @@ -0,0 +1,5 @@ +--- +"@kubb/plugin-zod": patch +--- + +use of `as ToZod` instead of `satisfies ToZod` diff --git a/.changeset/rotten-sloths-ring.md b/.changeset/rotten-sloths-ring.md new file mode 100644 index 000000000..428375e1d --- /dev/null +++ b/.changeset/rotten-sloths-ring.md @@ -0,0 +1,5 @@ +--- +"@kubb/plugin-client": patch +--- + +if client receives no body (no content) then it throws JSON parsing error diff --git a/docs/changelog.md b/docs/changelog.md index dca307e26..df21b77cd 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -4,6 +4,10 @@ title: Changelog # Changelog +## 3.4.5 +- [`plugin-client`](/plugins/plugin-client): if client receives no body (no content) then it throws JSON parsing error +- [`plugin-zod`](/plugins/plugin-zod): use of `as ToZod` instead of `satisfies ToZod` + ## 3.4.4 - [`plugin-client`](/plugins/plugin-client): url in text format instead of using URL diff --git a/examples/advanced/src/gen/clients/axios/petService/addPet.ts b/examples/advanced/src/gen/clients/axios/petService/addPet.ts index 28e449357..c92bd141f 100644 --- a/examples/advanced/src/gen/clients/axios/petService/addPet.ts +++ b/examples/advanced/src/gen/clients/axios/petService/addPet.ts @@ -3,7 +3,7 @@ import type { RequestConfig, ResponseErrorConfig } from '../../../../axios-clien import type { AddPetMutationRequest, AddPetMutationResponse, AddPet405 } from '../../../models/ts/petController/AddPet.ts' export function getAddPetUrl() { - return 'https://petstore3.swagger.io/api/v3/pet' + return 'https://petstore3.swagger.io/api/v3/pet' as const } /** diff --git a/examples/advanced/src/gen/clients/axios/petService/deletePet.ts b/examples/advanced/src/gen/clients/axios/petService/deletePet.ts index 781a043ce..90c68889b 100644 --- a/examples/advanced/src/gen/clients/axios/petService/deletePet.ts +++ b/examples/advanced/src/gen/clients/axios/petService/deletePet.ts @@ -3,7 +3,7 @@ import type { RequestConfig, ResponseErrorConfig } from '../../../../axios-clien import type { DeletePetMutationResponse, DeletePetPathParams, DeletePetHeaderParams, DeletePet400 } from '../../../models/ts/petController/DeletePet.ts' export function getDeletePetUrl({ petId }: { petId: DeletePetPathParams['petId'] }) { - return `https://petstore3.swagger.io/api/v3/pet/${petId}` + return `https://petstore3.swagger.io/api/v3/pet/${petId}` as const } /** diff --git a/examples/advanced/src/gen/clients/axios/petService/findPetsByTags.ts b/examples/advanced/src/gen/clients/axios/petService/findPetsByTags.ts index 6354569b6..7ecc2878e 100644 --- a/examples/advanced/src/gen/clients/axios/petService/findPetsByTags.ts +++ b/examples/advanced/src/gen/clients/axios/petService/findPetsByTags.ts @@ -8,7 +8,7 @@ import type { } from '../../../models/ts/petController/FindPetsByTags.ts' export function getFindPetsByTagsUrl() { - return 'https://petstore3.swagger.io/api/v3/pet/findByTags' + return 'https://petstore3.swagger.io/api/v3/pet/findByTags' as const } /** diff --git a/examples/advanced/src/gen/clients/axios/petService/getPetById.ts b/examples/advanced/src/gen/clients/axios/petService/getPetById.ts index 2696f4753..0dcfa10c6 100644 --- a/examples/advanced/src/gen/clients/axios/petService/getPetById.ts +++ b/examples/advanced/src/gen/clients/axios/petService/getPetById.ts @@ -3,7 +3,7 @@ import type { RequestConfig, ResponseErrorConfig } from '../../../../axios-clien import type { GetPetByIdQueryResponse, GetPetByIdPathParams, GetPetById400, GetPetById404 } from '../../../models/ts/petController/GetPetById.ts' export function getGetPetByIdUrl({ petId }: { petId: GetPetByIdPathParams['petId'] }) { - return `https://petstore3.swagger.io/api/v3/pet/${petId}` + return `https://petstore3.swagger.io/api/v3/pet/${petId}` as const } /** diff --git a/examples/advanced/src/gen/clients/axios/petService/updatePet.ts b/examples/advanced/src/gen/clients/axios/petService/updatePet.ts index 652e0da6f..0837f1be3 100644 --- a/examples/advanced/src/gen/clients/axios/petService/updatePet.ts +++ b/examples/advanced/src/gen/clients/axios/petService/updatePet.ts @@ -9,7 +9,7 @@ import type { } from '../../../models/ts/petController/UpdatePet.ts' export function getUpdatePetUrl() { - return 'https://petstore3.swagger.io/api/v3/pet' + return 'https://petstore3.swagger.io/api/v3/pet' as const } /** diff --git a/examples/advanced/src/gen/clients/axios/petService/updatePetWithForm.ts b/examples/advanced/src/gen/clients/axios/petService/updatePetWithForm.ts index 4962ac061..4134808ff 100644 --- a/examples/advanced/src/gen/clients/axios/petService/updatePetWithForm.ts +++ b/examples/advanced/src/gen/clients/axios/petService/updatePetWithForm.ts @@ -8,7 +8,7 @@ import type { } from '../../../models/ts/petController/UpdatePetWithForm.ts' export function getUpdatePetWithFormUrl({ petId }: { petId: UpdatePetWithFormPathParams['petId'] }) { - return `https://petstore3.swagger.io/api/v3/pet/${petId}` + return `https://petstore3.swagger.io/api/v3/pet/${petId}` as const } /** diff --git a/examples/advanced/src/gen/clients/axios/petService/uploadFile.ts b/examples/advanced/src/gen/clients/axios/petService/uploadFile.ts index 73db70b31..bf842ab13 100644 --- a/examples/advanced/src/gen/clients/axios/petService/uploadFile.ts +++ b/examples/advanced/src/gen/clients/axios/petService/uploadFile.ts @@ -8,7 +8,7 @@ import type { } from '../../../models/ts/petController/UploadFile.ts' export function getUploadFileUrl({ petId }: { petId: UploadFilePathParams['petId'] }) { - return `https://petstore3.swagger.io/api/v3/pet/${petId}/uploadImage` + return `https://petstore3.swagger.io/api/v3/pet/${petId}/uploadImage` as const } /** diff --git a/examples/advanced/src/gen/clients/axios/petsService/createPets.ts b/examples/advanced/src/gen/clients/axios/petsService/createPets.ts index 30bd6d008..44fbe36c6 100644 --- a/examples/advanced/src/gen/clients/axios/petsService/createPets.ts +++ b/examples/advanced/src/gen/clients/axios/petsService/createPets.ts @@ -9,7 +9,7 @@ import type { } from '../../../models/ts/petsController/CreatePets.ts' export function getCreatePetsUrl({ uuid }: { uuid: CreatePetsPathParams['uuid'] }) { - return `https://petstore3.swagger.io/api/v3/pets/${uuid}` + return `https://petstore3.swagger.io/api/v3/pets/${uuid}` as const } /** diff --git a/examples/advanced/src/gen/clients/axios/userService/createUser.ts b/examples/advanced/src/gen/clients/axios/userService/createUser.ts index 06eac0868..63c0d9c7b 100644 --- a/examples/advanced/src/gen/clients/axios/userService/createUser.ts +++ b/examples/advanced/src/gen/clients/axios/userService/createUser.ts @@ -3,7 +3,7 @@ import type { RequestConfig, ResponseErrorConfig } from '../../../../axios-clien import type { CreateUserMutationRequest, CreateUserMutationResponse } from '../../../models/ts/userController/CreateUser.ts' export function getCreateUserUrl() { - return 'https://petstore3.swagger.io/api/v3/user' + return 'https://petstore3.swagger.io/api/v3/user' as const } /** diff --git a/examples/advanced/src/gen/clients/axios/userService/createUsersWithListInput.ts b/examples/advanced/src/gen/clients/axios/userService/createUsersWithListInput.ts index caf96e1f9..eaf830af1 100644 --- a/examples/advanced/src/gen/clients/axios/userService/createUsersWithListInput.ts +++ b/examples/advanced/src/gen/clients/axios/userService/createUsersWithListInput.ts @@ -6,7 +6,7 @@ import type { } from '../../../models/ts/userController/CreateUsersWithListInput.ts' export function getCreateUsersWithListInputUrl() { - return 'https://petstore3.swagger.io/api/v3/user/createWithList' + return 'https://petstore3.swagger.io/api/v3/user/createWithList' as const } /** diff --git a/examples/advanced/src/gen/clients/axios/userService/deleteUser.ts b/examples/advanced/src/gen/clients/axios/userService/deleteUser.ts index 913a314a1..1cbcfda79 100644 --- a/examples/advanced/src/gen/clients/axios/userService/deleteUser.ts +++ b/examples/advanced/src/gen/clients/axios/userService/deleteUser.ts @@ -3,7 +3,7 @@ import type { RequestConfig, ResponseErrorConfig } from '../../../../axios-clien import type { DeleteUserMutationResponse, DeleteUserPathParams, DeleteUser400, DeleteUser404 } from '../../../models/ts/userController/DeleteUser.ts' export function getDeleteUserUrl({ username }: { username: DeleteUserPathParams['username'] }) { - return `https://petstore3.swagger.io/api/v3/user/${username}` + return `https://petstore3.swagger.io/api/v3/user/${username}` as const } /** diff --git a/examples/advanced/src/gen/clients/axios/userService/getUserByName.ts b/examples/advanced/src/gen/clients/axios/userService/getUserByName.ts index 97c6964d9..70a66012f 100644 --- a/examples/advanced/src/gen/clients/axios/userService/getUserByName.ts +++ b/examples/advanced/src/gen/clients/axios/userService/getUserByName.ts @@ -8,7 +8,7 @@ import type { } from '../../../models/ts/userController/GetUserByName.ts' export function getGetUserByNameUrl({ username }: { username: GetUserByNamePathParams['username'] }) { - return `https://petstore3.swagger.io/api/v3/user/${username}` + return `https://petstore3.swagger.io/api/v3/user/${username}` as const } /** diff --git a/examples/advanced/src/gen/clients/axios/userService/loginUser.ts b/examples/advanced/src/gen/clients/axios/userService/loginUser.ts index f45c6617b..1922c0115 100644 --- a/examples/advanced/src/gen/clients/axios/userService/loginUser.ts +++ b/examples/advanced/src/gen/clients/axios/userService/loginUser.ts @@ -3,7 +3,7 @@ import type { RequestConfig, ResponseErrorConfig } from '../../../../axios-clien import type { LoginUserQueryResponse, LoginUserQueryParams, LoginUser400 } from '../../../models/ts/userController/LoginUser.ts' export function getLoginUserUrl() { - return 'https://petstore3.swagger.io/api/v3/user/login' + return 'https://petstore3.swagger.io/api/v3/user/login' as const } /** diff --git a/examples/advanced/src/gen/clients/axios/userService/logoutUser.ts b/examples/advanced/src/gen/clients/axios/userService/logoutUser.ts index 5d553049c..34396ddd6 100644 --- a/examples/advanced/src/gen/clients/axios/userService/logoutUser.ts +++ b/examples/advanced/src/gen/clients/axios/userService/logoutUser.ts @@ -3,7 +3,7 @@ import type { RequestConfig, ResponseErrorConfig } from '../../../../axios-clien import type { LogoutUserQueryResponse } from '../../../models/ts/userController/LogoutUser.ts' export function getLogoutUserUrl() { - return 'https://petstore3.swagger.io/api/v3/user/logout' + return 'https://petstore3.swagger.io/api/v3/user/logout' as const } /** diff --git a/examples/advanced/src/gen/clients/axios/userService/updateUser.ts b/examples/advanced/src/gen/clients/axios/userService/updateUser.ts index 778942328..b6c18db1b 100644 --- a/examples/advanced/src/gen/clients/axios/userService/updateUser.ts +++ b/examples/advanced/src/gen/clients/axios/userService/updateUser.ts @@ -3,7 +3,7 @@ import type { RequestConfig, ResponseErrorConfig } from '../../../../axios-clien import type { UpdateUserMutationRequest, UpdateUserMutationResponse, UpdateUserPathParams } from '../../../models/ts/userController/UpdateUser.ts' export function getUpdateUserUrl({ username }: { username: UpdateUserPathParams['username'] }) { - return `https://petstore3.swagger.io/api/v3/user/${username}` + return `https://petstore3.swagger.io/api/v3/user/${username}` as const } /** diff --git a/examples/advanced/src/gen/zod/addPetRequestSchema.ts b/examples/advanced/src/gen/zod/addPetRequestSchema.ts index 7aa97a69a..ba2c4aecc 100644 --- a/examples/advanced/src/gen/zod/addPetRequestSchema.ts +++ b/examples/advanced/src/gen/zod/addPetRequestSchema.ts @@ -11,6 +11,6 @@ export const addPetRequestSchema = z.object({ photoUrls: z.array(z.string()), tags: z.array(z.lazy(() => tagTagSchema)).optional(), status: z.enum(['available', 'pending', 'sold']).describe('pet status in the store').optional(), -} satisfies ToZod) +}) as unknown as ToZod export type AddPetRequestSchema = AddPetRequest diff --git a/examples/advanced/src/gen/zod/addressSchema.ts b/examples/advanced/src/gen/zod/addressSchema.ts index 979b20246..10aa4c99e 100644 --- a/examples/advanced/src/gen/zod/addressSchema.ts +++ b/examples/advanced/src/gen/zod/addressSchema.ts @@ -7,6 +7,6 @@ export const addressSchema = z.object({ city: z.string().optional(), state: z.string().optional(), zip: z.string().optional(), -} satisfies ToZod
) +}) as unknown as ToZod
export type AddressSchema = Address diff --git a/examples/advanced/src/gen/zod/apiResponseSchema.ts b/examples/advanced/src/gen/zod/apiResponseSchema.ts index a66285c1d..fcb56b7de 100644 --- a/examples/advanced/src/gen/zod/apiResponseSchema.ts +++ b/examples/advanced/src/gen/zod/apiResponseSchema.ts @@ -6,6 +6,6 @@ export const apiResponseSchema = z.object({ code: z.number().int().optional(), type: z.string().optional(), message: z.string().optional(), -} satisfies ToZod) +}) as unknown as ToZod export type ApiResponseSchema = ApiResponse diff --git a/examples/advanced/src/gen/zod/categorySchema.ts b/examples/advanced/src/gen/zod/categorySchema.ts index a146f55a3..69cc70a36 100644 --- a/examples/advanced/src/gen/zod/categorySchema.ts +++ b/examples/advanced/src/gen/zod/categorySchema.ts @@ -5,6 +5,6 @@ import { z } from 'zod' export const categorySchema = z.object({ id: z.number().int().optional(), name: z.string().optional(), -} satisfies ToZod) +}) as unknown as ToZod export type CategorySchema = Category diff --git a/examples/advanced/src/gen/zod/customerSchema.ts b/examples/advanced/src/gen/zod/customerSchema.ts index 31b482b7b..a36f53e20 100644 --- a/examples/advanced/src/gen/zod/customerSchema.ts +++ b/examples/advanced/src/gen/zod/customerSchema.ts @@ -7,6 +7,6 @@ export const customerSchema = z.object({ id: z.number().int().optional(), username: z.string().optional(), address: z.array(z.lazy(() => addressSchema)).optional(), -} satisfies ToZod) +}) as unknown as ToZod export type CustomerSchema = Customer diff --git a/examples/advanced/src/gen/zod/orderSchema.ts b/examples/advanced/src/gen/zod/orderSchema.ts index 0f1668284..5cb7f8732 100644 --- a/examples/advanced/src/gen/zod/orderSchema.ts +++ b/examples/advanced/src/gen/zod/orderSchema.ts @@ -15,6 +15,6 @@ export const orderSchema = z.object({ .describe('HTTP Status') .optional(), complete: z.boolean().optional(), -} satisfies ToZod) +}) as unknown as ToZod export type OrderSchema = Order diff --git a/examples/advanced/src/gen/zod/petController/addPetSchema.ts b/examples/advanced/src/gen/zod/petController/addPetSchema.ts index 01c67dae4..d70cfcd3b 100644 --- a/examples/advanced/src/gen/zod/petController/addPetSchema.ts +++ b/examples/advanced/src/gen/zod/petController/addPetSchema.ts @@ -7,7 +7,7 @@ import { z } from 'zod' /** * @description Successful operation */ -export const addPet200Schema = z.lazy(() => petSchema).and(z.object({ name: z.never() })) +export const addPet200Schema = z.lazy(() => petSchema).and(z.object({ name: z.never() })) as unknown as ToZod export type AddPet200Schema = AddPet200 @@ -17,17 +17,17 @@ export type AddPet200Schema = AddPet200 export const addPet405Schema = z.object({ code: z.number().int().optional(), message: z.string().optional(), -} satisfies ToZod) +}) as unknown as ToZod export type AddPet405Schema = AddPet405 /** * @description Create a new pet in the store */ -export const addPetMutationRequestSchema = z.lazy(() => addPetRequestSchema) +export const addPetMutationRequestSchema = z.lazy(() => addPetRequestSchema) as unknown as ToZod export type AddPetMutationRequestSchema = AddPetMutationRequest -export const addPetMutationResponseSchema = z.lazy(() => addPet200Schema) +export const addPetMutationResponseSchema = z.lazy(() => addPet200Schema) as unknown as ToZod export type AddPetMutationResponseSchema = AddPetMutationResponse diff --git a/examples/advanced/src/gen/zod/petController/deletePetSchema.ts b/examples/advanced/src/gen/zod/petController/deletePetSchema.ts index 55c5bf10c..4c65c6d61 100644 --- a/examples/advanced/src/gen/zod/petController/deletePetSchema.ts +++ b/examples/advanced/src/gen/zod/petController/deletePetSchema.ts @@ -4,25 +4,25 @@ import { z } from 'zod' export const deletePetPathParamsSchema = z.object({ petId: z.number().int().describe('Pet id to delete'), -} satisfies ToZod) +}) as unknown as ToZod export type DeletePetPathParamsSchema = DeletePetPathParams export const deletePetHeaderParamsSchema = z .object({ api_key: z.string().optional(), - } satisfies ToZod) - .optional() + }) + .optional() as unknown as ToZod export type DeletePetHeaderParamsSchema = DeletePetHeaderParams /** * @description Invalid pet value */ -export const deletePet400Schema = z.any() +export const deletePet400Schema = z.any() as unknown as ToZod export type DeletePet400Schema = DeletePet400 -export const deletePetMutationResponseSchema = z.any() +export const deletePetMutationResponseSchema = z.any() as unknown as ToZod export type DeletePetMutationResponseSchema = DeletePetMutationResponse diff --git a/examples/advanced/src/gen/zod/petController/findPetsByStatusSchema.ts b/examples/advanced/src/gen/zod/petController/findPetsByStatusSchema.ts index e849bfe37..77c418cec 100644 --- a/examples/advanced/src/gen/zod/petController/findPetsByStatusSchema.ts +++ b/examples/advanced/src/gen/zod/petController/findPetsByStatusSchema.ts @@ -10,7 +10,7 @@ import { z } from 'zod' export const findPetsByStatusPathParamsSchema = z.object({ step_id: z.string(), -} satisfies ToZod) +}) as unknown as ToZod export type FindPetsByStatusPathParamsSchema = FindPetsByStatusPathParams @@ -20,17 +20,17 @@ export type FindPetsByStatusPathParamsSchema = FindPetsByStatusPathParams export const findPetsByStatus200Schema = z .array(z.lazy(() => petSchema)) .min(1) - .max(3) + .max(3) as unknown as ToZod export type FindPetsByStatus200Schema = FindPetsByStatus200 /** * @description Invalid status value */ -export const findPetsByStatus400Schema = z.any() +export const findPetsByStatus400Schema = z.any() as unknown as ToZod export type FindPetsByStatus400Schema = FindPetsByStatus400 -export const findPetsByStatusQueryResponseSchema = z.lazy(() => findPetsByStatus200Schema) +export const findPetsByStatusQueryResponseSchema = z.lazy(() => findPetsByStatus200Schema) as unknown as ToZod export type FindPetsByStatusQueryResponseSchema = FindPetsByStatusQueryResponse diff --git a/examples/advanced/src/gen/zod/petController/findPetsByTagsSchema.ts b/examples/advanced/src/gen/zod/petController/findPetsByTagsSchema.ts index fe08a2b3d..916a92942 100644 --- a/examples/advanced/src/gen/zod/petController/findPetsByTagsSchema.ts +++ b/examples/advanced/src/gen/zod/petController/findPetsByTagsSchema.ts @@ -14,31 +14,31 @@ export const findPetsByTagsQueryParamsSchema = z tags: z.array(z.string()).describe('Tags to filter by').optional(), page: z.string().describe('to request with required page number or pagination').optional(), pageSize: z.string().describe('to request with required page size').optional(), - } satisfies ToZod) - .optional() + }) + .optional() as unknown as ToZod export type FindPetsByTagsQueryParamsSchema = FindPetsByTagsQueryParams export const findPetsByTagsHeaderParamsSchema = z.object({ 'X-EXAMPLE': z.enum(['ONE', 'TWO', 'THREE']).describe('Header parameters'), -} satisfies ToZod) +}) as unknown as ToZod export type FindPetsByTagsHeaderParamsSchema = FindPetsByTagsHeaderParams /** * @description successful operation */ -export const findPetsByTags200Schema = z.array(z.lazy(() => petSchema)) +export const findPetsByTags200Schema = z.array(z.lazy(() => petSchema)) as unknown as ToZod export type FindPetsByTags200Schema = FindPetsByTags200 /** * @description Invalid tag value */ -export const findPetsByTags400Schema = z.any() +export const findPetsByTags400Schema = z.any() as unknown as ToZod export type FindPetsByTags400Schema = FindPetsByTags400 -export const findPetsByTagsQueryResponseSchema = z.lazy(() => findPetsByTags200Schema) +export const findPetsByTagsQueryResponseSchema = z.lazy(() => findPetsByTags200Schema) as unknown as ToZod export type FindPetsByTagsQueryResponseSchema = FindPetsByTagsQueryResponse diff --git a/examples/advanced/src/gen/zod/petController/getPetByIdSchema.ts b/examples/advanced/src/gen/zod/petController/getPetByIdSchema.ts index 1766159eb..629a56d25 100644 --- a/examples/advanced/src/gen/zod/petController/getPetByIdSchema.ts +++ b/examples/advanced/src/gen/zod/petController/getPetByIdSchema.ts @@ -5,31 +5,31 @@ import { z } from 'zod' export const getPetByIdPathParamsSchema = z.object({ petId: z.number().int().describe('ID of pet to return'), -} satisfies ToZod) +}) as unknown as ToZod export type GetPetByIdPathParamsSchema = GetPetByIdPathParams /** * @description successful operation */ -export const getPetById200Schema = z.lazy(() => petSchema).and(z.object({ name: z.never() })) +export const getPetById200Schema = z.lazy(() => petSchema).and(z.object({ name: z.never() })) as unknown as ToZod export type GetPetById200Schema = GetPetById200 /** * @description Invalid ID supplied */ -export const getPetById400Schema = z.any() +export const getPetById400Schema = z.any() as unknown as ToZod export type GetPetById400Schema = GetPetById400 /** * @description Pet not found */ -export const getPetById404Schema = z.any() +export const getPetById404Schema = z.any() as unknown as ToZod export type GetPetById404Schema = GetPetById404 -export const getPetByIdQueryResponseSchema = z.lazy(() => getPetById200Schema) +export const getPetByIdQueryResponseSchema = z.lazy(() => getPetById200Schema) as unknown as ToZod export type GetPetByIdQueryResponseSchema = GetPetByIdQueryResponse diff --git a/examples/advanced/src/gen/zod/petController/updatePetSchema.ts b/examples/advanced/src/gen/zod/petController/updatePetSchema.ts index cdf0d6bb9..22caaeeec 100644 --- a/examples/advanced/src/gen/zod/petController/updatePetSchema.ts +++ b/examples/advanced/src/gen/zod/petController/updatePetSchema.ts @@ -14,7 +14,7 @@ import { z } from 'zod' /** * @description Successful operation */ -export const updatePet200Schema = z.lazy(() => petSchema).and(z.object({ name: z.never() })) +export const updatePet200Schema = z.lazy(() => petSchema).and(z.object({ name: z.never() })) as unknown as ToZod export type UpdatePet200Schema = UpdatePet200 @@ -23,38 +23,41 @@ export type UpdatePet200Schema = UpdatePet200 */ export const updatePet202Schema = z.object({ id: z.number().int().optional(), -} satisfies ToZod) +}) as unknown as ToZod export type UpdatePet202Schema = UpdatePet202 /** * @description Invalid ID supplied */ -export const updatePet400Schema = z.any() +export const updatePet400Schema = z.any() as unknown as ToZod export type UpdatePet400Schema = UpdatePet400 /** * @description Pet not found */ -export const updatePet404Schema = z.any() +export const updatePet404Schema = z.any() as unknown as ToZod export type UpdatePet404Schema = UpdatePet404 /** * @description Validation exception */ -export const updatePet405Schema = z.any() +export const updatePet405Schema = z.any() as unknown as ToZod export type UpdatePet405Schema = UpdatePet405 /** * @description Update an existent pet in the store */ -export const updatePetMutationRequestSchema = z.lazy(() => petSchema).and(z.object({ id: z.never() })) +export const updatePetMutationRequestSchema = z.lazy(() => petSchema).and(z.object({ id: z.never() })) as unknown as ToZod export type UpdatePetMutationRequestSchema = UpdatePetMutationRequest -export const updatePetMutationResponseSchema = z.union([z.lazy(() => updatePet200Schema), z.lazy(() => updatePet202Schema)]) +export const updatePetMutationResponseSchema = z.union([ + z.lazy(() => updatePet200Schema), + z.lazy(() => updatePet202Schema), +]) as unknown as ToZod export type UpdatePetMutationResponseSchema = UpdatePetMutationResponse diff --git a/examples/advanced/src/gen/zod/petController/updatePetWithFormSchema.ts b/examples/advanced/src/gen/zod/petController/updatePetWithFormSchema.ts index 09a402fa9..849f0e913 100644 --- a/examples/advanced/src/gen/zod/petController/updatePetWithFormSchema.ts +++ b/examples/advanced/src/gen/zod/petController/updatePetWithFormSchema.ts @@ -9,7 +9,7 @@ import { z } from 'zod' export const updatePetWithFormPathParamsSchema = z.object({ petId: z.number().int().describe('ID of pet that needs to be updated'), -} satisfies ToZod) +}) as unknown as ToZod export type UpdatePetWithFormPathParamsSchema = UpdatePetWithFormPathParams @@ -17,18 +17,18 @@ export const updatePetWithFormQueryParamsSchema = z .object({ name: z.string().describe('Name of pet that needs to be updated').optional(), status: z.string().describe('Status of pet that needs to be updated').optional(), - } satisfies ToZod) - .optional() + }) + .optional() as unknown as ToZod export type UpdatePetWithFormQueryParamsSchema = UpdatePetWithFormQueryParams /** * @description Invalid input */ -export const updatePetWithForm405Schema = z.any() +export const updatePetWithForm405Schema = z.any() as unknown as ToZod export type UpdatePetWithForm405Schema = UpdatePetWithForm405 -export const updatePetWithFormMutationResponseSchema = z.any() +export const updatePetWithFormMutationResponseSchema = z.any() as unknown as ToZod export type UpdatePetWithFormMutationResponseSchema = UpdatePetWithFormMutationResponse diff --git a/examples/advanced/src/gen/zod/petController/uploadFileSchema.ts b/examples/advanced/src/gen/zod/petController/uploadFileSchema.ts index 81946a477..fda8d518d 100644 --- a/examples/advanced/src/gen/zod/petController/uploadFileSchema.ts +++ b/examples/advanced/src/gen/zod/petController/uploadFileSchema.ts @@ -11,29 +11,29 @@ import { z } from 'zod' export const uploadFilePathParamsSchema = z.object({ petId: z.number().int().describe('ID of pet to update'), -} satisfies ToZod) +}) as unknown as ToZod export type UploadFilePathParamsSchema = UploadFilePathParams export const uploadFileQueryParamsSchema = z .object({ additionalMetadata: z.string().describe('Additional Metadata').optional(), - } satisfies ToZod) - .optional() + }) + .optional() as unknown as ToZod export type UploadFileQueryParamsSchema = UploadFileQueryParams /** * @description successful operation */ -export const uploadFile200Schema = z.lazy(() => apiResponseSchema) +export const uploadFile200Schema = z.lazy(() => apiResponseSchema) as unknown as ToZod export type UploadFile200Schema = UploadFile200 -export const uploadFileMutationRequestSchema = z.instanceof(File) +export const uploadFileMutationRequestSchema = z.instanceof(File) as unknown as ToZod export type UploadFileMutationRequestSchema = UploadFileMutationRequest -export const uploadFileMutationResponseSchema = z.lazy(() => uploadFile200Schema) +export const uploadFileMutationResponseSchema = z.lazy(() => uploadFile200Schema) as unknown as ToZod export type UploadFileMutationResponseSchema = UploadFileMutationResponse diff --git a/examples/advanced/src/gen/zod/petNotFoundSchema.ts b/examples/advanced/src/gen/zod/petNotFoundSchema.ts index 501bdc2f2..0168a6037 100644 --- a/examples/advanced/src/gen/zod/petNotFoundSchema.ts +++ b/examples/advanced/src/gen/zod/petNotFoundSchema.ts @@ -5,6 +5,6 @@ import { z } from 'zod' export const petNotFoundSchema = z.object({ code: z.number().int().optional(), message: z.string().optional(), -} satisfies ToZod) +}) as unknown as ToZod export type PetNotFoundSchema = PetNotFound diff --git a/examples/advanced/src/gen/zod/petSchema.ts b/examples/advanced/src/gen/zod/petSchema.ts index cb65579d7..c750758fe 100644 --- a/examples/advanced/src/gen/zod/petSchema.ts +++ b/examples/advanced/src/gen/zod/petSchema.ts @@ -11,6 +11,6 @@ export const petSchema = z.object({ photoUrls: z.array(z.string()), tags: z.array(z.lazy(() => tagTagSchema)).optional(), status: z.enum(['available', 'pending', 'sold']).describe('pet status in the store').optional(), -} satisfies ToZod) +}) as unknown as ToZod export type PetSchema = Pet diff --git a/examples/advanced/src/gen/zod/petsController/createPetsSchema.ts b/examples/advanced/src/gen/zod/petsController/createPetsSchema.ts index 7564e65be..da078fe55 100644 --- a/examples/advanced/src/gen/zod/petsController/createPetsSchema.ts +++ b/examples/advanced/src/gen/zod/petsController/createPetsSchema.ts @@ -13,45 +13,45 @@ import { z } from 'zod' export const createPetsPathParamsSchema = z.object({ uuid: z.string().describe('UUID'), -} satisfies ToZod) +}) as unknown as ToZod export type CreatePetsPathParamsSchema = CreatePetsPathParams export const createPetsQueryParamsSchema = z .object({ offset: z.number().int().describe('Offset */').optional(), - } satisfies ToZod) - .optional() + }) + .optional() as unknown as ToZod export type CreatePetsQueryParamsSchema = CreatePetsQueryParams export const createPetsHeaderParamsSchema = z.object({ 'X-EXAMPLE': z.enum(['ONE', 'TWO', 'THREE']).describe('Header parameters'), -} satisfies ToZod) +}) as unknown as ToZod export type CreatePetsHeaderParamsSchema = CreatePetsHeaderParams /** * @description Null response */ -export const createPets201Schema = z.any() +export const createPets201Schema = z.any() as unknown as ToZod export type CreatePets201Schema = CreatePets201 /** * @description unexpected error */ -export const createPetsErrorSchema = z.lazy(() => petNotFoundSchema) +export const createPetsErrorSchema = z.lazy(() => petNotFoundSchema) as unknown as ToZod export type CreatePetsErrorSchema = CreatePetsError export const createPetsMutationRequestSchema = z.object({ name: z.string(), tag: z.string(), -} satisfies ToZod) +}) as unknown as ToZod export type CreatePetsMutationRequestSchema = CreatePetsMutationRequest -export const createPetsMutationResponseSchema = z.lazy(() => createPets201Schema) +export const createPetsMutationResponseSchema = z.lazy(() => createPets201Schema) as unknown as ToZod export type CreatePetsMutationResponseSchema = CreatePetsMutationResponse diff --git a/examples/advanced/src/gen/zod/tag/tagSchema.ts b/examples/advanced/src/gen/zod/tag/tagSchema.ts index 24620e023..36eef09fa 100644 --- a/examples/advanced/src/gen/zod/tag/tagSchema.ts +++ b/examples/advanced/src/gen/zod/tag/tagSchema.ts @@ -5,6 +5,6 @@ import { z } from 'zod' export const tagTagSchema = z.object({ id: z.number().int().min(5).max(7).default(1), name: z.string().optional(), -} satisfies ToZod) +}) as unknown as ToZod export type TagTagSchema = TagTag diff --git a/examples/advanced/src/gen/zod/userArraySchema.ts b/examples/advanced/src/gen/zod/userArraySchema.ts index 99a5203b2..b94e3324e 100644 --- a/examples/advanced/src/gen/zod/userArraySchema.ts +++ b/examples/advanced/src/gen/zod/userArraySchema.ts @@ -1,7 +1,8 @@ import type { UserArray } from '../models/ts/UserArray.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { userSchema } from './userSchema.ts' import { z } from 'zod' -export const userArraySchema = z.array(z.lazy(() => userSchema)) +export const userArraySchema = z.array(z.lazy(() => userSchema)) as unknown as ToZod export type UserArraySchema = UserArray diff --git a/examples/advanced/src/gen/zod/userController/createUserSchema.ts b/examples/advanced/src/gen/zod/userController/createUserSchema.ts index de3ad8a37..edeff2a3e 100644 --- a/examples/advanced/src/gen/zod/userController/createUserSchema.ts +++ b/examples/advanced/src/gen/zod/userController/createUserSchema.ts @@ -1,21 +1,22 @@ import type { CreateUserError, CreateUserMutationRequest, CreateUserMutationResponse } from '../../models/ts/userController/CreateUser.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { userSchema } from '../userSchema.ts' import { z } from 'zod' /** * @description successful operation */ -export const createUserErrorSchema = z.lazy(() => userSchema) +export const createUserErrorSchema = z.lazy(() => userSchema) as unknown as ToZod export type CreateUserErrorSchema = CreateUserError /** * @description Created user object */ -export const createUserMutationRequestSchema = z.lazy(() => userSchema) +export const createUserMutationRequestSchema = z.lazy(() => userSchema) as unknown as ToZod export type CreateUserMutationRequestSchema = CreateUserMutationRequest -export const createUserMutationResponseSchema = z.any() +export const createUserMutationResponseSchema = z.any() as unknown as ToZod export type CreateUserMutationResponseSchema = CreateUserMutationResponse diff --git a/examples/advanced/src/gen/zod/userController/createUsersWithListInputSchema.ts b/examples/advanced/src/gen/zod/userController/createUsersWithListInputSchema.ts index 69a5d4d69..8804ccc41 100644 --- a/examples/advanced/src/gen/zod/userController/createUsersWithListInputSchema.ts +++ b/examples/advanced/src/gen/zod/userController/createUsersWithListInputSchema.ts @@ -4,27 +4,30 @@ import type { CreateUsersWithListInputMutationRequest, CreateUsersWithListInputMutationResponse, } from '../../models/ts/userController/CreateUsersWithListInput.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { userSchema } from '../userSchema.ts' import { z } from 'zod' /** * @description Successful operation */ -export const createUsersWithListInput200Schema = z.lazy(() => userSchema) +export const createUsersWithListInput200Schema = z.lazy(() => userSchema) as unknown as ToZod export type CreateUsersWithListInput200Schema = CreateUsersWithListInput200 /** * @description successful operation */ -export const createUsersWithListInputErrorSchema = z.any() +export const createUsersWithListInputErrorSchema = z.any() as unknown as ToZod export type CreateUsersWithListInputErrorSchema = CreateUsersWithListInputError -export const createUsersWithListInputMutationRequestSchema = z.array(z.lazy(() => userSchema)) +export const createUsersWithListInputMutationRequestSchema = z.array(z.lazy(() => userSchema)) as unknown as ToZod export type CreateUsersWithListInputMutationRequestSchema = CreateUsersWithListInputMutationRequest -export const createUsersWithListInputMutationResponseSchema = z.lazy(() => createUsersWithListInput200Schema) +export const createUsersWithListInputMutationResponseSchema = z.lazy( + () => createUsersWithListInput200Schema, +) as unknown as ToZod export type CreateUsersWithListInputMutationResponseSchema = CreateUsersWithListInputMutationResponse diff --git a/examples/advanced/src/gen/zod/userController/deleteUserSchema.ts b/examples/advanced/src/gen/zod/userController/deleteUserSchema.ts index b702a4480..3c7ff532e 100644 --- a/examples/advanced/src/gen/zod/userController/deleteUserSchema.ts +++ b/examples/advanced/src/gen/zod/userController/deleteUserSchema.ts @@ -4,24 +4,24 @@ import { z } from 'zod' export const deleteUserPathParamsSchema = z.object({ username: z.string().describe('The name that needs to be deleted'), -} satisfies ToZod) +}) as unknown as ToZod export type DeleteUserPathParamsSchema = DeleteUserPathParams /** * @description Invalid username supplied */ -export const deleteUser400Schema = z.any() +export const deleteUser400Schema = z.any() as unknown as ToZod export type DeleteUser400Schema = DeleteUser400 /** * @description User not found */ -export const deleteUser404Schema = z.any() +export const deleteUser404Schema = z.any() as unknown as ToZod export type DeleteUser404Schema = DeleteUser404 -export const deleteUserMutationResponseSchema = z.any() +export const deleteUserMutationResponseSchema = z.any() as unknown as ToZod export type DeleteUserMutationResponseSchema = DeleteUserMutationResponse diff --git a/examples/advanced/src/gen/zod/userController/getUserByNameSchema.ts b/examples/advanced/src/gen/zod/userController/getUserByNameSchema.ts index 32bbc6ba7..1cf0d81a0 100644 --- a/examples/advanced/src/gen/zod/userController/getUserByNameSchema.ts +++ b/examples/advanced/src/gen/zod/userController/getUserByNameSchema.ts @@ -11,31 +11,31 @@ import { z } from 'zod' export const getUserByNamePathParamsSchema = z.object({ username: z.string().describe('The name that needs to be fetched. Use user1 for testing. '), -} satisfies ToZod) +}) as unknown as ToZod export type GetUserByNamePathParamsSchema = GetUserByNamePathParams /** * @description successful operation */ -export const getUserByName200Schema = z.lazy(() => userSchema) +export const getUserByName200Schema = z.lazy(() => userSchema) as unknown as ToZod export type GetUserByName200Schema = GetUserByName200 /** * @description Invalid username supplied */ -export const getUserByName400Schema = z.any() +export const getUserByName400Schema = z.any() as unknown as ToZod export type GetUserByName400Schema = GetUserByName400 /** * @description User not found */ -export const getUserByName404Schema = z.any() +export const getUserByName404Schema = z.any() as unknown as ToZod export type GetUserByName404Schema = GetUserByName404 -export const getUserByNameQueryResponseSchema = z.lazy(() => getUserByName200Schema) +export const getUserByNameQueryResponseSchema = z.lazy(() => getUserByName200Schema) as unknown as ToZod export type GetUserByNameQueryResponseSchema = GetUserByNameQueryResponse diff --git a/examples/advanced/src/gen/zod/userController/loginUserSchema.ts b/examples/advanced/src/gen/zod/userController/loginUserSchema.ts index b989c9d21..3caabf1dd 100644 --- a/examples/advanced/src/gen/zod/userController/loginUserSchema.ts +++ b/examples/advanced/src/gen/zod/userController/loginUserSchema.ts @@ -6,25 +6,25 @@ export const loginUserQueryParamsSchema = z .object({ username: z.string().describe('The user name for login').optional(), password: z.string().describe('The password for login in clear text').optional(), - } satisfies ToZod) - .optional() + }) + .optional() as unknown as ToZod export type LoginUserQueryParamsSchema = LoginUserQueryParams /** * @description successful operation */ -export const loginUser200Schema = z.string() +export const loginUser200Schema = z.string() as unknown as ToZod export type LoginUser200Schema = LoginUser200 /** * @description Invalid username/password supplied */ -export const loginUser400Schema = z.any() +export const loginUser400Schema = z.any() as unknown as ToZod export type LoginUser400Schema = LoginUser400 -export const loginUserQueryResponseSchema = z.lazy(() => loginUser200Schema) +export const loginUserQueryResponseSchema = z.lazy(() => loginUser200Schema) as unknown as ToZod export type LoginUserQueryResponseSchema = LoginUserQueryResponse diff --git a/examples/advanced/src/gen/zod/userController/logoutUserSchema.ts b/examples/advanced/src/gen/zod/userController/logoutUserSchema.ts index e0da31fe4..ff9dd531c 100644 --- a/examples/advanced/src/gen/zod/userController/logoutUserSchema.ts +++ b/examples/advanced/src/gen/zod/userController/logoutUserSchema.ts @@ -1,13 +1,14 @@ import type { LogoutUserError, LogoutUserQueryResponse } from '../../models/ts/userController/LogoutUser.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from 'zod' /** * @description successful operation */ -export const logoutUserErrorSchema = z.any() +export const logoutUserErrorSchema = z.any() as unknown as ToZod export type LogoutUserErrorSchema = LogoutUserError -export const logoutUserQueryResponseSchema = z.any() +export const logoutUserQueryResponseSchema = z.any() as unknown as ToZod export type LogoutUserQueryResponseSchema = LogoutUserQueryResponse diff --git a/examples/advanced/src/gen/zod/userController/updateUserSchema.ts b/examples/advanced/src/gen/zod/userController/updateUserSchema.ts index cdeb7d0b4..4e1ec18ed 100644 --- a/examples/advanced/src/gen/zod/userController/updateUserSchema.ts +++ b/examples/advanced/src/gen/zod/userController/updateUserSchema.ts @@ -5,24 +5,24 @@ import { z } from 'zod' export const updateUserPathParamsSchema = z.object({ username: z.string().describe('name that need to be deleted'), -} satisfies ToZod) +}) as unknown as ToZod export type UpdateUserPathParamsSchema = UpdateUserPathParams /** * @description successful operation */ -export const updateUserErrorSchema = z.any() +export const updateUserErrorSchema = z.any() as unknown as ToZod export type UpdateUserErrorSchema = UpdateUserError /** * @description Update an existent user in the store */ -export const updateUserMutationRequestSchema = z.lazy(() => userSchema) +export const updateUserMutationRequestSchema = z.lazy(() => userSchema) as unknown as ToZod export type UpdateUserMutationRequestSchema = UpdateUserMutationRequest -export const updateUserMutationResponseSchema = z.any() +export const updateUserMutationResponseSchema = z.any() as unknown as ToZod export type UpdateUserMutationResponseSchema = UpdateUserMutationResponse diff --git a/examples/advanced/src/gen/zod/userSchema.ts b/examples/advanced/src/gen/zod/userSchema.ts index 48d86b92f..9714a71df 100644 --- a/examples/advanced/src/gen/zod/userSchema.ts +++ b/examples/advanced/src/gen/zod/userSchema.ts @@ -12,6 +12,6 @@ export const userSchema = z.object({ password: z.string().optional(), phone: z.string().optional(), userStatus: z.number().int().describe('User Status').optional(), -} satisfies ToZod) +}) as unknown as ToZod export type UserSchema = User diff --git a/examples/client/src/gen/clients/axios/petService/addPet.ts b/examples/client/src/gen/clients/axios/petService/addPet.ts index a48e52024..dc1f5a9df 100644 --- a/examples/client/src/gen/clients/axios/petService/addPet.ts +++ b/examples/client/src/gen/clients/axios/petService/addPet.ts @@ -4,7 +4,7 @@ import type { AddPetMutationRequest, AddPetMutationResponse, AddPet405 } from '. import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios' export function getAddPetUrl() { - return '/pet' + return '/pet' as const } /** diff --git a/examples/client/src/gen/clients/axios/petService/deletePet.ts b/examples/client/src/gen/clients/axios/petService/deletePet.ts index ba3bdc4a4..44e13dadf 100644 --- a/examples/client/src/gen/clients/axios/petService/deletePet.ts +++ b/examples/client/src/gen/clients/axios/petService/deletePet.ts @@ -4,7 +4,7 @@ import type { DeletePetMutationResponse, DeletePetPathParams, DeletePetHeaderPar import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios' export function getDeletePetUrl({ petId }: { petId: DeletePetPathParams['petId'] }) { - return `/pet/${petId}` + return `/pet/${petId}` as const } /** diff --git a/examples/client/src/gen/clients/axios/petService/findPetsByStatus.ts b/examples/client/src/gen/clients/axios/petService/findPetsByStatus.ts index 0f6c262e3..11de152b6 100644 --- a/examples/client/src/gen/clients/axios/petService/findPetsByStatus.ts +++ b/examples/client/src/gen/clients/axios/petService/findPetsByStatus.ts @@ -4,7 +4,7 @@ import type { FindPetsByStatusQueryResponse, FindPetsByStatusQueryParams, FindPe import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios' export function getFindPetsByStatusUrl() { - return '/pet/findByStatus' + return '/pet/findByStatus' as const } /** diff --git a/examples/client/src/gen/clients/axios/petService/findPetsByTags.ts b/examples/client/src/gen/clients/axios/petService/findPetsByTags.ts index dce803475..25b6ee199 100644 --- a/examples/client/src/gen/clients/axios/petService/findPetsByTags.ts +++ b/examples/client/src/gen/clients/axios/petService/findPetsByTags.ts @@ -4,7 +4,7 @@ import type { FindPetsByTagsQueryResponse, FindPetsByTagsQueryParams, FindPetsBy import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios' export function getFindPetsByTagsUrl() { - return '/pet/findByTags' + return '/pet/findByTags' as const } /** diff --git a/examples/client/src/gen/clients/axios/petService/getPetById.ts b/examples/client/src/gen/clients/axios/petService/getPetById.ts index 445a7a323..604729679 100644 --- a/examples/client/src/gen/clients/axios/petService/getPetById.ts +++ b/examples/client/src/gen/clients/axios/petService/getPetById.ts @@ -4,7 +4,7 @@ import type { GetPetByIdQueryResponse, GetPetByIdPathParams, GetPetById400, GetP import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios' export function getGetPetByIdUrl({ petId }: { petId: GetPetByIdPathParams['petId'] }) { - return `/pet/${petId}` + return `/pet/${petId}` as const } /** diff --git a/examples/client/src/gen/clients/axios/petService/updatePet.ts b/examples/client/src/gen/clients/axios/petService/updatePet.ts index 1025195c5..7c3054777 100644 --- a/examples/client/src/gen/clients/axios/petService/updatePet.ts +++ b/examples/client/src/gen/clients/axios/petService/updatePet.ts @@ -10,7 +10,7 @@ import type { import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios' export function getUpdatePetUrl() { - return '/pet' + return '/pet' as const } /** diff --git a/examples/client/src/gen/clients/axios/petService/updatePetWithForm.ts b/examples/client/src/gen/clients/axios/petService/updatePetWithForm.ts index e5fe4c099..bf93d7efa 100644 --- a/examples/client/src/gen/clients/axios/petService/updatePetWithForm.ts +++ b/examples/client/src/gen/clients/axios/petService/updatePetWithForm.ts @@ -9,7 +9,7 @@ import type { import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios' export function getUpdatePetWithFormUrl({ petId }: { petId: UpdatePetWithFormPathParams['petId'] }) { - return `/pet/${petId}` + return `/pet/${petId}` as const } /** diff --git a/examples/client/src/gen/clients/axios/petService/uploadFile.ts b/examples/client/src/gen/clients/axios/petService/uploadFile.ts index 9ad1e8232..b5cc70d78 100644 --- a/examples/client/src/gen/clients/axios/petService/uploadFile.ts +++ b/examples/client/src/gen/clients/axios/petService/uploadFile.ts @@ -9,7 +9,7 @@ import type { import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios' export function getUploadFileUrl({ petId }: { petId: UploadFilePathParams['petId'] }) { - return `/pet/${petId}/uploadImage` + return `/pet/${petId}/uploadImage` as const } /** diff --git a/examples/client/src/gen/clients/axios/userService/createUser.ts b/examples/client/src/gen/clients/axios/userService/createUser.ts index cc8caa9da..b43e89b2a 100644 --- a/examples/client/src/gen/clients/axios/userService/createUser.ts +++ b/examples/client/src/gen/clients/axios/userService/createUser.ts @@ -4,7 +4,7 @@ import type { CreateUserMutationRequest, CreateUserMutationResponse } from '../. import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios' export function getCreateUserUrl() { - return '/user' + return '/user' as const } /** diff --git a/examples/client/src/gen/clients/axios/userService/createUsersWithListInput.ts b/examples/client/src/gen/clients/axios/userService/createUsersWithListInput.ts index d9da2ab09..0b6fcfb1a 100644 --- a/examples/client/src/gen/clients/axios/userService/createUsersWithListInput.ts +++ b/examples/client/src/gen/clients/axios/userService/createUsersWithListInput.ts @@ -7,7 +7,7 @@ import type { import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios' export function getCreateUsersWithListInputUrl() { - return '/user/createWithList' + return '/user/createWithList' as const } /** diff --git a/examples/client/src/gen/clients/axios/userService/deleteUser.ts b/examples/client/src/gen/clients/axios/userService/deleteUser.ts index 3f185cf5c..3a51c2827 100644 --- a/examples/client/src/gen/clients/axios/userService/deleteUser.ts +++ b/examples/client/src/gen/clients/axios/userService/deleteUser.ts @@ -4,7 +4,7 @@ import type { DeleteUserMutationResponse, DeleteUserPathParams, DeleteUser400, D import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios' export function getDeleteUserUrl({ username }: { username: DeleteUserPathParams['username'] }) { - return `/user/${username}` + return `/user/${username}` as const } /** diff --git a/examples/client/src/gen/clients/axios/userService/getUserByName.ts b/examples/client/src/gen/clients/axios/userService/getUserByName.ts index 2134b1d7a..dc47342ac 100644 --- a/examples/client/src/gen/clients/axios/userService/getUserByName.ts +++ b/examples/client/src/gen/clients/axios/userService/getUserByName.ts @@ -9,7 +9,7 @@ import type { import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios' export function getGetUserByNameUrl({ username }: { username: GetUserByNamePathParams['username'] }) { - return `/user/${username}` + return `/user/${username}` as const } /** diff --git a/examples/client/src/gen/clients/axios/userService/loginUser.ts b/examples/client/src/gen/clients/axios/userService/loginUser.ts index 9c3636e33..a5afb0250 100644 --- a/examples/client/src/gen/clients/axios/userService/loginUser.ts +++ b/examples/client/src/gen/clients/axios/userService/loginUser.ts @@ -4,7 +4,7 @@ import type { LoginUserQueryResponse, LoginUserQueryParams, LoginUser400 } from import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios' export function getLoginUserUrl() { - return '/user/login' + return '/user/login' as const } /** diff --git a/examples/client/src/gen/clients/axios/userService/logoutUser.ts b/examples/client/src/gen/clients/axios/userService/logoutUser.ts index b606c1be8..af16cb97d 100644 --- a/examples/client/src/gen/clients/axios/userService/logoutUser.ts +++ b/examples/client/src/gen/clients/axios/userService/logoutUser.ts @@ -4,7 +4,7 @@ import type { LogoutUserQueryResponse } from '../../../models/ts/userController/ import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios' export function getLogoutUserUrl() { - return '/user/logout' + return '/user/logout' as const } /** diff --git a/examples/client/src/gen/clients/axios/userService/updateUser.ts b/examples/client/src/gen/clients/axios/userService/updateUser.ts index 9a2acb4da..f837c6d98 100644 --- a/examples/client/src/gen/clients/axios/userService/updateUser.ts +++ b/examples/client/src/gen/clients/axios/userService/updateUser.ts @@ -4,7 +4,7 @@ import type { UpdateUserMutationRequest, UpdateUserMutationResponse, UpdateUserP import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios' export function getUpdateUserUrl({ username }: { username: UpdateUserPathParams['username'] }) { - return `/user/${username}` + return `/user/${username}` as const } /** diff --git a/examples/client/src/gen/tag.ts b/examples/client/src/gen/tag.ts index 9c259df66..953ef5ce6 100644 --- a/examples/client/src/gen/tag.ts +++ b/examples/client/src/gen/tag.ts @@ -7,7 +7,7 @@ import type { PlaceOrderPatchMutationRequest, PlaceOrderPatchMutationResponse, P import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios' export function getGetInventoryUrlController() { - return '/store/inventory' + return '/store/inventory' as const } /** @@ -25,7 +25,7 @@ export async function getInventoryController(config: Partial = {} } export function getPlaceOrderUrlController() { - return '/store/order' + return '/store/order' as const } /** @@ -44,7 +44,7 @@ export async function placeOrderController(data?: PlaceOrderMutationRequest, con } export function getPlaceOrderPatchUrlController() { - return '/store/order' + return '/store/order' as const } /** @@ -63,7 +63,7 @@ export async function placeOrderPatchController(data?: PlaceOrderPatchMutationRe } export function getGetOrderByIdUrlController(orderId: GetOrderByIdPathParams['orderId']) { - return `/store/order/${orderId}` + return `/store/order/${orderId}` as const } /** @@ -81,7 +81,7 @@ export async function getOrderByIdController(orderId: GetOrderByIdPathParams['or } export function getDeleteOrderUrlController(orderId: DeleteOrderPathParams['orderId']) { - return `/store/order/${orderId}` + return `/store/order/${orderId}` as const } /** diff --git a/examples/fetch/src/gen/addPet.ts b/examples/fetch/src/gen/addPet.ts index 9bfc2ab59..1ad7237bd 100644 --- a/examples/fetch/src/gen/addPet.ts +++ b/examples/fetch/src/gen/addPet.ts @@ -3,7 +3,7 @@ import type { AddPetMutationRequest, AddPetMutationResponse, AddPet405 } from '. import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/fetch' export function getAddPetUrl() { - return '/pet' + return '/pet' as const } /** diff --git a/examples/fetch/src/gen/createUser.ts b/examples/fetch/src/gen/createUser.ts index 3fa35bc4b..33044bc5a 100644 --- a/examples/fetch/src/gen/createUser.ts +++ b/examples/fetch/src/gen/createUser.ts @@ -3,7 +3,7 @@ import type { CreateUserMutationRequest, CreateUserMutationResponse } from './mo import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/fetch' export function getCreateUserUrl() { - return '/user' + return '/user' as const } /** diff --git a/examples/fetch/src/gen/createUsersWithListInput.ts b/examples/fetch/src/gen/createUsersWithListInput.ts index a74d7b7d9..381f39e1f 100644 --- a/examples/fetch/src/gen/createUsersWithListInput.ts +++ b/examples/fetch/src/gen/createUsersWithListInput.ts @@ -3,7 +3,7 @@ import type { CreateUsersWithListInputMutationRequest, CreateUsersWithListInputM import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/fetch' export function getCreateUsersWithListInputUrl() { - return '/user/createWithList' + return '/user/createWithList' as const } /** diff --git a/examples/fetch/src/gen/deleteOrder.ts b/examples/fetch/src/gen/deleteOrder.ts index f3058fa01..5d3dcec02 100644 --- a/examples/fetch/src/gen/deleteOrder.ts +++ b/examples/fetch/src/gen/deleteOrder.ts @@ -3,7 +3,7 @@ import type { DeleteOrderMutationResponse, DeleteOrderPathParams, DeleteOrder400 import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/fetch' export function getDeleteOrderUrl(orderId: DeleteOrderPathParams['orderId']) { - return `/store/order/${orderId}` + return `/store/order/${orderId}` as const } /** diff --git a/examples/fetch/src/gen/deletePet.ts b/examples/fetch/src/gen/deletePet.ts index 7d79a40fc..64db32845 100644 --- a/examples/fetch/src/gen/deletePet.ts +++ b/examples/fetch/src/gen/deletePet.ts @@ -3,7 +3,7 @@ import type { DeletePetMutationResponse, DeletePetPathParams, DeletePetHeaderPar import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/fetch' export function getDeletePetUrl(petId: DeletePetPathParams['petId']) { - return `/pet/${petId}` + return `/pet/${petId}` as const } /** diff --git a/examples/fetch/src/gen/deleteUser.ts b/examples/fetch/src/gen/deleteUser.ts index 2365d1646..bf2c28f11 100644 --- a/examples/fetch/src/gen/deleteUser.ts +++ b/examples/fetch/src/gen/deleteUser.ts @@ -3,7 +3,7 @@ import type { DeleteUserMutationResponse, DeleteUserPathParams, DeleteUser400, D import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/fetch' export function getDeleteUserUrl(username: DeleteUserPathParams['username']) { - return `/user/${username}` + return `/user/${username}` as const } /** diff --git a/examples/fetch/src/gen/findPetsByStatus.ts b/examples/fetch/src/gen/findPetsByStatus.ts index 89aa8d485..1a297c08e 100644 --- a/examples/fetch/src/gen/findPetsByStatus.ts +++ b/examples/fetch/src/gen/findPetsByStatus.ts @@ -3,7 +3,7 @@ import type { FindPetsByStatusQueryResponse, FindPetsByStatusQueryParams, FindPe import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/fetch' export function getFindPetsByStatusUrl() { - return '/pet/findByStatus' + return '/pet/findByStatus' as const } /** diff --git a/examples/fetch/src/gen/findPetsByTags.ts b/examples/fetch/src/gen/findPetsByTags.ts index 6f1f682e0..d3b69aee8 100644 --- a/examples/fetch/src/gen/findPetsByTags.ts +++ b/examples/fetch/src/gen/findPetsByTags.ts @@ -3,7 +3,7 @@ import type { FindPetsByTagsQueryResponse, FindPetsByTagsQueryParams, FindPetsBy import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/fetch' export function getFindPetsByTagsUrl() { - return '/pet/findByTags' + return '/pet/findByTags' as const } /** diff --git a/examples/fetch/src/gen/getInventory.ts b/examples/fetch/src/gen/getInventory.ts index 93d02feef..5267a3215 100644 --- a/examples/fetch/src/gen/getInventory.ts +++ b/examples/fetch/src/gen/getInventory.ts @@ -3,7 +3,7 @@ import type { GetInventoryQueryResponse } from './models.ts' import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/fetch' export function getGetInventoryUrl() { - return '/store/inventory' + return '/store/inventory' as const } /** diff --git a/examples/fetch/src/gen/getOrderById.ts b/examples/fetch/src/gen/getOrderById.ts index 81f7e3cb8..99a2fec68 100644 --- a/examples/fetch/src/gen/getOrderById.ts +++ b/examples/fetch/src/gen/getOrderById.ts @@ -3,7 +3,7 @@ import type { GetOrderByIdQueryResponse, GetOrderByIdPathParams, GetOrderById400 import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/fetch' export function getGetOrderByIdUrl(orderId: GetOrderByIdPathParams['orderId']) { - return `/store/order/${orderId}` + return `/store/order/${orderId}` as const } /** diff --git a/examples/fetch/src/gen/getPetById.ts b/examples/fetch/src/gen/getPetById.ts index dcca1e61c..ecf202f20 100644 --- a/examples/fetch/src/gen/getPetById.ts +++ b/examples/fetch/src/gen/getPetById.ts @@ -3,7 +3,7 @@ import type { GetPetByIdQueryResponse, GetPetByIdPathParams, GetPetById400, GetP import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/fetch' export function getGetPetByIdUrl(petId: GetPetByIdPathParams['petId']) { - return `/pet/${petId}` + return `/pet/${petId}` as const } /** diff --git a/examples/fetch/src/gen/getUserByName.ts b/examples/fetch/src/gen/getUserByName.ts index 7ced19a5e..90326ea94 100644 --- a/examples/fetch/src/gen/getUserByName.ts +++ b/examples/fetch/src/gen/getUserByName.ts @@ -3,7 +3,7 @@ import type { GetUserByNameQueryResponse, GetUserByNamePathParams, GetUserByName import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/fetch' export function getGetUserByNameUrl(username: GetUserByNamePathParams['username']) { - return `/user/${username}` + return `/user/${username}` as const } /** diff --git a/examples/fetch/src/gen/loginUser.ts b/examples/fetch/src/gen/loginUser.ts index 74bd302ae..0f7f85cdd 100644 --- a/examples/fetch/src/gen/loginUser.ts +++ b/examples/fetch/src/gen/loginUser.ts @@ -3,7 +3,7 @@ import type { LoginUserQueryResponse, LoginUserQueryParams, LoginUser400 } from import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/fetch' export function getLoginUserUrl() { - return '/user/login' + return '/user/login' as const } /** diff --git a/examples/fetch/src/gen/logoutUser.ts b/examples/fetch/src/gen/logoutUser.ts index f7e6c4e38..fc15aca89 100644 --- a/examples/fetch/src/gen/logoutUser.ts +++ b/examples/fetch/src/gen/logoutUser.ts @@ -3,7 +3,7 @@ import type { LogoutUserQueryResponse } from './models.ts' import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/fetch' export function getLogoutUserUrl() { - return '/user/logout' + return '/user/logout' as const } /** diff --git a/examples/fetch/src/gen/placeOrder.ts b/examples/fetch/src/gen/placeOrder.ts index d12e57073..ed8ad9617 100644 --- a/examples/fetch/src/gen/placeOrder.ts +++ b/examples/fetch/src/gen/placeOrder.ts @@ -3,7 +3,7 @@ import type { PlaceOrderMutationRequest, PlaceOrderMutationResponse, PlaceOrder4 import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/fetch' export function getPlaceOrderUrl() { - return '/store/order' + return '/store/order' as const } /** diff --git a/examples/fetch/src/gen/placeOrderPatch.ts b/examples/fetch/src/gen/placeOrderPatch.ts index 77311bb03..8436ff995 100644 --- a/examples/fetch/src/gen/placeOrderPatch.ts +++ b/examples/fetch/src/gen/placeOrderPatch.ts @@ -3,7 +3,7 @@ import type { PlaceOrderPatchMutationRequest, PlaceOrderPatchMutationResponse, P import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/fetch' export function getPlaceOrderPatchUrl() { - return '/store/order' + return '/store/order' as const } /** diff --git a/examples/fetch/src/gen/updatePet.ts b/examples/fetch/src/gen/updatePet.ts index f11454e34..4ca2e168c 100644 --- a/examples/fetch/src/gen/updatePet.ts +++ b/examples/fetch/src/gen/updatePet.ts @@ -3,7 +3,7 @@ import type { UpdatePetMutationRequest, UpdatePetMutationResponse, UpdatePet400, import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/fetch' export function getUpdatePetUrl() { - return '/pet' + return '/pet' as const } /** diff --git a/examples/fetch/src/gen/updatePetWithForm.ts b/examples/fetch/src/gen/updatePetWithForm.ts index c0d8579ab..282d1941b 100644 --- a/examples/fetch/src/gen/updatePetWithForm.ts +++ b/examples/fetch/src/gen/updatePetWithForm.ts @@ -3,7 +3,7 @@ import type { UpdatePetWithFormMutationResponse, UpdatePetWithFormPathParams, Up import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/fetch' export function getUpdatePetWithFormUrl(petId: UpdatePetWithFormPathParams['petId']) { - return `/pet/${petId}` + return `/pet/${petId}` as const } /** diff --git a/examples/fetch/src/gen/updateUser.ts b/examples/fetch/src/gen/updateUser.ts index 31c8ce1c6..e9c92e2f1 100644 --- a/examples/fetch/src/gen/updateUser.ts +++ b/examples/fetch/src/gen/updateUser.ts @@ -3,7 +3,7 @@ import type { UpdateUserMutationRequest, UpdateUserMutationResponse, UpdateUserP import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/fetch' export function getUpdateUserUrl(username: UpdateUserPathParams['username']) { - return `/user/${username}` + return `/user/${username}` as const } /** diff --git a/examples/fetch/src/gen/uploadFile.ts b/examples/fetch/src/gen/uploadFile.ts index 26f312b51..336ecee20 100644 --- a/examples/fetch/src/gen/uploadFile.ts +++ b/examples/fetch/src/gen/uploadFile.ts @@ -3,7 +3,7 @@ import type { UploadFileMutationRequest, UploadFileMutationResponse, UploadFileP import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/fetch' export function getUploadFileUrl(petId: UploadFilePathParams['petId']) { - return `/pet/${petId}/uploadImage` + return `/pet/${petId}/uploadImage` as const } /** diff --git a/examples/zod/kubb.config.js b/examples/zod/kubb.config.js index b3f421147..d1251e1e7 100644 --- a/examples/zod/kubb.config.js +++ b/examples/zod/kubb.config.js @@ -37,6 +37,7 @@ export default defineConfig(async () => { output: { path: './zod', }, + typed: true, transformers: { name: (name, type) => (type === 'file' ? `${name}.gen` : name), schema: ({ schema, parentName, name }, defaultSchemas) => { diff --git a/examples/zod/src/gen/zod/addPetRequestSchema.gen.ts b/examples/zod/src/gen/zod/addPetRequestSchema.gen.ts index cd8562087..07ea5bcae 100644 --- a/examples/zod/src/gen/zod/addPetRequestSchema.gen.ts +++ b/examples/zod/src/gen/zod/addPetRequestSchema.gen.ts @@ -1,3 +1,5 @@ +import type { AddPetRequestType } from '../ts/AddPetRequestType.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from '../../zod.ts' import { categorySchema } from './categorySchema.gen.ts' import { tagSchema } from './tagSchema.gen.ts' @@ -9,6 +11,6 @@ export const addPetRequestSchema = z.object({ photoUrls: z.array(z.string()), tags: z.array(z.lazy(() => tagSchema)).optional(), status: z.enum(['available', 'pending', 'sold']).describe('pet status in the store').optional(), -}) +}) as unknown as ToZod -export type AddPetRequestSchema = z.infer +export type AddPetRequestSchema = AddPetRequestType diff --git a/examples/zod/src/gen/zod/addPetSchema.gen.ts b/examples/zod/src/gen/zod/addPetSchema.gen.ts index 18e434313..ace30e192 100644 --- a/examples/zod/src/gen/zod/addPetSchema.gen.ts +++ b/examples/zod/src/gen/zod/addPetSchema.gen.ts @@ -1,3 +1,5 @@ +import type { AddPet200Type, AddPet405Type, AddPetMutationRequestType, AddPetMutationResponseType } from '../ts/AddPetType.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from '../../zod.ts' import { addPetRequestSchema } from './addPetRequestSchema.gen.ts' import { petSchema } from './petSchema.gen.ts' @@ -5,9 +7,9 @@ import { petSchema } from './petSchema.gen.ts' /** * @description Successful operation */ -export const addPet200Schema = z.lazy(() => petSchema) +export const addPet200Schema = z.lazy(() => petSchema) as unknown as ToZod -export type AddPet200Schema = z.infer +export type AddPet200Schema = AddPet200Type /** * @description Pet not found @@ -15,17 +17,17 @@ export type AddPet200Schema = z.infer export const addPet405Schema = z.object({ code: z.number().int().optional(), message: z.string().optional(), -}) +}) as unknown as ToZod -export type AddPet405Schema = z.infer +export type AddPet405Schema = AddPet405Type /** * @description Create a new pet in the store */ -export const addPetMutationRequestSchema = z.lazy(() => addPetRequestSchema) +export const addPetMutationRequestSchema = z.lazy(() => addPetRequestSchema) as unknown as ToZod -export type AddPetMutationRequestSchema = z.infer +export type AddPetMutationRequestSchema = AddPetMutationRequestType -export const addPetMutationResponseSchema = z.lazy(() => addPet200Schema) +export const addPetMutationResponseSchema = z.lazy(() => addPet200Schema) as unknown as ToZod -export type AddPetMutationResponseSchema = z.infer +export type AddPetMutationResponseSchema = AddPetMutationResponseType diff --git a/examples/zod/src/gen/zod/addressSchema.gen.ts b/examples/zod/src/gen/zod/addressSchema.gen.ts index 772a533c1..e837f1a79 100644 --- a/examples/zod/src/gen/zod/addressSchema.gen.ts +++ b/examples/zod/src/gen/zod/addressSchema.gen.ts @@ -1,3 +1,5 @@ +import type { AddressType } from '../ts/AddressType.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from '../../zod.ts' export const addressSchema = z.object({ @@ -5,6 +7,6 @@ export const addressSchema = z.object({ city: z.string().optional(), state: z.string().optional(), zip: z.string().optional(), -}) +}) as unknown as ToZod -export type AddressSchema = z.infer +export type AddressSchema = AddressType diff --git a/examples/zod/src/gen/zod/apiResponseSchema.gen.ts b/examples/zod/src/gen/zod/apiResponseSchema.gen.ts index 94d37ccb5..4358abae3 100644 --- a/examples/zod/src/gen/zod/apiResponseSchema.gen.ts +++ b/examples/zod/src/gen/zod/apiResponseSchema.gen.ts @@ -1,9 +1,11 @@ +import type { ApiResponseType } from '../ts/ApiResponseType.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from '../../zod.ts' export const apiResponseSchema = z.object({ code: z.number().int().optional(), type: z.string().optional(), message: z.string().optional(), -}) +}) as unknown as ToZod -export type ApiResponseSchema = z.infer +export type ApiResponseSchema = ApiResponseType diff --git a/examples/zod/src/gen/zod/categorySchema.gen.ts b/examples/zod/src/gen/zod/categorySchema.gen.ts index 58bac9912..2674ae8c5 100644 --- a/examples/zod/src/gen/zod/categorySchema.gen.ts +++ b/examples/zod/src/gen/zod/categorySchema.gen.ts @@ -1,9 +1,11 @@ +import type { CategoryType } from '../ts/CategoryType.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from '../../zod.ts' export const categorySchema = z.object({ id: z.number().int().optional(), name: z.string().optional(), parent: z.lazy(() => categorySchema).optional(), -}) +}) as unknown as ToZod -export type CategorySchema = z.infer +export type CategorySchema = CategoryType diff --git a/examples/zod/src/gen/zod/createPetsSchema.gen.ts b/examples/zod/src/gen/zod/createPetsSchema.gen.ts index 1fbd3d882..96eb1791f 100644 --- a/examples/zod/src/gen/zod/createPetsSchema.gen.ts +++ b/examples/zod/src/gen/zod/createPetsSchema.gen.ts @@ -1,47 +1,57 @@ +import type { + CreatePetsPathParamsType, + CreatePetsQueryParamsType, + CreatePetsHeaderParamsType, + CreatePets201Type, + CreatePetsErrorType, + CreatePetsMutationRequestType, + CreatePetsMutationResponseType, +} from '../ts/CreatePetsType.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from '../../zod.ts' import { petNotFoundSchema } from './petNotFoundSchema.gen.ts' export const createPetsPathParamsSchema = z.object({ uuid: z.string().describe('UUID'), -}) +}) as unknown as ToZod -export type CreatePetsPathParamsSchema = z.infer +export type CreatePetsPathParamsSchema = CreatePetsPathParamsType export const createPetsQueryParamsSchema = z .object({ offset: z.number().int().describe('Offset').optional(), }) - .optional() + .optional() as unknown as ToZod -export type CreatePetsQueryParamsSchema = z.infer +export type CreatePetsQueryParamsSchema = CreatePetsQueryParamsType export const createPetsHeaderParamsSchema = z.object({ 'X-EXAMPLE': z.enum(['ONE', 'TWO', 'THREE']).describe('Header parameters'), -}) +}) as unknown as ToZod -export type CreatePetsHeaderParamsSchema = z.infer +export type CreatePetsHeaderParamsSchema = CreatePetsHeaderParamsType /** * @description Null response */ -export const createPets201Schema = z.any() +export const createPets201Schema = z.any() as unknown as ToZod -export type CreatePets201Schema = z.infer +export type CreatePets201Schema = CreatePets201Type /** * @description unexpected error */ -export const createPetsErrorSchema = z.lazy(() => petNotFoundSchema) +export const createPetsErrorSchema = z.lazy(() => petNotFoundSchema) as unknown as ToZod -export type CreatePetsErrorSchema = z.infer +export type CreatePetsErrorSchema = CreatePetsErrorType export const createPetsMutationRequestSchema = z.object({ name: z.string(), tag: z.string(), -}) +}) as unknown as ToZod -export type CreatePetsMutationRequestSchema = z.infer +export type CreatePetsMutationRequestSchema = CreatePetsMutationRequestType -export const createPetsMutationResponseSchema = z.lazy(() => createPets201Schema) +export const createPetsMutationResponseSchema = z.lazy(() => createPets201Schema) as unknown as ToZod -export type CreatePetsMutationResponseSchema = z.infer +export type CreatePetsMutationResponseSchema = CreatePetsMutationResponseType diff --git a/examples/zod/src/gen/zod/createUserSchema.gen.ts b/examples/zod/src/gen/zod/createUserSchema.gen.ts index 74ce9db8f..dfca03029 100644 --- a/examples/zod/src/gen/zod/createUserSchema.gen.ts +++ b/examples/zod/src/gen/zod/createUserSchema.gen.ts @@ -1,20 +1,22 @@ +import type { CreateUserErrorType, CreateUserMutationRequestType, CreateUserMutationResponseType } from '../ts/CreateUserType.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from '../../zod.ts' import { userSchema } from './userSchema.gen.ts' /** * @description successful operation */ -export const createUserErrorSchema = z.lazy(() => userSchema) +export const createUserErrorSchema = z.lazy(() => userSchema) as unknown as ToZod -export type CreateUserErrorSchema = z.infer +export type CreateUserErrorSchema = CreateUserErrorType /** * @description Created user object */ -export const createUserMutationRequestSchema = z.lazy(() => userSchema) +export const createUserMutationRequestSchema = z.lazy(() => userSchema) as unknown as ToZod -export type CreateUserMutationRequestSchema = z.infer +export type CreateUserMutationRequestSchema = CreateUserMutationRequestType -export const createUserMutationResponseSchema = z.any() +export const createUserMutationResponseSchema = z.any() as unknown as ToZod -export type CreateUserMutationResponseSchema = z.infer +export type CreateUserMutationResponseSchema = CreateUserMutationResponseType diff --git a/examples/zod/src/gen/zod/createUsersWithListInputSchema.gen.ts b/examples/zod/src/gen/zod/createUsersWithListInputSchema.gen.ts index 8ae6f163d..3df6c43ad 100644 --- a/examples/zod/src/gen/zod/createUsersWithListInputSchema.gen.ts +++ b/examples/zod/src/gen/zod/createUsersWithListInputSchema.gen.ts @@ -1,24 +1,33 @@ +import type { + CreateUsersWithListInput200Type, + CreateUsersWithListInputErrorType, + CreateUsersWithListInputMutationRequestType, + CreateUsersWithListInputMutationResponseType, +} from '../ts/CreateUsersWithListInputType.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from '../../zod.ts' import { userSchema } from './userSchema.gen.ts' /** * @description Successful operation */ -export const createUsersWithListInput200Schema = z.lazy(() => userSchema) +export const createUsersWithListInput200Schema = z.lazy(() => userSchema) as unknown as ToZod -export type CreateUsersWithListInput200Schema = z.infer +export type CreateUsersWithListInput200Schema = CreateUsersWithListInput200Type /** * @description successful operation */ -export const createUsersWithListInputErrorSchema = z.any() +export const createUsersWithListInputErrorSchema = z.any() as unknown as ToZod -export type CreateUsersWithListInputErrorSchema = z.infer +export type CreateUsersWithListInputErrorSchema = CreateUsersWithListInputErrorType -export const createUsersWithListInputMutationRequestSchema = z.array(z.lazy(() => userSchema)) +export const createUsersWithListInputMutationRequestSchema = z.array(z.lazy(() => userSchema)) as unknown as ToZod -export type CreateUsersWithListInputMutationRequestSchema = z.infer +export type CreateUsersWithListInputMutationRequestSchema = CreateUsersWithListInputMutationRequestType -export const createUsersWithListInputMutationResponseSchema = z.lazy(() => createUsersWithListInput200Schema) +export const createUsersWithListInputMutationResponseSchema = z.lazy( + () => createUsersWithListInput200Schema, +) as unknown as ToZod -export type CreateUsersWithListInputMutationResponseSchema = z.infer +export type CreateUsersWithListInputMutationResponseSchema = CreateUsersWithListInputMutationResponseType diff --git a/examples/zod/src/gen/zod/customerSchema.gen.ts b/examples/zod/src/gen/zod/customerSchema.gen.ts index a205032f8..d9ad08327 100644 --- a/examples/zod/src/gen/zod/customerSchema.gen.ts +++ b/examples/zod/src/gen/zod/customerSchema.gen.ts @@ -1,3 +1,5 @@ +import type { CustomerType } from '../ts/CustomerType.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from '../../zod.ts' import { addressSchema } from './addressSchema.gen.ts' @@ -5,6 +7,6 @@ export const customerSchema = z.object({ id: z.number().int().optional(), username: z.string().optional(), address: z.array(z.lazy(() => addressSchema)).optional(), -}) +}) as unknown as ToZod -export type CustomerSchema = z.infer +export type CustomerSchema = CustomerType diff --git a/examples/zod/src/gen/zod/deleteOrderSchema.gen.ts b/examples/zod/src/gen/zod/deleteOrderSchema.gen.ts index e3de5b5be..a80c46cab 100644 --- a/examples/zod/src/gen/zod/deleteOrderSchema.gen.ts +++ b/examples/zod/src/gen/zod/deleteOrderSchema.gen.ts @@ -1,25 +1,27 @@ +import type { DeleteOrderPathParamsType, DeleteOrder400Type, DeleteOrder404Type, DeleteOrderMutationResponseType } from '../ts/DeleteOrderType.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from '../../zod.ts' export const deleteOrderPathParamsSchema = z.object({ orderId: z.number().int().describe('ID of the order that needs to be deleted'), -}) +}) as unknown as ToZod -export type DeleteOrderPathParamsSchema = z.infer +export type DeleteOrderPathParamsSchema = DeleteOrderPathParamsType /** * @description Invalid ID supplied */ -export const deleteOrder400Schema = z.any() +export const deleteOrder400Schema = z.any() as unknown as ToZod -export type DeleteOrder400Schema = z.infer +export type DeleteOrder400Schema = DeleteOrder400Type /** * @description Order not found */ -export const deleteOrder404Schema = z.any() +export const deleteOrder404Schema = z.any() as unknown as ToZod -export type DeleteOrder404Schema = z.infer +export type DeleteOrder404Schema = DeleteOrder404Type -export const deleteOrderMutationResponseSchema = z.any() +export const deleteOrderMutationResponseSchema = z.any() as unknown as ToZod -export type DeleteOrderMutationResponseSchema = z.infer +export type DeleteOrderMutationResponseSchema = DeleteOrderMutationResponseType diff --git a/examples/zod/src/gen/zod/deletePetSchema.gen.ts b/examples/zod/src/gen/zod/deletePetSchema.gen.ts index c972f8172..fe76a206c 100644 --- a/examples/zod/src/gen/zod/deletePetSchema.gen.ts +++ b/examples/zod/src/gen/zod/deletePetSchema.gen.ts @@ -1,26 +1,28 @@ +import type { DeletePetPathParamsType, DeletePetHeaderParamsType, DeletePet400Type, DeletePetMutationResponseType } from '../ts/DeletePetType.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from '../../zod.ts' export const deletePetPathParamsSchema = z.object({ petId: z.number().int().describe('Pet id to delete'), -}) +}) as unknown as ToZod -export type DeletePetPathParamsSchema = z.infer +export type DeletePetPathParamsSchema = DeletePetPathParamsType export const deletePetHeaderParamsSchema = z .object({ api_key: z.string().optional(), }) - .optional() + .optional() as unknown as ToZod -export type DeletePetHeaderParamsSchema = z.infer +export type DeletePetHeaderParamsSchema = DeletePetHeaderParamsType /** * @description Invalid pet value */ -export const deletePet400Schema = z.any() +export const deletePet400Schema = z.any() as unknown as ToZod -export type DeletePet400Schema = z.infer +export type DeletePet400Schema = DeletePet400Type -export const deletePetMutationResponseSchema = z.any() +export const deletePetMutationResponseSchema = z.any() as unknown as ToZod -export type DeletePetMutationResponseSchema = z.infer +export type DeletePetMutationResponseSchema = DeletePetMutationResponseType diff --git a/examples/zod/src/gen/zod/deleteUserSchema.gen.ts b/examples/zod/src/gen/zod/deleteUserSchema.gen.ts index bc971fbe9..b931be4ed 100644 --- a/examples/zod/src/gen/zod/deleteUserSchema.gen.ts +++ b/examples/zod/src/gen/zod/deleteUserSchema.gen.ts @@ -1,25 +1,27 @@ +import type { DeleteUserPathParamsType, DeleteUser400Type, DeleteUser404Type, DeleteUserMutationResponseType } from '../ts/DeleteUserType.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from '../../zod.ts' export const deleteUserPathParamsSchema = z.object({ username: z.string().describe('The name that needs to be deleted'), -}) +}) as unknown as ToZod -export type DeleteUserPathParamsSchema = z.infer +export type DeleteUserPathParamsSchema = DeleteUserPathParamsType /** * @description Invalid username supplied */ -export const deleteUser400Schema = z.any() +export const deleteUser400Schema = z.any() as unknown as ToZod -export type DeleteUser400Schema = z.infer +export type DeleteUser400Schema = DeleteUser400Type /** * @description User not found */ -export const deleteUser404Schema = z.any() +export const deleteUser404Schema = z.any() as unknown as ToZod -export type DeleteUser404Schema = z.infer +export type DeleteUser404Schema = DeleteUser404Type -export const deleteUserMutationResponseSchema = z.any() +export const deleteUserMutationResponseSchema = z.any() as unknown as ToZod -export type DeleteUserMutationResponseSchema = z.infer +export type DeleteUserMutationResponseSchema = DeleteUserMutationResponseType diff --git a/examples/zod/src/gen/zod/findPetsByStatusSchema.gen.ts b/examples/zod/src/gen/zod/findPetsByStatusSchema.gen.ts index 2c2c33ba9..85b023602 100644 --- a/examples/zod/src/gen/zod/findPetsByStatusSchema.gen.ts +++ b/examples/zod/src/gen/zod/findPetsByStatusSchema.gen.ts @@ -1,3 +1,10 @@ +import type { + FindPetsByStatusQueryParamsType, + FindPetsByStatus200Type, + FindPetsByStatus400Type, + FindPetsByStatusQueryResponseType, +} from '../ts/FindPetsByStatusType.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from '../../zod.ts' import { petSchema } from './petSchema.gen.ts' @@ -5,24 +12,24 @@ export const findPetsByStatusQueryParamsSchema = z .object({ status: z.enum(['available', 'pending', 'sold']).default('available').describe('Status values that need to be considered for filter'), }) - .optional() + .optional() as unknown as ToZod -export type FindPetsByStatusQueryParamsSchema = z.infer +export type FindPetsByStatusQueryParamsSchema = FindPetsByStatusQueryParamsType /** * @description successful operation */ -export const findPetsByStatus200Schema = z.array(z.lazy(() => petSchema)) +export const findPetsByStatus200Schema = z.array(z.lazy(() => petSchema)) as unknown as ToZod -export type FindPetsByStatus200Schema = z.infer +export type FindPetsByStatus200Schema = FindPetsByStatus200Type /** * @description Invalid status value */ -export const findPetsByStatus400Schema = z.any() +export const findPetsByStatus400Schema = z.any() as unknown as ToZod -export type FindPetsByStatus400Schema = z.infer +export type FindPetsByStatus400Schema = FindPetsByStatus400Type -export const findPetsByStatusQueryResponseSchema = z.lazy(() => findPetsByStatus200Schema) +export const findPetsByStatusQueryResponseSchema = z.lazy(() => findPetsByStatus200Schema) as unknown as ToZod -export type FindPetsByStatusQueryResponseSchema = z.infer +export type FindPetsByStatusQueryResponseSchema = FindPetsByStatusQueryResponseType diff --git a/examples/zod/src/gen/zod/findPetsByTagsSchema.gen.ts b/examples/zod/src/gen/zod/findPetsByTagsSchema.gen.ts index 9752954e9..47793a606 100644 --- a/examples/zod/src/gen/zod/findPetsByTagsSchema.gen.ts +++ b/examples/zod/src/gen/zod/findPetsByTagsSchema.gen.ts @@ -1,3 +1,11 @@ +import type { + FindPetsByTagsQueryParamsType, + FindPetsByTagsHeaderParamsType, + FindPetsByTags200Type, + FindPetsByTags400Type, + FindPetsByTagsQueryResponseType, +} from '../ts/FindPetsByTagsType.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from '../../zod.ts' import { petSchema } from './petSchema.gen.ts' @@ -7,30 +15,30 @@ export const findPetsByTagsQueryParamsSchema = z page: z.string().describe('to request with required page number or pagination').optional(), pageSize: z.string().describe('to request with required page size').optional(), }) - .optional() + .optional() as unknown as ToZod -export type FindPetsByTagsQueryParamsSchema = z.infer +export type FindPetsByTagsQueryParamsSchema = FindPetsByTagsQueryParamsType export const findPetsByTagsHeaderParamsSchema = z.object({ 'X-EXAMPLE': z.enum(['ONE', 'TWO', 'THREE']).describe('Header parameters'), -}) +}) as unknown as ToZod -export type FindPetsByTagsHeaderParamsSchema = z.infer +export type FindPetsByTagsHeaderParamsSchema = FindPetsByTagsHeaderParamsType /** * @description successful operation */ -export const findPetsByTags200Schema = z.array(z.lazy(() => petSchema)) +export const findPetsByTags200Schema = z.array(z.lazy(() => petSchema)) as unknown as ToZod -export type FindPetsByTags200Schema = z.infer +export type FindPetsByTags200Schema = FindPetsByTags200Type /** * @description Invalid tag value */ -export const findPetsByTags400Schema = z.any() +export const findPetsByTags400Schema = z.any() as unknown as ToZod -export type FindPetsByTags400Schema = z.infer +export type FindPetsByTags400Schema = FindPetsByTags400Type -export const findPetsByTagsQueryResponseSchema = z.lazy(() => findPetsByTags200Schema) +export const findPetsByTagsQueryResponseSchema = z.lazy(() => findPetsByTags200Schema) as unknown as ToZod -export type FindPetsByTagsQueryResponseSchema = z.infer +export type FindPetsByTagsQueryResponseSchema = FindPetsByTagsQueryResponseType diff --git a/examples/zod/src/gen/zod/getInventorySchema.gen.ts b/examples/zod/src/gen/zod/getInventorySchema.gen.ts index e17a56675..4ef233535 100644 --- a/examples/zod/src/gen/zod/getInventorySchema.gen.ts +++ b/examples/zod/src/gen/zod/getInventorySchema.gen.ts @@ -1,12 +1,14 @@ +import type { GetInventory200Type, GetInventoryQueryResponseType } from '../ts/GetInventoryType.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from '../../zod.ts' /** * @description successful operation */ -export const getInventory200Schema = z.object({}).catchall(z.number().int()) +export const getInventory200Schema = z.object({}).catchall(z.number().int()) as unknown as ToZod -export type GetInventory200Schema = z.infer +export type GetInventory200Schema = GetInventory200Type -export const getInventoryQueryResponseSchema = z.lazy(() => getInventory200Schema) +export const getInventoryQueryResponseSchema = z.lazy(() => getInventory200Schema) as unknown as ToZod -export type GetInventoryQueryResponseSchema = z.infer +export type GetInventoryQueryResponseSchema = GetInventoryQueryResponseType diff --git a/examples/zod/src/gen/zod/getOrderByIdSchema.gen.ts b/examples/zod/src/gen/zod/getOrderByIdSchema.gen.ts index d331df23c..b11da432d 100644 --- a/examples/zod/src/gen/zod/getOrderByIdSchema.gen.ts +++ b/examples/zod/src/gen/zod/getOrderByIdSchema.gen.ts @@ -1,33 +1,41 @@ +import type { + GetOrderByIdPathParamsType, + GetOrderById200Type, + GetOrderById400Type, + GetOrderById404Type, + GetOrderByIdQueryResponseType, +} from '../ts/GetOrderByIdType.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from '../../zod.ts' import { orderSchema } from './orderSchema.gen.ts' export const getOrderByIdPathParamsSchema = z.object({ orderId: z.number().int().describe('ID of order that needs to be fetched'), -}) +}) as unknown as ToZod -export type GetOrderByIdPathParamsSchema = z.infer +export type GetOrderByIdPathParamsSchema = GetOrderByIdPathParamsType /** * @description successful operation */ -export const getOrderById200Schema = z.lazy(() => orderSchema) +export const getOrderById200Schema = z.lazy(() => orderSchema) as unknown as ToZod -export type GetOrderById200Schema = z.infer +export type GetOrderById200Schema = GetOrderById200Type /** * @description Invalid ID supplied */ -export const getOrderById400Schema = z.any() +export const getOrderById400Schema = z.any() as unknown as ToZod -export type GetOrderById400Schema = z.infer +export type GetOrderById400Schema = GetOrderById400Type /** * @description Order not found */ -export const getOrderById404Schema = z.any() +export const getOrderById404Schema = z.any() as unknown as ToZod -export type GetOrderById404Schema = z.infer +export type GetOrderById404Schema = GetOrderById404Type -export const getOrderByIdQueryResponseSchema = z.lazy(() => getOrderById200Schema) +export const getOrderByIdQueryResponseSchema = z.lazy(() => getOrderById200Schema) as unknown as ToZod -export type GetOrderByIdQueryResponseSchema = z.infer +export type GetOrderByIdQueryResponseSchema = GetOrderByIdQueryResponseType diff --git a/examples/zod/src/gen/zod/getPetByIdSchema.gen.ts b/examples/zod/src/gen/zod/getPetByIdSchema.gen.ts index 83bd7c588..07430d712 100644 --- a/examples/zod/src/gen/zod/getPetByIdSchema.gen.ts +++ b/examples/zod/src/gen/zod/getPetByIdSchema.gen.ts @@ -1,33 +1,35 @@ +import type { GetPetByIdPathParamsType, GetPetById200Type, GetPetById400Type, GetPetById404Type, GetPetByIdQueryResponseType } from '../ts/GetPetByIdType.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from '../../zod.ts' import { petSchema } from './petSchema.gen.ts' export const getPetByIdPathParamsSchema = z.object({ petId: z.number().int().describe('ID of pet to return'), -}) +}) as unknown as ToZod -export type GetPetByIdPathParamsSchema = z.infer +export type GetPetByIdPathParamsSchema = GetPetByIdPathParamsType /** * @description successful operation */ -export const getPetById200Schema = z.lazy(() => petSchema) +export const getPetById200Schema = z.lazy(() => petSchema) as unknown as ToZod -export type GetPetById200Schema = z.infer +export type GetPetById200Schema = GetPetById200Type /** * @description Invalid ID supplied */ -export const getPetById400Schema = z.any() +export const getPetById400Schema = z.any() as unknown as ToZod -export type GetPetById400Schema = z.infer +export type GetPetById400Schema = GetPetById400Type /** * @description Pet not found */ -export const getPetById404Schema = z.any() +export const getPetById404Schema = z.any() as unknown as ToZod -export type GetPetById404Schema = z.infer +export type GetPetById404Schema = GetPetById404Type -export const getPetByIdQueryResponseSchema = z.lazy(() => getPetById200Schema) +export const getPetByIdQueryResponseSchema = z.lazy(() => getPetById200Schema) as unknown as ToZod -export type GetPetByIdQueryResponseSchema = z.infer +export type GetPetByIdQueryResponseSchema = GetPetByIdQueryResponseType diff --git a/examples/zod/src/gen/zod/getUserByNameSchema.gen.ts b/examples/zod/src/gen/zod/getUserByNameSchema.gen.ts index 475c73249..1a51ee58b 100644 --- a/examples/zod/src/gen/zod/getUserByNameSchema.gen.ts +++ b/examples/zod/src/gen/zod/getUserByNameSchema.gen.ts @@ -1,33 +1,41 @@ +import type { + GetUserByNamePathParamsType, + GetUserByName200Type, + GetUserByName400Type, + GetUserByName404Type, + GetUserByNameQueryResponseType, +} from '../ts/GetUserByNameType.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from '../../zod.ts' import { userSchema } from './userSchema.gen.ts' export const getUserByNamePathParamsSchema = z.object({ username: z.string().describe('The name that needs to be fetched. Use user1 for testing. '), -}) +}) as unknown as ToZod -export type GetUserByNamePathParamsSchema = z.infer +export type GetUserByNamePathParamsSchema = GetUserByNamePathParamsType /** * @description successful operation */ -export const getUserByName200Schema = z.lazy(() => userSchema) +export const getUserByName200Schema = z.lazy(() => userSchema) as unknown as ToZod -export type GetUserByName200Schema = z.infer +export type GetUserByName200Schema = GetUserByName200Type /** * @description Invalid username supplied */ -export const getUserByName400Schema = z.any() +export const getUserByName400Schema = z.any() as unknown as ToZod -export type GetUserByName400Schema = z.infer +export type GetUserByName400Schema = GetUserByName400Type /** * @description User not found */ -export const getUserByName404Schema = z.any() +export const getUserByName404Schema = z.any() as unknown as ToZod -export type GetUserByName404Schema = z.infer +export type GetUserByName404Schema = GetUserByName404Type -export const getUserByNameQueryResponseSchema = z.lazy(() => getUserByName200Schema) +export const getUserByNameQueryResponseSchema = z.lazy(() => getUserByName200Schema) as unknown as ToZod -export type GetUserByNameQueryResponseSchema = z.infer +export type GetUserByNameQueryResponseSchema = GetUserByNameQueryResponseType diff --git a/examples/zod/src/gen/zod/loginUserSchema.gen.ts b/examples/zod/src/gen/zod/loginUserSchema.gen.ts index 94957c7e5..6d21c352e 100644 --- a/examples/zod/src/gen/zod/loginUserSchema.gen.ts +++ b/examples/zod/src/gen/zod/loginUserSchema.gen.ts @@ -1,3 +1,5 @@ +import type { LoginUserQueryParamsType, LoginUser200Type, LoginUser400Type, LoginUserQueryResponseType } from '../ts/LoginUserType.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from '../../zod.ts' export const loginUserQueryParamsSchema = z @@ -5,24 +7,24 @@ export const loginUserQueryParamsSchema = z username: z.string().describe('The user name for login').optional(), password: z.string().describe('The password for login in clear text').optional(), }) - .optional() + .optional() as unknown as ToZod -export type LoginUserQueryParamsSchema = z.infer +export type LoginUserQueryParamsSchema = LoginUserQueryParamsType /** * @description successful operation */ -export const loginUser200Schema = z.string() +export const loginUser200Schema = z.string() as unknown as ToZod -export type LoginUser200Schema = z.infer +export type LoginUser200Schema = LoginUser200Type /** * @description Invalid username/password supplied */ -export const loginUser400Schema = z.any() +export const loginUser400Schema = z.any() as unknown as ToZod -export type LoginUser400Schema = z.infer +export type LoginUser400Schema = LoginUser400Type -export const loginUserQueryResponseSchema = z.lazy(() => loginUser200Schema) +export const loginUserQueryResponseSchema = z.lazy(() => loginUser200Schema) as unknown as ToZod -export type LoginUserQueryResponseSchema = z.infer +export type LoginUserQueryResponseSchema = LoginUserQueryResponseType diff --git a/examples/zod/src/gen/zod/logoutUserSchema.gen.ts b/examples/zod/src/gen/zod/logoutUserSchema.gen.ts index 7fc577734..ca654bddf 100644 --- a/examples/zod/src/gen/zod/logoutUserSchema.gen.ts +++ b/examples/zod/src/gen/zod/logoutUserSchema.gen.ts @@ -1,12 +1,14 @@ +import type { LogoutUserErrorType, LogoutUserQueryResponseType } from '../ts/LogoutUserType.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from '../../zod.ts' /** * @description successful operation */ -export const logoutUserErrorSchema = z.any() +export const logoutUserErrorSchema = z.any() as unknown as ToZod -export type LogoutUserErrorSchema = z.infer +export type LogoutUserErrorSchema = LogoutUserErrorType -export const logoutUserQueryResponseSchema = z.any() +export const logoutUserQueryResponseSchema = z.any() as unknown as ToZod -export type LogoutUserQueryResponseSchema = z.infer +export type LogoutUserQueryResponseSchema = LogoutUserQueryResponseType diff --git a/examples/zod/src/gen/zod/orderSchema.gen.ts b/examples/zod/src/gen/zod/orderSchema.gen.ts index 387a5a5d9..c5a682eca 100644 --- a/examples/zod/src/gen/zod/orderSchema.gen.ts +++ b/examples/zod/src/gen/zod/orderSchema.gen.ts @@ -1,3 +1,5 @@ +import type { OrderType } from '../ts/OrderType.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from '../../zod.ts' export const orderSchema = z.object({ @@ -11,6 +13,6 @@ export const orderSchema = z.object({ .describe('HTTP Status') .optional(), complete: z.boolean().optional(), -}) +}) as unknown as ToZod -export type OrderSchema = z.infer +export type OrderSchema = OrderType diff --git a/examples/zod/src/gen/zod/petNotFoundSchema.gen.ts b/examples/zod/src/gen/zod/petNotFoundSchema.gen.ts index 8922eca0a..294aaa8e0 100644 --- a/examples/zod/src/gen/zod/petNotFoundSchema.gen.ts +++ b/examples/zod/src/gen/zod/petNotFoundSchema.gen.ts @@ -1,8 +1,10 @@ +import type { PetNotFoundType } from '../ts/PetNotFoundType.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from '../../zod.ts' export const petNotFoundSchema = z.object({ code: z.number().int().optional(), message: z.string().optional(), -}) +}) as unknown as ToZod -export type PetNotFoundSchema = z.infer +export type PetNotFoundSchema = PetNotFoundType diff --git a/examples/zod/src/gen/zod/petSchema.gen.ts b/examples/zod/src/gen/zod/petSchema.gen.ts index c291f32c5..c73866fec 100644 --- a/examples/zod/src/gen/zod/petSchema.gen.ts +++ b/examples/zod/src/gen/zod/petSchema.gen.ts @@ -1,3 +1,5 @@ +import type { PetType } from '../ts/PetType.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from '../../zod.ts' import { categorySchema } from './categorySchema.gen.ts' import { tagSchema } from './tagSchema.gen.ts' @@ -13,6 +15,6 @@ export const petSchema = z.object({ photoUrls: z.array(z.string()), tags: z.array(z.lazy(() => tagSchema)).optional(), status: z.enum(['available', 'pending', 'sold']).describe('pet status in the store').optional(), -}) +}) as unknown as ToZod -export type PetSchema = z.infer +export type PetSchema = PetType diff --git a/examples/zod/src/gen/zod/placeOrderPatchSchema.gen.ts b/examples/zod/src/gen/zod/placeOrderPatchSchema.gen.ts index dfcb5ce6e..1cc3dcdb2 100644 --- a/examples/zod/src/gen/zod/placeOrderPatchSchema.gen.ts +++ b/examples/zod/src/gen/zod/placeOrderPatchSchema.gen.ts @@ -1,24 +1,31 @@ +import type { + PlaceOrderPatch200Type, + PlaceOrderPatch405Type, + PlaceOrderPatchMutationRequestType, + PlaceOrderPatchMutationResponseType, +} from '../ts/PlaceOrderPatchType.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from '../../zod.ts' import { orderSchema } from './orderSchema.gen.ts' /** * @description successful operation */ -export const placeOrderPatch200Schema = z.lazy(() => orderSchema) +export const placeOrderPatch200Schema = z.lazy(() => orderSchema) as unknown as ToZod -export type PlaceOrderPatch200Schema = z.infer +export type PlaceOrderPatch200Schema = PlaceOrderPatch200Type /** * @description Invalid input */ -export const placeOrderPatch405Schema = z.any() +export const placeOrderPatch405Schema = z.any() as unknown as ToZod -export type PlaceOrderPatch405Schema = z.infer +export type PlaceOrderPatch405Schema = PlaceOrderPatch405Type -export const placeOrderPatchMutationRequestSchema = z.lazy(() => orderSchema) +export const placeOrderPatchMutationRequestSchema = z.lazy(() => orderSchema) as unknown as ToZod -export type PlaceOrderPatchMutationRequestSchema = z.infer +export type PlaceOrderPatchMutationRequestSchema = PlaceOrderPatchMutationRequestType -export const placeOrderPatchMutationResponseSchema = z.lazy(() => placeOrderPatch200Schema) +export const placeOrderPatchMutationResponseSchema = z.lazy(() => placeOrderPatch200Schema) as unknown as ToZod -export type PlaceOrderPatchMutationResponseSchema = z.infer +export type PlaceOrderPatchMutationResponseSchema = PlaceOrderPatchMutationResponseType diff --git a/examples/zod/src/gen/zod/placeOrderSchema.gen.ts b/examples/zod/src/gen/zod/placeOrderSchema.gen.ts index 18bb98f99..c11b5feca 100644 --- a/examples/zod/src/gen/zod/placeOrderSchema.gen.ts +++ b/examples/zod/src/gen/zod/placeOrderSchema.gen.ts @@ -1,24 +1,26 @@ +import type { PlaceOrder200Type, PlaceOrder405Type, PlaceOrderMutationRequestType, PlaceOrderMutationResponseType } from '../ts/PlaceOrderType.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from '../../zod.ts' import { orderSchema } from './orderSchema.gen.ts' /** * @description successful operation */ -export const placeOrder200Schema = z.lazy(() => orderSchema) +export const placeOrder200Schema = z.lazy(() => orderSchema) as unknown as ToZod -export type PlaceOrder200Schema = z.infer +export type PlaceOrder200Schema = PlaceOrder200Type /** * @description Invalid input */ -export const placeOrder405Schema = z.any() +export const placeOrder405Schema = z.any() as unknown as ToZod -export type PlaceOrder405Schema = z.infer +export type PlaceOrder405Schema = PlaceOrder405Type -export const placeOrderMutationRequestSchema = z.lazy(() => orderSchema) +export const placeOrderMutationRequestSchema = z.lazy(() => orderSchema) as unknown as ToZod -export type PlaceOrderMutationRequestSchema = z.infer +export type PlaceOrderMutationRequestSchema = PlaceOrderMutationRequestType -export const placeOrderMutationResponseSchema = z.lazy(() => placeOrder200Schema) +export const placeOrderMutationResponseSchema = z.lazy(() => placeOrder200Schema) as unknown as ToZod -export type PlaceOrderMutationResponseSchema = z.infer +export type PlaceOrderMutationResponseSchema = PlaceOrderMutationResponseType diff --git a/examples/zod/src/gen/zod/tagSchema.gen.ts b/examples/zod/src/gen/zod/tagSchema.gen.ts index 1c3660be0..22d278b0c 100644 --- a/examples/zod/src/gen/zod/tagSchema.gen.ts +++ b/examples/zod/src/gen/zod/tagSchema.gen.ts @@ -1,8 +1,10 @@ +import type { TagType } from '../ts/TagType.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from '../../zod.ts' export const tagSchema = z.object({ id: z.number().int().optional(), name: z.string().optional(), -}) +}) as unknown as ToZod -export type TagSchema = z.infer +export type TagSchema = TagType diff --git a/examples/zod/src/gen/zod/updatePetSchema.gen.ts b/examples/zod/src/gen/zod/updatePetSchema.gen.ts index 135af1f52..57875aef6 100644 --- a/examples/zod/src/gen/zod/updatePetSchema.gen.ts +++ b/examples/zod/src/gen/zod/updatePetSchema.gen.ts @@ -1,41 +1,50 @@ +import type { + UpdatePet200Type, + UpdatePet400Type, + UpdatePet404Type, + UpdatePet405Type, + UpdatePetMutationRequestType, + UpdatePetMutationResponseType, +} from '../ts/UpdatePetType.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from '../../zod.ts' import { petSchema } from './petSchema.gen.ts' /** * @description Successful operation */ -export const updatePet200Schema = z.lazy(() => petSchema) +export const updatePet200Schema = z.lazy(() => petSchema) as unknown as ToZod -export type UpdatePet200Schema = z.infer +export type UpdatePet200Schema = UpdatePet200Type /** * @description Invalid ID supplied */ -export const updatePet400Schema = z.any() +export const updatePet400Schema = z.any() as unknown as ToZod -export type UpdatePet400Schema = z.infer +export type UpdatePet400Schema = UpdatePet400Type /** * @description Pet not found */ -export const updatePet404Schema = z.any() +export const updatePet404Schema = z.any() as unknown as ToZod -export type UpdatePet404Schema = z.infer +export type UpdatePet404Schema = UpdatePet404Type /** * @description Validation exception */ -export const updatePet405Schema = z.any() +export const updatePet405Schema = z.any() as unknown as ToZod -export type UpdatePet405Schema = z.infer +export type UpdatePet405Schema = UpdatePet405Type /** * @description Update an existent pet in the store */ -export const updatePetMutationRequestSchema = z.lazy(() => petSchema) +export const updatePetMutationRequestSchema = z.lazy(() => petSchema) as unknown as ToZod -export type UpdatePetMutationRequestSchema = z.infer +export type UpdatePetMutationRequestSchema = UpdatePetMutationRequestType -export const updatePetMutationResponseSchema = z.lazy(() => updatePet200Schema) +export const updatePetMutationResponseSchema = z.lazy(() => updatePet200Schema) as unknown as ToZod -export type UpdatePetMutationResponseSchema = z.infer +export type UpdatePetMutationResponseSchema = UpdatePetMutationResponseType diff --git a/examples/zod/src/gen/zod/updatePetWithFormSchema.gen.ts b/examples/zod/src/gen/zod/updatePetWithFormSchema.gen.ts index e00498052..14aba307f 100644 --- a/examples/zod/src/gen/zod/updatePetWithFormSchema.gen.ts +++ b/examples/zod/src/gen/zod/updatePetWithFormSchema.gen.ts @@ -1,27 +1,34 @@ +import type { + UpdatePetWithFormPathParamsType, + UpdatePetWithFormQueryParamsType, + UpdatePetWithForm405Type, + UpdatePetWithFormMutationResponseType, +} from '../ts/UpdatePetWithFormType.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from '../../zod.ts' export const updatePetWithFormPathParamsSchema = z.object({ petId: z.number().int().describe('ID of pet that needs to be updated'), -}) +}) as unknown as ToZod -export type UpdatePetWithFormPathParamsSchema = z.infer +export type UpdatePetWithFormPathParamsSchema = UpdatePetWithFormPathParamsType export const updatePetWithFormQueryParamsSchema = z .object({ name: z.string().describe('Name of pet that needs to be updated').optional(), status: z.string().describe('Status of pet that needs to be updated').optional(), }) - .optional() + .optional() as unknown as ToZod -export type UpdatePetWithFormQueryParamsSchema = z.infer +export type UpdatePetWithFormQueryParamsSchema = UpdatePetWithFormQueryParamsType /** * @description Invalid input */ -export const updatePetWithForm405Schema = z.any() +export const updatePetWithForm405Schema = z.any() as unknown as ToZod -export type UpdatePetWithForm405Schema = z.infer +export type UpdatePetWithForm405Schema = UpdatePetWithForm405Type -export const updatePetWithFormMutationResponseSchema = z.any() +export const updatePetWithFormMutationResponseSchema = z.any() as unknown as ToZod -export type UpdatePetWithFormMutationResponseSchema = z.infer +export type UpdatePetWithFormMutationResponseSchema = UpdatePetWithFormMutationResponseType diff --git a/examples/zod/src/gen/zod/updateUserSchema.gen.ts b/examples/zod/src/gen/zod/updateUserSchema.gen.ts index 214043dda..e9887eb96 100644 --- a/examples/zod/src/gen/zod/updateUserSchema.gen.ts +++ b/examples/zod/src/gen/zod/updateUserSchema.gen.ts @@ -1,26 +1,28 @@ +import type { UpdateUserPathParamsType, UpdateUserErrorType, UpdateUserMutationRequestType, UpdateUserMutationResponseType } from '../ts/UpdateUserType.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from '../../zod.ts' import { userSchema } from './userSchema.gen.ts' export const updateUserPathParamsSchema = z.object({ username: z.string().describe('name that need to be deleted'), -}) +}) as unknown as ToZod -export type UpdateUserPathParamsSchema = z.infer +export type UpdateUserPathParamsSchema = UpdateUserPathParamsType /** * @description successful operation */ -export const updateUserErrorSchema = z.any() +export const updateUserErrorSchema = z.any() as unknown as ToZod -export type UpdateUserErrorSchema = z.infer +export type UpdateUserErrorSchema = UpdateUserErrorType /** * @description Update an existent user in the store */ -export const updateUserMutationRequestSchema = z.lazy(() => userSchema) +export const updateUserMutationRequestSchema = z.lazy(() => userSchema) as unknown as ToZod -export type UpdateUserMutationRequestSchema = z.infer +export type UpdateUserMutationRequestSchema = UpdateUserMutationRequestType -export const updateUserMutationResponseSchema = z.any() +export const updateUserMutationResponseSchema = z.any() as unknown as ToZod -export type UpdateUserMutationResponseSchema = z.infer +export type UpdateUserMutationResponseSchema = UpdateUserMutationResponseType diff --git a/examples/zod/src/gen/zod/uploadFileSchema.gen.ts b/examples/zod/src/gen/zod/uploadFileSchema.gen.ts index 7a81f8d9b..3dd54a4f6 100644 --- a/examples/zod/src/gen/zod/uploadFileSchema.gen.ts +++ b/examples/zod/src/gen/zod/uploadFileSchema.gen.ts @@ -1,31 +1,39 @@ +import type { + UploadFilePathParamsType, + UploadFileQueryParamsType, + UploadFile200Type, + UploadFileMutationRequestType, + UploadFileMutationResponseType, +} from '../ts/UploadFileType.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from '../../zod.ts' import { apiResponseSchema } from './apiResponseSchema.gen.ts' export const uploadFilePathParamsSchema = z.object({ petId: z.number().int().describe('ID of pet to update'), -}) +}) as unknown as ToZod -export type UploadFilePathParamsSchema = z.infer +export type UploadFilePathParamsSchema = UploadFilePathParamsType export const uploadFileQueryParamsSchema = z .object({ additionalMetadata: z.string().describe('Additional Metadata').optional(), }) - .optional() + .optional() as unknown as ToZod -export type UploadFileQueryParamsSchema = z.infer +export type UploadFileQueryParamsSchema = UploadFileQueryParamsType /** * @description successful operation */ -export const uploadFile200Schema = z.lazy(() => apiResponseSchema) +export const uploadFile200Schema = z.lazy(() => apiResponseSchema) as unknown as ToZod -export type UploadFile200Schema = z.infer +export type UploadFile200Schema = UploadFile200Type -export const uploadFileMutationRequestSchema = z.instanceof(File) +export const uploadFileMutationRequestSchema = z.instanceof(File) as unknown as ToZod -export type UploadFileMutationRequestSchema = z.infer +export type UploadFileMutationRequestSchema = UploadFileMutationRequestType -export const uploadFileMutationResponseSchema = z.lazy(() => uploadFile200Schema) +export const uploadFileMutationResponseSchema = z.lazy(() => uploadFile200Schema) as unknown as ToZod -export type UploadFileMutationResponseSchema = z.infer +export type UploadFileMutationResponseSchema = UploadFileMutationResponseType diff --git a/examples/zod/src/gen/zod/userArraySchema.gen.ts b/examples/zod/src/gen/zod/userArraySchema.gen.ts index dbabeedbc..3a390912c 100644 --- a/examples/zod/src/gen/zod/userArraySchema.gen.ts +++ b/examples/zod/src/gen/zod/userArraySchema.gen.ts @@ -1,6 +1,8 @@ +import type { UserArrayType } from '../ts/UserArrayType.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from '../../zod.ts' import { userSchema } from './userSchema.gen.ts' -export const userArraySchema = z.array(z.lazy(() => userSchema)) +export const userArraySchema = z.array(z.lazy(() => userSchema)) as unknown as ToZod -export type UserArraySchema = z.infer +export type UserArraySchema = UserArrayType diff --git a/examples/zod/src/gen/zod/userSchema.gen.ts b/examples/zod/src/gen/zod/userSchema.gen.ts index 1cdbc7972..ccb5fed9d 100644 --- a/examples/zod/src/gen/zod/userSchema.gen.ts +++ b/examples/zod/src/gen/zod/userSchema.gen.ts @@ -1,3 +1,5 @@ +import type { UserType } from '../ts/UserType.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from '../../zod.ts' export const userSchema = z.object({ @@ -9,6 +11,6 @@ export const userSchema = z.object({ password: z.string().optional(), phone: z.string().optional(), userStatus: z.number().int().describe('User Status').optional(), -}) +}) as unknown as ToZod -export type UserSchema = z.infer +export type UserSchema = UserType diff --git a/examples/zod/src/gen/zodClients.ts b/examples/zod/src/gen/zodClients.ts index dbc529146..ad0cc9776 100644 --- a/examples/zod/src/gen/zodClients.ts +++ b/examples/zod/src/gen/zodClients.ts @@ -12,7 +12,7 @@ import { placeOrderPatchMutationResponseSchema } from './zod/placeOrderPatchSche import { placeOrderMutationResponseSchema } from './zod/placeOrderSchema.gen.ts' export function getGetInventoryUrl() { - return '/store/inventory' + return '/store/inventory' as const } /** @@ -30,7 +30,7 @@ export async function getInventory(config: Partial = {}) { } export function getPlaceOrderUrl() { - return '/store/order' + return '/store/order' as const } /** @@ -49,7 +49,7 @@ export async function placeOrder(data?: PlaceOrderMutationRequestType, config: P } export function getPlaceOrderPatchUrl() { - return '/store/order' + return '/store/order' as const } /** @@ -68,7 +68,7 @@ export async function placeOrderPatch(data?: PlaceOrderPatchMutationRequestType, } export function getGetOrderByIdUrl({ orderId }: { orderId: GetOrderByIdPathParamsType['orderId'] }) { - return `/store/order/${orderId}` + return `/store/order/${orderId}` as const } /** @@ -86,7 +86,7 @@ export async function getOrderById({ orderId }: { orderId: GetOrderByIdPathParam } export function getDeleteOrderUrl({ orderId }: { orderId: DeleteOrderPathParamsType['orderId'] }) { - return `/store/order/${orderId}` + return `/store/order/${orderId}` as const } /** diff --git a/packages/core/src/utils/URLPath.test.ts b/packages/core/src/utils/URLPath.test.ts index 72ab2a8dc..3b58038e9 100644 --- a/packages/core/src/utils/URLPath.test.ts +++ b/packages/core/src/utils/URLPath.test.ts @@ -10,7 +10,7 @@ describe('URLPath', () => { }) test('if templateStrings returns correct format with replacer', () => { - expect(simplePath.toTemplateString({replacer: (item) => `unref(${item})`})).toBe('`/user/${unref(userID)}`') + expect(simplePath.toTemplateString({ replacer: (item) => `unref(${item})` })).toBe('`/user/${unref(userID)}`') expect(simplePath.template).toBe('`/user/${userID}`') }) diff --git a/packages/plugin-client/src/clients/fetch.ts b/packages/plugin-client/src/clients/fetch.ts index 8e6796721..4ed0bf467 100644 --- a/packages/plugin-client/src/clients/fetch.ts +++ b/packages/plugin-client/src/clients/fetch.ts @@ -39,10 +39,10 @@ export const fetchClient = async headers: config.headers, }) - const data = (await response.json()) as TData + const data = [204, 205, 304].includes(response.status) || !response.body ? {} : await response.json() return { - data, + data: data as TData, status: response.status, statusText: response.statusText, headers: response.headers as Headers, diff --git a/packages/plugin-zod/src/components/Zod.tsx b/packages/plugin-zod/src/components/Zod.tsx index cbf40f824..968e777f1 100644 --- a/packages/plugin-zod/src/components/Zod.tsx +++ b/packages/plugin-zod/src/components/Zod.tsx @@ -47,7 +47,11 @@ export function Zod({ name, typeName, tree, inferTypeName, mapper, coercion, key comments: [description ? `@description ${transformers.jsStringEscape(description)}` : undefined].filter(Boolean), }} > - {[output, keysToOmit?.length ? `${suffix}(z.object({ ${keysToOmit.map((key) => `${key}: z.never()`).join(',')} }))` : undefined] + {[ + output, + keysToOmit?.length ? `${suffix}(z.object({ ${keysToOmit.map((key) => `${key}: z.never()`).join(',')} }))` : undefined, + typeName ? `as unknown as ToZod<${typeName}>` : undefined, + ] .filter(Boolean) .join('') || 'z.undefined()'} diff --git a/packages/plugin-zod/src/generators/__snapshots__/optionalPetTyped.ts b/packages/plugin-zod/src/generators/__snapshots__/optionalPetTyped.ts index 6877cf862..b80d30f1d 100644 --- a/packages/plugin-zod/src/generators/__snapshots__/optionalPetTyped.ts +++ b/packages/plugin-zod/src/generators/__snapshots__/optionalPetTyped.ts @@ -5,4 +5,4 @@ export const optionalPet = z.object({ id: z.number().int().optional(), name: z.string().optional(), tag: z.string().optional(), -} satisfies ToZod) +}) as unknown as ToZod diff --git a/packages/plugin-zod/src/generators/__snapshots__/pets.ts b/packages/plugin-zod/src/generators/__snapshots__/pets.ts index bdbd7a01e..b75355bd0 100644 --- a/packages/plugin-zod/src/generators/__snapshots__/pets.ts +++ b/packages/plugin-zod/src/generators/__snapshots__/pets.ts @@ -6,5 +6,5 @@ export const pets = z.array( id: z.number().int(), name: z.string(), tag: z.string().optional(), - } satisfies ToZod), -) + }), +) as unknown as ToZod diff --git a/packages/plugin-zod/src/parser.ts b/packages/plugin-zod/src/parser.ts index 3d7f8afe9..2a8e7bdb8 100644 --- a/packages/plugin-zod/src/parser.ts +++ b/packages/plugin-zod/src/parser.ts @@ -20,12 +20,7 @@ const zodKeywordMapper = { .filter(Boolean) .join('') }, - object: (value?: string, typeName?: string) => { - if (typeName) { - return `z.object({ - ${value} - } satisfies ToZod<${typeName}>)` - } + object: (value?: string) => { return `z.object({ ${value} })` @@ -117,7 +112,13 @@ const zodKeywordMapper = { phone: undefined, readOnly: undefined, writeOnly: undefined, - ref: (value?: string) => (value ? `z.lazy(() => ${value})` : undefined), + ref: (value?: string) => { + if (!value) { + return undefined + } + + return `z.lazy(() => ${value})` + }, blob: () => 'z.instanceof(File)', deprecated: undefined, example: undefined, @@ -299,7 +300,7 @@ export function parse({ parent, current, siblings }: SchemaTree, options: Parser : undefined const text = [ - zodKeywordMapper.object(properties, options.typeName), + zodKeywordMapper.object(properties), current.args?.strict ? zodKeywordMapper.strict() : undefined, additionalProperties ? zodKeywordMapper.catchall(additionalProperties) : undefined, ].filter(Boolean) diff --git a/packages/plugin-zod/src/utils/ToZod.ts b/packages/plugin-zod/src/utils/ToZod.ts index 6420a15de..fcea7c6c9 100644 --- a/packages/plugin-zod/src/utils/ToZod.ts +++ b/packages/plugin-zod/src/utils/ToZod.ts @@ -1,28 +1,60 @@ -import type { ZodArray, ZodDefault, ZodEffects, ZodNullable, ZodOptional, ZodType } from 'zod' - -type IsNullable = Extract extends never ? false : true -type IsOptional = Extract extends never ? false : true - -type ZodWithEffects = T | ZodType | ZodDefault> | ZodEffects, any, any> - /** * See https://github.com/colinhacks/tozod/blob/master/src/index.ts * Adapted based on https://github.com/colinhacks/zod/issues/372 */ -export type ToZod = T extends any[] - ? ZodArray> - : T extends Record // object - ? { - [K in keyof T]-?: T[K] extends any[] ? ZodArray> : ToZodSchemaPrimitive - } - : ZodWithEffects -type ToZodSchemaPrimitive = IsNullable extends true - ? IsOptional extends true - ? - | ZodWithEffects, undefined>>>>> - | ZodWithEffects, undefined>>>>> - : ZodWithEffects>>> - : IsOptional extends true - ? ZodWithEffects>>> | ZodWithEffects>>> - : ZodWithEffects +import type { z } from 'zod' + +type isAny = [any extends T ? 'true' : 'false'] extends ['true'] ? true : false +type nonoptional = T extends undefined ? never : T +type nonnullable = T extends null ? never : T +type equals = [X] extends [Y] ? ([Y] extends [X] ? true : false) : false + +type zodKey = isAny extends true + ? 'any' + : equals extends true //[T] extends [booleanUtil.Type] + ? 'boolean' + : [undefined] extends [T] + ? 'optional' + : [null] extends [T] + ? 'nullable' + : T extends any[] + ? 'array' + : equals extends true + ? 'string' + : equals extends true //[T] extends [bigintUtil.Type] + ? 'bigint' + : equals extends true //[T] extends [numberUtil.Type] + ? 'number' + : equals extends true //[T] extends [dateUtil.Type] + ? 'date' + : T extends { [k: string]: any } //[T] extends [structUtil.Type] + ? 'object' + : 'rest' + +export type ToZod = { + any: z.ZodAny + optional: z.ZodOptional>> + nullable: z.ZodNullable>> + array: T extends Array ? z.ZodArray> : never + string: z.ZodString + bigint: z.ZodBigInt + number: z.ZodNumber + boolean: z.ZodBoolean + date: z.ZodDate + + object: z.ZodObject< + { + [k in keyof T]: Extract + }, + 'passthrough', + z.ZodTypeAny, + T + > + rest: z.ZodType +}[zodKey] + +export type ZodShape = { + // Require all the keys from T + [key in keyof T]-?: ToZod +} diff --git a/packages/plugin-zod/src/utils/index.ts b/packages/plugin-zod/src/utils/index.ts index e7d850960..a696db076 100644 --- a/packages/plugin-zod/src/utils/index.ts +++ b/packages/plugin-zod/src/utils/index.ts @@ -1 +1 @@ -export type { ToZod } from './ToZod.ts' +export type { ToZod, ZodShape } from './ToZod.ts'