You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Convert OpenAPI Specification declaration files into type declarations and executable functions. Compared with other similar tools, it has the following characteristics
-Each API is a function for easy tree shaking at build time
16
-
-Easily integrate with local request clients, such as Axios instances created in local projects
17
-
-Easy to use, easy to learn, type safe
15
+
-每个 API 都是一个函数,用于在构建时轻松进行 tree shaking
16
+
-轻松与本地请求客户端集成,例如在本地项目中创建的 Axios 实例
17
+
-易于使用,易于学习,类型安全
18
18
19
19
# Install
20
20
21
21
```shell
22
-
npm i -D oas-gen-ts
22
+
npm i -D openapi-axios
23
23
```
24
24
25
25
or
26
26
27
27
```shell
28
-
yarn add --dev oas-gen-ts
28
+
yarn add --dev openapi-axios
29
29
```
30
30
31
31
# Usage
32
32
33
33
## CLI
34
34
35
-
Create oas.config.js or oas.json in the root directory of the project. The search order for configuration files is `oas.config.cjs`, `oas.config.js`, `oas.json`.
#Generate typescript files based on configuration files
53
-
npx oas-gen-ts
52
+
#根据配置文件生成typescript文件
53
+
npx openapi-axios
54
54
55
-
#The `src/apis/swagger/pet.ts` file will be generated
55
+
#将生成 `src/apis/swagger/pet.ts` 文件
56
56
```
57
57
58
-
The generated file will be exported as one function and one operation, like this:
58
+
生成的文件将导出为一个函数和一个操作,如下所示:
59
59
60
60
```ts
61
61
// src/apis/swagger/pet.ts
@@ -109,7 +109,7 @@ export async function findPetsByStatus(
109
109
// ...
110
110
```
111
111
112
-
Then you can directly import a function and use it. Calling an interface is as simple as calling a local function, is it similar to RPC (remote procedure call).
0 commit comments