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.parameters.*;
|
||||||
import io.swagger.models.properties.*;
|
import io.swagger.models.properties.*;
|
||||||
import io.swagger.parser.SwaggerParser;
|
import io.swagger.parser.SwaggerParser;
|
||||||
|
import lombok.val;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.collections.MapUtils;
|
import org.apache.commons.collections.MapUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
@ -226,6 +227,7 @@ public class Swagger2Parser extends SwaggerAbstractParser {
|
||||||
// todo 路径变量 {xxx} 是否要转换
|
// todo 路径变量 {xxx} 是否要转换
|
||||||
|
|
||||||
for (Parameter parameter : parameters) {
|
for (Parameter parameter : parameters) {
|
||||||
|
if (StringUtils.isNotBlank(parameter.getIn())) {
|
||||||
switch (parameter.getIn()) {
|
switch (parameter.getIn()) {
|
||||||
case SwaggerParameterType.PATH:
|
case SwaggerParameterType.PATH:
|
||||||
parsePathParameters(parameter, request.getRest());
|
parsePathParameters(parameter, request.getRest());
|
||||||
|
@ -251,6 +253,7 @@ public class Swagger2Parser extends SwaggerAbstractParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private String getBodyType(Operation operation) {
|
private String getBodyType(Operation operation) {
|
||||||
if (CollectionUtils.isEmpty(operation.getConsumes())) {
|
if (CollectionUtils.isEmpty(operation.getConsumes())) {
|
||||||
|
|
|
@ -34,6 +34,7 @@ import io.swagger.v3.parser.core.models.AuthorizationValue;
|
||||||
import io.swagger.v3.parser.core.models.SwaggerParseResult;
|
import io.swagger.v3.parser.core.models.SwaggerParseResult;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.collections.MapUtils;
|
import org.apache.commons.collections.MapUtils;
|
||||||
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
|
|
||||||
|
@ -626,6 +627,7 @@ public class Swagger3Parser extends SwaggerAbstractParser {
|
||||||
Schema schema = getSchema(parameter.getSchema());
|
Schema schema = getSchema(parameter.getSchema());
|
||||||
Set<String> refSet = new HashSet<>();
|
Set<String> refSet = new HashSet<>();
|
||||||
JsonSchemaItem jsonSchemaItem = parseSchema(schema, refSet);
|
JsonSchemaItem jsonSchemaItem = parseSchema(schema, refSet);
|
||||||
|
if (ObjectUtils.isNotEmpty(jsonSchemaItem)){
|
||||||
if (MapUtils.isEmpty(jsonSchemaItem.getProperties())) {
|
if (MapUtils.isEmpty(jsonSchemaItem.getProperties())) {
|
||||||
arguments.add(new KeyValue(queryParameter.getName(), getDefaultValue(queryParameter, jsonSchemaItem), getDefaultStringValue(queryParameter.getDescription()), parameter.getRequired(), getMin(jsonSchemaItem), getMax(jsonSchemaItem)));
|
arguments.add(new KeyValue(queryParameter.getName(), getDefaultValue(queryParameter, jsonSchemaItem), getDefaultStringValue(queryParameter.getDescription()), parameter.getRequired(), getMin(jsonSchemaItem), getMax(jsonSchemaItem)));
|
||||||
} else {
|
} else {
|
||||||
|
@ -638,6 +640,7 @@ public class Swagger3Parser extends SwaggerAbstractParser {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Schema getSchema(Schema schema) {
|
private Schema getSchema(Schema schema) {
|
||||||
if (schema != null && StringUtils.isBlank(schema.get$ref()) && StringUtils.equalsIgnoreCase(schema.getType(), "string")) {
|
if (schema != null && StringUtils.isBlank(schema.get$ref()) && StringUtils.equalsIgnoreCase(schema.getType(), "string")) {
|
||||||
|
|
Loading…
Reference in New Issue