UNPKG

@kubb/plugin-client

Version:

API client generator plugin for Kubb, creating type-safe HTTP clients (Axios, Fetch) from OpenAPI specifications for making API requests.

110 lines (102 loc) 3.91 kB
/** * Generated by Kubb (https://kubb.dev/). * Do not edit manually. */ import type { RequestConfig, ResponseErrorConfig } from './test/.kubb/fetch' import type { GetInventoryQueryResponse, PlaceOrderMutationRequest, PlaceOrderMutationResponse, PlaceOrder405, PlaceOrderPatchMutationRequest, PlaceOrderPatchMutationResponse, PlaceOrderPatch405, GetOrderByIdQueryResponse, GetOrderByIdPathParams, GetOrderById400, GetOrderById404, DeleteOrderMutationResponse, DeleteOrderPathParams, DeleteOrder400, DeleteOrder404, } from './findByTags' import { fetch } from './test/.kubb/fetch' export class Store { #client: typeof fetch constructor(config: Partial<RequestConfig> & { client?: typeof fetch } = {}) { this.#client = config.client || fetch } /** * @description Returns a map of status codes to quantities * @summary Returns pet inventories by status * {@link /store/inventory} */ async getInventory(config: Partial<RequestConfig> & { client?: typeof fetch } = {}) { const { client: request = this.#client, ...requestConfig } = config const res = await request<GetInventoryQueryResponse, ResponseErrorConfig<Error>, unknown>({ method: 'GET', url: `/store/inventory`, ...requestConfig }) return res.data } /** * @description Place a new order in the store * @summary Place an order for a pet * {@link /store/order} */ async placeOrder(data?: PlaceOrderMutationRequest, config: Partial<RequestConfig<PlaceOrderMutationRequest>> & { client?: typeof fetch } = {}) { const { client: request = this.#client, ...requestConfig } = config const requestData = data const res = await request<PlaceOrderMutationResponse, ResponseErrorConfig<PlaceOrder405>, PlaceOrderMutationRequest>({ method: 'POST', url: `/store/order`, data: requestData, ...requestConfig, }) return res.data } /** * @description Place a new order in the store with patch * @summary Place an order for a pet with patch * {@link /store/order} */ async placeOrderPatch( data?: PlaceOrderPatchMutationRequest, config: Partial<RequestConfig<PlaceOrderPatchMutationRequest>> & { client?: typeof fetch } = {}, ) { const { client: request = this.#client, ...requestConfig } = config const requestData = data const res = await request<PlaceOrderPatchMutationResponse, ResponseErrorConfig<PlaceOrderPatch405>, PlaceOrderPatchMutationRequest>({ method: 'PATCH', url: `/store/order`, data: requestData, ...requestConfig, }) return res.data } /** * @description For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions. * @summary Find purchase order by ID * {@link /store/order/:orderId} */ async getOrderById(orderId: GetOrderByIdPathParams['orderId'], config: Partial<RequestConfig> & { client?: typeof fetch } = {}) { const { client: request = this.#client, ...requestConfig } = config const res = await request<GetOrderByIdQueryResponse, ResponseErrorConfig<GetOrderById400 | GetOrderById404>, unknown>({ method: 'GET', url: `/store/order/${orderId}`, ...requestConfig, }) return res.data } /** * @description For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors * @summary Delete purchase order by ID * {@link /store/order/:orderId} */ async deleteOrder(orderId: DeleteOrderPathParams['orderId'], config: Partial<RequestConfig> & { client?: typeof fetch } = {}) { const { client: request = this.#client, ...requestConfig } = config const res = await request<DeleteOrderMutationResponse, ResponseErrorConfig<DeleteOrder400 | DeleteOrder404>, unknown>({ method: 'DELETE', url: `/store/order/${orderId}`, ...requestConfig, }) return res.data } }