From 96abac9c21201e0423478f6c63493e545279e775 Mon Sep 17 00:00:00 2001 From: feige996 <1020102647@qq.com> Date: Tue, 5 Aug 2025 17:52:54 +0800 Subject: [PATCH] =?UTF-8?q?feat(service):=20=E6=B7=BB=E5=8A=A0PetStore=20A?= =?UTF-8?q?PI=E6=9C=8D=E5=8A=A1=E5=B1=82=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 实现PetStore API的所有服务接口,包括用户、宠物和商店相关操作 添加类型定义、基础API请求和Vue Query封装 配置openapi-ts-request生成器路径 --- openapi-ts-request.config.ts | 2 +- src/service/displayEnumLabel.ts | 13 +++ src/service/index.ts | 11 ++ src/service/pet.ts | 185 ++++++++++++++++++++++++++++++++ src/service/pet.vuequery.ts | 151 ++++++++++++++++++++++++++ src/service/store.ts | 72 +++++++++++++ src/service/store.vuequery.ts | 75 +++++++++++++ src/service/types.ts | 146 +++++++++++++++++++++++++ src/service/user.ts | 150 ++++++++++++++++++++++++++ src/service/user.vuequery.ts | 149 +++++++++++++++++++++++++ 10 files changed, 953 insertions(+), 1 deletion(-) create mode 100644 src/service/displayEnumLabel.ts create mode 100644 src/service/index.ts create mode 100644 src/service/pet.ts create mode 100644 src/service/pet.vuequery.ts create mode 100644 src/service/store.ts create mode 100644 src/service/store.vuequery.ts create mode 100644 src/service/types.ts create mode 100644 src/service/user.ts create mode 100644 src/service/user.vuequery.ts diff --git a/openapi-ts-request.config.ts b/openapi-ts-request.config.ts index e24d862..7d16105 100644 --- a/openapi-ts-request.config.ts +++ b/openapi-ts-request.config.ts @@ -3,7 +3,7 @@ import type { GenerateServiceProps } from 'openapi-ts-request' export default [ { schemaPath: 'http://petstore.swagger.io/v2/swagger.json', - serversPath: './src/service/app', + serversPath: './src/service', requestLibPath: `import request from '@/http/vue-query';\n import { CustomRequestOptions } from '@/http/interceptor';`, requestOptionsType: 'CustomRequestOptions', isGenReactQuery: true, diff --git a/src/service/displayEnumLabel.ts b/src/service/displayEnumLabel.ts new file mode 100644 index 0000000..04b1487 --- /dev/null +++ b/src/service/displayEnumLabel.ts @@ -0,0 +1,13 @@ +/* eslint-disable */ +// @ts-ignore +import * as API from './types'; + +export function displayStatusEnum(field: API.StatusEnum) { + return { available: 'available', pending: 'pending', sold: 'sold' }[field]; +} + +export function displayStatusEnum2(field: API.StatusEnum2) { + return { placed: 'placed', approved: 'approved', delivered: 'delivered' }[ + field + ]; +} diff --git a/src/service/index.ts b/src/service/index.ts new file mode 100644 index 0000000..45b6e53 --- /dev/null +++ b/src/service/index.ts @@ -0,0 +1,11 @@ +/* eslint-disable */ +// @ts-ignore +export * from './types'; +export * from './displayEnumLabel'; + +export * from './pet'; +export * from './pet.vuequery'; +export * from './store'; +export * from './store.vuequery'; +export * from './user'; +export * from './user.vuequery'; diff --git a/src/service/pet.ts b/src/service/pet.ts new file mode 100644 index 0000000..50ecde2 --- /dev/null +++ b/src/service/pet.ts @@ -0,0 +1,185 @@ +/* eslint-disable */ +// @ts-ignore +import request from '@/http/vue-query'; +import { CustomRequestOptions } from '@/http/interceptor'; + +import * as API from './types'; + +/** Update an existing pet PUT /pet */ +export async function petUsingPut({ + body, + options, +}: { + body: API.Pet; + options?: CustomRequestOptions; +}) { + return request('/pet', { + method: 'PUT', + headers: { + 'Content-Type': 'application/json', + }, + data: body, + ...(options || {}), + }); +} + +/** Add a new pet to the store POST /pet */ +export async function petUsingPost({ + body, + options, +}: { + body: API.Pet; + options?: CustomRequestOptions; +}) { + return request('/pet', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + data: body, + ...(options || {}), + }); +} + +/** Find pet by ID Returns a single pet GET /pet/${param0} */ +export async function petPetIdUsingGet({ + params, + options, +}: { + // 叠加生成的Param类型 (非body参数openapi默认没有生成对象) + params: API.petPetIdUsingGetParams; + options?: CustomRequestOptions; +}) { + const { petId: param0, ...queryParams } = params; + + return request(`/pet/${param0}`, { + method: 'GET', + params: { ...queryParams }, + ...(options || {}), + }); +} + +/** Updates a pet in the store with form data POST /pet/${param0} */ +export async function petPetIdUsingPost({ + params, + body, + options, +}: { + // 叠加生成的Param类型 (非body参数openapi默认没有生成对象) + params: API.petPetIdUsingPostParams; + body: API.PetPetIdUsingPostBody; + options?: CustomRequestOptions; +}) { + const { petId: param0, ...queryParams } = params; + + return request(`/pet/${param0}`, { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + params: { ...queryParams }, + data: body, + ...(options || {}), + }); +} + +/** Deletes a pet DELETE /pet/${param0} */ +export async function petPetIdUsingDelete({ + params, + options, +}: { + // 叠加生成的Param类型 (非body参数openapi默认没有生成对象) + params: API.petPetIdUsingDeleteParams; + options?: CustomRequestOptions; +}) { + const { petId: param0, ...queryParams } = params; + + return request(`/pet/${param0}`, { + method: 'DELETE', + params: { ...queryParams }, + ...(options || {}), + }); +} + +/** uploads an image POST /pet/${param0}/uploadImage */ +export async function petPetIdUploadImageUsingPost({ + params, + body, + file, + options, +}: { + // 叠加生成的Param类型 (非body参数openapi默认没有生成对象) + params: API.petPetIdUploadImageUsingPostParams; + body: API.PetPetIdUploadImageUsingPostBody; + file?: File; + options?: CustomRequestOptions; +}) { + const { petId: param0, ...queryParams } = params; + const formData = new FormData(); + + if (file) { + formData.append('file', file); + } + + Object.keys(body).forEach((ele) => { + const item = (body as { [key: string]: any })[ele]; + + if (item !== undefined && item !== null) { + if (typeof item === 'object' && !(item instanceof File)) { + if (item instanceof Array) { + item.forEach((f) => formData.append(ele, f || '')); + } else { + formData.append(ele, JSON.stringify(item)); + } + } else { + formData.append(ele, item); + } + } + }); + + return request(`/pet/${param0}/uploadImage`, { + method: 'POST', + headers: { + 'Content-Type': 'multipart/form-data', + }, + params: { ...queryParams }, + data: formData, + ...(options || {}), + }); +} + +/** Finds Pets by status Multiple status values can be provided with comma separated strings GET /pet/findByStatus */ +export async function petFindByStatusUsingGet({ + params, + options, +}: { + // 叠加生成的Param类型 (非body参数openapi默认没有生成对象) + params: API.petFindByStatusUsingGetParams; + options?: CustomRequestOptions; +}) { + return request('/pet/findByStatus', { + method: 'GET', + params: { + ...params, + }, + ...(options || {}), + }); +} + +/** Finds Pets by tags Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. GET /pet/findByTags */ +export async function petFindByTagsUsingGet({ + params, + options, +}: { + // 叠加生成的Param类型 (非body参数openapi默认没有生成对象) + params: API.petFindByTagsUsingGetParams; + options?: CustomRequestOptions; +}) { + return request('/pet/findByTags', { + method: 'GET', + params: { + ...params, + }, + ...(options || {}), + }); +} diff --git a/src/service/pet.vuequery.ts b/src/service/pet.vuequery.ts new file mode 100644 index 0000000..4e28631 --- /dev/null +++ b/src/service/pet.vuequery.ts @@ -0,0 +1,151 @@ +/* eslint-disable */ +// @ts-ignore +import { queryOptions, useMutation } from '@tanstack/vue-query'; +import type { DefaultError } from '@tanstack/vue-query'; +import request from '@/http/vue-query'; +import { CustomRequestOptions } from '@/http/interceptor'; + +import * as apis from './pet'; +import * as API from './types'; + +/** Update an existing pet PUT /pet */ +export function usePetUsingPutMutation(options?: { + onSuccess?: (value?: unknown) => void; + onError?: (error?: DefaultError) => void; +}) { + const { onSuccess, onError } = options || {}; + + const response = useMutation({ + mutationFn: apis.petUsingPut, + onSuccess(data: unknown) { + onSuccess?.(data); + }, + onError(error) { + onError?.(error); + }, + }); + + return response; +} + +/** Add a new pet to the store POST /pet */ +export function usePetUsingPostMutation(options?: { + onSuccess?: (value?: unknown) => void; + onError?: (error?: DefaultError) => void; +}) { + const { onSuccess, onError } = options || {}; + + const response = useMutation({ + mutationFn: apis.petUsingPost, + onSuccess(data: unknown) { + onSuccess?.(data); + }, + onError(error) { + onError?.(error); + }, + }); + + return response; +} + +/** Find pet by ID Returns a single pet GET /pet/${param0} */ +export function petPetIdUsingGetQueryOptions(options: { + // 叠加生成的Param类型 (非body参数openapi默认没有生成对象) + params: API.petPetIdUsingGetParams; + options?: CustomRequestOptions; +}) { + return queryOptions({ + queryFn: async ({ queryKey }) => { + return apis.petPetIdUsingGet(queryKey[1] as typeof options); + }, + queryKey: ['petPetIdUsingGet', options], + }); +} + +/** Updates a pet in the store with form data POST /pet/${param0} */ +export function usePetPetIdUsingPostMutation(options?: { + onSuccess?: (value?: unknown) => void; + onError?: (error?: DefaultError) => void; +}) { + const { onSuccess, onError } = options || {}; + + const response = useMutation({ + mutationFn: apis.petPetIdUsingPost, + onSuccess(data: unknown) { + onSuccess?.(data); + }, + onError(error) { + onError?.(error); + }, + }); + + return response; +} + +/** Deletes a pet DELETE /pet/${param0} */ +export function usePetPetIdUsingDeleteMutation(options?: { + onSuccess?: (value?: unknown) => void; + onError?: (error?: DefaultError) => void; +}) { + const { onSuccess, onError } = options || {}; + + const response = useMutation({ + mutationFn: apis.petPetIdUsingDelete, + onSuccess(data: unknown) { + onSuccess?.(data); + }, + onError(error) { + onError?.(error); + }, + }); + + return response; +} + +/** uploads an image POST /pet/${param0}/uploadImage */ +export function usePetPetIdUploadImageUsingPostMutation(options?: { + onSuccess?: (value?: API.ApiResponse) => void; + onError?: (error?: DefaultError) => void; +}) { + const { onSuccess, onError } = options || {}; + + const response = useMutation({ + mutationFn: apis.petPetIdUploadImageUsingPost, + onSuccess(data: API.ApiResponse) { + onSuccess?.(data); + }, + onError(error) { + onError?.(error); + }, + }); + + return response; +} + +/** Finds Pets by status Multiple status values can be provided with comma separated strings GET /pet/findByStatus */ +export function petFindByStatusUsingGetQueryOptions(options: { + // 叠加生成的Param类型 (非body参数openapi默认没有生成对象) + params: API.petFindByStatusUsingGetParams; + options?: CustomRequestOptions; +}) { + return queryOptions({ + queryFn: async ({ queryKey }) => { + return apis.petFindByStatusUsingGet(queryKey[1] as typeof options); + }, + queryKey: ['petFindByStatusUsingGet', options], + }); +} + +/** Finds Pets by tags Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. GET /pet/findByTags */ +export function petFindByTagsUsingGetQueryOptions(options: { + // 叠加生成的Param类型 (非body参数openapi默认没有生成对象) + params: API.petFindByTagsUsingGetParams; + options?: CustomRequestOptions; +}) { + return queryOptions({ + queryFn: async ({ queryKey }) => { + return apis.petFindByTagsUsingGet(queryKey[1] as typeof options); + }, + queryKey: ['petFindByTagsUsingGet', options], + }); +} diff --git a/src/service/store.ts b/src/service/store.ts new file mode 100644 index 0000000..ff463fd --- /dev/null +++ b/src/service/store.ts @@ -0,0 +1,72 @@ +/* eslint-disable */ +// @ts-ignore +import request from '@/http/vue-query'; +import { CustomRequestOptions } from '@/http/interceptor'; + +import * as API from './types'; + +/** Returns pet inventories by status Returns a map of status codes to quantities GET /store/inventory */ +export async function storeInventoryUsingGet({ + options, +}: { + options?: CustomRequestOptions; +}) { + return request>('/store/inventory', { + method: 'GET', + ...(options || {}), + }); +} + +/** Place an order for a pet POST /store/order */ +export async function storeOrderUsingPost({ + body, + options, +}: { + body: API.Order; + options?: CustomRequestOptions; +}) { + return request('/store/order', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + data: body, + ...(options || {}), + }); +} + +/** Find purchase order by ID For valid response try integer IDs with value >= 1 and <= 10. Other values will generated exceptions GET /store/order/${param0} */ +export async function storeOrderOrderIdUsingGet({ + params, + options, +}: { + // 叠加生成的Param类型 (非body参数openapi默认没有生成对象) + params: API.storeOrderOrderIdUsingGetParams; + options?: CustomRequestOptions; +}) { + const { orderId: param0, ...queryParams } = params; + + return request(`/store/order/${param0}`, { + method: 'GET', + params: { ...queryParams }, + ...(options || {}), + }); +} + +/** Delete purchase order by ID For valid response try integer IDs with positive integer value. Negative or non-integer values will generate API errors DELETE /store/order/${param0} */ +export async function storeOrderOrderIdUsingDelete({ + params, + options, +}: { + // 叠加生成的Param类型 (非body参数openapi默认没有生成对象) + params: API.storeOrderOrderIdUsingDeleteParams; + options?: CustomRequestOptions; +}) { + const { orderId: param0, ...queryParams } = params; + + return request(`/store/order/${param0}`, { + method: 'DELETE', + params: { ...queryParams }, + ...(options || {}), + }); +} diff --git a/src/service/store.vuequery.ts b/src/service/store.vuequery.ts new file mode 100644 index 0000000..c6becfb --- /dev/null +++ b/src/service/store.vuequery.ts @@ -0,0 +1,75 @@ +/* eslint-disable */ +// @ts-ignore +import { queryOptions, useMutation } from '@tanstack/vue-query'; +import type { DefaultError } from '@tanstack/vue-query'; +import request from '@/http/vue-query'; +import { CustomRequestOptions } from '@/http/interceptor'; + +import * as apis from './store'; +import * as API from './types'; + +/** Returns pet inventories by status Returns a map of status codes to quantities GET /store/inventory */ +export function storeInventoryUsingGetQueryOptions(options: { + options?: CustomRequestOptions; +}) { + return queryOptions({ + queryFn: async ({ queryKey }) => { + return apis.storeInventoryUsingGet(queryKey[1] as typeof options); + }, + queryKey: ['storeInventoryUsingGet', options], + }); +} + +/** Place an order for a pet POST /store/order */ +export function useStoreOrderUsingPostMutation(options?: { + onSuccess?: (value?: API.Order) => void; + onError?: (error?: DefaultError) => void; +}) { + const { onSuccess, onError } = options || {}; + + const response = useMutation({ + mutationFn: apis.storeOrderUsingPost, + onSuccess(data: API.Order) { + onSuccess?.(data); + }, + onError(error) { + onError?.(error); + }, + }); + + return response; +} + +/** Find purchase order by ID For valid response try integer IDs with value >= 1 and <= 10. Other values will generated exceptions GET /store/order/${param0} */ +export function storeOrderOrderIdUsingGetQueryOptions(options: { + // 叠加生成的Param类型 (非body参数openapi默认没有生成对象) + params: API.storeOrderOrderIdUsingGetParams; + options?: CustomRequestOptions; +}) { + return queryOptions({ + queryFn: async ({ queryKey }) => { + return apis.storeOrderOrderIdUsingGet(queryKey[1] as typeof options); + }, + queryKey: ['storeOrderOrderIdUsingGet', options], + }); +} + +/** Delete purchase order by ID For valid response try integer IDs with positive integer value. Negative or non-integer values will generate API errors DELETE /store/order/${param0} */ +export function useStoreOrderOrderIdUsingDeleteMutation(options?: { + onSuccess?: (value?: unknown) => void; + onError?: (error?: DefaultError) => void; +}) { + const { onSuccess, onError } = options || {}; + + const response = useMutation({ + mutationFn: apis.storeOrderOrderIdUsingDelete, + onSuccess(data: unknown) { + onSuccess?.(data); + }, + onError(error) { + onError?.(error); + }, + }); + + return response; +} diff --git a/src/service/types.ts b/src/service/types.ts new file mode 100644 index 0000000..800530e --- /dev/null +++ b/src/service/types.ts @@ -0,0 +1,146 @@ +/* eslint-disable */ +// @ts-ignore + +export type ApiResponse = { + code?: number; + type?: string; + message?: string; +}; + +export type Category = { + id?: number; + name?: string; +}; + +export type Order = { + id?: number; + petId?: number; + quantity?: number; + shipDate?: string; + /** Order Status */ + status?: 'placed' | 'approved' | 'delivered'; + complete?: boolean; +}; + +export type Pet = { + id?: number; + category?: Category; + name: string; + photoUrls: string[]; + tags?: Tag[]; + /** pet status in the store */ + status?: 'available' | 'pending' | 'sold'; +}; + +export type petFindByStatusUsingGetParams = { + /** Status values that need to be considered for filter */ + status: ('available' | 'pending' | 'sold')[]; +}; + +export type petFindByTagsUsingGetParams = { + /** Tags to filter by */ + tags: string[]; +}; + +export type PetPetIdUploadImageUsingPostBody = { + /** Additional data to pass to server */ + additionalMetadata?: string; + /** file to upload */ + file?: string; +}; + +export type petPetIdUploadImageUsingPostParams = { + /** ID of pet to update */ + petId: number; +}; + +export type petPetIdUsingDeleteParams = { + /** Pet id to delete */ + petId: number; +}; + +export type petPetIdUsingGetParams = { + /** ID of pet to return */ + petId: number; +}; + +export type PetPetIdUsingPostBody = { + /** Updated name of the pet */ + name?: string; + /** Updated status of the pet */ + status?: string; +}; + +export type petPetIdUsingPostParams = { + /** ID of pet that needs to be updated */ + petId: number; +}; + +export enum StatusEnum { + 'available' = 'available', + 'pending' = 'pending', + 'sold' = 'sold', +} + +export type IStatusEnum = keyof typeof StatusEnum; + +export enum StatusEnum2 { + 'placed' = 'placed', + 'approved' = 'approved', + 'delivered' = 'delivered', +} + +export type IStatusEnum2 = keyof typeof StatusEnum2; + +export type storeOrderOrderIdUsingDeleteParams = { + /** ID of the order that needs to be deleted */ + orderId: number; +}; + +export type storeOrderOrderIdUsingGetParams = { + /** ID of pet that needs to be fetched */ + orderId: number; +}; + +export type Tag = { + id?: number; + name?: string; +}; + +export type User = { + id?: number; + username?: string; + firstName?: string; + lastName?: string; + email?: string; + password?: string; + phone?: string; + /** User Status */ + userStatus?: number; +}; + +export type UserCreateWithArrayUsingPostBody = User[]; + +export type UserCreateWithListUsingPostBody = User[]; + +export type userLoginUsingGetParams = { + /** The user name for login */ + username: string; + /** The password for login in clear text */ + password: string; +}; + +export type userUsernameUsingDeleteParams = { + /** The name that needs to be deleted */ + username: string; +}; + +export type userUsernameUsingGetParams = { + /** The name that needs to be fetched. Use user1 for testing. */ + username: string; +}; + +export type userUsernameUsingPutParams = { + /** name that need to be updated */ + username: string; +}; diff --git a/src/service/user.ts b/src/service/user.ts new file mode 100644 index 0000000..ee9ed8d --- /dev/null +++ b/src/service/user.ts @@ -0,0 +1,150 @@ +/* eslint-disable */ +// @ts-ignore +import request from '@/http/vue-query'; +import { CustomRequestOptions } from '@/http/interceptor'; + +import * as API from './types'; + +/** Create user This can only be done by the logged in user. 返回值: successful operation POST /user */ +export async function userUsingPost({ + body, + options, +}: { + body: API.User; + options?: CustomRequestOptions; +}) { + return request('/user', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + data: body, + ...(options || {}), + }); +} + +/** Get user by user name GET /user/${param0} */ +export async function userUsernameUsingGet({ + params, + options, +}: { + // 叠加生成的Param类型 (非body参数openapi默认没有生成对象) + params: API.userUsernameUsingGetParams; + options?: CustomRequestOptions; +}) { + const { username: param0, ...queryParams } = params; + + return request(`/user/${param0}`, { + method: 'GET', + params: { ...queryParams }, + ...(options || {}), + }); +} + +/** Updated user This can only be done by the logged in user. PUT /user/${param0} */ +export async function userUsernameUsingPut({ + params, + body, + options, +}: { + // 叠加生成的Param类型 (非body参数openapi默认没有生成对象) + params: API.userUsernameUsingPutParams; + body: API.User; + options?: CustomRequestOptions; +}) { + const { username: param0, ...queryParams } = params; + + return request(`/user/${param0}`, { + method: 'PUT', + headers: { + 'Content-Type': 'application/json', + }, + params: { ...queryParams }, + data: body, + ...(options || {}), + }); +} + +/** Delete user This can only be done by the logged in user. DELETE /user/${param0} */ +export async function userUsernameUsingDelete({ + params, + options, +}: { + // 叠加生成的Param类型 (非body参数openapi默认没有生成对象) + params: API.userUsernameUsingDeleteParams; + options?: CustomRequestOptions; +}) { + const { username: param0, ...queryParams } = params; + + return request(`/user/${param0}`, { + method: 'DELETE', + params: { ...queryParams }, + ...(options || {}), + }); +} + +/** Creates list of users with given input array 返回值: successful operation POST /user/createWithArray */ +export async function userCreateWithArrayUsingPost({ + body, + options, +}: { + body: API.UserCreateWithArrayUsingPostBody; + options?: CustomRequestOptions; +}) { + return request('/user/createWithArray', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + data: body, + ...(options || {}), + }); +} + +/** Creates list of users with given input array 返回值: successful operation POST /user/createWithList */ +export async function userCreateWithListUsingPost({ + body, + options, +}: { + body: API.UserCreateWithListUsingPostBody; + options?: CustomRequestOptions; +}) { + return request('/user/createWithList', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + data: body, + ...(options || {}), + }); +} + +/** Logs user into the system GET /user/login */ +export async function userLoginUsingGet({ + params, + options, +}: { + // 叠加生成的Param类型 (非body参数openapi默认没有生成对象) + params: API.userLoginUsingGetParams; + options?: CustomRequestOptions; +}) { + return request('/user/login', { + method: 'GET', + params: { + ...params, + }, + ...(options || {}), + }); +} + +/** Logs out current logged in user session 返回值: successful operation GET /user/logout */ +export async function userLogoutUsingGet({ + options, +}: { + options?: CustomRequestOptions; +}) { + return request('/user/logout', { + method: 'GET', + ...(options || {}), + }); +} diff --git a/src/service/user.vuequery.ts b/src/service/user.vuequery.ts new file mode 100644 index 0000000..23e8f78 --- /dev/null +++ b/src/service/user.vuequery.ts @@ -0,0 +1,149 @@ +/* eslint-disable */ +// @ts-ignore +import { queryOptions, useMutation } from '@tanstack/vue-query'; +import type { DefaultError } from '@tanstack/vue-query'; +import request from '@/http/vue-query'; +import { CustomRequestOptions } from '@/http/interceptor'; + +import * as apis from './user'; +import * as API from './types'; + +/** Create user This can only be done by the logged in user. 返回值: successful operation POST /user */ +export function useUserUsingPostMutation(options?: { + onSuccess?: (value?: unknown) => void; + onError?: (error?: DefaultError) => void; +}) { + const { onSuccess, onError } = options || {}; + + const response = useMutation({ + mutationFn: apis.userUsingPost, + onSuccess(data: unknown) { + onSuccess?.(data); + }, + onError(error) { + onError?.(error); + }, + }); + + return response; +} + +/** Get user by user name GET /user/${param0} */ +export function userUsernameUsingGetQueryOptions(options: { + // 叠加生成的Param类型 (非body参数openapi默认没有生成对象) + params: API.userUsernameUsingGetParams; + options?: CustomRequestOptions; +}) { + return queryOptions({ + queryFn: async ({ queryKey }) => { + return apis.userUsernameUsingGet(queryKey[1] as typeof options); + }, + queryKey: ['userUsernameUsingGet', options], + }); +} + +/** Updated user This can only be done by the logged in user. PUT /user/${param0} */ +export function useUserUsernameUsingPutMutation(options?: { + onSuccess?: (value?: unknown) => void; + onError?: (error?: DefaultError) => void; +}) { + const { onSuccess, onError } = options || {}; + + const response = useMutation({ + mutationFn: apis.userUsernameUsingPut, + onSuccess(data: unknown) { + onSuccess?.(data); + }, + onError(error) { + onError?.(error); + }, + }); + + return response; +} + +/** Delete user This can only be done by the logged in user. DELETE /user/${param0} */ +export function useUserUsernameUsingDeleteMutation(options?: { + onSuccess?: (value?: unknown) => void; + onError?: (error?: DefaultError) => void; +}) { + const { onSuccess, onError } = options || {}; + + const response = useMutation({ + mutationFn: apis.userUsernameUsingDelete, + onSuccess(data: unknown) { + onSuccess?.(data); + }, + onError(error) { + onError?.(error); + }, + }); + + return response; +} + +/** Creates list of users with given input array 返回值: successful operation POST /user/createWithArray */ +export function useUserCreateWithArrayUsingPostMutation(options?: { + onSuccess?: (value?: unknown) => void; + onError?: (error?: DefaultError) => void; +}) { + const { onSuccess, onError } = options || {}; + + const response = useMutation({ + mutationFn: apis.userCreateWithArrayUsingPost, + onSuccess(data: unknown) { + onSuccess?.(data); + }, + onError(error) { + onError?.(error); + }, + }); + + return response; +} + +/** Creates list of users with given input array 返回值: successful operation POST /user/createWithList */ +export function useUserCreateWithListUsingPostMutation(options?: { + onSuccess?: (value?: unknown) => void; + onError?: (error?: DefaultError) => void; +}) { + const { onSuccess, onError } = options || {}; + + const response = useMutation({ + mutationFn: apis.userCreateWithListUsingPost, + onSuccess(data: unknown) { + onSuccess?.(data); + }, + onError(error) { + onError?.(error); + }, + }); + + return response; +} + +/** Logs user into the system GET /user/login */ +export function userLoginUsingGetQueryOptions(options: { + // 叠加生成的Param类型 (非body参数openapi默认没有生成对象) + params: API.userLoginUsingGetParams; + options?: CustomRequestOptions; +}) { + return queryOptions({ + queryFn: async ({ queryKey }) => { + return apis.userLoginUsingGet(queryKey[1] as typeof options); + }, + queryKey: ['userLoginUsingGet', options], + }); +} + +/** Logs out current logged in user session 返回值: successful operation GET /user/logout */ +export function userLogoutUsingGetQueryOptions(options: { + options?: CustomRequestOptions; +}) { + return queryOptions({ + queryFn: async ({ queryKey }) => { + return apis.userLogoutUsingGet(queryKey[1] as typeof options); + }, + queryKey: ['userLogoutUsingGet', options], + }); +}