Skip to content

Commit cc88851

Browse files
authored
Merge pull request #416 from FrankCheungDev/fix/swagger3
优化默认模块添加逻辑
2 parents 92a0630 + 8b49a70 commit cc88851

4 files changed

Lines changed: 31 additions & 21 deletions

File tree

packages/pont-engine/src/compatible/scripts/swagger.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
import { compileTemplate } from '../compiler';
2121

2222
import { OriginBaseReader } from './base';
23+
import { DEFAULT_MODULE_NAME } from '../../constants/defaultModule';
2324

2425
enum SwaggerType {
2526
integer = 'integer',
@@ -423,8 +424,8 @@ export function parseSwaggerV3Mods(swagger: SwaggerV3DataSource, defNames: strin
423424
];
424425
}
425426

426-
if (!inter.tags) {
427-
inter.tags = ['defaultModule'];
427+
if (_.isEmpty(inter.tags)) {
428+
inter.tags = [DEFAULT_MODULE_NAME];
428429
}
429430

430431
allSwaggerInterfaces.push(inter);
@@ -446,10 +447,13 @@ export function parseSwaggerV3Mods(swagger: SwaggerV3DataSource, defNames: strin
446447
});
447448
}
448449

449-
swagger.tags.push({
450-
name: 'defaultModule',
451-
description: 'defaultModule'
452-
});
450+
// 推入默认模块时进行是否已存在相同模块进行判断
451+
if (!swagger.tags.some(tag => tag.name === DEFAULT_MODULE_NAME)) {
452+
swagger.tags.push({
453+
name: DEFAULT_MODULE_NAME,
454+
description: DEFAULT_MODULE_NAME
455+
});
456+
}
453457

454458
// swagger 2.0 中 tags属性是可选的
455459
const mods = (swagger.tags || [])
@@ -538,8 +542,8 @@ export function parseSwaggerMods(
538542
inter.path = path;
539543
inter.method = method;
540544

541-
if (!inter.tags) {
542-
inter.tags = ['defaultModule'];
545+
if (_.isEmpty(inter.tags)) {
546+
inter.tags = [DEFAULT_MODULE_NAME];
543547
}
544548

545549
allSwaggerInterfaces.push(inter);
@@ -551,8 +555,8 @@ export function parseSwaggerMods(
551555
}
552556

553557
swagger.tags.push({
554-
name: 'defaultModule',
555-
description: 'defaultModule'
558+
name: DEFAULT_MODULE_NAME,
559+
description: DEFAULT_MODULE_NAME
556560
});
557561

558562
// swagger 2.0 中 tags属性是可选的

packages/pont-engine/src/compiler/swagger/SwaggerV2.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
import { SwaggerInterface, Schema } from './type';
1313
import type { SwaggerParameter, SwaggerReferenceObject } from './type';
1414
import { compileTemplate, parseAst2StandardDataType } from './utils';
15+
import { DEFAULT_MODULE_NAME } from '../../constants/defaultModule';
1516

1617
// TODO: $ref, options, head
1718
interface SwaggerPathItemObject {
@@ -49,8 +50,8 @@ function parseSwaggerMods(
4950
inter.path = path;
5051
inter.method = method;
5152

52-
if (!inter.tags) {
53-
inter.tags = ['defaultModule'];
53+
if (_.isEmpty(inter.tags)) {
54+
inter.tags = [DEFAULT_MODULE_NAME];
5455
}
5556

5657
allSwaggerInterfaces.push(inter);
@@ -71,8 +72,8 @@ function parseSwaggerMods(
7172
}
7273

7374
swagger.tags.push({
74-
name: 'defaultModule',
75-
description: 'defaultModule'
75+
name: DEFAULT_MODULE_NAME,
76+
description: DEFAULT_MODULE_NAME
7677
});
7778

7879
// swagger 2.0 中 tags属性是可选的

packages/pont-engine/src/compiler/swagger/SwaggerV3.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import { SwaggerInterface, Schema } from './type';
1212
import type { SwaggerParameter, SwaggerReferenceObject, SwaggerProperty } from './type';
1313
import { compileTemplate, parseAst2StandardDataType } from './utils';
14+
import { DEFAULT_MODULE_NAME } from '../../constants/defaultModule';
1415

1516
// TODO: $ref, options, head
1617
interface SwaggerPathItemObject {
@@ -60,8 +61,8 @@ function parseSwaggerV3Mods(swagger: SwaggerV3DataSource, defNames: string[], us
6061
];
6162
}
6263

63-
if (!inter.tags) {
64-
inter.tags = ['defaultModule'];
64+
if (_.isEmpty(inter.tags)) {
65+
inter.tags = [DEFAULT_MODULE_NAME];
6566
}
6667

6768
allSwaggerInterfaces.push(inter);
@@ -82,11 +83,14 @@ function parseSwaggerV3Mods(swagger: SwaggerV3DataSource, defNames: string[], us
8283
}
8384
});
8485
}
85-
86-
swagger.tags.push({
87-
name: 'defaultModule',
88-
description: 'defaultModule'
89-
});
86+
87+
// 推入默认模块时进行是否已存在相同模块进行判断
88+
if (!swagger.tags.some(tag => tag.name === DEFAULT_MODULE_NAME)) {
89+
swagger.tags.push({
90+
name: DEFAULT_MODULE_NAME,
91+
description: DEFAULT_MODULE_NAME
92+
});
93+
}
9094

9195
// swagger 2.0 中 tags属性是可选的
9296
const mods = (swagger.tags || [])
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const DEFAULT_MODULE_NAME = 'defaultModule'

0 commit comments

Comments
 (0)