Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@
<configLocation>/script/shenyu_checkstyle.xml</configLocation>
<headerLocation>/script/checkstyle-header.txt</headerLocation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<excludes>**/transfer/**/*</excludes>
<excludes>**/transfer/**/*,**/generated*/**/*</excludes>
</configuration>
<executions>
<execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.ArrayList;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.Objects;
import org.apache.shenyu.admin.disruptor.RegisterClientServerDisruptorPublisher;
import org.apache.shenyu.admin.mapper.ApiMapper;
import org.apache.shenyu.admin.mapper.TagMapper;
Expand All @@ -40,7 +41,6 @@
import org.apache.shenyu.admin.model.vo.RuleVO;
import org.apache.shenyu.admin.model.vo.TagVO;
import org.apache.shenyu.admin.service.ApiService;
import org.apache.shenyu.common.enums.ApiSourceEnum;
import org.apache.shenyu.common.enums.PluginEnum;
import org.apache.shenyu.common.utils.JsonUtils;
import org.apache.shenyu.common.utils.ListUtil;
Expand Down Expand Up @@ -243,12 +243,14 @@ public ApiVO findById(final String id) {
tagVOs = tagDOS.stream().map(TagVO::buildTagVO).collect(Collectors.toList());
}
ApiVO apiVO = ApiVO.buildApiVO(item, tagVOs);
if (apiVO.getApiSource().equals(ApiSourceEnum.SWAGGER.getValue())) {
if (StringUtils.isNotBlank(apiVO.getDocument())) {
DocItem docItem = JsonUtils.jsonToObject(apiVO.getDocument(), DocItem.class);
apiVO.setRequestHeaders(docItem.getRequestHeaders());
apiVO.setRequestParameters(docItem.getRequestParameters());
apiVO.setResponseParameters(docItem.getResponseParameters());
apiVO.setBizCustomCodeList(docItem.getBizCodeList());
if (Objects.nonNull(docItem)) {
apiVO.setRequestHeaders(docItem.getRequestHeaders());
apiVO.setRequestParameters(docItem.getRequestParameters());
apiVO.setResponseParameters(docItem.getResponseParameters());
apiVO.setBizCustomCodeList(docItem.getBizCodeList());
}
}
Comment thread
moremind marked this conversation as resolved.
return apiVO;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,60 @@ public void testFindById() {
assertNotNull(byId);
}

@Test
public void testFindByIdWithDocumentNotBlank() {
String id = "456";
ApiDTO apiDTO = new ApiDTO();
apiDTO.setId(id);
apiDTO.setContextPath("string");
apiDTO.setApiPath("string");
apiDTO.setHttpMethod(0);
apiDTO.setConsume("string");
apiDTO.setProduce("string");
apiDTO.setVersion("string");
apiDTO.setRpcType("string");
apiDTO.setState(0);
apiDTO.setApiOwner("string");
apiDTO.setApiDesc("string");
apiDTO.setApiSource(0);
apiDTO.setDocument("{\"module\":\"test-module\",\"requestParameters\":[],\"responseParameters\":[]}");
ApiDO apiDO = ApiDO.buildApiDO(apiDTO);
Timestamp now = Timestamp.valueOf(LocalDateTime.now());
apiDO.setDateCreated(now);
apiDO.setDateUpdated(now);
given(this.apiMapper.selectByPrimaryKey(eq(id))).willReturn(apiDO);
ApiVO byId = this.apiService.findById(id);
assertNotNull(byId);
assertNotNull(byId.getRequestParameters());
assertNotNull(byId.getResponseParameters());
}

@Test
public void testFindByIdWithBlankDocument() {
String id = "789";
ApiDTO apiDTO = new ApiDTO();
apiDTO.setId(id);
apiDTO.setContextPath("string");
apiDTO.setApiPath("string");
apiDTO.setHttpMethod(0);
apiDTO.setConsume("string");
apiDTO.setProduce("string");
apiDTO.setVersion("string");
apiDTO.setRpcType("string");
apiDTO.setState(0);
apiDTO.setApiOwner("string");
apiDTO.setApiDesc("string");
apiDTO.setApiSource(0);
apiDTO.setDocument("");
ApiDO apiDO = ApiDO.buildApiDO(apiDTO);
Timestamp now = Timestamp.valueOf(LocalDateTime.now());
apiDO.setDateCreated(now);
apiDO.setDateUpdated(now);
given(this.apiMapper.selectByPrimaryKey(eq(id))).willReturn(apiDO);
ApiVO byId = this.apiService.findById(id);
assertNotNull(byId);
}

@Test
public void testListByPage() {
PageParameter pageParameter = new PageParameter();
Expand Down
50 changes: 50 additions & 0 deletions shenyu-client/shenyu-client-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,55 @@
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.6.2</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.6.1</version>
Comment thread
eye-gu marked this conversation as resolved.
Outdated
<extensions>true</extensions>
<configuration>
<protocArtifact>com.google.protobuf:protoc:${protobuf-java.version}:exe:${os.detected.classifier}</protocArtifact>
<protoSourceRoot>${project.basedir}/src/test/proto</protoSourceRoot>
<outputDirectory>${project.build.directory}/generated-test-sources/protobuf/java</outputDirectory>
<clearOutputDirectory>false</clearOutputDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<testSourceDirectories>
<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
</testSourceDirectories>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.apache.shenyu.client.core.client;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -213,7 +212,7 @@ private List<ApiDocRegisterDTO> buildApiDocDTO(final Object bean, final Method m
String apiPath = pathJoin(contextPath, superPath, value);
ApiHttpMethodEnum[] value3 = sextet.getValue3();
for (ApiHttpMethodEnum apiHttpMethodEnum : value3) {
String documentJson = buildDocumentJson(pairs.getRight(), apiPath, method);
String documentJson = buildDocumentJson(pairs.getRight(), apiPath, method, sextet.getValue4());
String extJson = buildExtJson(method);
ApiDocRegisterDTO build = ApiDocRegisterDTO.builder()
.consume(sextet.getValue1())
Expand Down Expand Up @@ -258,15 +257,8 @@ protected ApiDocRegisterDTO.ApiExt customApiDocExt(final ApiDocRegisterDTO.ApiEx
return ext;
}

private String buildDocumentJson(final List<String> tags, final String path, final Method method) {
Map<String, Object> documentMap = ImmutableMap.<String, Object>builder()
.put("tags", tags)
.put("operationId", path)
.put("parameters", OpenApiUtils.generateDocumentParameters(path, method))
.put("responses", OpenApiUtils.generateDocumentResponse(path))
.put("responseType", Collections.singletonList(OpenApiUtils.parseReturnType(method)))
.build();
return GsonUtils.getInstance().toJson(documentMap);
private String buildDocumentJson(final List<String> tags, final String path, final Method method, final RpcTypeEnum rpcTypeEnum) {
return OpenApiUtils.buildDocumentJson(tags, path, method, rpcTypeEnum);
}

protected abstract Sextet<String[], String, String, ApiHttpMethodEnum[], RpcTypeEnum, String> buildApiDocSextet(Method method, Annotation annotation, Map<String, T> beans);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.apache.shenyu.client.core.register.registrar;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;
import org.apache.shenyu.client.apidocs.annotations.ApiDoc;
Expand All @@ -42,9 +41,7 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public abstract class AbstractApiDocRegistrar extends AbstractApiRegistrar<ApiDocRegisterDTO> {

Expand Down Expand Up @@ -128,14 +125,7 @@ protected List<ApiDocRegisterDTO> parse(final ApiBean.ApiDefinition apiDefinitio
}

private String buildDocumentJson(final List<String> tags, final String path, final Method method) {
Map<String, Object> documentMap = ImmutableMap.<String, Object>builder()
.put("tags", tags)
.put("operationId", path)
.put("parameters", OpenApiUtils.generateDocumentParameters(path, method))
.put("responses", OpenApiUtils.generateDocumentResponse(path))
.put("responseType", Collections.singletonList(OpenApiUtils.parseReturnType(method)))
.build();
return GsonUtils.getInstance().toJson(documentMap);
return OpenApiUtils.buildDocumentJson(tags, path, method, rpcTypeEnum);
}

private String buildExtJson(final ApiBean.ApiDefinition apiDefinition) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.apache.shenyu.client.core.register.registrar;

import com.google.common.collect.ImmutableMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.shenyu.client.core.constant.ShenyuClientConstants;
import org.apache.shenyu.client.core.disruptor.ShenyuClientRegisterEventPublisher;
Expand All @@ -38,7 +37,6 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -132,14 +130,9 @@ private String getDocument(final ApiBean.ApiDefinition api) {
return document;
}
final String path = getPath(api);
final Map<String, Object> documentMap = ImmutableMap.<String, Object>builder()
.put("tags", buildTags(api))
.put("operationId", path)
.put("parameters", OpenApiUtils.generateDocumentParameters(path, api.getApiMethod()))
.put("responses", OpenApiUtils.generateDocumentResponse(path))
.put("responseType", Collections.singletonList(OpenApiUtils.parseReturnType(api.getApiMethod())))
.build();
return GsonUtils.getInstance().toJson(documentMap);
final String rpcType = getRpcType(api);
RpcTypeEnum rpcTypeEnum = RpcTypeEnum.acquireByName(rpcType);
return OpenApiUtils.buildDocumentJson(buildTags(api), path, api.getApiMethod(), rpcTypeEnum);
}

private String getRpcType(final ApiBean.ApiDefinition api) {
Expand Down
Loading
Loading