diff --git a/openapi-ts-request.config.ts b/openapi-ts-request.config.ts index 84c6ddf..18ce1dc 100644 --- a/openapi-ts-request.config.ts +++ b/openapi-ts-request.config.ts @@ -2,7 +2,7 @@ import type { GenerateServiceProps } from 'openapi-ts-request' export default [ { - schemaPath: 'http://petstore.swagger.io/v2/swagger.json', + schemaPath: 'https://ukw0y1.laf.run/unibest-opapi-test.json', serversPath: './src/service', requestLibPath: `import request from '@/http/vue-query';\n import { CustomRequestOptions } from '@/http/types';`, requestOptionsType: 'CustomRequestOptions', diff --git a/package.json b/package.json index f6b70a1..3d8e591 100644 --- a/package.json +++ b/package.json @@ -87,7 +87,7 @@ "build:quickapp-webview-huawei": "uni build -p quickapp-webview-huawei", "build:quickapp-webview-union": "uni build -p quickapp-webview-union", "type-check": "vue-tsc --noEmit", - "openapi-ts-request": "openapi-ts", + "openapi": "openapi-ts", "prepare": "git init && husky && node ./scripts/create-base-files.js", "docker:prepare": "node ./scripts/create-base-files.js", "lint": "eslint", diff --git a/src/http/http.ts b/src/http/http.ts index 6309526..147f532 100644 --- a/src/http/http.ts +++ b/src/http/http.ts @@ -24,7 +24,7 @@ export function http(options: CustomRequestOptions) { // 状态码 2xx,参考 axios 的设计 if (res.statusCode >= 200 && res.statusCode < 300) { // 2.1 处理业务逻辑错误 - const { code = 0, message = '', data = null } = res.data as IResponse + const { code = 0, message = '', msg = '', data = null } = res.data as IResponse // 0和200当做成功都很普遍,这里直接兼容两者,见 ResultEnum if (code !== ResultEnum.Success0 && code !== ResultEnum.Success200) { throw new Error(`请求错误[${code}]:${message || msg}`) diff --git a/src/pages/about/about.vue b/src/pages/about/about.vue index a4e84f3..b25c6a1 100644 --- a/src/pages/about/about.vue +++ b/src/pages/about/about.vue @@ -3,6 +3,7 @@ import { isApp, isAppAndroid, isAppHarmony, isAppIOS, isAppPlus, isH5, isMpWeixi import { LOGIN_PAGE } from '@/router/config' import { useTokenStore } from '@/store' import { tabbarStore } from '@/tabbar/store' +import RequestOpenApiComp from './components/request-openapi.vue' import RequestComp from './components/request.vue' import VBindCss from './components/VBindCss.vue' @@ -111,6 +112,7 @@ onShow(() => { + diff --git a/src/pages/about/components/request-openapi.vue b/src/pages/about/components/request-openapi.vue new file mode 100644 index 0000000..821ad6b --- /dev/null +++ b/src/pages/about/components/request-openapi.vue @@ -0,0 +1,61 @@ + + + diff --git a/src/service/displayEnumLabel.ts b/src/service/displayEnumLabel.ts deleted file mode 100644 index 04b1487..0000000 --- a/src/service/displayEnumLabel.ts +++ /dev/null @@ -1,13 +0,0 @@ -/* 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 index 2e13a3c..3bfbb5b 100644 --- a/src/service/index.ts +++ b/src/service/index.ts @@ -1,8 +1,6 @@ /* eslint-disable */ // @ts-ignore export * from './types'; -export * from './displayEnumLabel'; -export * from './pet'; -export * from './store'; -export * from './user'; +export * from './listAll'; +export * from './info'; diff --git a/src/service/info.ts b/src/service/info.ts new file mode 100644 index 0000000..b3f8e6b --- /dev/null +++ b/src/service/info.ts @@ -0,0 +1,18 @@ +/* eslint-disable */ +// @ts-ignore +import request from '@/http/vue-query'; +import { CustomRequestOptions } from '@/http/types'; + +import * as API from './types'; + +/** 用户信息 GET /user/info */ +export async function infoUsingGet({ + options, +}: { + options?: CustomRequestOptions; +}) { + return request('/user/info', { + method: 'GET', + ...(options || {}), + }); +} diff --git a/src/service/listAll.ts b/src/service/listAll.ts new file mode 100644 index 0000000..bcbd21b --- /dev/null +++ b/src/service/listAll.ts @@ -0,0 +1,18 @@ +/* eslint-disable */ +// @ts-ignore +import request from '@/http/vue-query'; +import { CustomRequestOptions } from '@/http/types'; + +import * as API from './types'; + +/** 用户列表 GET /user/listAll */ +export async function listAllUsingGet({ + options, +}: { + options?: CustomRequestOptions; +}) { + return request('/user/listAll', { + method: 'GET', + ...(options || {}), + }); +} diff --git a/src/service/pet.ts b/src/service/pet.ts deleted file mode 100644 index b625597..0000000 --- a/src/service/pet.ts +++ /dev/null @@ -1,185 +0,0 @@ -/* eslint-disable */ -// @ts-ignore -import request from '@/http/vue-query'; -import { CustomRequestOptions } from '@/http/types'; - -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/store.ts b/src/service/store.ts deleted file mode 100644 index 8f6c6be..0000000 --- a/src/service/store.ts +++ /dev/null @@ -1,72 +0,0 @@ -/* eslint-disable */ -// @ts-ignore -import request from '@/http/vue-query'; -import { CustomRequestOptions } from '@/http/types'; - -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/types.ts b/src/service/types.ts index 8715b7e..4e46b61 100644 --- a/src/service/types.ts +++ b/src/service/types.ts @@ -1,350 +1,29 @@ /* eslint-disable */ // @ts-ignore -export type ApiResponse = { - code?: number; - type?: string; - message?: string; +export type InfoUsingGetResponse = { + code: number; + msg: string; + data: UserItem; }; -export type Category = { - id?: number; - name?: string; +export type InfoUsingGetResponses = { + 200: InfoUsingGetResponse; }; -export type Order = { - id?: number; - petId?: number; - quantity?: number; - shipDate?: string; - /** Order Status */ - status?: 'placed' | 'approved' | 'delivered'; - complete?: boolean; +export type ListAllUsingGetResponse = { + code: number; + msg: string; + data: UserItem[]; }; -export type Pet = { - id?: number; - category?: Category; - name: string; - photoUrls: string[]; - tags?: Tag[]; - /** pet status in the store */ - status?: 'available' | 'pending' | 'sold'; +export type ListAllUsingGetResponses = { + 200: ListAllUsingGetResponse; }; -export type PetFindByStatusUsingGetParams = { - /** Status values that need to be considered for filter */ - status: ('available' | 'pending' | 'sold')[]; -}; - -export type PetFindByStatusUsingGetResponses = { - /** - * successful operation - */ - 200: Pet[]; - /** - * Invalid status value - */ - 400: unknown; -}; - -export type PetFindByTagsUsingGetParams = { - /** Tags to filter by */ - tags: string[]; -}; - -export type PetFindByTagsUsingGetResponses = { - /** - * successful operation - */ - 200: Pet[]; - /** - * Invalid tag value - */ - 400: unknown; -}; - -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 PetPetIdUploadImageUsingPostResponses = { - /** - * successful operation - */ - 200: ApiResponse; -}; - -export type PetPetIdUsingDeleteParams = { - /** Pet id to delete */ - petId: number; -}; - -export type PetPetIdUsingDeleteResponses = { - /** - * Invalid ID supplied - */ - 400: unknown; - /** - * Pet not found - */ - 404: unknown; -}; - -export type PetPetIdUsingGetParams = { - /** ID of pet to return */ - petId: number; -}; - -export type PetPetIdUsingGetResponses = { - /** - * successful operation - */ - 200: Pet; - /** - * Invalid ID supplied - */ - 400: unknown; - /** - * Pet not found - */ - 404: unknown; -}; - -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 type PetPetIdUsingPostResponses = { - /** - * Invalid input - */ - 405: unknown; -}; - -export type PetUsingPostResponses = { - /** - * Invalid input - */ - 405: unknown; -}; - -export type PetUsingPutResponses = { - /** - * Invalid ID supplied - */ - 400: unknown; - /** - * Pet not found - */ - 404: unknown; - /** - * Validation exception - */ - 405: unknown; -}; - -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 StoreInventoryUsingGetResponses = { - /** - * successful operation - */ - 200: Record; -}; - -export type StoreOrderOrderIdUsingDeleteParams = { - /** ID of the order that needs to be deleted */ - orderId: number; -}; - -export type StoreOrderOrderIdUsingDeleteResponses = { - /** - * Invalid ID supplied - */ - 400: unknown; - /** - * Order not found - */ - 404: unknown; -}; - -export type StoreOrderOrderIdUsingGetParams = { - /** ID of pet that needs to be fetched */ - orderId: number; -}; - -export type StoreOrderOrderIdUsingGetResponses = { - /** - * successful operation - */ - 200: Order; - /** - * Invalid ID supplied - */ - 400: unknown; - /** - * Order not found - */ - 404: unknown; -}; - -export type StoreOrderUsingPostResponses = { - /** - * successful operation - */ - 200: Order; - /** - * Invalid Order - */ - 400: unknown; -}; - -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 UserCreateWithArrayUsingPostResponses = { - /** - * successful operation - */ - default: unknown; -}; - -export type UserCreateWithListUsingPostBody = User[]; - -export type UserCreateWithListUsingPostResponses = { - /** - * successful operation - */ - default: unknown; -}; - -export type UserLoginUsingGetParams = { - /** The user name for login */ +export type UserItem = { + userId: number; username: string; - /** The password for login in clear text */ - password: string; -}; - -export type UserLoginUsingGetResponses = { - /** - * successful operation - */ - 200: string; - /** - * Invalid username/password supplied - */ - 400: unknown; -}; - -export type UserLogoutUsingGetResponses = { - /** - * successful operation - */ - default: unknown; -}; - -export type UserUsernameUsingDeleteParams = { - /** The name that needs to be deleted */ - username: string; -}; - -export type UserUsernameUsingDeleteResponses = { - /** - * Invalid username supplied - */ - 400: unknown; - /** - * User not found - */ - 404: unknown; -}; - -export type UserUsernameUsingGetParams = { - /** The name that needs to be fetched. Use user1 for testing. */ - username: string; -}; - -export type UserUsernameUsingGetResponses = { - /** - * successful operation - */ - 200: User; - /** - * Invalid username supplied - */ - 400: unknown; - /** - * User not found - */ - 404: unknown; -}; - -export type UserUsernameUsingPutParams = { - /** name that need to be updated */ - username: string; -}; - -export type UserUsernameUsingPutResponses = { - /** - * Invalid user supplied - */ - 400: unknown; - /** - * User not found - */ - 404: unknown; -}; - -export type UserUsingPostResponses = { - /** - * successful operation - */ - default: unknown; + nickname: string; + avatar: string; }; diff --git a/src/service/user.ts b/src/service/user.ts deleted file mode 100644 index f95e8e6..0000000 --- a/src/service/user.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* eslint-disable */ -// @ts-ignore -import request from '@/http/vue-query'; -import { CustomRequestOptions } from '@/http/types'; - -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 || {}), - }); -}