fix(接口测试): 修复swagger导入失败的缺陷
--bug=1026085 --user=王孝刚 [接口测试]github#24323接口导入-导入 Swagger 文件报“格式错误” https://www.tapd.cn/55049933/s/1375755
This commit is contained in:
parent
9c755fe8b0
commit
0d57785de6
|
@ -24,6 +24,7 @@ import io.swagger.models.auth.AuthorizationValue;
|
|||
import io.swagger.models.parameters.*;
|
||||
import io.swagger.models.properties.*;
|
||||
import io.swagger.parser.SwaggerParser;
|
||||
import lombok.val;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -226,28 +227,30 @@ public class Swagger2Parser extends SwaggerAbstractParser {
|
|||
// todo 路径变量 {xxx} 是否要转换
|
||||
|
||||
for (Parameter parameter : parameters) {
|
||||
switch (parameter.getIn()) {
|
||||
case SwaggerParameterType.PATH:
|
||||
parsePathParameters(parameter, request.getRest());
|
||||
break;
|
||||
case SwaggerParameterType.QUERY:
|
||||
parseQueryParameters(parameter, request.getArguments());
|
||||
break;
|
||||
case SwaggerParameterType.FORM_DATA:
|
||||
parseFormDataParameters((FormParameter) parameter, request.getBody());
|
||||
break;
|
||||
case SwaggerParameterType.BODY:
|
||||
parseRequestBodyParameters(parameter, request.getBody());
|
||||
break;
|
||||
case SwaggerParameterType.HEADER:
|
||||
parseHeaderParameters(parameter, request.getHeaders());
|
||||
break;
|
||||
case SwaggerParameterType.COOKIE:
|
||||
parseCookieParameters(parameter, request.getHeaders());
|
||||
break;
|
||||
if (StringUtils.isNotBlank(parameter.getIn())) {
|
||||
switch (parameter.getIn()) {
|
||||
case SwaggerParameterType.PATH:
|
||||
parsePathParameters(parameter, request.getRest());
|
||||
break;
|
||||
case SwaggerParameterType.QUERY:
|
||||
parseQueryParameters(parameter, request.getArguments());
|
||||
break;
|
||||
case SwaggerParameterType.FORM_DATA:
|
||||
parseFormDataParameters((FormParameter) parameter, request.getBody());
|
||||
break;
|
||||
case SwaggerParameterType.BODY:
|
||||
parseRequestBodyParameters(parameter, request.getBody());
|
||||
break;
|
||||
case SwaggerParameterType.HEADER:
|
||||
parseHeaderParameters(parameter, request.getHeaders());
|
||||
break;
|
||||
case SwaggerParameterType.COOKIE:
|
||||
parseCookieParameters(parameter, request.getHeaders());
|
||||
break;
|
||||
// case SwaggerParameterType.FILE:
|
||||
// parsePathParameters(parameter, request);
|
||||
// break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ import io.swagger.v3.parser.core.models.AuthorizationValue;
|
|||
import io.swagger.v3.parser.core.models.SwaggerParseResult;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.http.HttpMethod;
|
||||
|
||||
|
@ -626,16 +627,18 @@ public class Swagger3Parser extends SwaggerAbstractParser {
|
|||
Schema schema = getSchema(parameter.getSchema());
|
||||
Set<String> refSet = new HashSet<>();
|
||||
JsonSchemaItem jsonSchemaItem = parseSchema(schema, refSet);
|
||||
if (MapUtils.isEmpty(jsonSchemaItem.getProperties())) {
|
||||
arguments.add(new KeyValue(queryParameter.getName(), getDefaultValue(queryParameter, jsonSchemaItem), getDefaultStringValue(queryParameter.getDescription()), parameter.getRequired(), getMin(jsonSchemaItem), getMax(jsonSchemaItem)));
|
||||
} else {
|
||||
Map<String, JsonSchemaItem> properties = jsonSchemaItem.getProperties();
|
||||
properties.forEach((key, value) -> {
|
||||
arguments.add(new KeyValue(key, getDefaultValue(queryParameter, value),
|
||||
getDefaultStringValue(value.getDescription()),
|
||||
parameter.getRequired(),
|
||||
getMin(value), getMax(value)));
|
||||
});
|
||||
if (ObjectUtils.isNotEmpty(jsonSchemaItem)){
|
||||
if (MapUtils.isEmpty(jsonSchemaItem.getProperties())) {
|
||||
arguments.add(new KeyValue(queryParameter.getName(), getDefaultValue(queryParameter, jsonSchemaItem), getDefaultStringValue(queryParameter.getDescription()), parameter.getRequired(), getMin(jsonSchemaItem), getMax(jsonSchemaItem)));
|
||||
} else {
|
||||
Map<String, JsonSchemaItem> properties = jsonSchemaItem.getProperties();
|
||||
properties.forEach((key, value) -> {
|
||||
arguments.add(new KeyValue(key, getDefaultValue(queryParameter, value),
|
||||
getDefaultStringValue(value.getDescription()),
|
||||
parameter.getRequired(),
|
||||
getMin(value), getMax(value)));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue