From 9d6e84cf4de52b123c24ccd4e3a0eef66c53a721 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Mon, 18 Dec 2023 18:08:13 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AF=BC=E5=85=A5=E7=89=B9=E6=AE=8A=E7=9A=84?= =?UTF-8?q?swagger=E6=96=87=E4=BB=B6=EF=BC=8C=E4=B8=8D=E6=98=BE=E7=A4=BAre?= =?UTF-8?q?st=E5=8F=82=E6=95=B0=E7=9A=84=E7=BC=BA=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/metersphere/metersphere/issues/27986 --- .../api/parse/api/Swagger2Parser.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/api-test/backend/src/main/java/io/metersphere/api/parse/api/Swagger2Parser.java b/api-test/backend/src/main/java/io/metersphere/api/parse/api/Swagger2Parser.java index 4c0ac54bd5..cdcf7010a8 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/parse/api/Swagger2Parser.java +++ b/api-test/backend/src/main/java/io/metersphere/api/parse/api/Swagger2Parser.java @@ -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 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;