diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionService.java index 2229bc0157..a1551a98a9 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionService.java @@ -186,6 +186,7 @@ public class ApiDefinitionService { ProjectService.checkResourceExist(request.getProjectId()); ApiDefinition apiDefinition = new ApiDefinition(); BeanUtils.copyBean(apiDefinition, request); + apiDefinition.setVersionId(StringUtils.defaultIfBlank(request.getVersionId(), extBaseProjectVersionMapper.getDefaultVersion(request.getProjectId()))); checkAddExist(apiDefinition); checkResponseNameCode(request.getResponse()); apiDefinition.setId(IDGenerator.nextStr()); @@ -197,7 +198,6 @@ public class ApiDefinitionService { apiDefinition.setUpdateUser(userId); apiDefinition.setCreateTime(System.currentTimeMillis()); apiDefinition.setUpdateTime(System.currentTimeMillis()); - apiDefinition.setVersionId(StringUtils.defaultIfBlank(request.getVersionId(), extBaseProjectVersionMapper.getDefaultVersion(request.getProjectId()))); apiDefinition.setRefId(apiDefinition.getId()); if (CollectionUtils.isNotEmpty(request.getTags())) { apiDefinition.setTags(request.getTags()); diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionControllerTests.java index bcf2eb3afa..35c4294e93 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionControllerTests.java @@ -248,8 +248,11 @@ public class ApiDefinitionControllerTests extends BaseTest { request.setPath("/api/admin/posts"); request.setUploadFileIds(null); request.setLinkFileIds(null); + String versionId = request.getVersionId(); + request.setVersionId(null); mvcResult = this.requestPostWithOkAndReturn(ADD, request); resultData = getResultData(mvcResult, ApiDefinition.class); + request.setVersionId(versionId); assertAddApiDefinition(request, msHttpElement, resultData.getId()); testHandleFileAssociationUpgrade();