Skip to content

Commit 179e5c2

Browse files
committed
refactor(printer): 重构类型导入方式以提升代码清晰度
- 更新了多个文件中的 OpenAPI 相关类型导入方式 - 采用更清晰的 type 导入方式,避免未使用的值导入 - 调整了部分代码格式,提高了可读性
1 parent 6fa9422 commit 179e5c2

File tree

7 files changed

+24
-24
lines changed

7 files changed

+24
-24
lines changed

src/migrations/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { type OpenAPIAll, type OpenAPILatest, OpenAPIVersion } from '../types/openapi';
1+
import type { OpenAPIAll, OpenAPILatest } from '../types/openapi';
2+
import { OpenAPIVersion } from '../types/openapi';
23
import { migrate_2_0To3_0 } from './openapi-2_0';
34
import { migrate_3_0To3_1 } from './openapi-3_0';
45

src/migrations/openapi-2_0.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import type { OpenAPIV2, OpenAPIV3 } from '../types/openapi';
12
import path from 'node:path';
2-
import { type OpenAPIV2, type OpenAPIV3, OpenAPIVersion } from '../types/openapi';
3+
import { OpenAPIVersion } from '../types/openapi';
34
import { objectMap } from '../utils/object';
45
import { isBoolean, isUndefined } from '../utils/type-is';
56

src/migrations/openapi-3_0.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { type OpenAPIV3, type OpenAPIV3_1, OpenAPIVersion } from '../types/openapi';
1+
import type { OpenAPIV3, OpenAPIV3_1 } from '../types/openapi';
2+
import { OpenAPIVersion } from '../types/openapi';
23
import { objectMap } from '../utils/object';
34
import { isBoolean, isUndefined } from '../utils/type-is';
45

src/printer/Arg.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import type { OpenAPILatest } from '../types/openapi';
2+
import type { OpenApiLatest_Parameter } from './helpers';
23
import type { Named } from './Named';
34
import type { PrinterOptions } from './types';
4-
import { isRefParameter, type OpenApiLatest_Parameter, requiredKeyStringify } from './helpers';
5+
import { isRefParameter, requiredKeyStringify } from './helpers';
56
import { Schemata } from './Schemata';
67

78
export type ArgKind = 'path' | 'header' | 'cookie' | 'param' | 'data' | 'config' | 'response';

src/printer/Named.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,16 @@ export class Named {
4242
}
4343

4444
nextOperationId(method: string, url: string, operationId?: string) {
45-
operationId
46-
= operationId
47-
|| fixVarName(
48-
[
49-
method,
50-
url
51-
.replace(/\{.*?\}/g, '')
52-
.split('/')
53-
.filter(Boolean),
54-
].join('_'),
55-
);
45+
operationId = operationId
46+
|| fixVarName(
47+
[
48+
method,
49+
url
50+
.replace(/\{.*?\}/g, '')
51+
.split('/')
52+
.filter(Boolean),
53+
].join('_'),
54+
);
5655
return nextUniqueName(operationId, this.varNameCountMap);
5756
}
5857

src/printer/Schemata.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import type { OpenAPILatest } from '../types/openapi';
2+
import type { OpenApiLatest_Schema } from './helpers';
23
import type { Named } from './Named';
34
import { never } from '../utils/func';
45
import { isArray, isBoolean, isNumber, isString, isUndefined } from '../utils/type-is';
5-
import { isRefSchema, type OpenApiLatest_Schema, requiredTypeStringify } from './helpers';
6+
import { isRefSchema, requiredTypeStringify } from './helpers';
67
import { JsDoc } from './JsDoc';
78

89
interface SchemaResult {

src/printer/index.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import type { OpenAPILatest } from '../types/openapi';
2+
import type { OpenApiLatest_Media, OpenApiLatest_Operation, OpenApiLatest_Parameter, OpenApiLatest_PathItem, OpenApiLatest_Request, OpenApiLatest_Response, OpenApiLatest_Schema } from './helpers';
13
import type { PrinterConfigs, PrinterOptions } from './types';
2-
import { type OpenAPILatest, OpenAPIVersion } from '../types/openapi';
4+
import { OpenAPIVersion } from '../types/openapi';
35
import { toImportPath } from '../utils/path';
46
import { isString, isUndefined } from '../utils/type-is';
57
import { Arg } from './Arg';
@@ -20,13 +22,7 @@ import {
2022
isRefRequest,
2123
isRefResponse,
2224
isRefSchema,
23-
type OpenApiLatest_Media,
24-
type OpenApiLatest_Operation,
25-
type OpenApiLatest_Parameter,
26-
type OpenApiLatest_PathItem,
27-
type OpenApiLatest_Request,
28-
type OpenApiLatest_Response,
29-
type OpenApiLatest_Schema,
25+
3026
toImportString,
3127
} from './helpers';
3228
import { JsDoc } from './JsDoc';

0 commit comments

Comments
 (0)