From 685da4ccef9c7d21885ab80a264c43051b96c5cd Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Wed, 15 Jul 2020 15:35:36 +0800 Subject: [PATCH 01/10] =?UTF-8?q?feat:=20Swagger2=20=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/pom.xml | 7 + .../api/dto/parse/swagger/SwaggerApi.java | 1 + .../api/dto/parse/swagger/SwaggerRequest.java | 2 +- .../api/dto/scenario/KeyValue.java | 7 + .../api/parse/ApiImportAbstractParser.java | 39 ++++ .../api/parse/ApiImportParserFactory.java | 2 + .../metersphere/api/parse/PostmanParser.java | 42 ++-- .../metersphere/api/parse/Swagger2Parser.java | 185 ++++++++++++++++++ .../metersphere/api/parse/SwaggerParser.java | 106 ---------- .../commons/constants/ApiImportPlatform.java | 2 +- .../constants/SwaggerParameterType.java | 12 ++ .../api/test/components/import/ApiImport.vue | 9 +- .../api/test/model/ScenarioModel.js | 19 +- frontend/src/i18n/en-US.js | 4 +- frontend/src/i18n/zh-CN.js | 4 +- frontend/src/i18n/zh-TW.js | 4 +- 16 files changed, 302 insertions(+), 143 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/api/parse/Swagger2Parser.java delete mode 100644 backend/src/main/java/io/metersphere/api/parse/SwaggerParser.java create mode 100644 backend/src/main/java/io/metersphere/commons/constants/SwaggerParameterType.java diff --git a/backend/pom.xml b/backend/pom.xml index 0afd90ed95..f8e7467aef 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -190,6 +190,13 @@ spring-boot-starter-data-ldap + + + io.swagger + swagger-parser + 1.0.51 + + diff --git a/backend/src/main/java/io/metersphere/api/dto/parse/swagger/SwaggerApi.java b/backend/src/main/java/io/metersphere/api/dto/parse/swagger/SwaggerApi.java index 9eeeed860d..4d8fbb4275 100644 --- a/backend/src/main/java/io/metersphere/api/dto/parse/swagger/SwaggerApi.java +++ b/backend/src/main/java/io/metersphere/api/dto/parse/swagger/SwaggerApi.java @@ -14,4 +14,5 @@ public class SwaggerApi { private List schemes; private List tags; private JSONObject paths; + private JSONObject definitions; } diff --git a/backend/src/main/java/io/metersphere/api/dto/parse/swagger/SwaggerRequest.java b/backend/src/main/java/io/metersphere/api/dto/parse/swagger/SwaggerRequest.java index d4e0e9e59a..3aaa8e42d5 100644 --- a/backend/src/main/java/io/metersphere/api/dto/parse/swagger/SwaggerRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/parse/swagger/SwaggerRequest.java @@ -12,5 +12,5 @@ public class SwaggerRequest { private String operationId; private List consumes; private List produces; - private SwaggerParameter parameters; + private List parameters; } 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 67c7311b5d..f8c52eaf3a 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 @@ -6,6 +6,7 @@ import lombok.Data; public class KeyValue { private String name; private String value; + private String description; public KeyValue() { } @@ -14,4 +15,10 @@ public class KeyValue { this.name = name; this.value = value; } + + public KeyValue(String name, String value, String description) { + this.name = name; + this.value = value; + this.description = description; + } } 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 0e3ef0e4c1..d3c3244884 100644 --- a/backend/src/main/java/io/metersphere/api/parse/ApiImportAbstractParser.java +++ b/backend/src/main/java/io/metersphere/api/parse/ApiImportAbstractParser.java @@ -1,12 +1,19 @@ package io.metersphere.api.parse; +import io.metersphere.api.dto.scenario.KeyValue; +import io.metersphere.api.dto.scenario.Request; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.LogUtil; +import org.apache.commons.lang3.StringUtils; +import org.eclipse.jetty.http.HttpHeader; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; public abstract class ApiImportAbstractParser implements ApiImportParser { @@ -34,4 +41,36 @@ public abstract class ApiImportAbstractParser implements ApiImportParser { return testStr.toString(); } + protected void addContentType(Request request, String contentType) { + addHeader(request, HttpHeader.CONTENT_TYPE.toString(), contentType); + } + + protected void addCookie(Request request, String key, String value) { + List headers = Optional.ofNullable(request.getHeaders()).orElse(new ArrayList<>()); + boolean hasCookie = false; + for (KeyValue header : headers) { + if (StringUtils.equalsIgnoreCase(HttpHeader.COOKIE.name(), header.getName())) { + hasCookie = true; + String cookies = Optional.ofNullable(header.getValue()).orElse(""); + header.setValue(cookies + key + "=" + value + ";"); + } + } + if (!hasCookie) { + addHeader(request, HttpHeader.COOKIE.name(), key + "=" + value + ";"); + } + } + + protected void addHeader(Request request, String key, String value) { + List headers = Optional.ofNullable(request.getHeaders()).orElse(new ArrayList<>()); + boolean hasContentType = false; + for (KeyValue header : headers) { + if (StringUtils.equalsIgnoreCase(header.getName(), key)) { + hasContentType = true; + } + } + if (!hasContentType) { + headers.add(new KeyValue(key, value)); + } + request.setHeaders(headers); + } } diff --git a/backend/src/main/java/io/metersphere/api/parse/ApiImportParserFactory.java b/backend/src/main/java/io/metersphere/api/parse/ApiImportParserFactory.java index d2a25ba819..a7580d23f5 100644 --- a/backend/src/main/java/io/metersphere/api/parse/ApiImportParserFactory.java +++ b/backend/src/main/java/io/metersphere/api/parse/ApiImportParserFactory.java @@ -12,6 +12,8 @@ public class ApiImportParserFactory { return new MsParser(); } else if (StringUtils.equals(ApiImportPlatform.Postman.name(), platform)) { return new PostmanParser(); + } else if (StringUtils.equals(ApiImportPlatform.Swagger2.name(), platform)) { + return new Swagger2Parser(); } return null; } diff --git a/backend/src/main/java/io/metersphere/api/parse/PostmanParser.java b/backend/src/main/java/io/metersphere/api/parse/PostmanParser.java index 6345093cd1..3b5ff3455b 100644 --- a/backend/src/main/java/io/metersphere/api/parse/PostmanParser.java +++ b/backend/src/main/java/io/metersphere/api/parse/PostmanParser.java @@ -14,6 +14,7 @@ import io.metersphere.commons.constants.PostmanRequestBodyMode; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.LogUtil; import org.apache.commons.lang3.StringUtils; +import org.eclipse.jetty.http.HttpHeader; import java.io.BufferedReader; import java.io.IOException; @@ -64,32 +65,27 @@ public class PostmanParser extends ApiImportAbstractParser { request.setMethod(requestDesc.getMethod()); request.setHeaders(parseKeyValue(requestDesc.getHeader())); request.setParameters(parseKeyValue(url.getQuery())); - Body body = new Body(); - JSONObject postmanBody = requestDesc.getBody(); - String bodyMode = postmanBody.getString("mode"); - if (StringUtils.equals(bodyMode, PostmanRequestBodyMode.RAW.value())) { - body.setRaw(postmanBody.getString(bodyMode)); - body.setType(MsRequestBodyType.RAW.value()); - String contentType = postmanBody.getJSONObject("options").getJSONObject("raw").getString("language"); - List headers = request.getHeaders(); - boolean hasContentType = false; - for (KeyValue header : headers) { - if (StringUtils.equalsIgnoreCase(header.getName(), "Content-Type")) { - hasContentType = true; - } - } - if (!hasContentType) { - headers.add(new KeyValue("Content-Type", contentType)); - } - } else if (StringUtils.equals(bodyMode, PostmanRequestBodyMode.FORM_DATA.value()) || StringUtils.equals(bodyMode, PostmanRequestBodyMode.URLENCODED.value())) { - List postmanKeyValues = JSON.parseArray(postmanBody.getString(bodyMode), PostmanKeyValue.class); - body.setType(MsRequestBodyType.KV.value()); - body.setKvs(parseKeyValue(postmanKeyValues)); - } - request.setBody(body); + request.setBody(parseBody(requestDesc, request)); requests.add(request); } return requests; } + private Body parseBody(PostmanRequest requestDesc, Request request) { + Body body = new Body(); + JSONObject postmanBody = requestDesc.getBody(); + String bodyMode = postmanBody.getString("mode"); + if (StringUtils.equals(bodyMode, PostmanRequestBodyMode.RAW.value())) { + body.setRaw(postmanBody.getString(bodyMode)); + body.setType(MsRequestBodyType.RAW.value()); + String contentType = postmanBody.getJSONObject("options").getJSONObject("raw").getString("language"); + addContentType(request, contentType); + } else if (StringUtils.equals(bodyMode, PostmanRequestBodyMode.FORM_DATA.value()) || StringUtils.equals(bodyMode, PostmanRequestBodyMode.URLENCODED.value())) { + List postmanKeyValues = JSON.parseArray(postmanBody.getString(bodyMode), PostmanKeyValue.class); + body.setType(MsRequestBodyType.KV.value()); + body.setKvs(parseKeyValue(postmanKeyValues)); + } + return body; + } + } diff --git a/backend/src/main/java/io/metersphere/api/parse/Swagger2Parser.java b/backend/src/main/java/io/metersphere/api/parse/Swagger2Parser.java new file mode 100644 index 0000000000..df35aaae2e --- /dev/null +++ b/backend/src/main/java/io/metersphere/api/parse/Swagger2Parser.java @@ -0,0 +1,185 @@ +package io.metersphere.api.parse; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import io.metersphere.api.dto.parse.ApiImport; +import io.metersphere.api.dto.scenario.Body; +import io.metersphere.api.dto.scenario.KeyValue; +import io.metersphere.api.dto.scenario.Request; +import io.metersphere.api.dto.scenario.Scenario; +import io.metersphere.commons.constants.MsRequestBodyType; +import io.metersphere.commons.constants.SwaggerParameterType; +import io.swagger.models.*; +import io.swagger.models.parameters.*; +import io.swagger.models.properties.ArrayProperty; +import io.swagger.models.properties.ObjectProperty; +import io.swagger.models.properties.Property; +import io.swagger.models.properties.RefProperty; +import io.swagger.parser.SwaggerParser; + +import java.io.InputStream; +import java.util.*; + +public class Swagger2Parser extends ApiImportAbstractParser { + + @Override + public ApiImport parse(InputStream source) { + String testStr = getApiTestStr(source); +// Swagger swagger = new SwaggerParser().read("http://petstore.swagger.io/v2/swagger.json"); + Swagger swagger = new SwaggerParser().readWithInfo(testStr).getSwagger(); + ApiImport apiImport = new ApiImport(); + apiImport.setScenarios(parseRequests(swagger)); + return apiImport; + } + + private List parseRequests(Swagger swagger) { + Map paths = swagger.getPaths(); + Set pathNames = paths.keySet(); + Map scenarioMap = new HashMap<>(); + List scenarios = new ArrayList<>(); + for (String pathName : pathNames) { + Path path = paths.get(pathName); + Map operationMap = path.getOperationMap(); + Set httpMethods = operationMap.keySet(); + for (HttpMethod method : httpMethods) { + Operation operation = operationMap.get(method); + Request request = new Request(); + request.setName(operation.getOperationId()); + request.setPath(pathName); + request.setUseEnvironment(true); + request.setMethod(method.name()); + parseParameters(operation, swagger.getDefinitions(), request); + List tags = operation.getTags(); + if (tags != null) { + tags.forEach(tag -> { + Scenario scenario = Optional.ofNullable(scenarioMap.get(tag)).orElse(new Scenario()); + List requests = Optional.ofNullable(scenario.getRequests()).orElse(new ArrayList<>()); + requests.add(request); + scenario.setRequests(requests);scenario.setName(tag); + scenarioMap.put(tag, scenario); + }); + } else { + Scenario scenario = Optional.ofNullable(scenarioMap.get("default")).orElse(new Scenario()); + List requests = Optional.ofNullable(scenario.getRequests()).orElse(new ArrayList<>()); + requests.add(request); + scenario.setRequests(requests); + scenarioMap.put("default", scenario); + } + + } + } + scenarioMap.values().forEach(scenario -> { + scenarios.add(scenario); + }); + return scenarios; + } + + private void parseParameters(Operation operation, Map definitions, Request request) { + + List parameters = operation.getParameters(); + + for (Parameter parameter : parameters) { + switch (parameter.getIn()){ +// case SwaggerParameterType.PATH: +// parsePathParameters(parameter, request); +// break; + case SwaggerParameterType.QUERY: + parseQueryParameters(parameter, request); + break; + case SwaggerParameterType.FORM_DATA: + parseFormDataParameters(parameter, request); + break; + case SwaggerParameterType.BODY: + parseBodyParameters(parameter, request, definitions); + break; + case SwaggerParameterType.HEADER: + parseHeaderParameters(parameter, request); + break; + case SwaggerParameterType.COOKIE: + parseCookieParameters(parameter, request); + break; +// case SwaggerParameterType.FILE: +// parsePathParameters(parameter, request); +// break; + } + } + } + + private void parseCookieParameters(Parameter parameter, Request request) { + CookieParameter cookieParameter = (CookieParameter) parameter; + addCookie(request, cookieParameter.getName(), cookieParameter.getDescription()); + } + + private void parseHeaderParameters(Parameter parameter, Request request) { + HeaderParameter headerParameter = (HeaderParameter) parameter; + addHeader(request, headerParameter.getName(), headerParameter.getDescription()); + } + + private void parseBodyParameters(Parameter parameter, Request request, Map definitions) { + BodyParameter bodyParameter = (BodyParameter) parameter; + Body body = Optional.ofNullable(request.getBody()).orElse(new Body()); + body.setType(MsRequestBodyType.RAW.value()); + Model schema = bodyParameter.getSchema(); + + if (schema instanceof RefModel) { + RefModel refModel = (RefModel) bodyParameter.getSchema(); + Model model = definitions.get(refModel.getSimpleRef()); + JSONObject bodyParameters = getBodyJSONObjectParameters(model.getProperties(), definitions); + body.setRaw(bodyParameters.toJSONString()); + } else if (schema instanceof ArrayModel) { + ArrayModel arrayModel = (ArrayModel) bodyParameter.getSchema(); + Property items = arrayModel.getItems(); + if (items instanceof RefProperty) { + RefProperty refProperty = (RefProperty) items; + Model model = definitions.get(refProperty.getSimpleRef()); + JSONArray propertyList = new JSONArray(); + propertyList.add(getBodyJSONObjectParameters(model.getProperties(), definitions)); + body.setRaw(propertyList.toString()); + } + } + request.setBody(body); + addContentType(request, "application/json"); + + } + + private JSONObject getBodyJSONObjectParameters(Map properties, Map definitions) { + JSONObject jsonObject = new JSONObject(); + properties.forEach((key, value) -> { + if (value instanceof ObjectProperty) { + ObjectProperty objectProperty = (ObjectProperty) value; + jsonObject.put(key, getBodyJSONObjectParameters(objectProperty.getProperties(), definitions)); + } else if (value instanceof ArrayProperty) { + ArrayProperty arrayProperty = (ArrayProperty) value; + Property items = arrayProperty.getItems(); + if (items instanceof RefProperty) { + RefProperty refProperty = (RefProperty) items; + Model model = definitions.get(refProperty.getSimpleRef()); + JSONArray propertyList = new JSONArray(); + propertyList.add(getBodyJSONObjectParameters(model.getProperties(), definitions)); + jsonObject.put(key, propertyList); + } else { + jsonObject.put(key, new ArrayList<>()); + } + } else { + jsonObject.put(key, Optional.ofNullable(value.getDescription()).orElse("")); + } + }); + return jsonObject; + } + + private void parseFormDataParameters(Parameter parameter, Request request) { + Body body = Optional.ofNullable(request.getBody()).orElse(new Body()); + body.setType(MsRequestBodyType.FORM_DATA.value()); + List keyValues = Optional.ofNullable(body.getKvs()).orElse(new ArrayList<>()); + keyValues.add(new KeyValue(parameter.getName(), "", parameter.getDescription())); + body.setKvs(keyValues); + request.setBody(body); + } + + private void parseQueryParameters(Parameter parameter, Request request) { + QueryParameter queryParameter = (QueryParameter) parameter; + List parameters = Optional.ofNullable(request.getParameters()).orElse(new ArrayList<>()); + parameters.add(new KeyValue(queryParameter.getName(), "", queryParameter.getDescription())); + request.setParameters(parameters); + } +} diff --git a/backend/src/main/java/io/metersphere/api/parse/SwaggerParser.java b/backend/src/main/java/io/metersphere/api/parse/SwaggerParser.java deleted file mode 100644 index e3ff9db8f2..0000000000 --- a/backend/src/main/java/io/metersphere/api/parse/SwaggerParser.java +++ /dev/null @@ -1,106 +0,0 @@ -package io.metersphere.api.parse; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import io.metersphere.api.dto.parse.ApiImport; -import io.metersphere.api.dto.parse.postman.PostmanItem; -import io.metersphere.api.dto.parse.postman.PostmanRequest; -import io.metersphere.api.dto.parse.postman.PostmanUrl; -import io.metersphere.api.dto.parse.swagger.SwaggerApi; -import io.metersphere.api.dto.parse.swagger.SwaggerInfo; -import io.metersphere.api.dto.parse.swagger.SwaggerRequest; -import io.metersphere.api.dto.scenario.Request; -import io.metersphere.api.dto.scenario.Scenario; - -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -public class SwaggerParser extends ApiImportAbstractParser { - - @Override - public ApiImport parse(InputStream source) { - String testStr = getApiTestStr(source); - - SwaggerApi swaggerApi = JSON.parseObject(testStr.toString(), SwaggerApi.class); - - SwaggerInfo info = swaggerApi.getInfo(); - - String title = info.getTitle(); - - -// List requests = parseRequests(swaggerApi); -// ApiImport apiImport = new ApiImport(); -// List scenarios = new ArrayList<>(); -// Scenario scenario = new Scenario(); -// scenario.setRequests(requests); -// scenario.setName(info.getName()); -// scenarios.add(scenario); -// apiImport.setScenarios(scenarios); -// return apiImport; - return null; - } - -// private List parseRequests(SwaggerApi swaggerApi) { -// JSONObject paths = swaggerApi.getPaths(); -// -// Set pathNames = paths.keySet(); -// -// for (String path : pathNames) { -// JSONObject pathObject = paths.getJSONObject(path); -// Set methods = pathObject.keySet(); -// for (String method : methods) { -// SwaggerRequest swaggerRequest = JSON.parseObject(pathObject.getJSONObject(method).toJSONString(), SwaggerRequest.class); -// Request request = new Request(); -// request.setName(swaggerRequest.getOperationId()); -// request.setUrl(url.getRaw()); -// request.setPath(.getRaw()); -// request.setUseEnvironment(false); -// request.setMethod(requestDesc.getMethod()); -// request.setHeaders(parseKeyValue(requestDesc.getHeader())); -// request.setParameters(parseKeyValue(url.getQuery())); -// -// } -// } -// -// List item = postmanCollection.getItem(); -// List requests = new ArrayList<>(); -// for (PostmanItem requestItem : item) { -// Request request = new Request(); -// PostmanRequest requestDesc = requestItem.getRequest(); -// PostmanUrl url = requestDesc.getUrl(); -// request.setName(requestItem.getName()); -// request.setUrl(url.getRaw()); -// request.setUseEnvironment(false); -// request.setMethod(requestDesc.getMethod()); -// request.setHeaders(parseKeyValue(requestDesc.getHeader())); -// request.setParameters(parseKeyValue(url.getQuery())); -// Body body = new Body(); -// JSONObject postmanBody = requestDesc.getBody(); -// String bodyMode = postmanBody.getString("mode"); -// if (StringUtils.equals(bodyMode, PostmanRequestBodyMode.RAW.value())) { -// body.setRaw(postmanBody.getString(bodyMode)); -// body.setType(MsRequestBodyType.RAW.value()); -// String contentType = postmanBody.getJSONObject("options").getJSONObject("raw").getString("language"); -// List headers = request.getHeaders(); -// boolean hasContentType = false; -// for (KeyValue header : headers) { -// if (StringUtils.equalsIgnoreCase(header.getName(), "Content-Type")) { -// hasContentType = true; -// } -// } -// if (!hasContentType) { -// headers.add(new KeyValue("Content-Type", contentType)); -// } -// } else if (StringUtils.equals(bodyMode, PostmanRequestBodyMode.FORM_DATA.value()) || StringUtils.equals(bodyMode, PostmanRequestBodyMode.URLENCODED.value())) { -// List postmanKeyValues = JSON.parseArray(postmanBody.getString(bodyMode), PostmanKeyValue.class); -// body.setType(MsRequestBodyType.KV.value()); -// body.setKvs(parseKeyValue(postmanKeyValues)); -// } -// request.setBody(body); -// requests.add(request); -// } -// return requests; -// } -} diff --git a/backend/src/main/java/io/metersphere/commons/constants/ApiImportPlatform.java b/backend/src/main/java/io/metersphere/commons/constants/ApiImportPlatform.java index a5bea45b77..2f6336d1e2 100644 --- a/backend/src/main/java/io/metersphere/commons/constants/ApiImportPlatform.java +++ b/backend/src/main/java/io/metersphere/commons/constants/ApiImportPlatform.java @@ -1,5 +1,5 @@ package io.metersphere.commons.constants; public enum ApiImportPlatform { - Metersphere, Postman + Metersphere, Postman, Swagger2 } diff --git a/backend/src/main/java/io/metersphere/commons/constants/SwaggerParameterType.java b/backend/src/main/java/io/metersphere/commons/constants/SwaggerParameterType.java new file mode 100644 index 0000000000..5178bf1638 --- /dev/null +++ b/backend/src/main/java/io/metersphere/commons/constants/SwaggerParameterType.java @@ -0,0 +1,12 @@ +package io.metersphere.commons.constants; + +public class SwaggerParameterType { + + public static final String PATH = "path"; + public static final String FORM_DATA = "formData"; + public static final String FILE = "file"; + public static final String HEADER = "header"; + public static final String BODY = "body"; + public static final String COOKIE = "cookie"; + public static final String QUERY = "query"; +} diff --git a/frontend/src/business/components/api/test/components/import/ApiImport.vue b/frontend/src/business/components/api/test/components/import/ApiImport.vue index 5aad534353..203de004ca 100644 --- a/frontend/src/business/components/api/test/components/import/ApiImport.vue +++ b/frontend/src/business/components/api/test/components/import/ApiImport.vue @@ -56,7 +56,14 @@ name: 'Postman', value: 'Postman', tip: this.$t('api_test.api_import.postman_tip'), - exportTip: this.$t('api_test.api_import.post_man_export_tip'), + exportTip: this.$t('api_test.api_import.post_export_tip'), + suffixes: new Set(['json']) + }, + { + name: 'Swagger', + value: 'Swagger2', + tip: this.$t('api_test.api_import.swagger_tip'), + exportTip: this.$t('api_test.api_import.swagger_export_tip'), suffixes: new Set(['json']) } ], diff --git a/frontend/src/business/components/api/test/model/ScenarioModel.js b/frontend/src/business/components/api/test/model/ScenarioModel.js index 10f97ed0ac..fbe8facfdc 100644 --- a/frontend/src/business/components/api/test/model/ScenarioModel.js +++ b/frontend/src/business/components/api/test/model/ScenarioModel.js @@ -394,16 +394,19 @@ const JMX_ASSERTION_CONDITION = { class JMXRequest { constructor(request) { - if (request && request instanceof Request && request.url) { - let url = new URL(request.url); - this.method = request.method; - this.hostname = decodeURIComponent(url.hostname); - this.pathname = decodeURIComponent(url.pathname); - this.path = decodeURIComponent(request.path); + if (request && request instanceof Request && (request.url || request.path)) { this.useEnvironment = request.useEnvironment; this.environment = request.environment; - this.port = url.port; - this.protocol = url.protocol.split(":")[0]; + this.path = decodeURIComponent(request.path); + this.method = request.method; + if (!request.useEnvironment) { + let url = new URL(request.url); + this.hostname = decodeURIComponent(url.hostname); + this.pathname = decodeURIComponent(url.pathname); + this.port = url.port; + this.protocol = url.protocol.split(":")[0]; + } + if (this.method.toUpperCase() !== "GET") { // this.pathname += url.search.replace('&', '&'); this.pathname += '?'; diff --git a/frontend/src/i18n/en-US.js b/frontend/src/i18n/en-US.js index c4d37e6f4b..0591f84d5d 100644 --- a/frontend/src/i18n/en-US.js +++ b/frontend/src/i18n/en-US.js @@ -374,8 +374,10 @@ export default { export_tip: "Export Tip", ms_tip: "Support for Metersphere JSON format", ms_export_tip: "Export jSON-formatted files via Metersphere website or browser plug-ins", + swagger_tip: "Only Swagger2.x json files are supported", postman_tip: "Only Postman Collection V2.1 json files are supported", - post_man_export_tip: "Export the test collection by Postman", + postman_export_tip: "Export the test collection by Postman", + swagger_export_tip: "Export jSON-formatted files via Swagger website", suffixFormatErr: "The file format does not meet the requirements", } }, diff --git a/frontend/src/i18n/zh-CN.js b/frontend/src/i18n/zh-CN.js index 5c85719e17..3c22ad0056 100644 --- a/frontend/src/i18n/zh-CN.js +++ b/frontend/src/i18n/zh-CN.js @@ -373,7 +373,9 @@ export default { ms_tip: "支持 Metersphere json 格式", ms_export_tip: "通过 Metersphere Api 测试页面或者浏览器插件导出 json 格式文件", postman_tip: "只支持 Postman Collection v2.1 格式的 json 文件", - post_man_export_tip: "通过 Postman 导出测试集合", + swagger_tip: "只支持 Swagger2.x 版本的 json 文件", + post_export_tip: "通过 Postman 导出测试集合", + swagger_export_tip: "通过 Swagger 页面导出", suffixFormatErr: "文件格式不符合要求", } }, diff --git a/frontend/src/i18n/zh-TW.js b/frontend/src/i18n/zh-TW.js index 27c55c02bf..425d6525c8 100644 --- a/frontend/src/i18n/zh-TW.js +++ b/frontend/src/i18n/zh-TW.js @@ -373,7 +373,9 @@ export default { ms_tip: "支持 Metersphere json 格式", ms_export_tip: "通過 Metersphere Api 測試頁面或者瀏覽器插件導出 json 格式文件", postman_tip: "只支持 Postman Collection v2.1 格式的 json 文件", - post_man_export_tip: "通過 Postman 導出測試集合", + swagger_tip: "只支持 Swagger2.x 版本的 json 文件", + post_export_tip: "通過 Postman 導出測試集合", + swagger_export_tip: "通過 Swagger 頁面導出", suffixFormatErr: "文件格式不符合要求", } }, From 73161105f58ae2e0c9c2dfe5e2659688aab3f2ed Mon Sep 17 00:00:00 2001 From: q4speed Date: Wed, 15 Jul 2020 16:00:37 +0800 Subject: [PATCH 02/10] =?UTF-8?q?refactor:=20=E5=8E=BB=E6=8E=89=E6=97=A0?= =?UTF-8?q?=E7=94=A8=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/search/MsTableAdvSearchBar.vue | 42 ++++--------------- 1 file changed, 8 insertions(+), 34 deletions(-) diff --git a/frontend/src/business/components/common/components/search/MsTableAdvSearchBar.vue b/frontend/src/business/components/common/components/search/MsTableAdvSearchBar.vue index 4ae64e0037..add1b2f22e 100644 --- a/frontend/src/business/components/common/components/search/MsTableAdvSearchBar.vue +++ b/frontend/src/business/components/common/components/search/MsTableAdvSearchBar.vue @@ -4,11 +4,6 @@
- - - - -
@@ -26,7 +21,7 @@