APIConfig 说明
APIConfig 定义了 tsdk 的 API 基本配置规范,内容如下:
src/shared/tsdk-types.ts
import * as z from 'zod';
export const APITypes = {
user: 'user',
admin: 'admin',
common: 'common',
} as const;
export const APITypesKey = Object.keys(APITypes).filter((item) => item !== APITypes.common);
export type APIType = keyof typeof APITypes;
export interface APIConfig {
/** The API type. Like: user side or admin side. */
type: APIType;
/** The API path */
path: string;
method: 'get' | 'post' | 'delete' | 'put' | 'patch' | 'head' | 'options';
/** Request data validate scheme */
schema?: z.ZodTypeAny;
/** The API need auth? Default is false */
needAuth?: boolean;
/** The API disabled? Default is false */
disabled?: boolean;
/** The API description */
description: string;
/** The API category */
category?: string;
/** custom headers for client */
headers?: { [key: string]: any };
/**
* is params in url? for generate API sdk base documentation.
* default undefined,
* if `:`, will support `/api/:a/b/:c`,
* if `{}`, will support `/api/{a}/b/{c}`,
* and will replace with data with {a: 1, c: 2} to `/api/1/b/2` */
paramsInUrl?: ':' | '{}';
/** Force the API is fetch data, for sometimes the backend API is all `post` method */
isGet?: boolean;
}字段说明
type- API 类型path- API 路径method- HTTP 请求方法description- API 备注category- 可选,API 模块分类schema- 可选,运行时类型校验表达式,使用 zodneedAuth- 可选,是否需要登录才能访问disabled- 可选,是否禁止 APIheaders- 可选,自定义 headersparamsInUrl- 可选,值为{}|:, 用来替换 url 中的参数isGet- 可选,值为true时,生成SWR或者ReactQuery,即使 method 不是 get 方法,也会被当作 get 方法看待;为false,则当作非get看待,生成更新类型的 hook