feat(接口测试): 接口执行解析rest参数和认证配置

This commit is contained in:
AgAngle 2024-02-20 15:31:28 +08:00 committed by Craftsman
parent 47d3c0d7ff
commit 94b6478422
19 changed files with 261 additions and 84 deletions

View File

@ -14,11 +14,11 @@ public class MsHTTPConfig {
/**
* 连接超时
*/
private Long connectTimeout;
private Long connectTimeout = 6000L;
/**
* 响应超时
*/
private Long responseTimeout;
private Long responseTimeout = 6000L;
/**
* 证书别名
*/

View File

@ -1,6 +1,6 @@
package io.metersphere.api.dto.request.http;
import io.metersphere.api.dto.request.http.auth.HTTPAuth;
import io.metersphere.api.dto.request.http.auth.HTTPAuthConfig;
import io.metersphere.api.dto.request.http.body.Body;
import io.metersphere.plugin.api.spi.AbstractMsTestElement;
import io.metersphere.sdk.constants.HttpMethodConstants;
@ -66,12 +66,12 @@ public class MsHTTPElement extends AbstractMsTestElement {
* 其他配置
*/
@Valid
private MsHTTPConfig otherConfig;
private MsHTTPConfig otherConfig = new MsHTTPConfig();
/**
* 认证配置
*/
@Valid
private HTTPAuth authConfig;
private HTTPAuthConfig authConfig = new HTTPAuthConfig();
/**
* 模块ID
* 运行时参数接口无需设置

View File

@ -1,15 +1,19 @@
package io.metersphere.api.dto.request.http.auth;
import com.fasterxml.jackson.annotation.JsonTypeName;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
/**
* @Author: jianxing
* @CreateTime: 2023-11-07 11:00
*/
@Data
@JsonTypeName("BASIC")
public class BasicAuth extends HTTPAuth {
private String userName;
private String password;
@Override
public boolean isValid() {
return StringUtils.isNotBlank(userName) && StringUtils.isNotBlank(password);
}
}

View File

@ -1,15 +1,18 @@
package io.metersphere.api.dto.request.http.auth;
import com.fasterxml.jackson.annotation.JsonTypeName;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
/**
* @Author: jianxing
* @CreateTime: 2023-11-07 11:00
*/
@Data
@JsonTypeName("DIGEST")
public class DigestAuth extends HTTPAuth {
private String userName;
private String password;
public boolean isValid() {
return StringUtils.isNotBlank(userName) && StringUtils.isNotBlank(password);
}
}

View File

@ -1,27 +1,13 @@
package io.metersphere.api.dto.request.http.auth;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import lombok.Data;
/**
* http 认证配置
* <pre>
* 该参数传参时需要传入 authType 字段用于区分是哪种认证方式
* authType 取值为:
* BASIC ({@link BasicAuth})
* DIGEST ({@link DigestAuth})
* NONE ({@link NoAuth})
* </pre>
* @Author: jianxing
* @CreateTime: 2023-11-07 11:00
*/
@Data
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "authType")
@JsonSubTypes({
@JsonSubTypes.Type(value = NoAuth.class),
@JsonSubTypes.Type(value = BasicAuth.class),
@JsonSubTypes.Type(value = DigestAuth.class),
})
public abstract class HTTPAuth {
public abstract boolean isValid();
}

View File

@ -0,0 +1,41 @@
package io.metersphere.api.dto.request.http.auth;
import io.metersphere.system.valid.EnumValue;
import lombok.Data;
import java.util.HashMap;
/**
* http 认证配置
*
* @Author: jianxing
* @CreateTime: 2023-11-07 11:00
*/
@Data
public class HTTPAuthConfig {
/**
* 认证方式
* {@link HTTPAuthType}
*/
@EnumValue(enumClass = HTTPAuthType.class)
private String authType = HTTPAuthType.NONE.name();
private BasicAuth basicAuth;
private DigestAuth digestAuth;
public boolean isHTTPAuthValid() {
HashMap<String, HTTPAuth> httpAuthHashMap = HashMap.newHashMap(2);
httpAuthHashMap.put(HTTPAuthType.BASIC.name(), basicAuth);
httpAuthHashMap.put(HTTPAuthType.DIGEST.name(), digestAuth);
HTTPAuth httpAuth = httpAuthHashMap.get(authType);
return httpAuth != null && httpAuth.isValid();
}
/**
* http 认证方式
*/
public enum HTTPAuthType {
NONE,
BASIC,
DIGEST
}
}

View File

@ -9,5 +9,5 @@ import lombok.Data;
*/
@Data
@JsonTypeName("NONE")
public class NoAuth extends HTTPAuth {
public class NoAuth extends HTTPAuthConfig {
}

View File

@ -2,8 +2,13 @@ package io.metersphere.api.parser.jmeter;
import io.metersphere.api.dto.ApiParamConfig;
import io.metersphere.api.dto.request.http.MsHTTPConfig;
import io.metersphere.api.dto.request.http.MsHTTPElement;
import io.metersphere.api.dto.request.http.QueryParam;
import io.metersphere.api.dto.request.http.RestParam;
import io.metersphere.api.dto.request.http.auth.BasicAuth;
import io.metersphere.api.dto.request.http.auth.DigestAuth;
import io.metersphere.api.dto.request.http.auth.HTTPAuthConfig;
import io.metersphere.api.dto.request.http.body.Body;
import io.metersphere.api.parser.jmeter.body.MsBodyConverter;
import io.metersphere.api.parser.jmeter.body.MsBodyConverterFactory;
@ -25,6 +30,8 @@ import io.metersphere.sdk.util.LogUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.protocol.http.control.AuthManager;
import org.apache.jmeter.protocol.http.control.Authorization;
import org.apache.jmeter.protocol.http.control.Header;
import org.apache.jmeter.protocol.http.control.HeaderManager;
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy;
@ -34,10 +41,12 @@ import org.apache.jorphan.collections.HashTree;
import org.springframework.http.HttpMethod;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import static io.metersphere.api.parser.jmeter.constants.JmeterAlias.HEADER_PANEL;
import static io.metersphere.api.parser.jmeter.constants.JmeterAlias.HTTP_TEST_SAMPLE_GUI;
import static io.metersphere.api.parser.jmeter.constants.JmeterAlias.*;
/**
* @Author: jianxing
@ -71,22 +80,89 @@ public class MsHTTPElementConverter extends AbstractJmeterElementConverter<MsHTT
// path 设置完整的url
sampler.setPath(getPath(msHTTPElement, httpConfig));
setHttpOtherConfig(msHTTPElement.getOtherConfig(), sampler);
// 处理请求体
handleBody(sampler, msHTTPElement, config);
HashTree httpTree = tree.add(sampler);
// 处理请求头
HeaderManager httpHeader = getHttpHeader(msHTTPElement, apiParamConfig, httpConfig);
if (httpHeader != null) {
httpTree.add(httpHeader);
}
HTTPAuthConfig authConfig = msHTTPElement.getAuthConfig();
// 处理认证信息
AuthManager authManager = getAuthManager(sampler, authConfig);
if (authManager != null) {
httpTree.add(authManager);
}
parseChild(httpTree, msHTTPElement, config);
}
/**
* 设置超时时间等配置
* @param msHTTPConfig
* @param sampler
*/
private void setHttpOtherConfig(MsHTTPConfig msHTTPConfig, HTTPSamplerProxy sampler) {
sampler.setConnectTimeout(msHTTPConfig.getConnectTimeout().toString());
sampler.setResponseTimeout(msHTTPConfig.getResponseTimeout().toString());
sampler.setFollowRedirects(msHTTPConfig.getFollowRedirects());
sampler.setAutoRedirects(msHTTPConfig.getAutoRedirects());
}
private static final Map<String, AuthManager.Mechanism> mechanismMap = HashMap.newHashMap(2);
private static final Map<String, BiConsumer<Authorization, HTTPAuthConfig>> authHanlerMap = HashMap.newHashMap(2);
static {
mechanismMap.put(HTTPAuthConfig.HTTPAuthType.BASIC.name(), AuthManager.Mechanism.BASIC);
mechanismMap.put(HTTPAuthConfig.HTTPAuthType.DIGEST.name(), AuthManager.Mechanism.DIGEST);
authHanlerMap.put(HTTPAuthConfig.HTTPAuthType.BASIC.name(), (authorization, httpAuth) -> {
BasicAuth basicAuth = httpAuth.getBasicAuth();
authorization.setUser(basicAuth.getUserName());
authorization.setPass(basicAuth.getPassword());
});
authHanlerMap.put(HTTPAuthConfig.HTTPAuthType.DIGEST.name(), (authorization, httpAuth) -> {
DigestAuth digestAuth = httpAuth.getDigestAuth() ;
authorization.setUser(digestAuth.getUserName());
authorization.setPass(digestAuth.getPassword());
});
}
/**
* 获取认证配置
* @param sampler
* @param authConfig
* @return
*/
private AuthManager getAuthManager(HTTPSamplerProxy sampler, HTTPAuthConfig authConfig) {
if (authConfig == null || !authConfig.isHTTPAuthValid()) {
return null;
}
Authorization auth = new Authorization();
auth.setURL(sampler.getPath());
auth.setMechanism(mechanismMap.get(authConfig.getAuthType()));
authHanlerMap.get(authConfig.getAuthType()).accept(auth, authConfig);
AuthManager authManager = new AuthManager();
authManager.setEnabled(true);
authManager.setName("AuthManager");
authManager.setProperty(TestElement.TEST_CLASS, AuthManager.class.getName());
authManager.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass(AUTH_PANEL));
authManager.addAuth(auth);
return authManager;
}
/**
* 设置步骤标识
* 当前步骤唯一标识结果和步骤匹配的关键
*
* @param msHTTPElement
* @param config
* @param sampler
@ -105,9 +181,71 @@ public class MsHTTPElementConverter extends AbstractJmeterElementConverter<MsHTT
String protocol = httpConfig.getProtocol().toLowerCase();
url = protocol + "://" + (httpConfig.getUrl() + "/" + url).replace("//", "/");
}
url = getPathWithQueryRest(msHTTPElement, url);
return getPathWithQuery(url, msHTTPElement.getQuery());
}
/**
* 替换 rest 参数
* @param msHTTPElement
* @param path
* @return
*/
private String getPathWithQueryRest(MsHTTPElement msHTTPElement, String path) {
List<RestParam> rest = msHTTPElement.getRest();
if (CollectionUtils.isEmpty(rest)) {
return path;
}
rest = rest.stream()
.filter(RestParam::getEnable)
.filter(RestParam::isValid)
.filter(RestParam::isNotBlankValue)
.toList();
if (CollectionUtils.isEmpty(rest)) {
return path;
}
Map<String, String> keyValueMap = new HashMap<>();
for (RestParam restParam : rest) {
try {
String value = restParam.getValue();
value = Mock.buildFunctionCallString(value);
value = BooleanUtils.isTrue(restParam.getEncode()) ? String.format(URL_ENCODE, value.replace(",", "\\,")) : value;
keyValueMap.put(restParam.getKey(), value);
} catch (Exception e) {
LogUtils.error(e);
}
}
try {
Pattern p = Pattern.compile("(\\{)([\\w]+)(\\})");
Matcher m = p.matcher(path);
while (m.find()) {
String group = m.group(2);
if (!isRestVariable(path, group) && keyValueMap.containsKey(group)) {
path = path.replace("{" + group + "}", keyValueMap.get(group));
}
}
} catch (Exception e) {
LogUtils.error(e);
}
return path;
}
private boolean isRestVariable(String path, String value) {
Pattern p = Pattern.compile("(\\$\\{)([\\w]+)(\\})");
Matcher m = p.matcher(path);
while (m.find()) {
String group = m.group(2);
if (group.equals(value)) {
return true;
}
}
return false;
}
private HeaderManager getHttpHeader(MsHTTPElement msHTTPElement, ApiParamConfig apiParamConfig, HttpConfig httpConfig) {
Map<String, String> headerMap = new HashMap<>();
@ -260,7 +398,7 @@ public class MsHTTPElementConverter extends AbstractJmeterElementConverter<MsHTT
stringBuffer.append(queryParam.getEncode() ? String.format(URL_ENCODE, queryParam.getKey()) : queryParam.getKey());
if (queryParam.getValue() != null) {
try {
String value = queryParam.getValue().startsWith("@") ? Mock.buildFunctionCallString(queryParam.getValue()) : queryParam.getValue();
String value = Mock.buildFunctionCallString(queryParam.getValue());
value = queryParam.getEncode() ? String.format(URL_ENCODE, value.replace(",", "\\,")) : value;
if (StringUtils.isNotEmpty(value) && value.contains(StringUtils.CR)) {
value = value.replaceAll(StringUtils.CR, StringUtils.EMPTY);

View File

@ -14,7 +14,11 @@ import org.apache.jmeter.protocol.http.util.HTTPFileArg;
public class MsBinaryBodyConverter extends MsBodyConverter<BinaryBody> {
@Override
public void parse(HTTPSamplerProxy sampler, BinaryBody body, ParameterConfig config) {
HTTPFileArg httpFileArg = getHttpFileArg(body.getFile());
ApiFile file = body.getFile();
if (file == null) {
return;
}
HTTPFileArg httpFileArg = getHttpFileArg(file);
sampler.setHTTPFiles(new HTTPFileArg[]{httpFileArg});
}
}

View File

@ -19,4 +19,5 @@ public class JmeterAlias {
public static final String USER_PARAMETERS_GUI = "UserParametersGui";
public static final String COOKIE_PANEL = "CookiePanel";
public static final String HEADER_PANEL = "HeaderPanel";
public static final String AUTH_PANEL = "AuthPanel";
}

View File

@ -57,7 +57,7 @@ public class ScriptFilter {
public static void verify(String language, String label, String script) {
// 默认 groovy
ScriptLanguageType scriptLanguageType = Arrays.stream(ScriptLanguageType.values())
.filter(item -> StringUtils.equals(item.getValue(), language))
.filter(item -> StringUtils.equals(item.name(), language))
.findFirst()
.orElse(ScriptLanguageType.GROOVY);

View File

@ -34,7 +34,7 @@ public abstract class ScriptProcessorConverter extends MsProcessorConverter<Scri
// }
// python js cache 打开
boolean cacheKey = StringUtils.equalsAny(scriptProcessor.getScriptLanguage(), ScriptLanguageType.PYTHON.getValue(), ScriptLanguageType.JAVASCRIPT.getValue());
boolean cacheKey = StringUtils.equalsAny(scriptProcessor.getScriptLanguage(), ScriptLanguageType.PYTHON.name(), ScriptLanguageType.JAVASCRIPT.name());
testElement.setProperty(JmeterProperty.CACHE_KEY, cacheKey);
testElement.setProperty(TestElement.TEST_CLASS, testElement.getClass().getSimpleName());
testElement.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass(JmeterAlias.TEST_BEAN_GUI));
@ -44,6 +44,6 @@ public abstract class ScriptProcessorConverter extends MsProcessorConverter<Scri
}
public static boolean isJSR233(ScriptProcessor scriptProcessor) {
return !StringUtils.equals(scriptProcessor.getScriptLanguage(), ScriptLanguageType.BEANSHELL.getValue());
return !StringUtils.equals(scriptProcessor.getScriptLanguage(), ScriptLanguageType.BEANSHELL.name());
}
}

View File

@ -55,7 +55,7 @@ public class VariableAssertionConverter extends AssertionConverter<MsVariableAss
String name = String.format("Variable '%s' expect %s %s", variableName, condition.toLowerCase().replace("_", ""), expectedValue);
scriptProcessor.setName(name);
scriptProcessor.setScriptLanguage(ScriptLanguageType.BEANSHELL_JSR233.getValue());
scriptProcessor.setScriptLanguage(ScriptLanguageType.BEANSHELL_JSR233.name());
JSR223Assertion jsr223Assertion = new JSR223Assertion();
ScriptProcessorConverter.parse(jsr223Assertion, scriptProcessor);
return jsr223Assertion;

View File

@ -9,6 +9,10 @@ import io.metersphere.api.dto.assertion.MsAssertionConfig;
import io.metersphere.api.dto.debug.*;
import io.metersphere.api.dto.request.MsCommonElement;
import io.metersphere.api.dto.request.http.MsHTTPElement;
import io.metersphere.api.dto.request.http.RestParam;
import io.metersphere.api.dto.request.http.auth.BasicAuth;
import io.metersphere.api.dto.request.http.auth.DigestAuth;
import io.metersphere.api.dto.request.http.auth.HTTPAuthConfig;
import io.metersphere.api.dto.request.http.body.Body;
import io.metersphere.api.mapper.ApiDebugBlobMapper;
import io.metersphere.api.mapper.ApiDebugMapper;
@ -36,6 +40,7 @@ import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.uid.IDGenerator;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.*;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
@ -377,6 +382,17 @@ public class ApiDebugControllerTests extends BaseTest {
assertErrorCode(this.requestPost(DEBUG, request), ApiResultCode.RESOURCE_POOL_EXECUTE_ERROR);
mockPost("/api/debug", "");
msHTTPElement.setPath("/test/{rest1}/aa");
msHTTPElement.setRest(getRestParams());
msHTTPElement.getOtherConfig().setAutoRedirects(true);
msHTTPElement.getOtherConfig().setFollowRedirects(false);
msHTTPElement.getOtherConfig().setResponseTimeout(7000L);
DigestAuth digestAuth = new DigestAuth();
digestAuth.setUserName("aa");
digestAuth.setPassword("bb");
msHTTPElement.getAuthConfig().setAuthType(HTTPAuthConfig.HTTPAuthType.DIGEST.name());
msHTTPElement.getAuthConfig().setDigestAuth(digestAuth);
request.setRequest(getMsElementParam(msHTTPElement));
// @@请求成功
this.requestPostWithOk(DEBUG, request);
@ -391,6 +407,11 @@ public class ApiDebugControllerTests extends BaseTest {
msHTTPElement = MsHTTPElementTest.getMsHttpElement();
msHTTPElement.setChildren(linkedList);
msHTTPElement.setEnable(true);
BasicAuth basicAuth = new BasicAuth();
basicAuth.setUserName("a");
basicAuth.setPassword("b");
msHTTPElement.getAuthConfig().setAuthType(HTTPAuthConfig.HTTPAuthType.BASIC.name());
msHTTPElement.getAuthConfig().setBasicAuth(basicAuth);
request.setRequest(getMsElementParam(msHTTPElement));
this.requestPostWithOk(DEBUG, request);
@ -434,6 +455,20 @@ public class ApiDebugControllerTests extends BaseTest {
requestPostPermissionTest(PermissionConstants.PROJECT_API_DEBUG_EXECUTE, DEBUG, request);
}
private List<RestParam> getRestParams() {
RestParam restParam1 = new RestParam();
restParam1.setKey("rest1");
restParam1.setValue("value");
RestParam restParam2 = new RestParam();
restParam2.setKey("rest2");
restParam2.setValue("value2");
restParam2.setEncode(true);
RestParam restParam3 = new RestParam();
restParam3.setKey("rest3");
restParam3.setEnable(false);
return List.of(restParam1, restParam2, restParam3);
}
private void testBodyParse(ApiDebugRunRequest request, MsHTTPElement msHTTPElement, Body generalBody) throws Exception {
// 测试 FORM_DATA
generalBody.setBodyType(Body.BodyType.FORM_DATA.name());

View File

@ -3,9 +3,9 @@ package io.metersphere.api.controller;
import io.metersphere.api.dto.ApiTestPluginOptionRequest;
import io.metersphere.api.service.BaseResourcePoolTestService;
import io.metersphere.plugin.api.dto.ApiPluginSelectOption;
import io.metersphere.project.api.KeyValueParam;
import io.metersphere.project.constants.ScriptLanguageType;
import io.metersphere.project.dto.customfunction.request.CustomFunctionRunRequest;
import io.metersphere.project.api.KeyValueParam;
import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.system.base.BasePluginTestService;
import io.metersphere.system.base.BaseTest;
@ -25,7 +25,6 @@ import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static io.metersphere.sdk.constants.InternalUserRole.ADMIN;
import static io.metersphere.system.controller.handler.result.MsHttpResultCode.NOT_FOUND;
@ -78,7 +77,7 @@ public class ApiTestControllerTests extends BaseTest {
CustomFunctionRunRequest request = new CustomFunctionRunRequest();
request.setReportId(IDGenerator.nextStr());
request.setProjectId(DEFAULT_PROJECT_ID);
request.setType(ScriptLanguageType.BEANSHELL.getValue());
request.setType(ScriptLanguageType.BEANSHELL.name());
request.setScript("""
log.info("========");
log.info("${test}");

View File

@ -6,10 +6,6 @@ import io.metersphere.api.dto.assertion.MsAssertionConfig;
import io.metersphere.api.dto.definition.HttpResponse;
import io.metersphere.api.dto.request.MsCommonElement;
import io.metersphere.api.dto.request.http.*;
import io.metersphere.api.dto.request.http.auth.BasicAuth;
import io.metersphere.api.dto.request.http.auth.DigestAuth;
import io.metersphere.api.dto.request.http.auth.HTTPAuth;
import io.metersphere.api.dto.request.http.auth.NoAuth;
import io.metersphere.api.dto.request.http.body.*;
import io.metersphere.api.dto.request.processors.MsProcessorConfig;
import io.metersphere.api.dto.schema.JsonSchemaItem;
@ -105,33 +101,6 @@ public class MsHTTPElementTest {
return body;
}
@Test
public void authConfigTest() {
MsHTTPElement msHTTPElement = getMsHttpElement();
List authConfigs = new ArrayList<>();
authConfigs.add(new NoAuth());
BasicAuth basicAuth = new BasicAuth();
basicAuth.setUserName("test");
basicAuth.setPassword("passwd");
authConfigs.add(basicAuth);
DigestAuth digestAuth = new DigestAuth();
digestAuth.setUserName("test");
digestAuth.setPassword("passwd");
authConfigs.add(digestAuth);
for (Object authConfig : authConfigs) {
msHTTPElement.setAuthConfig((HTTPAuth) authConfig);
String json = ApiDataUtils.toJSONString(msHTTPElement);
Assertions.assertNotNull(json);
Assertions.assertEquals(ApiDataUtils.parseObject(json, AbstractMsTestElement.class), msHTTPElement);
}
}
@Test
public void processorParseTest() {
@ -157,13 +126,13 @@ public class MsHTTPElementTest {
ScriptProcessor scriptProcessor = new ScriptProcessor();
scriptProcessor.setEnable(true);
scriptProcessor.setScript("script");
scriptProcessor.setScriptLanguage(ScriptLanguageType.JAVASCRIPT.getValue());
scriptProcessor.setScriptLanguage(ScriptLanguageType.JAVASCRIPT.name());
processors.add(scriptProcessor);
ScriptProcessor beanShellScriptProcessor = new ScriptProcessor();
beanShellScriptProcessor.setEnable(true);
beanShellScriptProcessor.setScript("script");
beanShellScriptProcessor.setScriptLanguage(ScriptLanguageType.BEANSHELL.getValue());
beanShellScriptProcessor.setScriptLanguage(ScriptLanguageType.BEANSHELL.name());
processors.add(beanShellScriptProcessor);
SQLProcessor sqlProcessor = new SQLProcessor();

View File

@ -25,4 +25,8 @@ public class KeyValueParam {
public boolean isValid() {
return StringUtils.isNotBlank(key);
}
public boolean isNotBlankValue() {
return StringUtils.isNotBlank(value);
}
}

View File

@ -5,19 +5,9 @@ package io.metersphere.project.constants;
* @CreateTime: 2024-01-19 18:19
*/
public enum ScriptLanguageType {
BEANSHELL("beanshell"),
BEANSHELL_JSR233("beanshell-jsr233"),
GROOVY("groovy"),
JAVASCRIPT("javascript"),
PYTHON("python");
private String value;
ScriptLanguageType(String value) {
this.value = value;
}
public String getValue() {
return value;
}
BEANSHELL,
BEANSHELL_JSR233,
GROOVY,
JAVASCRIPT,
PYTHON
}

View File

@ -1,5 +1,7 @@
package io.metersphere.project.dto.customfunction.request;
import io.metersphere.project.constants.ScriptLanguageType;
import io.metersphere.system.valid.EnumValue;
import io.metersphere.validation.groups.Created;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
@ -33,6 +35,7 @@ public class CustomFunctionRequest implements Serializable {
private String name;
@Schema(description = "脚本语言类型")
@EnumValue(enumClass = ScriptLanguageType.class)
private String type;
@Schema(description = "脚本状态(草稿/测试通过)")