From ae08ff23116ca4520f8f12ae9f27e45a808dfb4f Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Thu, 21 Mar 2024 15:13:36 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Dv2=E7=89=88=E6=9C=AC=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E5=AF=BC=E5=85=A5=E7=9A=84=E7=BC=BA=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1037505 --user=王孝刚 【接口测试】接口定义-导入接口-导入从MS导出的swagger 3.0 格式文件失败 https://www.tapd.cn/55049933/s/1478660 --- .../io/metersphere/api/parser/api/Swagger3Parser.java | 9 ++++++++- .../io/metersphere/api/utils/JsonSchemaBuilder.java | 3 +++ .../business/ms-common-script/ms-script-menu.vue | 11 +---------- .../src/components/business/ms-common-script/utils.ts | 3 +-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/Swagger3Parser.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/Swagger3Parser.java index 6c61c7f394..a42a2a761f 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/Swagger3Parser.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/Swagger3Parser.java @@ -166,6 +166,9 @@ public class Swagger3Parser implements ImportParser { content.forEach((key, value) -> { setBodyData(key, value, body); }); + } else { + body.setBodyType(Body.BodyType.NONE.name()); + body.setNoneBody(new NoneBody()); } } else { body.setBodyType(Body.BodyType.NONE.name()); @@ -175,6 +178,10 @@ public class Swagger3Parser implements ImportParser { private void parseWWWFormBody(JsonSchemaItem item, Body body) { WWWFormBody wwwFormBody = new WWWFormBody(); + if (item == null) { + body.setWwwFormBody(wwwFormBody); + return; + } List required = item.getRequired(); List formDataKVS = new ArrayList<>(); item.getProperties().forEach((key, value) -> { @@ -738,7 +745,7 @@ public class Swagger3Parser implements ImportParser { private String formatPath(String url) { try { URI urlObject = new URI(url); - String path = StringUtils.isBlank(urlObject.getPath()) ? "/" : urlObject.getPath(); + String path = StringUtils.isBlank(urlObject.getPath()) ? url : urlObject.getPath(); StringBuilder pathBuffer = new StringBuilder(path); if (StringUtils.isNotEmpty(urlObject.getQuery())) { pathBuffer.append("?").append(urlObject.getQuery()); diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/utils/JsonSchemaBuilder.java b/backend/services/api-test/src/main/java/io/metersphere/api/utils/JsonSchemaBuilder.java index 7d3c877d78..620bf76a14 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/utils/JsonSchemaBuilder.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/utils/JsonSchemaBuilder.java @@ -60,6 +60,9 @@ public class JsonSchemaBuilder { private static JsonNode generateJson(JsonNode jsonSchemaNode, Map processMap) { ObjectNode jsonNode = objectMapper.createObjectNode(); + if (jsonSchemaNode instanceof NullNode) { + return NullNode.getInstance(); + } String type = jsonSchemaNode.get(PropertyConstant.TYPE).asText(); if (StringUtils.equals(type, PropertyConstant.OBJECT)) { JsonNode propertiesNode = jsonSchemaNode.get(PropertyConstant.PROPERTIES); diff --git a/frontend/src/components/business/ms-common-script/ms-script-menu.vue b/frontend/src/components/business/ms-common-script/ms-script-menu.vue index b484edc8a0..6b01b1693b 100644 --- a/frontend/src/components/business/ms-common-script/ms-script-menu.vue +++ b/frontend/src/components/business/ms-common-script/ms-script-menu.vue @@ -86,6 +86,7 @@ function getCustomFunction() { emit('insertCommonScript'); } + // 从Api定义导入 function getApiExport() { emit('formApiImport'); @@ -108,16 +109,6 @@ headers.set('Content-type', 'application/json'); return getCodeTemplate(innerLanguageType.value, { requestHeaders: headers }); } - case 'api_stop': { - if (innerLanguageType.value === LanguageEnum.PYTHON) { - return ` - import java - StandardJMeterEngine = java.type('org.apache.jmeter.engine.StandardJMeterEngine') - StandardJMeterEngine.stopThreadNow(ctx.getThread().getThreadName()) - `; - } - return 'ctx.getEngine().stopThreadNow(ctx.getThread().getThreadName());'; - } default: return ''; } diff --git a/frontend/src/components/business/ms-common-script/utils.ts b/frontend/src/components/business/ms-common-script/utils.ts index d12abb1dc5..e23b09a4ce 100644 --- a/frontend/src/components/business/ms-common-script/utils.ts +++ b/frontend/src/components/business/ms-common-script/utils.ts @@ -49,8 +49,7 @@ export const SCRIPT_MENU: CommonScriptMenu[] = [ }, { title: t('project.processor.terminationTest'), - value: 'api_stop', - command: 'api_stop', + value: 'ctx.getEngine().stopTest();', }, ];