mirror of
https://gitee.com/fit2cloud-feizhiyun/MeterSphere.git
synced 2024-11-29 18:48:13 +08:00
fix(接口测试): 记录swagger导入验证出错问题
--user=郭雨琦 --bug=1011901 [接口测试] github#12268swagger接口定时同步,执行一次后后台报错 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001011901
This commit is contained in:
parent
7ecc2b313b
commit
deb847ff5b
@ -13,6 +13,8 @@ import io.metersphere.api.dto.scenario.request.RequestType;
|
||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||
import io.metersphere.base.domain.ApiModule;
|
||||
import io.metersphere.commons.constants.SwaggerParameterType;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.utils.LoggerUtil;
|
||||
import io.swagger.models.*;
|
||||
import io.swagger.models.auth.AuthorizationValue;
|
||||
import io.swagger.models.parameters.*;
|
||||
@ -32,11 +34,18 @@ public class Swagger2Parser extends SwaggerAbstractParser {
|
||||
|
||||
@Override
|
||||
public ApiDefinitionImport parse(InputStream source, ApiTestImportRequest request) {
|
||||
Swagger swagger;
|
||||
Swagger swagger = null;
|
||||
String sourceStr = "";
|
||||
List<AuthorizationValue> auths = setAuths(request);
|
||||
if (StringUtils.isNotBlank(request.getSwaggerUrl())) { // 使用 url 导入 swagger
|
||||
swagger = new SwaggerParser().read(request.getSwaggerUrl(), auths, true);
|
||||
if (StringUtils.isNotBlank(request.getSwaggerUrl())) {
|
||||
try {
|
||||
// 使用 url 导入 swagger
|
||||
swagger = new SwaggerParser().read(request.getSwaggerUrl(), auths, true);
|
||||
}catch (Exception e){
|
||||
LoggerUtil.error(e);
|
||||
MSException.throwException("swagger验证失败");
|
||||
}
|
||||
|
||||
} else {
|
||||
sourceStr = getApiTestStr(source); // 导入的二进制文件转换为 String
|
||||
swagger = new SwaggerParser().readWithInfo(sourceStr).getSwagger();
|
||||
|
Loading…
Reference in New Issue
Block a user