1.3.10 • Published 6 months ago
@ebelong-lib/lianxi-openapi v1.3.10
联犀 openapi
Intuitive, type safe 无任何注入,只有类型声明和部分常量 无需生成大量请求代码,只需实现一个请求 client 即可实现调用所有接口且类型安全
- 💡 Intuitive
- 🔑 Type Safe
- ⚙️ Devtools support
- 🔌 Extensible
- 🏗 Modular by design
FAQ
A few notes about the project and possible questions:
Q:
A:
Installation
# or npm or yarn
yarn add @ebelong-lib/lianxi-openapi
Usage
推荐使用 openapi-fetch
import createClient from "openapi-fetch";
import { Paths } from "@ebelong-lib/lianxi-openapi";
/**
* 构造请求client
*/
export const fetchClient = createClient<Paths>({
baseUrl: import.meta.env.VITE_BASE_API_URL,
});
// 使用(这里要先写第二个参数写{},第一个路径参数才会有IDE提示,框架bug)
fetchClient
.POST("/api/v1/system/user/info/index", {
body: {
page: { page: 1, size: 10 },
},
})
.then((res) => {
console.log(res.data?.data?.list);
});
配合其他请求库使用
import {
Paths,
PostRequestDataType,
PostResponseDataType,
} from "@ebelong-lib/lianxi-openapi";
function Post<T extends keyof Paths>({
path,
data,
}: {
path: T;
data: PostRequestDataType<Paths[T]>;
}): Promise<PostResponseDataType<Paths[T]>> {
// 使用请求
return xxx.request({
url: path,
method: "POST",
body: data,
}) as PostResponseDataType<Paths[T]>;
}
// 使用
const { data: userList } = await Post({
path: "/api/v1/system/user/info/index",
data: { page: { page: 1, size: 10 } },
});
console.log("user list:", userList?.list);
模块导出说明
import {
SchemaCore, // core 模块相关的Schema
SchemaThings, // things 模块相关的Schema
TypesThings, // things 模块相关的 type
TypesCore, // core 模块相关的 type
Paths, // 请求的路径集合
PostRequestDataType, // 构造请求参数类型
PostResponseDataType, // 构造返回参数类型
/**待补充 */
} from "@ebelong-lib/lianxi-openapi";
1.3.10
6 months ago
1.3.9
6 months ago
1.3.8
6 months ago
1.3.7
7 months ago
1.3.6
7 months ago
1.3.5
7 months ago
1.3.4
9 months ago
1.3.3
9 months ago
1.3.2
9 months ago
1.3.0
10 months ago
1.2.0
10 months ago
1.1.0
10 months ago
1.0.4-alpha.17
10 months ago
1.0.4-alpha.16
10 months ago
1.0.4-alpha.15
10 months ago
1.0.4-alpha.14
10 months ago
1.0.4-alpha.13
10 months ago
1.0.4-alpha.12
10 months ago
1.0.4-alpha.11
10 months ago
1.0.4-alpha.10
10 months ago
1.0.4-alpha.9
10 months ago
1.0.4-alpha.8
10 months ago
1.0.4-alpha.7
10 months ago
1.0.4-alpha.6
10 months ago
1.0.4-alpha.5
10 months ago
1.0.4-alpha.4
10 months ago
1.0.4-alpha.3
10 months ago
1.0.4-alpha.2
10 months ago
1.0.4-alpha.1
10 months ago