refactor: swagger导入支持多层级的tag

This commit is contained in:
chenjianxing 2022-01-21 11:19:10 +08:00 committed by fit2-zhao
parent 637a179f17
commit fa6117e276
1 changed files with 22 additions and 5 deletions

View File

@ -19,6 +19,24 @@ public abstract class SwaggerAbstractParser extends ApiImportAbstractParser<ApiD
} }
} else { } else {
tags.forEach(tag -> { tags.forEach(tag -> {
// 涉及到多级目录的结构 一级目录/二级目录
if (tag.contains("/")) {
String[] tagTree = tag.split("/");
ApiModule pModule = parentModule;
String prefix = selectModulePath;
for (String item : tagTree) {
pModule = buildModule(pModule, apiDefinition, item, prefix);
prefix += "/" + item;
}
} else {
buildModule(parentModule, apiDefinition, tag, selectModulePath);
}
});
}
}
private ApiModule buildModule(ApiModule parentModule, ApiDefinitionWithBLOBs apiDefinition,
String tag, String selectModulePath) {
ApiModule module = ApiDefinitionImportUtil.buildModule(parentModule, tag, this.projectId); ApiModule module = ApiDefinitionImportUtil.buildModule(parentModule, tag, this.projectId);
apiDefinition.setModuleId(module.getId()); apiDefinition.setModuleId(module.getId());
if (StringUtils.isNotBlank(selectModulePath)) { if (StringUtils.isNotBlank(selectModulePath)) {
@ -26,8 +44,7 @@ public abstract class SwaggerAbstractParser extends ApiImportAbstractParser<ApiD
} else { } else {
apiDefinition.setModulePath("/" + tag); apiDefinition.setModulePath("/" + tag);
} }
}); return module;
}
} }
} }