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

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

View File

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