openapi-ts-request 0.11.1 → 0.12.0
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 +2 -0
- package/dist/bin/openapi.js +2 -0
- package/dist/generator/serviceGenarator.js +24 -14
- package/dist/index.d.ts +4 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -150,6 +150,7 @@ $ openapi --help
|
|
|
150
150
|
--authorization <string> docs authorization
|
|
151
151
|
--nullable <boolean> null instead of optional (default: false)
|
|
152
152
|
--isTranslateToEnglishTag <boolean>translate chinese tag name to english tag name (default: false)
|
|
153
|
+
--isOnlyGenTypeScriptType <boolean>only generate typescript type (default: false)
|
|
153
154
|
--isCamelCase <boolean> camelCase naming of controller files and request client (default: true)
|
|
154
155
|
-h, --help display help for command
|
|
155
156
|
```
|
|
@@ -177,6 +178,7 @@ openapi --i ./spec.json --o ./apis
|
|
|
177
178
|
| authorization | 否 | string | - | 文档权限凭证 |
|
|
178
179
|
| nullable | 否 | boolean | false | 使用 null 代替可选 |
|
|
179
180
|
| isTranslateToEnglishTag | 否 | boolean | false | 将中文 tag 名称翻译成英文 tag 名称 |
|
|
181
|
+
| isOnlyGenTypeScriptType | 否 | boolean | false | 仅生成 typescript 类型 |
|
|
180
182
|
| isCamelCase | 否 | boolean | true | 小驼峰命名文件和请求函数 |
|
|
181
183
|
| hook | 否 | [Custom Hook](#Custom-Hook) | - | 自定义 hook |
|
|
182
184
|
|
package/dist/bin/openapi.js
CHANGED
|
@@ -23,6 +23,7 @@ const params = commander_1.program
|
|
|
23
23
|
.option('--authorization <string>', 'docs authorization')
|
|
24
24
|
.option('--nullable <boolean>', 'null instead of optional', false)
|
|
25
25
|
.option('--isTranslateToEnglishTag <boolean>', 'translate chinese tag name to english tag name', false)
|
|
26
|
+
.option('--isOnlyGenTypeScriptType <boolean>', 'only generate typescript type', false)
|
|
26
27
|
.option('--isCamelCase <boolean>', 'camelCase naming of controller files and request client', true)
|
|
27
28
|
.parse(process.argv)
|
|
28
29
|
.opts();
|
|
@@ -51,6 +52,7 @@ function run() {
|
|
|
51
52
|
authorization: params.authorization,
|
|
52
53
|
nullable: JSON.parse(params.nullable) === true,
|
|
53
54
|
isTranslateToEnglishTag: JSON.parse(params.isTranslateToEnglishTag) === true,
|
|
55
|
+
isOnlyGenTypeScriptType: JSON.parse(params.isOnlyGenTypeScriptType) === true,
|
|
54
56
|
isCamelCase: JSON.parse(params.isCamelCase) === true,
|
|
55
57
|
});
|
|
56
58
|
process.exit(0);
|
|
@@ -80,7 +80,7 @@ class ServiceGenerator {
|
|
|
80
80
|
});
|
|
81
81
|
// 生成枚举翻译
|
|
82
82
|
const enums = (0, lodash_1.filter)(interfaceTPConfigs, (item) => item.isEnum);
|
|
83
|
-
if (!(0, lodash_1.isEmpty)(enums)) {
|
|
83
|
+
if (!this.config.isOnlyGenTypeScriptType && !(0, lodash_1.isEmpty)(enums)) {
|
|
84
84
|
this.genFileFromTemplate(`${config_1.displayEnumLabelFileName}.ts`, config_1.TypescriptFileType.displayEnumLabel, {
|
|
85
85
|
list: enums,
|
|
86
86
|
namespace: this.config.namespace,
|
|
@@ -89,23 +89,29 @@ class ServiceGenerator {
|
|
|
89
89
|
}
|
|
90
90
|
const displayTypeLabels = (0, lodash_1.filter)(interfaceTPConfigs, (item) => !item.isEnum);
|
|
91
91
|
// 生成 type 翻译
|
|
92
|
-
if (this.config.
|
|
92
|
+
if (!this.config.isOnlyGenTypeScriptType &&
|
|
93
|
+
this.config.isDisplayTypeLabel &&
|
|
94
|
+
!(0, lodash_1.isEmpty)(displayTypeLabels)) {
|
|
93
95
|
this.genFileFromTemplate(`${config_1.displayTypeLabelFileName}.ts`, config_1.TypescriptFileType.displayTypeLabel, {
|
|
94
96
|
list: displayTypeLabels,
|
|
95
97
|
namespace: this.config.namespace,
|
|
96
98
|
interfaceFileName: config_1.interfaceFileName,
|
|
97
99
|
});
|
|
98
100
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
(
|
|
101
|
+
if (!this.config.isOnlyGenTypeScriptType) {
|
|
102
|
+
const prettierError = [];
|
|
103
|
+
// 生成 service controller 文件
|
|
104
|
+
this.getServiceTPConfigs().forEach((tp) => {
|
|
105
|
+
const hasError = this.genFileFromTemplate((0, util_1.getFinalFileName)(`${tp.className}.ts`), config_1.TypescriptFileType.serviceController, Object.assign({ namespace: this.config.namespace, requestOptionsType: this.config.requestOptionsType, requestImportStatement: this.config.requestImportStatement, interfaceFileName: config_1.interfaceFileName }, tp));
|
|
106
|
+
prettierError.push(hasError);
|
|
107
|
+
});
|
|
108
|
+
if (prettierError.includes(true)) {
|
|
109
|
+
(0, log_1.default)('🚥 格式化失败,请检查 service controller 文件内可能存在的语法错误');
|
|
110
|
+
}
|
|
107
111
|
}
|
|
108
|
-
if (this.config.
|
|
112
|
+
if (!this.config.isOnlyGenTypeScriptType &&
|
|
113
|
+
this.config.isGenJsonSchemas &&
|
|
114
|
+
!(0, lodash_1.isEmpty)(this.schemaList)) {
|
|
109
115
|
// 处理重复的 schemaName
|
|
110
116
|
(0, util_1.handleDuplicateTypeNames)(this.schemaList);
|
|
111
117
|
// 生成 schema 文件
|
|
@@ -118,11 +124,15 @@ class ServiceGenerator {
|
|
|
118
124
|
list: this.classNameList,
|
|
119
125
|
namespace: this.config.namespace,
|
|
120
126
|
interfaceFileName: config_1.interfaceFileName,
|
|
121
|
-
isGenJsonSchemas: this.config.
|
|
127
|
+
isGenJsonSchemas: !this.config.isOnlyGenTypeScriptType &&
|
|
128
|
+
this.config.isGenJsonSchemas &&
|
|
129
|
+
!(0, lodash_1.isEmpty)(this.schemaList),
|
|
122
130
|
schemaFileName: config_1.schemaFileName,
|
|
123
|
-
isDisplayEnumLabel: !(0, lodash_1.isEmpty)(enums),
|
|
131
|
+
isDisplayEnumLabel: !this.config.isOnlyGenTypeScriptType && !(0, lodash_1.isEmpty)(enums),
|
|
124
132
|
displayEnumLabelFileName: config_1.displayEnumLabelFileName,
|
|
125
|
-
isDisplayTypeLabel: this.config.
|
|
133
|
+
isDisplayTypeLabel: !this.config.isOnlyGenTypeScriptType &&
|
|
134
|
+
this.config.isDisplayTypeLabel &&
|
|
135
|
+
!(0, lodash_1.isEmpty)(displayTypeLabels),
|
|
126
136
|
displayTypeLabelFileName: config_1.displayTypeLabelFileName,
|
|
127
137
|
});
|
|
128
138
|
// 打印日志
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -21,7 +21,7 @@ function generateService(_a) {
|
|
|
21
21
|
yield (0, util_1.translateChineseModuleNodeToEnglish)(openAPI);
|
|
22
22
|
}
|
|
23
23
|
const requestImportStatement = (0, util_1.getImportStatement)(requestLibPath);
|
|
24
|
-
const serviceGenerator = new serviceGenarator_1.default(Object.assign({ schemaPath, serversPath: './src/apis', requestImportStatement, requestOptionsType: '{[key: string]: unknown}', namespace: 'API', nullable: false, isCamelCase: true, isDisplayTypeLabel: false, isGenJsonSchemas: false, allowedTags: allowedTags
|
|
24
|
+
const serviceGenerator = new serviceGenarator_1.default(Object.assign({ schemaPath, serversPath: './src/apis', requestImportStatement, requestOptionsType: '{[key: string]: unknown}', namespace: 'API', nullable: false, isCamelCase: true, isDisplayTypeLabel: false, isGenJsonSchemas: false, isOnlyGenTypeScriptType: false, allowedTags: allowedTags
|
|
25
25
|
? (0, lodash_1.map)(allowedTags, (item) => item.toLowerCase())
|
|
26
26
|
: null }, rest), openAPI);
|
|
27
27
|
serviceGenerator.genFile();
|
package/package.json
CHANGED