From ca95b0cb99bdb0021110775f1d14af5ef997a0e7 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Mon, 6 Sep 2021 15:42:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20swagger2=E5=AF=BC=E5=85=A5=E4=B9=8B?= =?UTF-8?q?=E5=90=8E=E9=BB=98=E8=AE=A4=E5=80=BC=E6=B2=A1=E6=9C=89=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=20--bug=3D1005571=20--user=3D=E9=99=88=E5=BB=BA?= =?UTF-8?q?=E6=98=9F=20=E3=80=90github#5081=E3=80=91=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=20=E4=BD=BF=E7=94=A8swagger2.0=E7=9A=84?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=EF=BC=8Cswagger=E5=B7=B2=E7=BB=8F=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E4=BA=86header=E7=9A=84=E5=8F=98=E9=87=8F=E5=92=8C?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=80=BC=EF=BC=8C=E8=80=8C=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E5=90=8E=20=E6=8E=A5=E5=8F=A3=E6=B2=A1=E6=9C=89=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E5=80=BC=20https://www.tapd.cn/55049933/s/1044012?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/definition/parse/Swagger2Parser.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 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 f7f302edb8..5a8b51e0e7 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 @@ -169,7 +169,14 @@ public class Swagger2Parser extends SwaggerAbstractParser { private void parsePathParameters(Parameter parameter, List rests) { PathParameter pathParameter = (PathParameter) parameter; - rests.add(new KeyValue(pathParameter.getName(), "", getDefaultStringValue(parameter.getDescription()), pathParameter.getRequired())); + rests.add(new KeyValue(pathParameter.getName(), getDefaultValue(pathParameter), getDefaultStringValue(parameter.getDescription()), pathParameter.getRequired())); + } + + private String getDefaultValue(AbstractSerializableParameter parameter) { + if (parameter.getDefault() != null) { + return getDefaultStringValue(parameter.getDefault().toString()); + } + return ""; } private String getDefaultStringValue(String val) { @@ -178,12 +185,12 @@ public class Swagger2Parser extends SwaggerAbstractParser { private void parseCookieParameters(Parameter parameter, List headers) { CookieParameter cookieParameter = (CookieParameter) parameter; - addCookie(headers, cookieParameter.getName(), "", getDefaultStringValue(cookieParameter.getDescription()), parameter.getRequired()); + addCookie(headers, cookieParameter.getName(), getDefaultValue(cookieParameter), getDefaultStringValue(cookieParameter.getDescription()), parameter.getRequired()); } private void parseHeaderParameters(Parameter parameter, List headers) { HeaderParameter headerParameter = (HeaderParameter) parameter; - addHeader(headers, headerParameter.getName(), "", getDefaultStringValue(headerParameter.getDescription()), + addHeader(headers, headerParameter.getName(), getDefaultValue(headerParameter), getDefaultStringValue(headerParameter.getDescription()), "", parameter.getRequired()); } @@ -342,7 +349,7 @@ public class Swagger2Parser extends SwaggerAbstractParser { private void parseFormDataParameters(FormParameter parameter, Body body) { List keyValues = Optional.ofNullable(body.getKvs()).orElse(new ArrayList<>()); - KeyValue kv = new KeyValue(parameter.getName(), "", getDefaultStringValue(parameter.getDescription()), parameter.getRequired()); + KeyValue kv = new KeyValue(parameter.getName(), getDefaultValue(parameter), getDefaultStringValue(parameter.getDescription()), parameter.getRequired()); if (StringUtils.equals(parameter.getType(), "file")) { kv.setType("file"); } @@ -352,6 +359,6 @@ public class Swagger2Parser extends SwaggerAbstractParser { private void parseQueryParameters(Parameter parameter, List arguments) { QueryParameter queryParameter = (QueryParameter) parameter; - arguments.add(new KeyValue(queryParameter.getName(), "", getDefaultStringValue(queryParameter.getDescription()), queryParameter.getRequired())); + arguments.add(new KeyValue(queryParameter.getName(), getDefaultValue(queryParameter), getDefaultStringValue(queryParameter.getDescription()), queryParameter.getRequired())); } }