fix(接口测试): 修复导入特殊的swagger文件,不显示rest参数的缺陷

https://github.com/metersphere/metersphere/issues/27986
This commit is contained in:
wxg0103 2023-12-18 18:08:13 +08:00 committed by Craftsman
parent 2127170ca6
commit 9d6e84cf4d
1 changed files with 20 additions and 0 deletions

View File

@ -146,6 +146,7 @@ public class Swagger2Parser extends SwaggerAbstractParser {
ApiDefinitionWithBLOBs apiDefinition = buildApiDefinition(request.getId(), operation, pathName, method.name(), importRequest);
apiDefinition.setDescription(operation.getDescription());
parseParameters(operation, request);
parseParameters(path,request);
addBodyHeader(request);
if (StringUtils.isNotBlank(basePath)) {
String pathStr = (basePath + apiDefinition.getPath()).replaceAll("//", "/");
@ -250,6 +251,25 @@ public class Swagger2Parser extends SwaggerAbstractParser {
}
}
private void parseParameters(Path path, MsHTTPSamplerProxy request) {
if (path.getParameters() == null) {
return;
}
List<Parameter> parameters = path.getParameters();
// 处理特殊格式 rest参数是和请求平级的情况
for (Parameter parameter : parameters) {
if (StringUtils.isNotBlank(parameter.getIn())) {
switch (parameter.getIn()) {
case SwaggerParameterType.PATH -> parsePathParameters(parameter, request.getRest());
case SwaggerParameterType.QUERY -> parseQueryParameters(parameter, request.getArguments());
case SwaggerParameterType.HEADER -> parseHeaderParameters(parameter, request.getHeaders());
case SwaggerParameterType.COOKIE -> parseCookieParameters(parameter, request.getHeaders());
}
}
}
}
private String getBodyType(Operation operation) {
if (CollectionUtils.isEmpty(operation.getConsumes())) {
return Body.JSON_STR;