fix(接口测试): 修复swagger导入失败的缺陷
--bug=1026085 --user=王孝刚 [接口测试]github#24323接口导入-导入 Swagger 文件报“格式错误” https://www.tapd.cn/55049933/s/1377700
This commit is contained in:
parent
59b9f18d01
commit
c18e6edeb4
|
@ -55,6 +55,9 @@ public class Swagger2Parser extends SwaggerAbstractParser {
|
|||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
try {
|
||||
if (StringUtils.isNotBlank(sourceStr)){
|
||||
sourceStr = replaceStr(sourceStr);
|
||||
}
|
||||
JsonNode jsonNode = objectMapper.readTree(sourceStr);
|
||||
if (!jsonNode.has("swagger") && !jsonNode.has("openapi")) {
|
||||
MSException.throwException("wrong format");
|
||||
|
@ -82,6 +85,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<>();
|
||||
|
|
|
@ -509,7 +509,9 @@ public class Swagger3Parser extends SwaggerAbstractParser {
|
|||
}
|
||||
if (this.components.getSchemas() != null) {
|
||||
Schema schema = this.components.getSchemas().get(ref);
|
||||
schema.setName(ref);
|
||||
if (ObjectUtils.isNotEmpty(schema)) {
|
||||
schema.setName(ref);
|
||||
}
|
||||
return schema;
|
||||
}
|
||||
return null;
|
||||
|
|
Loading…
Reference in New Issue