@kubb/plugin-client
Version:
API client generator plugin for Kubb, creating type-safe HTTP clients (Axios, Fetch) from OpenAPI specifications for making API requests.
187 lines (176 loc) • 6.09 kB
text/typescript
/**
* Generated by Kubb (https://kubb.dev/).
* Do not edit manually.
*/
import type { RequestConfig, ResponseErrorConfig } from './test/.kubb/fetch'
import type {
UpdatePetMutationRequest,
UpdatePetMutationResponse,
UpdatePet400,
UpdatePet404,
UpdatePet405,
AddPetMutationRequest,
AddPetMutationResponse,
AddPet405,
FindPetsByStatusQueryResponse,
FindPetsByStatusQueryParams,
FindPetsByStatus400,
FindPetsByTagsQueryResponse,
FindPetsByTagsQueryParams,
FindPetsByTags400,
GetPetByIdQueryResponse,
GetPetByIdPathParams,
GetPetById400,
GetPetById404,
UpdatePetWithFormMutationResponse,
UpdatePetWithFormPathParams,
UpdatePetWithFormQueryParams,
UpdatePetWithForm405,
DeletePetMutationResponse,
DeletePetPathParams,
DeletePetHeaderParams,
DeletePet400,
UploadFileMutationRequest,
UploadFileMutationResponse,
UploadFilePathParams,
UploadFileQueryParams,
} from './findByTags'
import { buildFormData } from './test/.kubb/config'
import { fetch } from './test/.kubb/fetch'
export class Pet {
#client: typeof fetch
constructor(config: Partial<RequestConfig> & { client?: typeof fetch } = {}) {
this.#client = config.client || fetch
}
/**
* @description Update an existing pet by Id
* @summary Update an existing pet
* {@link /pet}
*/
async updatePet(data: UpdatePetMutationRequest, config: Partial<RequestConfig<UpdatePetMutationRequest>> & { client?: typeof fetch } = {}) {
const { client: request = this.#client, ...requestConfig } = config
const requestData = data
const res = await request<UpdatePetMutationResponse, ResponseErrorConfig<UpdatePet400 | UpdatePet404 | UpdatePet405>, UpdatePetMutationRequest>({
method: 'PUT',
url: `/pet`,
data: requestData,
...requestConfig,
})
return res.data
}
/**
* @description Add a new pet to the store
* @summary Add a new pet to the store
* {@link /pet}
*/
async addPet(data: AddPetMutationRequest, config: Partial<RequestConfig<AddPetMutationRequest>> & { client?: typeof fetch } = {}) {
const { client: request = this.#client, ...requestConfig } = config
const requestData = data
const res = await request<AddPetMutationResponse, ResponseErrorConfig<AddPet405>, AddPetMutationRequest>({
method: 'POST',
url: `/pet`,
data: requestData,
...requestConfig,
})
return res.data
}
/**
* @description Multiple status values can be provided with comma separated strings
* @summary Finds Pets by status
* {@link /pet/findByStatus}
*/
async findPetsByStatus(params?: FindPetsByStatusQueryParams, config: Partial<RequestConfig> & { client?: typeof fetch } = {}) {
const { client: request = this.#client, ...requestConfig } = config
const res = await request<FindPetsByStatusQueryResponse, ResponseErrorConfig<FindPetsByStatus400>, unknown>({
method: 'GET',
url: `/pet/findByStatus`,
params,
...requestConfig,
})
return res.data
}
/**
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
* @summary Finds Pets by tags
* {@link /pet/findByTags}
*/
async findPetsByTags(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> & { client?: typeof fetch } = {}) {
const { client: request = this.#client, ...requestConfig } = config
const res = await request<FindPetsByTagsQueryResponse, ResponseErrorConfig<FindPetsByTags400>, unknown>({
method: 'GET',
url: `/pet/findByTags`,
params,
...requestConfig,
})
return res.data
}
/**
* @description Returns a single pet
* @summary Find pet by ID
* {@link /pet/:petId}
*/
async getPetById(petId: GetPetByIdPathParams['petId'], config: Partial<RequestConfig> & { client?: typeof fetch } = {}) {
const { client: request = this.#client, ...requestConfig } = config
const res = await request<GetPetByIdQueryResponse, ResponseErrorConfig<GetPetById400 | GetPetById404>, unknown>({
method: 'GET',
url: `/pet/${petId}`,
...requestConfig,
})
return res.data
}
/**
* @summary Updates a pet in the store with form data
* {@link /pet/:petId}
*/
async updatePetWithForm(
petId: UpdatePetWithFormPathParams['petId'],
params?: UpdatePetWithFormQueryParams,
config: Partial<RequestConfig> & { client?: typeof fetch } = {},
) {
const { client: request = this.#client, ...requestConfig } = config
const res = await request<UpdatePetWithFormMutationResponse, ResponseErrorConfig<UpdatePetWithForm405>, unknown>({
method: 'POST',
url: `/pet/${petId}`,
params,
...requestConfig,
})
return res.data
}
/**
* @description delete a pet
* @summary Deletes a pet
* {@link /pet/:petId}
*/
async deletePet(petId: DeletePetPathParams['petId'], headers?: DeletePetHeaderParams, config: Partial<RequestConfig> & { client?: typeof fetch } = {}) {
const { client: request = this.#client, ...requestConfig } = config
const res = await request<DeletePetMutationResponse, ResponseErrorConfig<DeletePet400>, unknown>({
method: 'DELETE',
url: `/pet/${petId}`,
...requestConfig,
headers: { ...headers, ...requestConfig.headers },
})
return res.data
}
/**
* @summary uploads an image
* {@link /pet/:petId/uploadImage}
*/
async uploadFile(
petId: UploadFilePathParams['petId'],
data: UploadFileMutationRequest,
params?: UploadFileQueryParams,
config: Partial<RequestConfig<UploadFileMutationRequest>> & { client?: typeof fetch } = {},
) {
const { client: request = this.#client, ...requestConfig } = config
const requestData = data
const formData = buildFormData(requestData)
const res = await request<UploadFileMutationResponse, ResponseErrorConfig<Error>, UploadFileMutationRequest>({
method: 'POST',
url: `/pet/${petId}/uploadImage`,
params,
data: formData as FormData,
...requestConfig,
})
return res.data
}
}