From c79a7732e747680c0bde22a69557e3731f1f812d Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 14 Oct 2021 16:58:03 +0800 Subject: [PATCH] =?UTF-8?q?feat=20(=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89):?= =?UTF-8?q?=20=E5=AE=8C=E6=88=90http=E5=8D=8F=E8=AE=AE=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E5=8E=86=E5=8F=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../log/utils/ReflexObjectUtil.java | 6 +- .../log/utils/dff/ApiDefinitionDiffUtil.java | 31 +++++- .../log/vo/api/DefinitionReference.java | 14 +++ .../components/auth/ApiAuthConfig.vue | 94 ++++++++++--------- .../history/api/ApiDubboParameters.vue | 16 +++- .../history/api/ApiHistoryDetail.vue | 18 +++- .../history/api/ApiHttpRequestParams.vue | 74 ++++++++++++++- .../history/api/ApiJdbcParameters.vue | 34 ++++++- 8 files changed, 220 insertions(+), 67 deletions(-) diff --git a/backend/src/main/java/io/metersphere/log/utils/ReflexObjectUtil.java b/backend/src/main/java/io/metersphere/log/utils/ReflexObjectUtil.java index c60d8c6a7d..5b1f8302b1 100644 --- a/backend/src/main/java/io/metersphere/log/utils/ReflexObjectUtil.java +++ b/backend/src/main/java/io/metersphere/log/utils/ReflexObjectUtil.java @@ -154,10 +154,10 @@ public class ReflexObjectUtil { DetailColumn column = new DetailColumn(); BeanUtils.copyBean(column, originalColumns.get(i)); column.setNewValue(newColumns.get(i).getOriginalValue()); - if (originalColumns.get(i).getColumnName().equals("tags")) { + if (StringUtils.isNotEmpty(originalColumns.get(i).getColumnName()) && originalColumns.get(i).getColumnName().equals("tags")) { GsonDiff diff = new GsonDiff(); - String oldTags = "{\"root\":" + originalColumns.get(i).getOriginalValue().toString() + "}"; - String newTags = "{\"root\":" + newColumns.get(i).getOriginalValue().toString() + "}"; + String oldTags = "{\"root\":" + ((originalColumns.get(i) != null && originalColumns.get(i).getOriginalValue() != null) ? originalColumns.get(i).getOriginalValue().toString() : "\"\"") + "}"; + String newTags = "{\"root\":" + ((newColumns.get(i) != null && newColumns.get(i).getOriginalValue() != null) ? newColumns.get(i).getOriginalValue().toString() : "\"\"") + "}"; String diffStr = diff.diff(oldTags, newTags); String diffValue = diff.apply(newTags, diffStr); column.setDiffValue(diffValue); diff --git a/backend/src/main/java/io/metersphere/log/utils/dff/ApiDefinitionDiffUtil.java b/backend/src/main/java/io/metersphere/log/utils/dff/ApiDefinitionDiffUtil.java index d68ec7352d..e833d0f8d9 100644 --- a/backend/src/main/java/io/metersphere/log/utils/dff/ApiDefinitionDiffUtil.java +++ b/backend/src/main/java/io/metersphere/log/utils/dff/ApiDefinitionDiffUtil.java @@ -50,7 +50,9 @@ public class ApiDefinitionDiffUtil { MsDubboSampler dubboSamplerOld = bloBsOld.toJavaObject(MsDubboSampler.class); diffDubbo(dubboSamplerNew, dubboSamplerOld, jsonDiff, diffMap); } - return JSON.toJSONString(diffMap); + if (diffMap.size() > 1) { + return JSON.toJSONString(diffMap); + } } catch (Exception e) { e.printStackTrace(); } @@ -59,7 +61,7 @@ public class ApiDefinitionDiffUtil { private static void diffHttp(MsHTTPSamplerProxy httpNew, MsHTTPSamplerProxy httpOld, JsonDiff jsonDiff, Map diffMap) { // 请求头对比 old/new - if (CollectionUtils.isNotEmpty(httpNew.getHeaders())) { + if (CollectionUtils.isNotEmpty(httpNew.getHeaders()) && CollectionUtils.isNotEmpty(httpOld.getHeaders())) { httpNew.getHeaders().remove(httpNew.getHeaders().size() - 1); httpOld.getHeaders().remove(httpOld.getHeaders().size() - 1); } @@ -73,7 +75,7 @@ public class ApiDefinitionDiffUtil { } } // 对比QUERY参数 - if (CollectionUtils.isNotEmpty(httpNew.getArguments())) { + if (CollectionUtils.isNotEmpty(httpNew.getArguments()) && CollectionUtils.isNotEmpty(httpOld.getArguments())) { httpNew.getArguments().remove(httpNew.getArguments().size() - 1); httpOld.getArguments().remove(httpOld.getArguments().size() - 1); } @@ -87,7 +89,7 @@ public class ApiDefinitionDiffUtil { } } // 对比REST参数 - if (CollectionUtils.isNotEmpty(httpNew.getRest())) { + if (CollectionUtils.isNotEmpty(httpNew.getRest()) && CollectionUtils.isNotEmpty(httpOld.getRest())) { httpNew.getRest().remove(httpNew.getRest().size() - 1); httpOld.getRest().remove(httpOld.getRest().size() - 1); } @@ -112,7 +114,7 @@ public class ApiDefinitionDiffUtil { } } // 对比BODY-FORM参数 - if (CollectionUtils.isNotEmpty(httpNew.getBody().getKvs())) { + if (CollectionUtils.isNotEmpty(httpNew.getBody().getKvs()) && CollectionUtils.isNotEmpty(httpOld.getBody().getKvs())) { httpNew.getBody().getKvs().remove(httpNew.getBody().getKvs().size() - 1); httpOld.getBody().getKvs().remove(httpOld.getBody().getKvs().size() - 1); } @@ -131,6 +133,25 @@ public class ApiDefinitionDiffUtil { diffMap.put("body_raw_2", httpOld.getBody().getRaw()); } + // 认证配置 + if (httpNew.getAuthManager() != null || httpOld.getAuthManager() != null) { + List authColumns = ReflexObjectUtil.getColumns(httpNew.getAuthManager(), DefinitionReference.authColumns); + List authColumnsOld = ReflexObjectUtil.getColumns(httpOld.getAuthManager(), DefinitionReference.authColumns); + List authDiffColumns = getColumn(authColumns, authColumnsOld); + if (CollectionUtils.isNotEmpty(authDiffColumns)) { + diffMap.put("body_auth", JSON.toJSONString(authDiffColumns)); + } else if (CollectionUtils.isEmpty(authDiffColumns) && CollectionUtils.isEmpty(authColumnsOld) && CollectionUtils.isNotEmpty(authColumns)) { + diffMap.put("body_auth", JSON.toJSONString(authColumns)); + } + } + + // 其他设置 + List columns = ReflexObjectUtil.getColumns(httpNew, DefinitionReference.httpColumns); + List columnsOld = ReflexObjectUtil.getColumns(httpOld, DefinitionReference.httpColumns); + List diffColumns = getColumn(columns, columnsOld); + if (CollectionUtils.isNotEmpty(diffColumns)) { + diffMap.put("body_config", JSON.toJSONString(diffColumns)); + } } } diff --git a/backend/src/main/java/io/metersphere/log/vo/api/DefinitionReference.java b/backend/src/main/java/io/metersphere/log/vo/api/DefinitionReference.java index 51554cef6e..8551b5c841 100644 --- a/backend/src/main/java/io/metersphere/log/vo/api/DefinitionReference.java +++ b/backend/src/main/java/io/metersphere/log/vo/api/DefinitionReference.java @@ -7,11 +7,15 @@ public class DefinitionReference { public static Map definitionColumns = new LinkedHashMap<>(); public static Map caseColumns = new LinkedHashMap<>(); public static Map jdbcColumns = new LinkedHashMap<>(); + public static Map httpColumns = new LinkedHashMap<>(); + public static Map authColumns = new LinkedHashMap<>(); static { definitionColumns.clear(); caseColumns.clear(); jdbcColumns.clear(); + httpColumns.clear(); + authColumns.clear(); definitionColumns.put("name", "接口名称"); definitionColumns.put("createUser", "创建人"); definitionColumns.put("method", "请求类型"); @@ -46,6 +50,16 @@ public class DefinitionReference { jdbcColumns.put("queryTimeout", "超时时间"); jdbcColumns.put("resultVariable", "存储结果"); jdbcColumns.put("variableNames", "按列存储"); + // http + httpColumns.put("connectTimeout","连接超时"); + httpColumns.put("responseTimeout","响应超时"); + httpColumns.put("alias","证书别名"); + httpColumns.put("followRedirects","跟随重定向"); + // http auth + authColumns.put("verification","认证方式"); + authColumns.put("username","用户名"); + authColumns.put("password","密码"); + authColumns.put("encrypt","加密"); } } \ No newline at end of file diff --git a/frontend/src/business/components/api/definition/components/auth/ApiAuthConfig.vue b/frontend/src/business/components/api/definition/components/auth/ApiAuthConfig.vue index 0f9fa7a651..907c105d33 100644 --- a/frontend/src/business/components/api/definition/components/auth/ApiAuthConfig.vue +++ b/frontend/src/business/components/api/definition/components/auth/ApiAuthConfig.vue @@ -55,58 +55,60 @@ diff --git a/frontend/src/business/components/history/api/ApiDubboParameters.vue b/frontend/src/business/components/history/api/ApiDubboParameters.vue index a4d07b0346..997207e97f 100644 --- a/frontend/src/business/components/history/api/ApiDubboParameters.vue +++ b/frontend/src/business/components/history/api/ApiDubboParameters.vue @@ -3,11 +3,20 @@ - - + + + @@ -113,8 +122,9 @@ export default { white-space: nowrap; width: 120px; } + .ms-tag-del { - text-decoration:line-through; + text-decoration: line-through; text-decoration-color: red; -moz-text-decoration-line: line-through; background: #F3E6E7; diff --git a/frontend/src/business/components/history/api/ApiHistoryDetail.vue b/frontend/src/business/components/history/api/ApiHistoryDetail.vue index 1dab0f2537..6da10a38b4 100644 --- a/frontend/src/business/components/history/api/ApiHistoryDetail.vue +++ b/frontend/src/business/components/history/api/ApiHistoryDetail.vue @@ -101,9 +101,13 @@ export default { this.detail.body = {}; this.detail.headerId = getUUID(); if (diffValue.body) { - let jsonSchema = (JSON.parse(diffValue.body)).jsonSchema; - this.formatJson(jsonSchema.properties); - this.detail.body.jsonSchema = jsonSchema; + let json = (JSON.parse(diffValue.body)); + if (json && json.jsonSchema && json.jsonSchema.properties) { + this.formatJson(json.jsonSchema.properties); + this.detail.body.jsonSchema = json.jsonSchema; + } else if (json && json["++jsonSchema"]) { + this.detail.body.jsonSchema = json["++jsonSchema"]; + } this.detail.headerId = getUUID(); } if (diffValue.body_form) { @@ -131,6 +135,14 @@ export default { this.detail.rest = rest; this.detail.headerId = getUUID(); } + if (diffValue.body_auth) { + this.detail.body_auth = JSON.parse(diffValue.body_auth); + this.detail.headerId = getUUID(); + } + if (diffValue.body_config) { + this.detail.body_config = JSON.parse(diffValue.body_config); + this.detail.headerId = getUUID(); + } }, formatTcp(diffValue) { if (!this.detail.body) { diff --git a/frontend/src/business/components/history/api/ApiHttpRequestParams.vue b/frontend/src/business/components/history/api/ApiHttpRequestParams.vue index d9f4b0d4d1..ac527bfa48 100644 --- a/frontend/src/business/components/history/api/ApiHttpRequestParams.vue +++ b/frontend/src/business/components/history/api/ApiHttpRequestParams.vue @@ -29,12 +29,47 @@ - - - + + + + + + + + + + + - - + + + + + + + + + + + + + @@ -79,6 +114,10 @@ export default { this.activeName = "headers"; } else if (this.request.rest) { this.activeName = "rest"; + } else if (this.request.body_config) { + this.activeName = "advancedConfig"; + } else if (this.request.body_auth) { + this.activeName = "authConfig"; } this.reloadCodeEdit(); }, @@ -101,6 +140,10 @@ export default { this.activeName = "headers"; } else if (this.request.rest) { this.activeName = "rest"; + } else if (this.request.body_config) { + this.activeName = "advancedConfig"; + } else if (this.request.body_auth) { + this.activeName = "authConfig"; } this.reloadCodeEdit(); } @@ -145,6 +188,27 @@ export default { margin-right: 45px; } +.current-value { + display: inline-block; + overflow-x: hidden; + padding-bottom: 0; + text-overflow: ellipsis; + vertical-align: middle; + white-space: nowrap; + width: 120px; +} + +.ms-tag-del { + text-decoration: line-through; + text-decoration-color: red; + -moz-text-decoration-line: line-through; + background: #F3E6E7; +} + +.ms-tag-add { + background: #E2ECDC; +} + @import "~jsondiffpatch/dist/formatters-styles/html.css"; @import "~jsondiffpatch/dist/formatters-styles/annotated.css"; diff --git a/frontend/src/business/components/history/api/ApiJdbcParameters.vue b/frontend/src/business/components/history/api/ApiJdbcParameters.vue index a4de08f517..c1b7c90324 100644 --- a/frontend/src/business/components/history/api/ApiJdbcParameters.vue +++ b/frontend/src/business/components/history/api/ApiJdbcParameters.vue @@ -3,11 +3,20 @@ - - + + + @@ -90,6 +99,27 @@ export default { display: inline-block; } +.current-value { + display: inline-block; + overflow-x: hidden; + padding-bottom: 0; + text-overflow: ellipsis; + vertical-align: middle; + white-space: nowrap; + width: 120px; +} + +.ms-tag-del { + text-decoration: line-through; + text-decoration-color: red; + -moz-text-decoration-line: line-through; + background: #F3E6E7; +} + +.ms-tag-add { + background: #E2ECDC; +} + .one-row .el-form-item:nth-child(2) { margin-left: 60px; }