From 866d693d1a74c90d3bddd885acf9f97512cbe1c6 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Fri, 10 Jun 2022 19:38:20 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89):=20?= =?UTF-8?q?=E4=B8=8D=E5=90=8C=E7=9A=84=E7=8A=B6=E6=80=81=E7=A0=81=E5=AF=B9?= =?UTF-8?q?=E5=BA=94=E4=B8=8D=E5=90=8C=E7=9A=84Schema=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E5=93=8D=E5=BA=94=E5=86=85=E5=AE=B9=E6=98=BE=E7=A4=BA=E6=9C=89?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --user=郭雨琦 --bug=1013977 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001013977 --- .../dto/definition/parse/Swagger2Parser.java | 44 ++++++++++++------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/parse/Swagger2Parser.java b/backend/src/main/java/io/metersphere/api/dto/definition/parse/Swagger2Parser.java index 9f908b9ddb..d136adf0af 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/parse/Swagger2Parser.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/parse/Swagger2Parser.java @@ -263,25 +263,35 @@ public class Swagger2Parser extends SwaggerAbstractParser { msResponse.getBody().setType(getResponseBodyType(operation)); // todo 状态码要调整? msResponse.setStatusCode(new ArrayList<>()); + Response response = null; + String responseCode = null; if (responses != null && responses.size() > 0) { - responses.forEach((responseCode, response) -> { - if(StringUtils.isNotBlank(response.getDescription())){ - msResponse.getStatusCode().add(new KeyValue(responseCode, response.getDescription())); - }else{ - msResponse.getStatusCode().add(new KeyValue(responseCode, responseCode)); - } - if (responseCode.equals("200")&&response.getResponseSchema()!=null) { - parseResponseBody(response.getResponseSchema(),msResponse.getBody()); - msResponse.getBody().setFormat("JSON-SCHEMA"); - } else { - String body = parseSchema(response.getResponseSchema()); - if (StringUtils.isNotBlank(body)) { - msResponse.getBody().setRaw(body); - } - } - parseResponseHeader(response, msResponse.getHeaders()); - }); + Map.Entry next = responses.entrySet().iterator().next(); + responseCode = next.getKey(); + response = next.getValue(); } + if (response!=null && responseCode!=null) { + if (StringUtils.isNotBlank(response.getDescription())) { + msResponse.getStatusCode().add(new KeyValue(responseCode, response.getDescription())); + } else { + msResponse.getStatusCode().add(new KeyValue(responseCode, responseCode)); + } + if (response.getResponseSchema()!=null) { + parseResponseBody(response.getResponseSchema(),msResponse.getBody()); + msResponse.getBody().setFormat("JSON-SCHEMA"); + String body = parseSchema(response.getResponseSchema()); + if (StringUtils.isNotBlank(body)) { + msResponse.getBody().setRaw(body); + } + } else { + String body = parseSchema(response.getResponseSchema()); + if (StringUtils.isNotBlank(body)) { + msResponse.getBody().setRaw(body); + } + } + parseResponseHeader(response, msResponse.getHeaders()); + } + return msResponse; }