openapi-ts-request 0.4.9 → 0.4.11
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 +5 -1
- package/dist/generator/config.js +0 -2
- package/dist/generator/serviceGenarator.js +32 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
- 支持 Swagger2.0/OpenAPI 3.0,3.1 定义
|
|
12
12
|
- 生成 TS 类型, 请求客户端, 请求模拟服务, 枚举, 类型字段翻译, JSON Schemas
|
|
13
13
|
- 支持通过 npx、CLI、Nodejs 的方式使用
|
|
14
|
-
- 支持自定义请求工具函数, 支持 Fetch、Axios、UniApp-Request、Node.js、XHR 客户端
|
|
14
|
+
- 支持自定义请求工具函数, 支持 Fetch、Axios、[UniApp-Request](https://github.com/openapi-ui/openapi-ts-request/issues/46)、Node.js、XHR 客户端
|
|
15
15
|
- 支持通过 tags 过滤生成结果
|
|
16
16
|
- 支持 JSON 定义文件
|
|
17
17
|
|
|
@@ -200,6 +200,10 @@ export declare function patchSchema<T extends object>(
|
|
|
200
200
|
|
|
201
201
|
目前使用 [mockjs](http://mockjs.com) 生成 mock 数据,mocks 文件启动需要借助 [@umijs/server](https://umijs.org/docs/guides/mock),后面会寻找其他方案以达到更好的 mock 体验
|
|
202
202
|
|
|
203
|
+
## 适配uniapp
|
|
204
|
+
|
|
205
|
+
适配 uniapp 推荐采用自定义 request 函数的方式,你也可以使用 `@uni-helper/axios-adapter` 适配器,详情见 [issue#46](https://github.com/openapi-ui/openapi-ts-request/issues/46)
|
|
206
|
+
|
|
203
207
|
## 贡献
|
|
204
208
|
|
|
205
209
|
### 环境要求
|
package/dist/generator/config.js
CHANGED
|
@@ -167,9 +167,10 @@ class ServiceGenerator {
|
|
|
167
167
|
type: this.getType(parameter.schema),
|
|
168
168
|
});
|
|
169
169
|
});
|
|
170
|
-
|
|
170
|
+
const typeName = this.getTypeName(Object.assign(Object.assign({}, operationObject), { method, path: pathKey }));
|
|
171
|
+
if (props.length > 0 && typeName) {
|
|
171
172
|
lastTypes.push({
|
|
172
|
-
typeName
|
|
173
|
+
typeName,
|
|
173
174
|
type: 'Record<string, unknown>',
|
|
174
175
|
props: [props],
|
|
175
176
|
isEnum: false,
|
|
@@ -212,16 +213,18 @@ class ServiceGenerator {
|
|
|
212
213
|
(schema === null || schema === void 0 ? void 0 : schema.isAllowed)) {
|
|
213
214
|
const isEnum = result.isEnum;
|
|
214
215
|
const typeName = (0, util_1.resolveTypeName)(schemaKey);
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
216
|
+
if (typeName) {
|
|
217
|
+
lastTypes.push({
|
|
218
|
+
typeName,
|
|
219
|
+
type: getDefinesType(),
|
|
220
|
+
props: (result.props || []),
|
|
221
|
+
isEnum,
|
|
222
|
+
displayLabelFuncName: isEnum
|
|
223
|
+
? (0, lodash_1.camelCase)(`display-${typeName}-Enum`)
|
|
224
|
+
: '',
|
|
225
|
+
enumLabelType: isEnum ? result.enumLabelType : '',
|
|
226
|
+
});
|
|
227
|
+
}
|
|
225
228
|
if (this.config.isGenJsonSchemas) {
|
|
226
229
|
this.schemaList.push({
|
|
227
230
|
typeName: `$${(0, util_1.resolveTypeName)(schemaKey)}`,
|
|
@@ -529,15 +532,16 @@ class ServiceGenerator {
|
|
|
529
532
|
.map((p) => this.resolveRefObject(p))
|
|
530
533
|
.filter((p) => p.in === source)
|
|
531
534
|
.map((p) => {
|
|
532
|
-
var _a, _b, _c, _d;
|
|
533
|
-
const isDirectObject = (((_a = p.schema) === null || _a === void 0 ? void 0 : _a.type) ||
|
|
535
|
+
var _a, _b, _c, _d, _e;
|
|
536
|
+
const isDirectObject = (((_a = p.schema) === null || _a === void 0 ? void 0 : _a.type) === 'object' ||
|
|
534
537
|
p.type) === 'object';
|
|
535
538
|
const refList = (((_b = p.schema) === null || _b === void 0 ? void 0 : _b.$ref) ||
|
|
536
539
|
p.$ref ||
|
|
537
540
|
'').split('/');
|
|
538
541
|
const ref = refList[refList.length - 1];
|
|
539
542
|
const deRefObj = (0, lodash_1.entries)((_c = this.openAPIData.components) === null || _c === void 0 ? void 0 : _c.schemas).find(([k]) => k === ref) || [];
|
|
540
|
-
const isRefObject = ((_d = deRefObj[1]) === null || _d === void 0 ? void 0 : _d.type) === 'object'
|
|
543
|
+
const isRefObject = ((_d = deRefObj[1]) === null || _d === void 0 ? void 0 : _d.type) === 'object' &&
|
|
544
|
+
!(0, lodash_1.isEmpty)((_e = deRefObj[1]) === null || _e === void 0 ? void 0 : _e.properties);
|
|
541
545
|
return Object.assign(Object.assign({}, p), { isObject: isDirectObject || isRefObject, type: this.getType(p.schema || config_1.DEFAULT_SCHEMA, this.config.namespace) });
|
|
542
546
|
});
|
|
543
547
|
if (params.length) {
|
|
@@ -602,8 +606,14 @@ class ServiceGenerator {
|
|
|
602
606
|
}
|
|
603
607
|
resolveEnumObject(schemaObject) {
|
|
604
608
|
const enumArray = schemaObject.enum;
|
|
605
|
-
|
|
609
|
+
let enumStr = '';
|
|
606
610
|
let enumLabelTypeStr = '';
|
|
611
|
+
if (!config_1.numberEnum.includes(schemaObject.type)) {
|
|
612
|
+
enumStr = `{${(0, lodash_1.map)(enumArray, (value) => `${value}="${value}"`).join(',')}}`;
|
|
613
|
+
}
|
|
614
|
+
else {
|
|
615
|
+
enumStr = `{${(0, lodash_1.map)(enumArray, (value) => `NUMBER_${value}=${value}`).join(',')}}`;
|
|
616
|
+
}
|
|
607
617
|
// 翻译枚举
|
|
608
618
|
if (schemaObject['x-enum-varnames'] && schemaObject['x-enum-comments']) {
|
|
609
619
|
enumLabelTypeStr = `{${(0, lodash_1.map)(enumArray, (value, index) => {
|
|
@@ -612,7 +622,12 @@ class ServiceGenerator {
|
|
|
612
622
|
}).join(',')}}`;
|
|
613
623
|
}
|
|
614
624
|
else {
|
|
615
|
-
|
|
625
|
+
if (!config_1.numberEnum.includes(schemaObject.type)) {
|
|
626
|
+
enumLabelTypeStr = `{${(0, lodash_1.map)(enumArray, (value) => `${value}:"${value}"`).join(',')}}`;
|
|
627
|
+
}
|
|
628
|
+
else {
|
|
629
|
+
enumLabelTypeStr = `{${(0, lodash_1.map)(enumArray, (value) => `NUMBER_${value}:${value}`).join(',')}}`;
|
|
630
|
+
}
|
|
616
631
|
}
|
|
617
632
|
return {
|
|
618
633
|
isEnum: true,
|
package/package.json
CHANGED