Skip to content

Commit

Permalink
Merge pull request #1505 from kubb-labs/fix/1504-zod-typed
Browse files Browse the repository at this point in the history
fix: use of `as ToZod` instead of `satisfies ToZod`
  • Loading branch information
stijnvanhulle authored Jan 9, 2025
2 parents 7d2fbc0 + 4f571fa commit de525b6
Show file tree
Hide file tree
Showing 123 changed files with 573 additions and 387 deletions.
5 changes: 5 additions & 0 deletions .changeset/lazy-grapes-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kubb/plugin-zod": patch
---

use of `as ToZod` instead of `satisfies ToZod`
5 changes: 5 additions & 0 deletions .changeset/rotten-sloths-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kubb/plugin-client": patch
---

if client receives no body (no content) then it throws JSON parsing error
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/src/gen/zod/addPetRequestSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AddPetRequest>)
}) as unknown as ToZod<AddPetRequest>

export type AddPetRequestSchema = AddPetRequest
2 changes: 1 addition & 1 deletion examples/advanced/src/gen/zod/addressSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export const addressSchema = z.object({
city: z.string().optional(),
state: z.string().optional(),
zip: z.string().optional(),
} satisfies ToZod<Address>)
}) as unknown as ToZod<Address>

export type AddressSchema = Address
2 changes: 1 addition & 1 deletion examples/advanced/src/gen/zod/apiResponseSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ export const apiResponseSchema = z.object({
code: z.number().int().optional(),
type: z.string().optional(),
message: z.string().optional(),
} satisfies ToZod<ApiResponse>)
}) as unknown as ToZod<ApiResponse>

export type ApiResponseSchema = ApiResponse
2 changes: 1 addition & 1 deletion examples/advanced/src/gen/zod/categorySchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import { z } from 'zod'
export const categorySchema = z.object({
id: z.number().int().optional(),
name: z.string().optional(),
} satisfies ToZod<Category>)
}) as unknown as ToZod<Category>

export type CategorySchema = Category
2 changes: 1 addition & 1 deletion examples/advanced/src/gen/zod/customerSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Customer>)
}) as unknown as ToZod<Customer>

export type CustomerSchema = Customer
2 changes: 1 addition & 1 deletion examples/advanced/src/gen/zod/orderSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export const orderSchema = z.object({
.describe('HTTP Status')
.optional(),
complete: z.boolean().optional(),
} satisfies ToZod<Order>)
}) as unknown as ToZod<Order>

export type OrderSchema = Order
8 changes: 4 additions & 4 deletions examples/advanced/src/gen/zod/petController/addPetSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AddPet200>

export type AddPet200Schema = AddPet200

Expand All @@ -17,17 +17,17 @@ export type AddPet200Schema = AddPet200
export const addPet405Schema = z.object({
code: z.number().int().optional(),
message: z.string().optional(),
} satisfies ToZod<AddPet405>)
}) as unknown as ToZod<AddPet405>

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<AddPetMutationRequest>

export type AddPetMutationRequestSchema = AddPetMutationRequest

export const addPetMutationResponseSchema = z.lazy(() => addPet200Schema)
export const addPetMutationResponseSchema = z.lazy(() => addPet200Schema) as unknown as ToZod<AddPetMutationResponse>

export type AddPetMutationResponseSchema = AddPetMutationResponse
10 changes: 5 additions & 5 deletions examples/advanced/src/gen/zod/petController/deletePetSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ import { z } from 'zod'

export const deletePetPathParamsSchema = z.object({
petId: z.number().int().describe('Pet id to delete'),
} satisfies ToZod<DeletePetPathParams>)
}) as unknown as ToZod<DeletePetPathParams>

export type DeletePetPathParamsSchema = DeletePetPathParams

export const deletePetHeaderParamsSchema = z
.object({
api_key: z.string().optional(),
} satisfies ToZod<DeletePetHeaderParams>)
.optional()
})
.optional() as unknown as ToZod<DeletePetHeaderParams>

export type DeletePetHeaderParamsSchema = DeletePetHeaderParams

/**
* @description Invalid pet value
*/
export const deletePet400Schema = z.any()
export const deletePet400Schema = z.any() as unknown as ToZod<DeletePet400>

export type DeletePet400Schema = DeletePet400

export const deletePetMutationResponseSchema = z.any()
export const deletePetMutationResponseSchema = z.any() as unknown as ToZod<DeletePetMutationResponse>

export type DeletePetMutationResponseSchema = DeletePetMutationResponse
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { z } from 'zod'

export const findPetsByStatusPathParamsSchema = z.object({
step_id: z.string(),
} satisfies ToZod<FindPetsByStatusPathParams>)
}) as unknown as ToZod<FindPetsByStatusPathParams>

export type FindPetsByStatusPathParamsSchema = FindPetsByStatusPathParams

Expand All @@ -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<FindPetsByStatus200>

export type FindPetsByStatus200Schema = FindPetsByStatus200

/**
* @description Invalid status value
*/
export const findPetsByStatus400Schema = z.any()
export const findPetsByStatus400Schema = z.any() as unknown as ToZod<FindPetsByStatus400>

export type FindPetsByStatus400Schema = FindPetsByStatus400

export const findPetsByStatusQueryResponseSchema = z.lazy(() => findPetsByStatus200Schema)
export const findPetsByStatusQueryResponseSchema = z.lazy(() => findPetsByStatus200Schema) as unknown as ToZod<FindPetsByStatusQueryResponse>

export type FindPetsByStatusQueryResponseSchema = FindPetsByStatusQueryResponse
Original file line number Diff line number Diff line change
Expand Up @@ -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<FindPetsByTagsQueryParams>)
.optional()
})
.optional() as unknown as ToZod<FindPetsByTagsQueryParams>

export type FindPetsByTagsQueryParamsSchema = FindPetsByTagsQueryParams

export const findPetsByTagsHeaderParamsSchema = z.object({
'X-EXAMPLE': z.enum(['ONE', 'TWO', 'THREE']).describe('Header parameters'),
} satisfies ToZod<FindPetsByTagsHeaderParams>)
}) as unknown as ToZod<FindPetsByTagsHeaderParams>

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<FindPetsByTags200>

export type FindPetsByTags200Schema = FindPetsByTags200

/**
* @description Invalid tag value
*/
export const findPetsByTags400Schema = z.any()
export const findPetsByTags400Schema = z.any() as unknown as ToZod<FindPetsByTags400>

export type FindPetsByTags400Schema = FindPetsByTags400

export const findPetsByTagsQueryResponseSchema = z.lazy(() => findPetsByTags200Schema)
export const findPetsByTagsQueryResponseSchema = z.lazy(() => findPetsByTags200Schema) as unknown as ToZod<FindPetsByTagsQueryResponse>

export type FindPetsByTagsQueryResponseSchema = FindPetsByTagsQueryResponse
10 changes: 5 additions & 5 deletions examples/advanced/src/gen/zod/petController/getPetByIdSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<GetPetByIdPathParams>)
}) as unknown as ToZod<GetPetByIdPathParams>

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<GetPetById200>

export type GetPetById200Schema = GetPetById200

/**
* @description Invalid ID supplied
*/
export const getPetById400Schema = z.any()
export const getPetById400Schema = z.any() as unknown as ToZod<GetPetById400>

export type GetPetById400Schema = GetPetById400

/**
* @description Pet not found
*/
export const getPetById404Schema = z.any()
export const getPetById404Schema = z.any() as unknown as ToZod<GetPetById404>

export type GetPetById404Schema = GetPetById404

export const getPetByIdQueryResponseSchema = z.lazy(() => getPetById200Schema)
export const getPetByIdQueryResponseSchema = z.lazy(() => getPetById200Schema) as unknown as ToZod<GetPetByIdQueryResponse>

export type GetPetByIdQueryResponseSchema = GetPetByIdQueryResponse
Loading

0 comments on commit de525b6

Please sign in to comment.