openapi-ts-request 0.12.0 → 0.12.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.
|
@@ -627,11 +627,11 @@ class ServiceGenerator {
|
|
|
627
627
|
const enumArray = schemaObject.enum;
|
|
628
628
|
let enumStr = '';
|
|
629
629
|
let enumLabelTypeStr = '';
|
|
630
|
-
if (
|
|
631
|
-
enumStr = `{${(0, lodash_1.map)(enumArray, (value) =>
|
|
630
|
+
if (config_1.numberEnum.includes(schemaObject.type) || (0, util_1.isAllNumeric)(enumArray)) {
|
|
631
|
+
enumStr = `{${(0, lodash_1.map)(enumArray, (value) => `NUMBER_${value}=${Number(value)}`).join(',')}}`;
|
|
632
632
|
}
|
|
633
633
|
else {
|
|
634
|
-
enumStr = `{${(0, lodash_1.map)(enumArray, (value) =>
|
|
634
|
+
enumStr = `{${(0, lodash_1.map)(enumArray, (value) => `${value}="${value}"`).join(',')}}`;
|
|
635
635
|
}
|
|
636
636
|
// 翻译枚举
|
|
637
637
|
if (schemaObject['x-enum-varnames'] && schemaObject['x-enum-comments']) {
|
|
@@ -647,11 +647,11 @@ class ServiceGenerator {
|
|
|
647
647
|
}).join(',')}}`;
|
|
648
648
|
}
|
|
649
649
|
else {
|
|
650
|
-
if (
|
|
651
|
-
enumLabelTypeStr = `{${(0, lodash_1.map)(enumArray, (value) =>
|
|
650
|
+
if (config_1.numberEnum.includes(schemaObject.type) || (0, util_1.isAllNumeric)(enumArray)) {
|
|
651
|
+
enumLabelTypeStr = `{${(0, lodash_1.map)(enumArray, (value) => `NUMBER_${value}:${Number(value)}`).join(',')}}`;
|
|
652
652
|
}
|
|
653
653
|
else {
|
|
654
|
-
enumLabelTypeStr = `{${(0, lodash_1.map)(enumArray, (value) =>
|
|
654
|
+
enumLabelTypeStr = `{${(0, lodash_1.map)(enumArray, (value) => `${value}:"${value}"`).join(',')}}`;
|
|
655
655
|
}
|
|
656
656
|
}
|
|
657
657
|
return {
|
package/dist/generator/util.d.ts
CHANGED
|
@@ -19,3 +19,4 @@ export declare function isNonArraySchemaObject(schema: unknown): schema is NonAr
|
|
|
19
19
|
export declare function isArraySchemaObject(schema: unknown): schema is ArraySchemaObject;
|
|
20
20
|
export declare function isBinaryArraySchemaObject(schema: unknown): schema is BinaryArraySchemaObject;
|
|
21
21
|
export declare function resolveRefs(obj: OpenAPIObject, fields: string[]): unknown;
|
|
22
|
+
export declare function isAllNumeric(arr: any): boolean;
|
package/dist/generator/util.js
CHANGED
|
@@ -19,6 +19,7 @@ exports.isNonArraySchemaObject = isNonArraySchemaObject;
|
|
|
19
19
|
exports.isArraySchemaObject = isArraySchemaObject;
|
|
20
20
|
exports.isBinaryArraySchemaObject = isBinaryArraySchemaObject;
|
|
21
21
|
exports.resolveRefs = resolveRefs;
|
|
22
|
+
exports.isAllNumeric = isAllNumeric;
|
|
22
23
|
const tslib_1 = require("tslib");
|
|
23
24
|
const lodash_1 = require("lodash");
|
|
24
25
|
const reserved_words_1 = tslib_1.__importDefault(require("reserved-words"));
|
|
@@ -327,3 +328,6 @@ function resolveRefs(obj, fields) {
|
|
|
327
328
|
return s;
|
|
328
329
|
}, obj);
|
|
329
330
|
}
|
|
331
|
+
function isAllNumeric(arr) {
|
|
332
|
+
return (0, lodash_1.every)(arr, (item) => (0, lodash_1.isString)(item) && /^[0-9]+$/.test(item));
|
|
333
|
+
}
|
package/package.json
CHANGED