openapi-ts-request 0.4.4 → 0.4.6
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.md +23 -20
- package/dist/bin/cli.js +6 -1
- package/dist/bin/openapi.js +10 -10
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -29,18 +29,22 @@ pnpm i openapi-ts-request -D
|
|
|
29
29
|
|
|
30
30
|
### CosmiConfig
|
|
31
31
|
|
|
32
|
-
在项目根目录新建 ```openapi-ts.config.ts```
|
|
33
|
-
> 配置文件还支持 ***.openapi-ts.ts***, ***openapi-ts.config.cjs*** 等格式,参考 [cosmiconfig](https://github.com/cosmiconfig/cosmiconfig?tab=readme-ov-file#cosmiconfig)
|
|
32
|
+
在项目根目录新建 ```openapi-ts-request.config.ts```
|
|
33
|
+
> 配置文件还支持 ***.openapi-ts-request.ts***, ***openapi-ts-request.config.cjs*** 等格式,参考 [cosmiconfig](https://github.com/cosmiconfig/cosmiconfig?tab=readme-ov-file#cosmiconfig)
|
|
34
34
|
|
|
35
35
|
```ts
|
|
36
|
+
import type { GenerateServiceProps } from 'openapi-ts-request'
|
|
37
|
+
|
|
36
38
|
export default {
|
|
37
39
|
schemaPath: 'http://petstore.swagger.io/v2/swagger.json',
|
|
38
|
-
}
|
|
40
|
+
} as GenerateServiceProps
|
|
39
41
|
```
|
|
40
42
|
|
|
41
43
|
支持传入数组配置进行生成
|
|
42
44
|
|
|
43
45
|
```ts
|
|
46
|
+
import type { GenerateServiceProps } from 'openapi-ts-request'
|
|
47
|
+
|
|
44
48
|
export default [
|
|
45
49
|
{
|
|
46
50
|
schemaPath: 'http://app.swagger.io/v2/swagger.json',
|
|
@@ -50,7 +54,7 @@ export default [
|
|
|
50
54
|
schemaPath: 'http://auth.swagger.io/v2/swagger.json',
|
|
51
55
|
serversPath: './src/apis/auth',
|
|
52
56
|
}
|
|
53
|
-
]
|
|
57
|
+
] as GenerateServiceProps[]
|
|
54
58
|
```
|
|
55
59
|
|
|
56
60
|
在 ```package.json``` 的 ```script``` 中添加命令: ```"openapi": "openapi-ts",```
|
|
@@ -63,7 +67,7 @@ npm run openapi
|
|
|
63
67
|
|
|
64
68
|
### JS
|
|
65
69
|
|
|
66
|
-
任意目录 ```xxx/xxx``` 新建 ```openapi-ts.config.js```
|
|
70
|
+
任意目录 ```xxx/xxx``` 新建 ```openapi-ts-request.config.js```
|
|
67
71
|
|
|
68
72
|
```ts
|
|
69
73
|
const { generateService } = require('openapi-ts-request')
|
|
@@ -74,7 +78,7 @@ generateService({
|
|
|
74
78
|
})
|
|
75
79
|
```
|
|
76
80
|
|
|
77
|
-
在 ```package.json``` 的 ```script``` 中添加命令: ```"openapi": "node xxx/xxx/openapi-ts.config.js"```
|
|
81
|
+
在 ```package.json``` 的 ```script``` 中添加命令: ```"openapi": "node xxx/xxx/openapi-ts-request.config.js"```
|
|
78
82
|
|
|
79
83
|
生成结果:
|
|
80
84
|
|
|
@@ -84,7 +88,7 @@ npm run openapi
|
|
|
84
88
|
|
|
85
89
|
### TS
|
|
86
90
|
|
|
87
|
-
任意目录 ```xxx/xxx``` 新建 ```openapi-ts.config.ts```
|
|
91
|
+
任意目录 ```xxx/xxx``` 新建 ```openapi-ts-request.config.ts```
|
|
88
92
|
|
|
89
93
|
```ts
|
|
90
94
|
const { generateService } = require('openapi-ts-request')
|
|
@@ -95,7 +99,7 @@ generateService({
|
|
|
95
99
|
})
|
|
96
100
|
```
|
|
97
101
|
|
|
98
|
-
在 ```package.json``` 的 ```script``` 中添加命令: ```"openapi": "ts-node xxx/xxx/openapi-ts.config.ts",```
|
|
102
|
+
在 ```package.json``` 的 ```script``` 中添加命令: ```"openapi": "ts-node xxx/xxx/openapi-ts-request.config.ts",```
|
|
99
103
|
|
|
100
104
|
生成结果:
|
|
101
105
|
|
|
@@ -129,21 +133,20 @@ $ openapi --help
|
|
|
129
133
|
Options:
|
|
130
134
|
-V, --version output the version number
|
|
131
135
|
-i, --input <string> OpenAPI specification, can be a path, url (required)
|
|
132
|
-
-o, --output <string>
|
|
136
|
+
-o, --output <string> output directory (required)
|
|
133
137
|
--requestLibPath <string> custom request lib path, for example: "@/request", "node-fetch"
|
|
134
|
-
--allowedTags <string[]>
|
|
135
|
-
--requestOptionsType <string>
|
|
138
|
+
--allowedTags <string[]> generate results from allowed tags
|
|
139
|
+
--requestOptionsType <string> custom request method options parameter type (default: "{ [key:
|
|
136
140
|
string]: unknown }")
|
|
137
141
|
--requestImportStatement <string> custom request import statement, for example: "const request =
|
|
138
|
-
require(
|
|
139
|
-
--apiPrefix <string>
|
|
140
|
-
|
|
141
|
-
--isDisplayTypeLabel <boolean>
|
|
142
|
-
--isGenJsonSchemas <boolean>
|
|
143
|
-
--mockFolder <string>
|
|
144
|
-
--nullable <boolean> null instead of optional (default: false)
|
|
145
|
-
--isCamelCase <boolean>
|
|
146
|
-
(default: true)
|
|
142
|
+
require('@/request')"
|
|
143
|
+
--apiPrefix <string> custom the prefix of the api path, for example: "api"(variable),
|
|
144
|
+
"'api'"(string)
|
|
145
|
+
--isDisplayTypeLabel <boolean> generate label matching type field (default: false)
|
|
146
|
+
--isGenJsonSchemas <boolean> generate JSON Schemas (default: false)
|
|
147
|
+
--mockFolder <string> mock file path (default: "./mocks")
|
|
148
|
+
--nullable <boolean> null instead of optional (default: false)
|
|
149
|
+
--isCamelCase <boolean> camelCase naming of controller files and request client (default: true)
|
|
147
150
|
-h, --help display help for command
|
|
148
151
|
```
|
|
149
152
|
|
package/dist/bin/cli.js
CHANGED
|
@@ -5,8 +5,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
7
7
|
const cosmiconfig_1 = require("cosmiconfig");
|
|
8
|
+
const cosmiconfig_typescript_loader_1 = require("cosmiconfig-typescript-loader");
|
|
8
9
|
const index_1 = require("../index");
|
|
9
|
-
const explorerSync = (0, cosmiconfig_1.cosmiconfigSync)('openapi-ts-request'
|
|
10
|
+
const explorerSync = (0, cosmiconfig_1.cosmiconfigSync)('openapi-ts-request', {
|
|
11
|
+
loaders: {
|
|
12
|
+
'.ts': (0, cosmiconfig_typescript_loader_1.TypeScriptLoader)(),
|
|
13
|
+
},
|
|
14
|
+
});
|
|
10
15
|
const config = (_a = explorerSync.search()) === null || _a === void 0 ? void 0 : _a.config;
|
|
11
16
|
function run() {
|
|
12
17
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
package/dist/bin/openapi.js
CHANGED
|
@@ -11,17 +11,17 @@ const params = commander_1.program
|
|
|
11
11
|
.usage('[options]')
|
|
12
12
|
.version(pkg.version)
|
|
13
13
|
.requiredOption('-i, --input <string>', 'OpenAPI specification, can be a path, url (required)')
|
|
14
|
-
.requiredOption('-o, --output <string>', '
|
|
14
|
+
.requiredOption('-o, --output <string>', 'output directory (required)')
|
|
15
15
|
.option('--requestLibPath <string>', 'custom request lib path, for example: "@/request", "node-fetch"')
|
|
16
|
-
.option('--allowedTags <string[]>', '
|
|
17
|
-
.option('--requestOptionsType <string>', '
|
|
18
|
-
.option('--requestImportStatement <string>',
|
|
19
|
-
.option('--apiPrefix <string>',
|
|
20
|
-
.option('--isDisplayTypeLabel <boolean>', '
|
|
21
|
-
.option('--isGenJsonSchemas <boolean>', '
|
|
22
|
-
.option('--mockFolder <string>', 'Mock file path
|
|
23
|
-
.option('--nullable <boolean>', 'null instead of optional
|
|
24
|
-
.option('--isCamelCase <boolean>', '
|
|
16
|
+
.option('--allowedTags <string[]>', 'generate results from allowed tags')
|
|
17
|
+
.option('--requestOptionsType <string>', 'custom request method options parameter type (default: "{ [key: string]: unknown }")')
|
|
18
|
+
.option('--requestImportStatement <string>', `custom request import statement, for example: "const request = require('@/request')"`)
|
|
19
|
+
.option('--apiPrefix <string>', `custom the prefix of the api path, for example: "api"(variable), "'api'"(string)`)
|
|
20
|
+
.option('--isDisplayTypeLabel <boolean>', 'generate label matching type field', false)
|
|
21
|
+
.option('--isGenJsonSchemas <boolean>', 'generate JSON Schemas', false)
|
|
22
|
+
.option('--mockFolder <string>', 'Mock file path (default: "./mocks")')
|
|
23
|
+
.option('--nullable <boolean>', 'null instead of optional', false)
|
|
24
|
+
.option('--isCamelCase <boolean>', 'camelCase naming of controller files and request client', true)
|
|
25
25
|
.parse(process.argv)
|
|
26
26
|
.opts();
|
|
27
27
|
function getPath(path) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openapi-ts-request",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.6",
|
|
4
4
|
"description": "Swagger2/OpenAPI3 to TypeScript, request client, request mock service, enum, type field label, JSON Schemas",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"chalk": "^4.1.2",
|
|
27
27
|
"commander": "^12.1.0",
|
|
28
28
|
"cosmiconfig": "^9.0.0",
|
|
29
|
+
"cosmiconfig-typescript-loader": "^5.0.0",
|
|
29
30
|
"glob": "^10.4.2",
|
|
30
31
|
"lodash": "^4.17.21",
|
|
31
32
|
"memoizee": "^0.4.17",
|