anl 26.106.1 → 26.107.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ar.md +314 -51
- package/README.es.md +314 -51
- package/README.fr.md +369 -51
- package/README.jp.md +266 -35
- package/README.md +335 -38
- package/README.ru.md +266 -35
- package/README.zh.md +365 -60
- package/lib/package.json.js +1 -1
- package/lib/src/build-type/core/get-data.js +1 -1
- package/lib/src/build-type/core/path.js +1 -1
- package/lib/src/build-type/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -104,7 +104,7 @@ $ anl type
|
|
|
104
104
|
"saveApiListFolderPath": "apps/api/",
|
|
105
105
|
"saveEnumFolderPath": "apps/enums",
|
|
106
106
|
"importEnumPath": "../../enums",
|
|
107
|
-
"
|
|
107
|
+
"swaggerConfig": {
|
|
108
108
|
"url": "https://generator3.swagger.io/openapi2.json",
|
|
109
109
|
"apiListFileName": "index.ts",
|
|
110
110
|
"publicPrefix": "api",
|
|
@@ -120,7 +120,8 @@ $ anl type
|
|
|
120
120
|
"includeInterface": [
|
|
121
121
|
{
|
|
122
122
|
"path": "/api/user",
|
|
123
|
-
"method": "get"
|
|
123
|
+
"method": "get",
|
|
124
|
+
"dataLevel": "data"
|
|
124
125
|
}
|
|
125
126
|
],
|
|
126
127
|
"excludeInterface": [
|
|
@@ -158,7 +159,7 @@ $ anl type
|
|
|
158
159
|
"varnames": "enum-varnames",
|
|
159
160
|
"comment": "enum-descriptions"
|
|
160
161
|
},
|
|
161
|
-
"
|
|
162
|
+
"swaggerConfig": [
|
|
162
163
|
{
|
|
163
164
|
"url": "https://generator3.swagger.io/openapi1.json",
|
|
164
165
|
"apiListFileName": "op.ts",
|
|
@@ -176,30 +177,41 @@ $ anl type
|
|
|
176
177
|
|
|
177
178
|
#### Configuration Item Descriptions
|
|
178
179
|
|
|
179
|
-
| Configuration Item
|
|
180
|
-
|
|
|
181
|
-
| saveTypeFolderPath
|
|
182
|
-
| saveApiListFolderPath
|
|
183
|
-
| saveEnumFolderPath
|
|
184
|
-
| importEnumPath
|
|
185
|
-
| swaggerJsonUrl
|
|
186
|
-
|
|
|
187
|
-
|
|
|
188
|
-
|
|
|
189
|
-
|
|
|
190
|
-
|
|
|
191
|
-
|
|
|
192
|
-
| dataLevel
|
|
193
|
-
|
|
|
194
|
-
|
|
|
195
|
-
|
|
|
196
|
-
|
|
|
197
|
-
|
|
|
198
|
-
|
|
|
199
|
-
|
|
|
200
|
-
|
|
|
201
|
-
|
|
|
202
|
-
|
|
|
180
|
+
| Configuration Item | Type | Required | Description |
|
|
181
|
+
| ---------------------------------- | ------------------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
182
|
+
| saveTypeFolderPath | string | Yes | Type definition file save path |
|
|
183
|
+
| saveApiListFolderPath | string | Yes | API request function file save path |
|
|
184
|
+
| saveEnumFolderPath | string | Yes | Enum data file save path |
|
|
185
|
+
| importEnumPath | string | Yes | Enum import path (path referenced by enum files in apps/types/models/\*.ts) |
|
|
186
|
+
| swaggerJsonUrl | string | No | Swagger JSON documentation address (migrated to `swaggerConfig`, retained for backward compatibility) **This field will be removed in future versions** |
|
|
187
|
+
| swaggerConfig | object \| Array<object> | No | Swagger server configuration. Single server can be an object, multiple servers use an array. Each server can configure `url`, `publicPrefix`, `modulePrefix`, `apiListFileName`, `headers`, `dataLevel`, `parameterSeparator`, `includeInterface`, `excludeInterface`<br />See single and multiple Swagger server configuration examples above |
|
|
188
|
+
| swaggerConfig[].url | string | Yes | Swagger JSON documentation address |
|
|
189
|
+
| swaggerConfig[].publicPrefix | string | No | Common prefix on url path, e.g.: api/users, api/users/{id}, api is the common prefix |
|
|
190
|
+
| swaggerConfig[].apiListFileName | string | No | API list file name, defaults to `index.ts`. When using multiple servers, each server's file name must be unique |
|
|
191
|
+
| swaggerConfig[].headers | object | No | Request header configuration for this server |
|
|
192
|
+
| swaggerConfig[].modulePrefix | string | No | Request path prefix (can be understood as module name), automatically added to the front of each API request path.<br />For example: when `modulePrefix: "/forward"`<br />`/publicPrefix/modulePrefix/user` becomes `/api/forward/user` |
|
|
193
|
+
| swaggerConfig[].dataLevel | 'data' \| 'serve' \| 'axios' | No | Interface return data level for this server. If not set, uses global `dataLevel` configuration |
|
|
194
|
+
| swaggerConfig[].parameterSeparator | '$' \| '\_' | No | Separator used when generating API names and type names for this server. If not set, uses global `parameterSeparator` configuration |
|
|
195
|
+
| swaggerConfig[].includeInterface | Array<{path: string, method: string, dataLevel?: 'data' \| 'serve' \| 'axios'}> | No | List of interfaces to include for this server. Each interface can configure `dataLevel` individually with the highest priority. If not set, uses global `includeInterface` configuration |
|
|
196
|
+
| swaggerConfig[].excludeInterface | Array<{path: string, method: string}> | No | List of interfaces to exclude for this server. If not set, uses global `excludeInterface` configuration |
|
|
197
|
+
| requestMethodsImportPath | string | Yes | Request method import path |
|
|
198
|
+
| dataLevel | 'data' \| 'serve' \| 'axios' | No | Global interface return data level configuration, default: `'serve'`. Each server can override individually |
|
|
199
|
+
| formatting | object | No | Code formatting configuration |
|
|
200
|
+
| formatting.indentation | string | No | Code indentation character, e.g.: `"\t"` or `" "` (two spaces) |
|
|
201
|
+
| formatting.lineEnding | string | No | Line ending, e.g.: `"\n"` (LF) or `"\r\n"` (CRLF) |
|
|
202
|
+
| headers | object | No | Request header configuration (migrated to `swaggerConfig`, retained for backward compatibility) |
|
|
203
|
+
| includeInterface | Array<{path: string, method: string, dataLevel?: 'data' \| 'serve' \| 'axios'}> | No | Global included interfaces: The interface list file specified by `saveApiListFolderPath` will only include interfaces in the list, mutually exclusive with `excludeInterface` field. Each interface can configure `dataLevel` individually. Each server can override individually |
|
|
204
|
+
| excludeInterface | Array<{path: string, method: string}> | No | Global excluded interfaces: The interface list file specified by `saveApiListFolderPath` will not include interfaces in this list, mutually exclusive with `includeInterface`. Each server can override individually |
|
|
205
|
+
| publicPrefix | string | No | Global common prefix on url path (migrated to `swaggerConfig`, retained for backward compatibility) |
|
|
206
|
+
| modulePrefix | string | No | Global request path prefix (each server can override individually) |
|
|
207
|
+
| apiListFileName | string | No | Global API list file name, defaults to `index.ts` (migrated to `swaggerConfig`, retained for backward compatibility) |
|
|
208
|
+
| enmuConfig | object | Yes | Enum configuration object |
|
|
209
|
+
| enmuConfig.erasableSyntaxOnly | boolean | Yes | Align with tsconfig.json `compilerOptions.erasableSyntaxOnly`. When `true`, generates const objects instead of enums (type-only syntax). Default: `false` |
|
|
210
|
+
| enmuConfig.varnames | string | No | Swagger schema field name for custom enum member names. Default: `enum-varnames`. |
|
|
211
|
+
| enmuConfig.comment | string | No | Swagger schema field name for custom enum descriptions (used for generating comments). Default: `enum-descriptions`. |
|
|
212
|
+
| parameterSeparator | '$' \| '\_' | No | Global separator used between path segments and parameters when generating API names and type names. For example, `/users/{userId}/posts` with separator `'_'` generates `users_userId_posts_GET`. Default: `'_'`. Each server can override individually |
|
|
213
|
+
| enmuConfig.varnames | string | No | Schema field name that stores custom enum member identifiers. Default: `enum-varnames`. |
|
|
214
|
+
| enmuConfig.comment | string | No | Schema field name that stores enum member descriptions (used for inline comments). Default: `enum-descriptions`. |
|
|
203
215
|
|
|
204
216
|
#### Configuration Items and Generated Files Correspondence
|
|
205
217
|
|
|
@@ -253,6 +265,52 @@ export const userDetailGet = (params: UserDetail_GET.Query) => GET<UserDetail_GE
|
|
|
253
265
|
|
|
254
266
|
### Feature Descriptions
|
|
255
267
|
|
|
268
|
+
#### Configuration Priority
|
|
269
|
+
|
|
270
|
+
The tool supports global configuration and server-level configuration, following these priority rules:
|
|
271
|
+
|
|
272
|
+
**Priority: Interface-level configuration > Server-level configuration > Global configuration > Default values**
|
|
273
|
+
|
|
274
|
+
The following configuration items support multi-level priority override:
|
|
275
|
+
|
|
276
|
+
- `dataLevel`: Interface return data level
|
|
277
|
+
- **Interface-level**: `includeInterface[].dataLevel` - Highest priority
|
|
278
|
+
- **Server-level**: `swaggerConfig[].dataLevel` - Secondary priority
|
|
279
|
+
- **Global configuration**: `dataLevel` - Base priority
|
|
280
|
+
- **Default value**: `'serve'`
|
|
281
|
+
- `parameterSeparator`: Separator for API names and type names
|
|
282
|
+
- `includeInterface`: List of included interfaces
|
|
283
|
+
- `excludeInterface`: List of excluded interfaces
|
|
284
|
+
- `modulePrefix`: Request path prefix
|
|
285
|
+
- `publicPrefix`: URL common prefix
|
|
286
|
+
- `headers`: Request header configuration
|
|
287
|
+
|
|
288
|
+
**Example:**
|
|
289
|
+
|
|
290
|
+
```json
|
|
291
|
+
{
|
|
292
|
+
"dataLevel": "serve",
|
|
293
|
+
"parameterSeparator": "_",
|
|
294
|
+
"swaggerConfig": [
|
|
295
|
+
{
|
|
296
|
+
"url": "http://api1.example.com/swagger.json",
|
|
297
|
+
"dataLevel": "data",
|
|
298
|
+
"apiListFileName": "api1.ts"
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
"url": "http://api2.example.com/swagger.json",
|
|
302
|
+
"apiListFileName": "api2.ts"
|
|
303
|
+
}
|
|
304
|
+
]
|
|
305
|
+
}
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
In the above configuration:
|
|
309
|
+
|
|
310
|
+
- `api1.ts` uses `dataLevel: "data"` (server-level configuration)
|
|
311
|
+
- `api2.ts` uses `dataLevel: "serve"` (global configuration)
|
|
312
|
+
- Both servers use `parameterSeparator: "_"` (global configuration)
|
|
313
|
+
|
|
256
314
|
#### Type Parsing
|
|
257
315
|
|
|
258
316
|
- Supports all OpenAPI 3.0 specification data types
|
|
@@ -303,6 +361,100 @@ interface User {
|
|
|
303
361
|
}
|
|
304
362
|
```
|
|
305
363
|
|
|
364
|
+
#### Data Level Configuration (dataLevel)
|
|
365
|
+
|
|
366
|
+
`dataLevel` is used to configure the extraction level of interface return data, supporting three options:
|
|
367
|
+
|
|
368
|
+
1. **`'serve'` (default)**: Extracts the `data` field from server response
|
|
369
|
+
|
|
370
|
+
```typescript
|
|
371
|
+
// Server returns: { code: 200, message: 'success', data: { id: 1, name: 'user' } }
|
|
372
|
+
// Function returns: { id: 1, name: 'user' }
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
2. **`'data'`**: Extracts the `data.data` field (for nested data scenarios)
|
|
376
|
+
|
|
377
|
+
```typescript
|
|
378
|
+
// Server returns: { data: { code: 200, data: { id: 1, name: 'user' } } }
|
|
379
|
+
// Function returns: { id: 1, name: 'user' }
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
3. **`'axios'`**: Returns the complete axios response object
|
|
383
|
+
```typescript
|
|
384
|
+
// Server returns: { code: 200, message: 'success', data: { id: 1, name: 'user' } }
|
|
385
|
+
// Function returns: { code: 200, message: 'success', data: { id: 1, name: 'user' } }
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
**Configuration Priority:**
|
|
389
|
+
|
|
390
|
+
`dataLevel` supports three-level configuration priority:
|
|
391
|
+
|
|
392
|
+
```
|
|
393
|
+
Interface-level > Server-level > Global configuration > Default value
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
**Configuration example:**
|
|
397
|
+
|
|
398
|
+
```json
|
|
399
|
+
{
|
|
400
|
+
"dataLevel": "serve",
|
|
401
|
+
"swaggerConfig": [
|
|
402
|
+
{
|
|
403
|
+
"url": "http://api1.example.com/swagger.json",
|
|
404
|
+
"dataLevel": "data",
|
|
405
|
+
"includeInterface": [
|
|
406
|
+
{
|
|
407
|
+
"path": "/api/user/detail",
|
|
408
|
+
"method": "get",
|
|
409
|
+
"dataLevel": "axios"
|
|
410
|
+
},
|
|
411
|
+
{
|
|
412
|
+
"path": "/api/user/list",
|
|
413
|
+
"method": "get"
|
|
414
|
+
}
|
|
415
|
+
]
|
|
416
|
+
}
|
|
417
|
+
]
|
|
418
|
+
}
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
In the above configuration:
|
|
422
|
+
- `/api/user/detail` interface uses `dataLevel: "axios"` (interface-level configuration, highest priority)
|
|
423
|
+
- `/api/user/list` interface uses `dataLevel: "data"` (server-level configuration)
|
|
424
|
+
- Other server interfaces use `dataLevel: "serve"` (global configuration)
|
|
425
|
+
|
|
426
|
+
> **Note**:
|
|
427
|
+
> - Interface-level `dataLevel` configuration has the highest priority, suitable for scenarios where individual interfaces need special handling
|
|
428
|
+
> - Server-level `dataLevel` configuration will override global configuration
|
|
429
|
+
> - Uses default value `'serve'` when not configured
|
|
430
|
+
|
|
431
|
+
#### Code Formatting
|
|
432
|
+
|
|
433
|
+
The tool supports custom code formatting options, controlled by the `formatting` configuration:
|
|
434
|
+
|
|
435
|
+
**Configuration example:**
|
|
436
|
+
|
|
437
|
+
```json
|
|
438
|
+
{
|
|
439
|
+
"formatting": {
|
|
440
|
+
"indentation": "\t",
|
|
441
|
+
"lineEnding": "\n"
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
**Configuration description:**
|
|
447
|
+
|
|
448
|
+
- `indentation`: Code indentation character
|
|
449
|
+
- `"\t"`: Use Tab indentation (default)
|
|
450
|
+
- `" "`: Use 2 spaces indentation
|
|
451
|
+
- `" "`: Use 4 spaces indentation
|
|
452
|
+
- `lineEnding`: Line ending type
|
|
453
|
+
- `"\n"`: LF (Linux/macOS style, recommended)
|
|
454
|
+
- `"\r\n"`: CRLF (Windows style)
|
|
455
|
+
|
|
456
|
+
**Note:** If Prettier is configured in the project, the generated code will automatically use Prettier for formatting, and the `formatting` configuration may be overridden by Prettier.
|
|
457
|
+
|
|
306
458
|
#### File Upload
|
|
307
459
|
|
|
308
460
|
When file upload types are detected, corresponding request headers are automatically added:
|
|
@@ -329,7 +481,8 @@ The tool supports filtering interfaces to be generated through configuration:
|
|
|
329
481
|
1. Include specific interfaces
|
|
330
482
|
- Specify interfaces to be generated through the `includeInterface` configuration item
|
|
331
483
|
- Only interfaces specified in the configuration will be generated
|
|
332
|
-
- Configuration format is an object array containing `path` and `
|
|
484
|
+
- Configuration format is an object array containing `path`, `method`, and optional `dataLevel`
|
|
485
|
+
- Each interface can configure `dataLevel` individually with the highest priority
|
|
333
486
|
|
|
334
487
|
2. Exclude specific interfaces
|
|
335
488
|
- Specify interfaces to be excluded through the `excludeInterface` configuration item
|
|
@@ -343,7 +496,8 @@ Example configuration: This configuration is in `an.config.json`
|
|
|
343
496
|
"includeInterface": [
|
|
344
497
|
{
|
|
345
498
|
"path": "/api/user",
|
|
346
|
-
"method": "get"
|
|
499
|
+
"method": "get",
|
|
500
|
+
"dataLevel": "data"
|
|
347
501
|
}
|
|
348
502
|
],
|
|
349
503
|
"excludeInterface": [
|
|
@@ -361,8 +515,8 @@ Note: `includeInterface` and `excludeInterface` cannot be used simultaneously. I
|
|
|
361
515
|
|
|
362
516
|
The tool supports configuring multiple Swagger servers, each server can be configured independently:
|
|
363
517
|
|
|
364
|
-
- **Single server**: `
|
|
365
|
-
- **Multiple servers**: `
|
|
518
|
+
- **Single server**: `swaggerConfig` can be directly filled with an object
|
|
519
|
+
- **Multiple servers**: `swaggerConfig` uses an array format, each server must configure a unique `apiListFileName`
|
|
366
520
|
|
|
367
521
|
**How it works:**
|
|
368
522
|
|
|
@@ -370,23 +524,78 @@ The tool supports configuring multiple Swagger servers, each server can be confi
|
|
|
370
524
|
- Subsequent servers' APIs will be appended to their respective `apiListFileName` files
|
|
371
525
|
- Type definitions and enums will be merged into a unified folder to avoid duplication
|
|
372
526
|
|
|
527
|
+
**Server-level configuration:**
|
|
528
|
+
|
|
529
|
+
Each server supports independent configuration of the following options. If not set, global configuration will be used:
|
|
530
|
+
|
|
531
|
+
- `dataLevel` - Interface return data level
|
|
532
|
+
- `parameterSeparator` - Separator for API names and type names
|
|
533
|
+
- `includeInterface` - List of included interfaces
|
|
534
|
+
- `excludeInterface` - List of excluded interfaces
|
|
535
|
+
- `modulePrefix` - Request path prefix
|
|
536
|
+
|
|
537
|
+
#### Path Prefix (modulePrefix)
|
|
538
|
+
|
|
539
|
+
`modulePrefix` is used to automatically add a prefix to all API request paths, which is particularly useful in the following scenarios:
|
|
540
|
+
|
|
541
|
+
1. **Reverse proxy scenarios**: When backend services are forwarded through a reverse proxy
|
|
542
|
+
2. **API Gateway**: Uniformly add gateway prefix to paths
|
|
543
|
+
3. **Multi-environment configuration**: Use different path prefixes for different environments
|
|
544
|
+
|
|
545
|
+
**Usage example:**
|
|
546
|
+
|
|
547
|
+
```json
|
|
548
|
+
{
|
|
549
|
+
"swaggerConfig": [
|
|
550
|
+
{
|
|
551
|
+
"url": "http://api.example.com/swagger.json",
|
|
552
|
+
"modulePrefix": "/forward",
|
|
553
|
+
"apiListFileName": "api.ts"
|
|
554
|
+
}
|
|
555
|
+
]
|
|
556
|
+
}
|
|
557
|
+
```
|
|
558
|
+
|
|
559
|
+
**Effect:**
|
|
560
|
+
|
|
561
|
+
The path `/api/user/list` defined in Swagger will be generated as:
|
|
562
|
+
|
|
563
|
+
```typescript
|
|
564
|
+
export const apiUserListGet = (params: ApiUserList_GET.Query) => GET<ApiUserList_GET.Response>('/forward/api/user/list', params);
|
|
565
|
+
```
|
|
566
|
+
|
|
567
|
+
**Difference from publicPrefix:**
|
|
568
|
+
|
|
569
|
+
- `publicPrefix`: Used to remove common prefix from interface paths (only affects generated function names)
|
|
570
|
+
- `modulePrefix`: Used to add prefix to actual request paths (affects runtime request URLs)
|
|
571
|
+
|
|
373
572
|
**Configuration example:**
|
|
374
573
|
|
|
375
574
|
```json
|
|
376
575
|
{
|
|
377
|
-
"
|
|
576
|
+
"swaggerConfig": [
|
|
378
577
|
{
|
|
379
578
|
"url": "http://api1.example.com/swagger.json",
|
|
380
579
|
"apiListFileName": "api1.ts",
|
|
381
580
|
"publicPrefix": "/api/v1",
|
|
581
|
+
"modulePrefix": "/forward",
|
|
582
|
+
"dataLevel": "serve",
|
|
583
|
+
"parameterSeparator": "_",
|
|
382
584
|
"headers": {
|
|
383
585
|
"Authorization": "Bearer token1"
|
|
384
|
-
}
|
|
586
|
+
},
|
|
587
|
+
"includeInterface": [
|
|
588
|
+
{
|
|
589
|
+
"path": "/api/v1/users",
|
|
590
|
+
"method": "get"
|
|
591
|
+
}
|
|
592
|
+
]
|
|
385
593
|
},
|
|
386
594
|
{
|
|
387
595
|
"url": "http://api2.example.com/swagger.json",
|
|
388
596
|
"apiListFileName": "api2.ts",
|
|
389
597
|
"publicPrefix": "/api/v2",
|
|
598
|
+
"dataLevel": "data",
|
|
390
599
|
"headers": {
|
|
391
600
|
"Authorization": "Bearer token2"
|
|
392
601
|
}
|
|
@@ -399,7 +608,7 @@ The tool supports configuring multiple Swagger servers, each server can be confi
|
|
|
399
608
|
|
|
400
609
|
- Old configuration (`swaggerJsonUrl`, `publicPrefix`, `headers`) is still compatible
|
|
401
610
|
- The tool will automatically detect old configuration and suggest migration methods
|
|
402
|
-
- It's recommended to migrate to the new `
|
|
611
|
+
- It's recommended to migrate to the new `swaggerConfig` configuration for better flexibility
|
|
403
612
|
|
|
404
613
|
#### HTTP Method Support
|
|
405
614
|
|
|
@@ -420,21 +629,109 @@ All methods support type-safe parameter and response type definitions.
|
|
|
420
629
|
|
|
421
630
|
1. Ensure the Swagger JSON documentation address is accessible
|
|
422
631
|
2. Paths in the configuration file need to be relative to the project root directory
|
|
423
|
-
3. Generated files will overwrite existing files with the same name
|
|
632
|
+
3. Generated files will overwrite existing files with the same name (but `config.ts`, `error-message.ts`, `fetch.ts`, `api-type.d.ts` will not be overwritten if they already exist)
|
|
424
633
|
4. It's recommended to add generated files to version control
|
|
425
634
|
5. When using multiple Swagger servers, ensure each server's `apiListFileName` is unique to avoid file overwriting
|
|
426
635
|
6. When configuring multiple servers, type definitions and enums will be merged. If different servers have types with the same name, conflicts may occur
|
|
636
|
+
7. Server-level configuration (`dataLevel`, `parameterSeparator`, `includeInterface`, `excludeInterface`, `modulePrefix`) will override global configuration
|
|
637
|
+
8. `includeInterface` and `excludeInterface` cannot be configured simultaneously. If both are configured, `includeInterface` will be prioritized
|
|
427
638
|
|
|
428
639
|
### Common Issues
|
|
429
640
|
|
|
430
|
-
1. Generated type file formatting fails
|
|
641
|
+
1. **Generated type file formatting fails**
|
|
431
642
|
- Check if prettier is installed
|
|
432
643
|
- Confirm if there's a prettier configuration file in the project root directory
|
|
644
|
+
- Check if the `formatting` configuration is correct
|
|
433
645
|
|
|
434
|
-
2. Request function import path error
|
|
435
|
-
- Check if the requestMethodsImportPath configuration is correct
|
|
646
|
+
2. **Request function import path error**
|
|
647
|
+
- Check if the `requestMethodsImportPath` configuration is correct
|
|
436
648
|
- Confirm if the request method file exists
|
|
437
649
|
|
|
650
|
+
3. **When to use `modulePrefix`?**
|
|
651
|
+
- When your APIs need to be accessed through a reverse proxy or gateway
|
|
652
|
+
- For example: Swagger defines `/api/user`, but the actual request needs to be `/gateway/api/user`
|
|
653
|
+
- Set `modulePrefix: "/gateway"` to achieve this
|
|
654
|
+
|
|
655
|
+
4. **What's the difference between `publicPrefix` and `modulePrefix`?**
|
|
656
|
+
- `publicPrefix`: Removes prefix from interface paths, only affects generated function names
|
|
657
|
+
- Example: `/api/user/list` after removing `/api`, function name becomes `userListGet`
|
|
658
|
+
- `modulePrefix`: Adds prefix to request paths, affects actual request URLs
|
|
659
|
+
- Example: `/api/user/list` after adding `/forward`, request URL becomes `/forward/api/user/list`
|
|
660
|
+
|
|
661
|
+
5. **How to configure different `dataLevel` for multiple servers?**
|
|
662
|
+
|
|
663
|
+
```json
|
|
664
|
+
{
|
|
665
|
+
"dataLevel": "serve",
|
|
666
|
+
"swaggerConfig": [
|
|
667
|
+
{
|
|
668
|
+
"url": "http://old-api.com/swagger.json",
|
|
669
|
+
"dataLevel": "axios",
|
|
670
|
+
"apiListFileName": "old-api.ts"
|
|
671
|
+
},
|
|
672
|
+
{
|
|
673
|
+
"url": "http://new-api.com/swagger.json",
|
|
674
|
+
"apiListFileName": "new-api.ts"
|
|
675
|
+
}
|
|
676
|
+
]
|
|
677
|
+
}
|
|
678
|
+
```
|
|
679
|
+
|
|
680
|
+
- `old-api.ts` uses `dataLevel: "axios"`
|
|
681
|
+
- `new-api.ts` uses the global `dataLevel: "serve"`
|
|
682
|
+
|
|
683
|
+
6. **How to configure different `dataLevel` for individual interfaces?**
|
|
684
|
+
|
|
685
|
+
```json
|
|
686
|
+
{
|
|
687
|
+
"dataLevel": "serve",
|
|
688
|
+
"swaggerConfig": [
|
|
689
|
+
{
|
|
690
|
+
"url": "http://api.com/swagger.json",
|
|
691
|
+
"apiListFileName": "api.ts",
|
|
692
|
+
"dataLevel": "data",
|
|
693
|
+
"includeInterface": [
|
|
694
|
+
{
|
|
695
|
+
"path": "/api/user/detail",
|
|
696
|
+
"method": "get",
|
|
697
|
+
"dataLevel": "axios"
|
|
698
|
+
},
|
|
699
|
+
{
|
|
700
|
+
"path": "/api/user/list",
|
|
701
|
+
"method": "get"
|
|
702
|
+
}
|
|
703
|
+
]
|
|
704
|
+
}
|
|
705
|
+
]
|
|
706
|
+
}
|
|
707
|
+
```
|
|
708
|
+
|
|
709
|
+
- `/api/user/detail` uses interface-level `dataLevel: "axios"` (highest priority)
|
|
710
|
+
- `/api/user/list` uses server-level `dataLevel: "data"`
|
|
711
|
+
- Other server interfaces use global `dataLevel: "serve"`
|
|
712
|
+
|
|
713
|
+
7. **How to generate only specific interfaces?**
|
|
714
|
+
- Use `includeInterface` configuration:
|
|
715
|
+
```json
|
|
716
|
+
{
|
|
717
|
+
"swaggerConfig": [
|
|
718
|
+
{
|
|
719
|
+
"url": "http://api.com/swagger.json",
|
|
720
|
+
"includeInterface": [
|
|
721
|
+
{ "path": "/api/user", "method": "get" },
|
|
722
|
+
{ "path": "/api/user/{id}", "method": "post" }
|
|
723
|
+
]
|
|
724
|
+
}
|
|
725
|
+
]
|
|
726
|
+
}
|
|
727
|
+
```
|
|
728
|
+
- Or use `excludeInterface` to exclude unwanted interfaces
|
|
729
|
+
|
|
730
|
+
8. **What if generated files are overwritten?**
|
|
731
|
+
- Files like `config.ts`, `error-message.ts`, `fetch.ts`, `api-type.d.ts` are only generated when they don't exist
|
|
732
|
+
- API list files and type files are regenerated each time
|
|
733
|
+
- It's recommended to add generated files to version control for easy tracking of changes
|
|
734
|
+
|
|
438
735
|
# `anl lint` Command Usage
|
|
439
736
|
|
|
440
737
|
> Provides **interactive multi-select** configuration for various lint tools in frontend projects, including:
|