openapi-ts-request 0.9.0 → 0.11.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
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
根据 [Swagger2/OpenAPI3](https://swagger.io/blog/news/whats-new-in-openapi-3-0/) 文档生成 TS 类型, 客户端请求函数, 模拟请求响应服务, 枚举, 类型字段翻译, JSON Schemas
|
|
8
8
|
|
|
9
|
+
文档:[使用手册](https://github.com/openapi-ui/openapi-ts-request/issues/100)
|
|
10
|
+
|
|
9
11
|
## 功能
|
|
10
12
|
|
|
11
13
|
- 支持 Swagger2.0/OpenAPI 3.0,3.1 定义
|
|
@@ -207,7 +209,7 @@ export declare function patchSchema<T extends object>(
|
|
|
207
209
|
|
|
208
210
|
## 适配uniapp
|
|
209
211
|
|
|
210
|
-
适配 uniapp 推荐采用自定义 request 函数的方式,你也可以使用 `@uni-helper/axios-adapter` 适配器,详情见 [
|
|
212
|
+
适配 uniapp 推荐采用自定义 request 函数的方式,你也可以使用 `@uni-helper/axios-adapter` 适配器,详情见 [【使用手册 2.2】](https://github.com/openapi-ui/openapi-ts-request/issues/100)
|
|
211
213
|
|
|
212
214
|
## 贡献
|
|
213
215
|
|
|
@@ -145,7 +145,7 @@ class ServiceGenerator {
|
|
|
145
145
|
if (!(0, lodash_1.isEmpty)((_a = this.config) === null || _a === void 0 ? void 0 : _a.allowedTags) &&
|
|
146
146
|
!(0, lodash_1.isEmpty)(operationObject.tags)) {
|
|
147
147
|
if (!(0, lodash_1.isEmpty)((0, lodash_1.intersection)(this.config.allowedTags, (0, lodash_1.map)(operationObject.tags, (tag) => tag.toLowerCase())))) {
|
|
148
|
-
(0, util_1.
|
|
148
|
+
(0, util_1.markAllowedSchema)(JSON.stringify(pathItem), schemas);
|
|
149
149
|
}
|
|
150
150
|
else {
|
|
151
151
|
return;
|
|
@@ -316,7 +316,7 @@ class ServiceGenerator {
|
|
|
316
316
|
};
|
|
317
317
|
return Object.assign(Object.assign({}, newApi), { functionName: this.config.isCamelCase
|
|
318
318
|
? (0, lodash_1.camelCase)(functionName)
|
|
319
|
-
: functionName, typeName: this.getTypeName(newApi), path: getPrefixPath(), pathInComment: formattedPath.replace(/\*/g, '*'), hasPathVariables: formattedPath.includes('{'), hasApiPrefix: !!this.config.apiPrefix, method: newApi.method,
|
|
319
|
+
: functionName, typeName: this.getTypeName(newApi), path: getPrefixPath(), pathInComment: formattedPath.replace(/\*/g, '*'), apifoxRunLink: newApi === null || newApi === void 0 ? void 0 : newApi['x-run-in-apifox'], hasPathVariables: formattedPath.includes('{'), hasApiPrefix: !!this.config.apiPrefix, method: newApi.method,
|
|
320
320
|
// 如果 functionName 和 summary 相同,则不显示 summary
|
|
321
321
|
desc: functionName === newApi.summary
|
|
322
322
|
? (newApi.description || '').replace(config_1.lineBreakReg, '')
|
|
@@ -593,7 +593,7 @@ class ServiceGenerator {
|
|
|
593
593
|
}
|
|
594
594
|
resolveArray(schemaObject) {
|
|
595
595
|
if ((0, util_1.isReferenceObject)(schemaObject.items)) {
|
|
596
|
-
const refName = (0, util_1.
|
|
596
|
+
const refName = (0, util_1.getRefName)(schemaObject.items);
|
|
597
597
|
return {
|
|
598
598
|
type: `${refName}[]`,
|
|
599
599
|
};
|
|
@@ -607,6 +607,7 @@ class ServiceGenerator {
|
|
|
607
607
|
};
|
|
608
608
|
}
|
|
609
609
|
resolveEnumObject(schemaObject) {
|
|
610
|
+
var _a;
|
|
610
611
|
const enumArray = schemaObject.enum;
|
|
611
612
|
let enumStr = '';
|
|
612
613
|
let enumLabelTypeStr = '';
|
|
@@ -623,6 +624,12 @@ class ServiceGenerator {
|
|
|
623
624
|
return `${value}:"${schemaObject['x-enum-comments'][enumKey]}"`;
|
|
624
625
|
}).join(',')}}`;
|
|
625
626
|
}
|
|
627
|
+
else if ((_a = schemaObject === null || schemaObject === void 0 ? void 0 : schemaObject['x-apifox']) === null || _a === void 0 ? void 0 : _a['enumDescriptions']) {
|
|
628
|
+
enumLabelTypeStr = `{${(0, lodash_1.map)(enumArray, (value) => {
|
|
629
|
+
const enumLabel = schemaObject['x-apifox']['enumDescriptions'][value];
|
|
630
|
+
return `${value}:"${enumLabel}"`;
|
|
631
|
+
}).join(',')}}`;
|
|
632
|
+
}
|
|
626
633
|
else {
|
|
627
634
|
if (!config_1.numberEnum.includes(schemaObject.type)) {
|
|
628
635
|
enumLabelTypeStr = `{${(0, lodash_1.map)(enumArray, (value) => `${value}:"${value}"`).join(',')}}`;
|
package/dist/generator/util.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { ArraySchemaObject, BinaryArraySchemaObject, ComponentsObject, ISchemaOb
|
|
|
2
2
|
import { ITypeItem } from './type';
|
|
3
3
|
export declare function stripDot(str: string): string;
|
|
4
4
|
export declare function resolveTypeName(typeName: string): string;
|
|
5
|
+
export declare function getRefName(refObject: ReferenceObject | string): string;
|
|
5
6
|
export declare function getLastRefName(refPath?: string): string;
|
|
6
7
|
export declare function getDefaultType(schemaObject?: ISchemaObject | string, namespace?: string, schemas?: ComponentsObject['schemas']): string;
|
|
7
8
|
export declare function getDefaultFileTag(operationObject: OperationObject, apiPath: string): string[];
|
|
@@ -11,7 +12,7 @@ export declare function genDefaultFunctionName(path: string, pathBasePrefix: str
|
|
|
11
12
|
export declare function getFinalFileName(s: string): string;
|
|
12
13
|
export declare function replaceDot(s: string): string;
|
|
13
14
|
export declare function resolveFunctionName(functionName: string, methodName: string): string;
|
|
14
|
-
export declare function
|
|
15
|
+
export declare function markAllowedSchema(schemaStr: string, schemas: ComponentsObject['schemas']): void;
|
|
15
16
|
export declare function isReferenceObject(schema: unknown): schema is ReferenceObject;
|
|
16
17
|
export declare function isSchemaObject(schema: unknown): schema is SchemaObject;
|
|
17
18
|
export declare function isNonArraySchemaObject(schema: unknown): schema is NonArraySchemaObject;
|
package/dist/generator/util.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.stripDot = stripDot;
|
|
4
4
|
exports.resolveTypeName = resolveTypeName;
|
|
5
|
+
exports.getRefName = getRefName;
|
|
5
6
|
exports.getLastRefName = getLastRefName;
|
|
6
7
|
exports.getDefaultType = getDefaultType;
|
|
7
8
|
exports.getDefaultFileTag = getDefaultFileTag;
|
|
@@ -11,7 +12,7 @@ exports.genDefaultFunctionName = genDefaultFunctionName;
|
|
|
11
12
|
exports.getFinalFileName = getFinalFileName;
|
|
12
13
|
exports.replaceDot = replaceDot;
|
|
13
14
|
exports.resolveFunctionName = resolveFunctionName;
|
|
14
|
-
exports.
|
|
15
|
+
exports.markAllowedSchema = markAllowedSchema;
|
|
15
16
|
exports.isReferenceObject = isReferenceObject;
|
|
16
17
|
exports.isSchemaObject = isSchemaObject;
|
|
17
18
|
exports.isNonArraySchemaObject = isNonArraySchemaObject;
|
|
@@ -285,13 +286,13 @@ function resolveFunctionName(functionName, methodName) {
|
|
|
285
286
|
return functionName;
|
|
286
287
|
}
|
|
287
288
|
// 标记引用的 $ref 对应的schema
|
|
288
|
-
function
|
|
289
|
+
function markAllowedSchema(schemaStr, schemas) {
|
|
289
290
|
const refs = schemaStr === null || schemaStr === void 0 ? void 0 : schemaStr.match(/#\/components\/schemas\/([\w%«».-]+)/g);
|
|
290
291
|
(0, lodash_1.forEach)(refs, (ref) => {
|
|
291
292
|
const schema = schemas === null || schemas === void 0 ? void 0 : schemas[getLastRefName(ref)];
|
|
292
293
|
if (schema && !schema.isAllowed) {
|
|
293
294
|
schema.isAllowed = true;
|
|
294
|
-
|
|
295
|
+
markAllowedSchema(JSON.stringify(schema), schemas);
|
|
295
296
|
}
|
|
296
297
|
});
|
|
297
298
|
}
|
|
@@ -44,6 +44,9 @@ export declare function inferSchema(thing: ParameterObject | SchemaObject | Refe
|
|
|
44
44
|
'x-enum-comments'?: {
|
|
45
45
|
[name: string]: string;
|
|
46
46
|
};
|
|
47
|
+
'x-apifox'?: {
|
|
48
|
+
enumDescriptions: Record<string, string>;
|
|
49
|
+
};
|
|
47
50
|
items: import("../type").ISchemaObject;
|
|
48
51
|
} | {
|
|
49
52
|
type: string;
|
|
@@ -86,5 +89,8 @@ export declare function inferSchema(thing: ParameterObject | SchemaObject | Refe
|
|
|
86
89
|
'x-enum-comments'?: {
|
|
87
90
|
[name: string]: string;
|
|
88
91
|
};
|
|
92
|
+
'x-apifox'?: {
|
|
93
|
+
enumDescriptions: Record<string, string>;
|
|
94
|
+
};
|
|
89
95
|
};
|
|
90
96
|
export declare function getRandomInt(min: number, max: number): number;
|
package/dist/type.d.ts
CHANGED
|
@@ -14,6 +14,9 @@ type ICustomBaseSchemaObject = {
|
|
|
14
14
|
'x-enum-comments'?: {
|
|
15
15
|
[name: string]: string;
|
|
16
16
|
};
|
|
17
|
+
'x-apifox'?: {
|
|
18
|
+
enumDescriptions: Record<string, string>;
|
|
19
|
+
};
|
|
17
20
|
};
|
|
18
21
|
export type ArraySchemaObject = Modify<OpenAPIV3.ArraySchemaObject, ICustomBaseSchemaObject & {
|
|
19
22
|
items: ISchemaObject;
|
|
@@ -28,7 +31,9 @@ export type PathItemObject = Modify<OpenAPIV3.PathItemObject, {
|
|
|
28
31
|
}>;
|
|
29
32
|
export type OperationObject = Modify<OpenAPIV3.OperationObject, {
|
|
30
33
|
parameters?: (ReferenceObject | ParameterObject)[];
|
|
31
|
-
}
|
|
34
|
+
}> & {
|
|
35
|
+
'x-run-in-apifox'?: string;
|
|
36
|
+
};
|
|
32
37
|
export type ComponentsObject = OpenAPIV3.ComponentsObject;
|
|
33
38
|
export type OpenAPIObject = OpenAPIV3.Document;
|
|
34
39
|
export type ParameterObject = Modify<OpenAPIV3.ParameterObject, {
|
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openapi-ts-request",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Swagger2/OpenAPI3 to TypeScript, request client, request mock service, enum, type field label, JSON Schemas",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=18.0.0",
|
|
7
|
+
"pnpm": ">=9"
|
|
8
|
+
},
|
|
5
9
|
"repository": {
|
|
6
10
|
"type": "git",
|
|
7
11
|
"url": "git+git@github.com:openapi-ui/openapi-ts-request.git"
|
|
@@ -4,7 +4,7 @@ import * as {{ namespace }} from './{{ interfaceFileName }}';
|
|
|
4
4
|
{{ requestImportStatement }}
|
|
5
5
|
|
|
6
6
|
{% for api in list -%}
|
|
7
|
-
/** {{ api.desc if api.desc else '此处后端没有提供注释' }} {{api.method | upper}} {{ api.pathInComment | safe }} */
|
|
7
|
+
/** {{ api.desc if api.desc else '此处后端没有提供注释' }} {{ api.method | upper }} {{ api.pathInComment | safe }}{{ ' ' if api.apifoxRunLink else '' }}{{ api.apifoxRunLink | safe }} */
|
|
8
8
|
export async function {{ api.functionName }}(
|
|
9
9
|
{%- if api.params and api.hasParams %}
|
|
10
10
|
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
|