fix(接口测试): 修复swagger文件导入失败问题
--user=郭雨琦 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001019960
This commit is contained in:
parent
6ea6859227
commit
14d59e0ce2
|
@ -49,6 +49,10 @@ public class Swagger2Parser extends SwaggerAbstractParser {
|
|||
|
||||
} else {
|
||||
sourceStr = getApiTestStr(source); // 导入的二进制文件转换为 String
|
||||
//注:有一特殊情况,swagger2.0 文件里如果在response的parameter参数下的properties的参数里存在 required 为string类型,
|
||||
//swagger2.0不会导入,需替换一下
|
||||
sourceStr = replaceStr(sourceStr);
|
||||
|
||||
JSONObject jsonObject = JSONUtil.parseObject(sourceStr);
|
||||
if (jsonObject.opt("swagger") == null || jsonObject.opt("swagger") == "null" || jsonObject.opt("swagger") == StringUtils.SPACE) {
|
||||
if (jsonObject.opt("openapi") == null || jsonObject.opt("openapi") == "null" || jsonObject.opt("openapi") == StringUtils.SPACE) {
|
||||
|
@ -57,9 +61,9 @@ public class Swagger2Parser extends SwaggerAbstractParser {
|
|||
}
|
||||
swagger = new SwaggerParser().readWithInfo(sourceStr, false).getSwagger();
|
||||
}
|
||||
if (swagger == null || swagger.getSwagger() == null) { // 不是 2.0 版本,则尝试转换 3.0
|
||||
if (swagger == null || swagger.getSwagger() == null) {
|
||||
// 不是 2.0 版本,则尝试转换 3.0
|
||||
Swagger3Parser swagger3Parser = new Swagger3Parser();
|
||||
|
||||
return swagger3Parser.parse(sourceStr, request);
|
||||
}
|
||||
ApiDefinitionImport definitionImport = new ApiDefinitionImport();
|
||||
|
@ -68,6 +72,10 @@ public class Swagger2Parser extends SwaggerAbstractParser {
|
|||
return definitionImport;
|
||||
}
|
||||
|
||||
public static String replaceStr(String sourceStr) {
|
||||
return sourceStr.replaceAll("\"required\": \".*\"", "\"required\": []");
|
||||
}
|
||||
|
||||
// 鉴权设置
|
||||
private List<AuthorizationValue> setAuths(ApiTestImportRequest request) {
|
||||
List<AuthorizationValue> auths = new ArrayList<>();
|
||||
|
|
Loading…
Reference in New Issue