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
`@alova/wormhole` is a more modern openAPI generation solution for the alova library. It can generate API functions, complete API types, and complete API documents at the same time. Alova's development tools can eliminate the intermediate API documents for you, shortening the collaboration distance between the front-end and back-end like a wormhole. It is also the underlying implementation of the vscode extension.
6
+
7
+
## Installation
8
+
9
+
```bash
10
+
# npm
11
+
npm i @alova/wormhole -D
12
+
# yarn
13
+
yarn add @alova/wormhole -D
14
+
# pnpm
15
+
pnpm add @alova/wormhole -D
16
+
```
17
+
18
+
:::info extension installation tips
19
+
20
+
If you are using vscode, it is strongly recommended that you use `@alova/wormhole` with alova's vscode extension. Please refer to [Editor Extension Integration](/tutorial/getting-started/extension-integration) to install vscode extension
21
+
.
22
+
23
+
If you are using other editors, you can also use the `@alova/wormhole` command to generate complete API information.
24
+
25
+
:::
26
+
27
+
## Commands
28
+
29
+
### gen
30
+
31
+
```bash
32
+
alova gen [-f, --force] [-c --cwd <path>] [-w --workspace]
33
+
```
34
+
35
+
gen will look for the `alova.config.{cjs,js,mjs,ts}` configuration file and use it to automatically generate API related information.
36
+
37
+
**Parameters:**
38
+
39
+
-**-f, --force**: By default, the latest openAPI file will be checked for updates. If this parameter is specified, the check will be ignored and regeneration will be forced.
40
+
41
+
-**-c, --cwd \<path\>**: Specify the working directory of the configuration file to be generated. The default is the current directory.
42
+
43
+
-**-w, --workspace**: Specifies whether to generate in workspace mode. It will search for configuration files based on `workspaces` in `package.json` or subpackages defined in `pnpm-workspace.yaml`, and generate API-related information for all subpackages.
44
+
45
+
### init
46
+
47
+
```bash
48
+
alova init [-t, --type <type>] [-c --cwd <path>]
49
+
```
50
+
51
+
Generate alova.config configuration file in the current directory. It will automatically generate configuration files with different suffixes according to the project type.
52
+
53
+
**Parameters: **
54
+
55
+
-**-t, --type**: Specifies the type of configuration file to be generated. The optional values are: `auto/ts/typescript/module/commonjs`. The default is `auto`. It will automatically generate configuration files with different suffixes according to the project type.
56
+
57
+
-**-c, --cwd \<path\>**: Specifies the working directory of the configuration file to be generated. The default is the current directory.
Search for all directories containing alova.config configuration files under the monorepo project. It will search for configuration files based on `workspaces` in `package.json` or subpackages defined in `pnpm-workspace.yaml`
<aclassName="button button--primary"href="vscode:extension/Alova.alova-vscode-extension">Install VSCode extension (supports swagger-v2 and openapi-v3 specifications)</a>
20
+
21
+
import Tabs from '@theme/Tabs';
22
+
import TabItem from '@theme/TabItem';
23
+
24
+
<Tabs>
25
+
<TabItemvalue="1"label="npm">
26
+
27
+
```bash
28
+
npm install @alova/wormhole --save
29
+
```
30
+
31
+
</TabItem>
32
+
<TabItemvalue="2"label="yarn">
33
+
34
+
```bash
35
+
yarn add @alova/wormhole
36
+
```
37
+
38
+
</TabItem>
39
+
<TabItemvalue="3"label="pnpm">
40
+
41
+
```bash
42
+
pnpm add @alova/wormhole
43
+
```
44
+
45
+
</TabItem>
46
+
</Tabs>
47
+
48
+
Install `@alova/wormhole` and alova's vscode extension at the same time to enjoy the complete features. `@alova/wormhole` provides automatic generation features. The vscode extension can quickly call `@alova/wormhole` and provide shortcut keys for quickly finding interface documents in the editor.
49
+
50
+
If you are using an editor such as WebStorm, you can use [@alova/wormhole's commands](/api/wormhole#commands) to automatically generate API call functions, complete TypeScript types of APIs, and API documentation information.
51
+
21
52
## Configuration
22
53
23
54
When using the extension, you need to specify the input source and output directory from the openapi file, etc. You can create a configuration file in the project root directory, which supports the following formats:
@@ -35,27 +66,27 @@ The specific configuration parameters are as follows, taking commonjs as an exam
35
66
```js
36
67
// alova.config.js
37
68
module.exports= {
38
-
// API generation setting array, each item represents an automatically generated rule, including the generated input and output directories, standard file addresses, etc.
69
+
// API generation setting array, each item represents an automatically generated rule, including the generated input and output directories, standard file paths, etc.
// Input parameter 2: local address with the current project as the relative directory
76
+
// Input parameter 2: local url with the current project as the relative directory
46
77
// input: 'openapi/api.json'
47
78
48
-
// Input parameter 3: When there is no direct reference to the openapi file, it is a document address, and the document type must be specified with the platform parameter
79
+
// Input parameter 3: When there is no direct reference to the openapi file, it is a document url, and the document type must be specified with the platform parameter
49
80
// input: 'http://192.168.5.123:8080'
50
81
51
82
// (Optional) platform is a platform that supports openapi. Currently only swagger is supported. The default is empty
52
-
// When this parameter is specified, the input field only needs to specify the document address without specifying the openapi file
83
+
// When this parameter is specified, the input field only needs to specify the document url without specifying the openapi file
53
84
platform:'swagger',
54
85
55
-
// Output path of interface file and type file. Multiple generators cannot have the same address, otherwise the generated code will overwrite each other.
86
+
// Output path of interface file and type file. Multiple generators cannot have the same output path, otherwise the generated code will overwrite each other.
56
87
output:'src/api',
57
88
58
-
// (Optional) Specify the mediaType of the generated response data. Use this data type to generate the ts format of the response with a 200 status code. The default is application/json.
89
+
// (Optional) Specify the mediaType of the generated response data. Use this data type to generate the ts format of the response with a 2xx status code. The default is application/json.
59
90
responseMediaType:'application/json',
60
91
61
92
// (Optional) Specify the bodyMediaType of the generated request body data. Use this data type to generate the ts format of the request body. The default is application/json.
@@ -77,8 +108,16 @@ module.exports = {
77
108
*/
78
109
global:'Apis',
79
110
111
+
/**
112
+
* The host object of global mounting, default is `globalThis`, it means `window` in browser and `global` in nodejs
113
+
*/
114
+
globalHost:'globalThis'
115
+
80
116
/**
81
117
* (Optional) Filter or convert the generated api interface function, return a new apiDescriptor to generate the api call function, if this function is not specified, the apiDescripor object is not converted
118
+
*
119
+
* The type of `apiDescriptor` is the same as the api item of openapi file.
// Returning a falsy value means filtering this api
@@ -262,4 +301,6 @@ In this way, you can integrate the automatically generated code without changing
262
301
263
302
1. In a ts project, if you find that vscode cannot correctly prompt, please set `"strictNullChecks": true` in `tsconfig.json`.
264
303
265
-
2. Sometimes the api will prompt as `any` type, you can try to solve it as follows: Step 1, confirm whether this api is introduced in the entry file, and step 2, restart vscode
304
+
2. Sometimes the api will prompt as `any` type, you can try to solve it as follows:
305
+
- Step 1, confirm whether this api is introduced in the entry file.
0 commit comments