Skip to content

Commit

Permalink
fix(接口测试): 修复swagger导入失败的缺陷
Browse files Browse the repository at this point in the history
--bug=1026085 --user=王孝刚 [接口测试]github#24323接口导入-导入 Swagger 文件报“格式错误”
https://www.tapd.cn/55049933/s/1377700
  • Loading branch information
wxg0103 authored and liuruibin committed Jun 1, 2023
1 parent 59b9f18 commit c18e6ed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public ApiDefinitionImport parse(InputStream source, ApiTestImportRequest reques
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");
Expand Down Expand Up @@ -82,6 +85,10 @@ public ApiDefinitionImport parse(InputStream source, ApiTestImportRequest reques
return definitionImport;
}

public static String replaceStr(String sourceStr) {
return sourceStr.replaceAll("\"required\": \"(.*?)\"", "\"required\": []");
}

// 鉴权设置
private List<AuthorizationValue> setAuths(ApiTestImportRequest request) {
List<AuthorizationValue> auths = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,9 @@ private Schema getModelByRef(String ref) {
}
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;
Expand Down

0 comments on commit c18e6ed

Please sign in to comment.