This is an automated email from the ASF dual-hosted git repository.
Aias00 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 2b0a8a0a92 fix(admin): remove the unsupported YAPI import source
(#7946)
2b0a8a0a92 is described below
commit 2b0a8a0a92df20476b8a8b49434ab8c560ea9888
Author: redyyang <[email protected]>
AuthorDate: Fri Oct 23 11:17:08 2026 +0800
fix(admin): remove the unsupported YAPI import source (#7946)
* fix(admin): remove the unsupported YAPI import source
* fix(admin): preserve API source provenance when editing historical records
* test(ci): align cryptor failures and wait for usable SDK routes
---
.../shenyu/admin/controller/ApiController.java | 3 +-
.../org/apache/shenyu/admin/model/dto/ApiDTO.java | 14 ++++--
.../apache/shenyu/admin/model/entity/ApiDO.java | 2 +-
.../org/apache/shenyu/admin/model/vo/ApiVO.java | 2 +-
.../shenyu/admin/service/impl/ApiServiceImpl.java | 3 ++
.../src/main/resources/static/index.16dee401.js | 2 +-
.../shenyu/admin/controller/ApiControllerTest.java | 51 +++++++++++++++++++---
.../apache/shenyu/admin/mapper/ApiMapperTest.java | 27 ++++++++++++
.../apache/shenyu/common/enums/ApiSourceEnum.java | 7 +--
.../shenyu/common/enums/ApiSourceEnumTest.java | 2 -
.../register/common/dto/ApiDocRegisterDTO.java | 2 +-
11 files changed, 92 insertions(+), 23 deletions(-)
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ApiController.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ApiController.java
index a0e8fbb9c2..00e3bcf970 100644
---
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ApiController.java
+++
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ApiController.java
@@ -30,6 +30,7 @@ import org.apache.shenyu.admin.service.ApiService;
import org.apache.shenyu.admin.utils.ShenyuResultMessage;
import org.apache.shenyu.admin.validation.annotation.Existed;
import org.apache.shiro.authz.annotation.RequiresPermissions;
+import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@@ -96,7 +97,7 @@ public class ApiController {
*/
@PostMapping
@RequiresPermissions("system:api:add")
- public ShenyuAdminResult createApi(@Valid @RequestBody final ApiDTO
apiDTO) {
+ public ShenyuAdminResult createApi(@Validated(ApiDTO.Create.class)
@RequestBody final ApiDTO apiDTO) {
return ShenyuAdminResult.success(apiService.createOrUpdate(apiDTO));
}
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/ApiDTO.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/ApiDTO.java
index 0837d9a8c8..4f459ba2c0 100644
--- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/ApiDTO.java
+++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/ApiDTO.java
@@ -103,11 +103,11 @@ public class ApiDTO implements Serializable {
private String apiDesc;
/**
- * 0-swagger,1-annotation generation,2-create manuallym,3-import
swagger,4-import yapi.
+ * 0-swagger,1-annotation generation,2-create manually,3-import swagger.
*/
- @NotNull(message = "apiSource not null")
- @Min(value = 0, message = "state min 0")
- @Max(value = 4, message = "state max 4")
+ @NotNull(message = "apiSource not null", groups = Create.class)
+ @Min(value = 0, message = "apiSource min 0", groups = Create.class)
+ @Max(value = 3, message = "apiSource max 3", groups = Create.class)
private Integer apiSource;
/**
@@ -481,4 +481,10 @@ public class ApiDTO implements Serializable {
rpcType, state, ext, apiOwner, apiDesc, apiSource, document,
documentMd5, dateCreated, dateUpdated, tagIds);
}
+ /**
+ * Creation validates provenance in addition to the common API fields.
+ */
+ public interface Create extends jakarta.validation.groups.Default {
+ }
+
}
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/ApiDO.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/ApiDO.java
index b52d2098b1..54caac3f02 100644
--- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/ApiDO.java
+++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/ApiDO.java
@@ -91,7 +91,7 @@ public class ApiDO {
private String apiDesc;
/**
- * 0-swagger,1-annotation generation,2-create manuallym,3-import
swagger,4-import yapi.
+ * 0-swagger,1-annotation generation,2-create manually,3-import swagger.
*/
private Integer apiSource;
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/ApiVO.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/ApiVO.java
index 72e9c9f935..e88a5bbd50 100644
--- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/ApiVO.java
+++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/ApiVO.java
@@ -93,7 +93,7 @@ public class ApiVO implements Serializable {
private String apiDesc;
/**
- * 0-swagger,1-annotation generation,2-create manuallym,3-import
swagger,4-import yapi.
+ * 0-swagger,1-annotation generation,2-create manually,3-import swagger.
*/
private Integer apiSource;
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java
index 43e02883c5..c8702f9f13 100644
---
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java
+++
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java
@@ -113,6 +113,9 @@ public class ApiServiceImpl implements ApiService {
*/
private String update(final ApiDTO apiDTO) {
ApiDO apiDO = ApiDO.buildApiDO(apiDTO);
+ // Source records creation provenance, including historical retired
sources.
+ // The selective update must retain it even when the client supplies
another value.
+ apiDO.setApiSource(null);
final int updateRows = apiMapper.updateByPrimaryKeySelective(apiDO);
if (updateRows > 0) {
if (Objects.nonNull(apiDTO.getTagIds())) {
diff --git a/shenyu-admin/src/main/resources/static/index.16dee401.js
b/shenyu-admin/src/main/resources/static/index.16dee401.js
index 26eee627d7..9f18cb6dd8 100644
--- a/shenyu-admin/src/main/resources/static/index.16dee401.js
+++ b/shenyu-admin/src/main/resources/static/index.16dee401.js
@@ -1 +1 @@
-!function(e){function t(r){if(n[r])return n[r].exports;var
o=n[r]={i:r,l:!1,exports:{}};return
e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var
n={};t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var
n=e&&e.__esModule?function(){return e.default}:function(){return e};return
t.d(n,"a",n),n},t.o=function(e,t){return
Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s="lVK7")}({"+0it":function(e,t,n){"us
[...]
\ No newline at end of file
+!function(e){function t(r){if(n[r])return n[r].exports;var
o=n[r]={i:r,l:!1,exports:{}};return
e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var
n={};t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var
n=e&&e.__esModule?function(){return e.default}:function(){return e};return
t.d(n,"a",n),n},t.o=function(e,t){return
Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s="lVK7")}({"+0it":function(e,t,n){"us
[...]
\ No newline at end of file
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/ApiControllerTest.java
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/ApiControllerTest.java
index f7e13afe62..8fdce6e6a1 100644
---
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/ApiControllerTest.java
+++
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/ApiControllerTest.java
@@ -32,6 +32,9 @@ import org.apache.shenyu.common.utils.GsonUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.NullSource;
+import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
@@ -50,6 +53,7 @@ import java.util.List;
import static org.hamcrest.core.Is.is;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
import static
org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static
org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@@ -127,8 +131,9 @@ public final class ApiControllerTest {
.andReturn();
}
- @Test
- public void testCreateApi() throws Exception {
+ @ParameterizedTest
+ @ValueSource(ints = {0, 1, 2, 3})
+ public void testCreateApi(final int apiSource) throws Exception {
ApiDTO apiDTO = new ApiDTO();
apiDTO.setContextPath("string");
apiDTO.setApiPath("string");
@@ -140,7 +145,7 @@ public final class ApiControllerTest {
apiDTO.setState(0);
apiDTO.setApiOwner("string");
apiDTO.setApiDesc("string");
- apiDTO.setApiSource(0);
+ apiDTO.setApiSource(apiSource);
apiDTO.setDocument("document");
apiDTO.setExt("ext");
given(this.apiService.createOrUpdate(apiDTO)).willReturn(ShenyuResultMessage.CREATE_SUCCESS);
@@ -152,6 +157,20 @@ public final class ApiControllerTest {
.andReturn();
}
+ @Test
+ public void testCreateApiRejectsUnsupportedSource() throws Exception {
+ ApiDTO apiDTO = new ApiDTO();
+ apiDTO.setHttpMethod(0);
+ apiDTO.setState(0);
+ apiDTO.setApiSource(4);
+ this.mockMvc.perform(MockMvcRequestBuilders.post("/api")
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(GsonUtils.getInstance().toJson(apiDTO)))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.message", is("Request error! invalid
argument [apiSource: apiSource max 3]")));
+ verifyNoInteractions(apiService);
+ }
+
@Test
public void testCreateApiStateMinException() throws Exception {
ApiDTO apiDTO = new ApiDTO();
@@ -200,8 +219,9 @@ public final class ApiControllerTest {
.andReturn();
}
- @Test
- public void testUpdateApi() throws Exception {
+ @ParameterizedTest
+ @ValueSource(ints = {0, 1, 2, 3})
+ public void testUpdateApi(final int apiSource) throws Exception {
ApiDTO apiDTO = new ApiDTO();
apiDTO.setContextPath("string");
apiDTO.setApiPath("string");
@@ -213,7 +233,7 @@ public final class ApiControllerTest {
apiDTO.setState(0);
apiDTO.setApiOwner("string");
apiDTO.setApiDesc("string");
- apiDTO.setApiSource(0);
+ apiDTO.setApiSource(apiSource);
apiDTO.setDocument("document");
apiDTO.setExt("ext");
apiDTO.setId("123");
@@ -229,6 +249,25 @@ public final class ApiControllerTest {
}
+ @ParameterizedTest
+ @NullSource
+ @ValueSource(ints = {4})
+ public void testUpdateApiAcceptsHistoricalOrOmittedSource(final Integer
apiSource) throws Exception {
+ ApiDTO apiDTO = new ApiDTO();
+ apiDTO.setId("123");
+ apiDTO.setHttpMethod(0);
+ apiDTO.setState(0);
+ apiDTO.setApiSource(apiSource);
+
when(SpringBeanUtils.getInstance().getBean(ApiMapper.class)).thenReturn(apiMapper);
+ when(apiMapper.existed(apiDTO.getId())).thenReturn(true);
+
given(this.apiService.createOrUpdate(apiDTO)).willReturn(ShenyuResultMessage.UPDATE_SUCCESS);
+ this.mockMvc.perform(MockMvcRequestBuilders.put("/api/{id}",
apiDTO.getId())
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(GsonUtils.getInstance().toJson(apiDTO)))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.message",
is(ShenyuResultMessage.UPDATE_SUCCESS)));
+ }
+
@Test
public void testDeleteApis() throws Exception {
given(this.apiService.delete(Collections.singletonList("123"))).willReturn(StringUtils.EMPTY);
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/ApiMapperTest.java
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/ApiMapperTest.java
index cd5a1dda76..8190d82065 100644
---
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/ApiMapperTest.java
+++
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/ApiMapperTest.java
@@ -18,6 +18,7 @@
package org.apache.shenyu.admin.mapper;
import org.apache.shenyu.admin.AbstractSpringIntegrationTest;
+import org.apache.shenyu.admin.model.dto.ApiDTO;
import org.apache.shenyu.admin.model.entity.ApiDO;
import org.apache.shenyu.admin.model.page.PageParameter;
import org.apache.shenyu.admin.model.query.ApiQuery;
@@ -27,6 +28,9 @@ import org.apache.shenyu.admin.service.ApiService;
import org.apache.shenyu.common.utils.UUIDUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.NullSource;
+import org.junit.jupiter.params.provider.ValueSource;
import jakarta.annotation.Resource;
import java.sql.Timestamp;
@@ -59,6 +63,29 @@ public final class ApiMapperTest extends
AbstractSpringIntegrationTest {
assertEquals(1, count);
}
+ @ParameterizedTest
+ @NullSource
+ @ValueSource(ints = {2, 4})
+ public void testUpdateHistoricalApiRetainsProvenance(final Integer
submittedSource) {
+ apiDO.setApiSource(4);
+ apiMapper.updateByPrimaryKeySelective(apiDO);
+ ApiDTO update = new ApiDTO();
+ update.setId(apiDO.getId());
+ update.setDocument(apiDO.getDocument());
+ update.setApiSource(submittedSource);
+ update.setApiDesc("edited historical API");
+ update.setApiOwner("new owner");
+ update.setState(1);
+
+ apiService.createOrUpdate(update);
+
+ ApiDO stored = apiMapper.selectByPrimaryKey(apiDO.getId());
+ assertEquals(4, stored.getApiSource());
+ assertEquals("edited historical API", stored.getApiDesc());
+ assertEquals("new owner", stored.getApiOwner());
+ assertEquals(1, stored.getState());
+ }
+
@Test
public void testApiListPaginationExcludesDocument() {
ApiDO first = buildApiDO();
diff --git
a/shenyu-common/src/main/java/org/apache/shenyu/common/enums/ApiSourceEnum.java
b/shenyu-common/src/main/java/org/apache/shenyu/common/enums/ApiSourceEnum.java
index c35fa9c771..a28c5383db 100644
---
a/shenyu-common/src/main/java/org/apache/shenyu/common/enums/ApiSourceEnum.java
+++
b/shenyu-common/src/main/java/org/apache/shenyu/common/enums/ApiSourceEnum.java
@@ -40,12 +40,7 @@ public enum ApiSourceEnum {
/**
* import_swagger.
*/
- IMPORT_SWAGGER("import_swagger", 3),
-
- /**
- * import_yapi.
- */
- IMPORT_YAPI("import_yapi", 4);
+ IMPORT_SWAGGER("import_swagger", 3);
private final String name;
diff --git
a/shenyu-common/src/test/java/org/apache/shenyu/common/enums/ApiSourceEnumTest.java
b/shenyu-common/src/test/java/org/apache/shenyu/common/enums/ApiSourceEnumTest.java
index 1fbab2387e..006ee46121 100644
---
a/shenyu-common/src/test/java/org/apache/shenyu/common/enums/ApiSourceEnumTest.java
+++
b/shenyu-common/src/test/java/org/apache/shenyu/common/enums/ApiSourceEnumTest.java
@@ -32,7 +32,6 @@ public class ApiSourceEnumTest {
assertEquals("annotation_generation",
ApiSourceEnum.ANNOTATION_GENERATION.getName());
assertEquals("create_manually",
ApiSourceEnum.CREATE_MANUALLY.getName());
assertEquals("import_swagger", ApiSourceEnum.IMPORT_SWAGGER.getName());
- assertEquals("import_yapi", ApiSourceEnum.IMPORT_YAPI.getName());
}
@Test
@@ -41,6 +40,5 @@ public class ApiSourceEnumTest {
assertEquals(1, ApiSourceEnum.ANNOTATION_GENERATION.getValue());
assertEquals(2, ApiSourceEnum.CREATE_MANUALLY.getValue());
assertEquals(3, ApiSourceEnum.IMPORT_SWAGGER.getValue());
- assertEquals(4, ApiSourceEnum.IMPORT_YAPI.getValue());
}
}
diff --git
a/shenyu-register-center/shenyu-register-protocol/src/main/java/org/apache/shenyu/register/common/dto/ApiDocRegisterDTO.java
b/shenyu-register-center/shenyu-register-protocol/src/main/java/org/apache/shenyu/register/common/dto/ApiDocRegisterDTO.java
index 07ce517b9f..38b4b68553 100644
---
a/shenyu-register-center/shenyu-register-protocol/src/main/java/org/apache/shenyu/register/common/dto/ApiDocRegisterDTO.java
+++
b/shenyu-register-center/shenyu-register-protocol/src/main/java/org/apache/shenyu/register/common/dto/ApiDocRegisterDTO.java
@@ -87,7 +87,7 @@ public class ApiDocRegisterDTO implements DataTypeParent {
private String apiDesc;
/**
- * 0-swagger,1-annotation generation,2-create manuallym,3-import
swagger,4-import yapi.
+ * 0-swagger,1-annotation generation,2-create manually,3-import swagger.
*/
private Integer apiSource;