From 53943f41768da6f0a28fa0995ebd5107991439bc Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Thu, 31 Dec 2020 13:58:42 +0800 Subject: [PATCH 1/4] =?UTF-8?q?refactor:=20=E4=BB=A3=E7=A0=81=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/dto/scenario/KeyValue.java | 11 ++-- .../api/parse/ApiImportAbstractParser.java | 4 +- .../metersphere/api/parse/Swagger2Parser.java | 9 ++-- .../metersphere/api/parse/Swagger3Parser.java | 52 +++++++++++-------- backend/src/main/java/io/metersphere/xpack | 2 +- 5 files changed, 40 insertions(+), 38 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/scenario/KeyValue.java b/backend/src/main/java/io/metersphere/api/dto/scenario/KeyValue.java index 06317a0745..2d5191ac4e 100644 --- a/backend/src/main/java/io/metersphere/api/dto/scenario/KeyValue.java +++ b/backend/src/main/java/io/metersphere/api/dto/scenario/KeyValue.java @@ -32,12 +32,7 @@ public class KeyValue { } public KeyValue(String name, String value, String description, String contentType) { - this.name = name; - this.value = value; - this.description = description; - this.contentType = contentType; - this.enable = true; - this.required = true; + this(name, value, description, contentType, true); } public KeyValue(String name, String value, String description, String contentType, boolean required) { @@ -49,6 +44,10 @@ public class KeyValue { this.required = required; } + public KeyValue(String name, String value, String description, boolean required) { + this(name, value, description, "", required); + } + public boolean isValid() { return (StringUtils.isNotBlank(name) || StringUtils.isNotBlank(value)) && !StringUtils.equalsIgnoreCase(type, "file"); } diff --git a/backend/src/main/java/io/metersphere/api/parse/ApiImportAbstractParser.java b/backend/src/main/java/io/metersphere/api/parse/ApiImportAbstractParser.java index 1d0366f428..0fde847e07 100644 --- a/backend/src/main/java/io/metersphere/api/parse/ApiImportAbstractParser.java +++ b/backend/src/main/java/io/metersphere/api/parse/ApiImportAbstractParser.java @@ -142,10 +142,10 @@ public abstract class ApiImportAbstractParser implements ApiImportParser { } protected void addCookie(List headers, String key, String value) { - addCookie(headers, key, value, "", "", true); + addCookie(headers, key, value, "", true); } - protected void addCookie(List headers, String key, String value, String description, String contentType, boolean required) { + protected void addCookie(List headers, String key, String value, String description, boolean required) { boolean hasCookie = false; for (KeyValue header : headers) { if (StringUtils.equalsIgnoreCase("Cookie", header.getName())) { diff --git a/backend/src/main/java/io/metersphere/api/parse/Swagger2Parser.java b/backend/src/main/java/io/metersphere/api/parse/Swagger2Parser.java index 61d15ed5ce..d1a312941b 100644 --- a/backend/src/main/java/io/metersphere/api/parse/Swagger2Parser.java +++ b/backend/src/main/java/io/metersphere/api/parse/Swagger2Parser.java @@ -166,8 +166,7 @@ public class Swagger2Parser extends ApiImportAbstractParser { private void parseCookieParameters(Parameter parameter, List headers) { CookieParameter cookieParameter = (CookieParameter) parameter; - addCookie(headers, cookieParameter.getName(), "", getDefaultStringValue(cookieParameter.getDescription()), - "", parameter.getRequired()); + addCookie(headers, cookieParameter.getName(), "", getDefaultStringValue(cookieParameter.getDescription()), parameter.getRequired()); } private void parseHeaderParameters(Parameter parameter, List headers) { @@ -301,8 +300,7 @@ public class Swagger2Parser extends ApiImportAbstractParser { 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(), "", getDefaultStringValue(parameter.getDescription()), parameter.getRequired()); if (StringUtils.equals(parameter.getType(), "file")) { kv.setType("file"); } @@ -312,7 +310,6 @@ public class Swagger2Parser extends ApiImportAbstractParser { 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(), "", getDefaultStringValue(queryParameter.getDescription()), queryParameter.getRequired())); } } diff --git a/backend/src/main/java/io/metersphere/api/parse/Swagger3Parser.java b/backend/src/main/java/io/metersphere/api/parse/Swagger3Parser.java index 994eb55346..3e8ab93dd9 100644 --- a/backend/src/main/java/io/metersphere/api/parse/Swagger3Parser.java +++ b/backend/src/main/java/io/metersphere/api/parse/Swagger3Parser.java @@ -17,7 +17,6 @@ import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.XMLUtils; -import io.swagger.models.parameters.FormParameter; import io.swagger.parser.OpenAPIParser; import io.swagger.v3.oas.models.*; import io.swagger.v3.oas.models.headers.Header; @@ -179,12 +178,12 @@ public class Swagger3Parser extends ApiImportAbstractParser { private void parseCookieParameters(Parameter parameter, List headers) { CookieParameter cookieParameter = (CookieParameter) parameter; - addCookie(headers, cookieParameter.getName(), "", getDefaultStringValue(cookieParameter.getDescription()), "", true); + addCookie(headers, cookieParameter.getName(), "", getDefaultStringValue(cookieParameter.getDescription()), parameter.getRequired()); } private void parseHeaderParameters(Parameter parameter, List headers) { HeaderParameter headerParameter = (HeaderParameter) parameter; - addHeader(headers, headerParameter.getName(), "", getDefaultStringValue(headerParameter.getDescription()), "", true); + addHeader(headers, headerParameter.getName(), "", getDefaultStringValue(headerParameter.getDescription()), "", parameter.getRequired()); } private HttpResponse parseResponse(ApiResponses responses) { @@ -250,9 +249,9 @@ public class Swagger3Parser extends ApiImportAbstractParser { } Set refSet = new HashSet<>(); - Map binaryKeyMap = new HashMap(); + Map infoMap = new HashMap(); Schema schema = mediaType.getSchema(); - Object bodyData = parseSchema(schema, refSet, binaryKeyMap); + Object bodyData = parseSchema(schema, refSet, infoMap); if (bodyData == null) { return; @@ -261,7 +260,7 @@ public class Swagger3Parser extends ApiImportAbstractParser { body.setType(getBodyType(contentType)); if (StringUtils.equals(contentType, org.springframework.http.MediaType.APPLICATION_FORM_URLENCODED_VALUE)) { - parseKvBody(schema, body, bodyData, binaryKeyMap); + parseKvBody(schema, body, bodyData, infoMap); } else if (StringUtils.equals(contentType, org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE)) { body.setRaw(bodyData.toString()); } else if (StringUtils.equals(contentType, org.springframework.http.MediaType.APPLICATION_JSON_VALUE)) { @@ -269,27 +268,34 @@ public class Swagger3Parser extends ApiImportAbstractParser { } else if (StringUtils.equals(contentType, org.springframework.http.MediaType.APPLICATION_XML_VALUE)) { body.setRaw(parseXmlBody(schema, bodyData)); } else if (StringUtils.equals(contentType, org.springframework.http.MediaType.APPLICATION_OCTET_STREAM_VALUE)) { - parseKvBody(schema, body, bodyData, binaryKeyMap); + parseKvBody(schema, body, bodyData, infoMap); } else { body.setRaw(bodyData.toString()); } } - private void parseKvBody(Schema schema, Body body, Object data, Map binaryKeyMap) { + private void parseKvBody(Schema schema, Body body, Object data, Map infoMap) { if (data instanceof JSONObject) { ((JSONObject) data).forEach((k, v) -> { KeyValue kv = new KeyValue(k, v.toString()); - if (binaryKeyMap.keySet().contains(k)) { - kv.setDescription(binaryKeyMap.get(k)); - kv.setType("file"); + Schema schemaInfo = infoMap.get(k); + if (schemaInfo != null) { + kv.setDescription(schemaInfo.getDescription()); +// kv.setRequired(schemaInfo.getRequired()); + if (schemaInfo instanceof BinarySchema) { + kv.setType("file"); + } } body.getKvs().add(kv); }); } else { KeyValue kv = new KeyValue(schema.getName(), data.toString(), schema.getDescription()); - if (binaryKeyMap.keySet().contains(schema.getName())) { - kv.setDescription(binaryKeyMap.get(schema.getDescription())); - kv.setType("file"); + Schema schemaInfo = infoMap.get(schema.getName()); + if (schemaInfo != null) { + kv.setDescription(schemaInfo.getDescription()); + if (schemaInfo instanceof BinarySchema) { + kv.setType("file"); + } } body.getKvs().add(kv); } @@ -315,37 +321,37 @@ public class Swagger3Parser extends ApiImportAbstractParser { return this.components.getSchemas().get(ref); } - private Object parseSchema(Schema schema, Set refSet, Map binaryKeyMap) { + private Object parseSchema(Schema schema, Set refSet, Map infoMap) { + infoMap.put(schema.getName(), schema); if (StringUtils.isNotBlank(schema.get$ref())) { if (refSet.contains(schema.get$ref())) { return new JSONObject(); } refSet.add(schema.get$ref()); - Object propertiesResult = parseSchemaProperties(getModelByRef(schema.get$ref()), refSet, binaryKeyMap); + Object propertiesResult = parseSchemaProperties(getModelByRef(schema.get$ref()), refSet, infoMap); return propertiesResult == null ? getDefaultValueByPropertyType(schema) : propertiesResult; } else if (schema instanceof ArraySchema) { JSONArray jsonArray = new JSONArray(); Schema items = ((ArraySchema) schema).getItems(); - parseSchema(items, refSet, binaryKeyMap); - jsonArray.add(parseSchema(items, refSet, binaryKeyMap)); + parseSchema(items, refSet, infoMap); + jsonArray.add(parseSchema(items, refSet, infoMap)); return jsonArray; } else if (schema instanceof BinarySchema) { - binaryKeyMap.put(schema.getName(), schema.getDescription()); return getDefaultValueByPropertyType(schema); } else { - Object propertiesResult = parseSchemaProperties(schema, refSet, binaryKeyMap); + Object propertiesResult = parseSchemaProperties(schema, refSet, infoMap); return propertiesResult == null ? getDefaultValueByPropertyType(schema) : propertiesResult; } } - private Object parseSchemaProperties(Schema schema, Set refSet, Map binaryKeyMap) { + private Object parseSchemaProperties(Schema schema, Set refSet, Map infoMap) { Map properties = schema.getProperties(); if (MapUtils.isEmpty(properties)) { return null; } JSONObject jsonObject = new JSONObject(); properties.forEach((key, value) -> { - jsonObject.put(key, parseSchema(value, refSet, binaryKeyMap)); + jsonObject.put(key, parseSchema(value, refSet, infoMap)); }); return jsonObject; } @@ -363,6 +369,6 @@ public class Swagger3Parser extends ApiImportAbstractParser { private void parseQueryParameters(Parameter parameter, List arguments) { QueryParameter queryParameter = (QueryParameter) parameter; - arguments.add(new KeyValue(queryParameter.getName(), "", getDefaultStringValue(queryParameter.getDescription()))); + arguments.add(new KeyValue(queryParameter.getName(), "", getDefaultStringValue(queryParameter.getDescription()), parameter.getRequired())); } } diff --git a/backend/src/main/java/io/metersphere/xpack b/backend/src/main/java/io/metersphere/xpack index 068127ce59..f27d1609d7 160000 --- a/backend/src/main/java/io/metersphere/xpack +++ b/backend/src/main/java/io/metersphere/xpack @@ -1 +1 @@ -Subproject commit 068127ce59ea8b016434ed52a9de4a7a4b13bdb4 +Subproject commit f27d1609d77f7d6c988d37d709466e844d350e17 From d4fd50b274557f123b2de03e295cb084961a37ee Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Thu, 31 Dec 2020 14:06:20 +0800 Subject: [PATCH 2/4] =?UTF-8?q?refactor:=20=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E5=90=8D=E7=A7=B0=E9=95=BF=E5=BA=A6=E5=A2=9E=E5=A4=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/db/migration/V59__test_plan_add_project_id.sql | 1 + .../business/components/track/case/components/TestCaseEdit.vue | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/src/main/resources/db/migration/V59__test_plan_add_project_id.sql b/backend/src/main/resources/db/migration/V59__test_plan_add_project_id.sql index 8f3cea94a6..9312102fb3 100644 --- a/backend/src/main/resources/db/migration/V59__test_plan_add_project_id.sql +++ b/backend/src/main/resources/db/migration/V59__test_plan_add_project_id.sql @@ -1,4 +1,5 @@ alter table test_plan add project_id varchar(50) null comment '测试计划所属项目'; +ALTER TABLE api_test_case MODIFY COLUMN name varchar(255) NOT NULL COMMENT 'Test name'; DROP PROCEDURE IF EXISTS test_cursor; DELIMITER // diff --git a/frontend/src/business/components/track/case/components/TestCaseEdit.vue b/frontend/src/business/components/track/case/components/TestCaseEdit.vue index 5125544200..8fd3e6ca53 100644 --- a/frontend/src/business/components/track/case/components/TestCaseEdit.vue +++ b/frontend/src/business/components/track/case/components/TestCaseEdit.vue @@ -307,7 +307,7 @@ export default { rules: { name: [ {required: true, message: this.$t('test_track.case.input_name'), trigger: 'blur'}, - {max: 50, message: this.$t('test_track.length_less_than') + '50', trigger: 'blur'} + {max: 255, message: this.$t('test_track.length_less_than') + '255', trigger: 'blur'} ], module: [{required: true, message: this.$t('test_track.case.input_module'), trigger: 'change'}], maintainer: [{required: true, message: this.$t('test_track.case.input_maintainer'), trigger: 'change'}], From 2d344f28e322d3c8468dc24543b426e5931392b9 Mon Sep 17 00:00:00 2001 From: LuoTing <36292514+luty2018@users.noreply.github.com> Date: Thu, 31 Dec 2020 14:27:53 +0800 Subject: [PATCH 3/4] Update v1.6.1-issue.md --- .github/ISSUE_TEMPLATE/v1.6.1-issue.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/v1.6.1-issue.md b/.github/ISSUE_TEMPLATE/v1.6.1-issue.md index 4d25616e97..8dbbdf6871 100644 --- a/.github/ISSUE_TEMPLATE/v1.6.1-issue.md +++ b/.github/ISSUE_TEMPLATE/v1.6.1-issue.md @@ -1,5 +1,5 @@ --- -name: v1.6.1 问题 +name: v1.6反馈 about: 提交关于 v1.6.1 的缺陷与建议,赢取Lv同款鼠标垫!马克杯!文化衫! title: "[v1.6.1]" labels: v1.6.1 From 83945506994d3a9dc82e99b6d0a7bcf4fc563138 Mon Sep 17 00:00:00 2001 From: LuoTing <36292514+luty2018@users.noreply.github.com> Date: Thu, 31 Dec 2020 14:28:40 +0800 Subject: [PATCH 4/4] Update v1.6.1-issue.md --- .github/ISSUE_TEMPLATE/v1.6.1-issue.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/v1.6.1-issue.md b/.github/ISSUE_TEMPLATE/v1.6.1-issue.md index 8dbbdf6871..f1c3ff67b8 100644 --- a/.github/ISSUE_TEMPLATE/v1.6.1-issue.md +++ b/.github/ISSUE_TEMPLATE/v1.6.1-issue.md @@ -1,8 +1,8 @@ --- name: v1.6反馈 -about: 提交关于 v1.6.1 的缺陷与建议,赢取Lv同款鼠标垫!马克杯!文化衫! -title: "[v1.6.1]" -labels: v1.6.1 +about: 提交关于 v1.6的缺陷与建议,赢取Lv同款鼠标垫!马克杯!文化衫! +title: "[v1.6]" +labels: v1.6 assignees: luty2018 ---