Merge branch 'master' into eureka

eureka
tanghc 5 years ago
commit 8455e54f89
  1. 5
      changelog.md
  2. 2
      sop-auth/pom.xml
  3. 2
      sop-common/pom.xml
  4. 4
      sop-common/sop-gateway-common/pom.xml
  5. 4
      sop-common/sop-service-common/pom.xml
  6. 20
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/ServiceApiInfo.java
  7. 17
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/manager/ApiMetaBuilder.java
  8. 13
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingHandlerMapping.java
  9. 7
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingStringValueResolver.java
  10. 2
      sop-example/sop-book/sop-book-web/pom.xml
  11. 2
      sop-example/sop-easyopen/pom.xml
  12. 2
      sop-example/sop-springmvc/pom.xml
  13. 2
      sop-example/sop-story/sop-story-web/pom.xml
  14. 4
      sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/TraditionalWebappController.java
  15. 2
      sop-gateway/pom.xml
  16. 2
      sop-website/pom.xml
  17. 11
      sop-website/src/main/java/com/gitee/sop/websiteserver/manager/SwaggerDocParser.java

@ -1,5 +1,10 @@
# changelog
## 2.5.6
- 优化文档显示
- 修复路由拉取接口重复BUG
## 2.5.5
- 优化文档显示

@ -26,7 +26,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>2.5.5-SNAPSHOT</version>
<version>2.5.6-SNAPSHOT</version>
</dependency>
<!-- sop相关配置 end-->

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-common</artifactId>
<version>2.5.5-SNAPSHOT</version>
<version>2.5.6-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>

@ -5,11 +5,11 @@
<parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-common</artifactId>
<version>2.5.5-SNAPSHOT</version>
<version>2.5.6-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>sop-gateway-common</artifactId>
<version>2.5.5-SNAPSHOT</version>
<version>2.5.6-SNAPSHOT</version>
<packaging>jar</packaging>
<name>sop-gateway-common</name>

@ -6,11 +6,11 @@
<parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-common</artifactId>
<version>2.5.5-SNAPSHOT</version>
<version>2.5.6-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>sop-service-common</artifactId>
<version>2.5.5-SNAPSHOT</version>
<version>2.5.6-SNAPSHOT</version>
<packaging>jar</packaging>
<name>sop-service-common</name>

@ -2,8 +2,11 @@ package com.gitee.sop.servercommon.bean;
import com.gitee.sop.servercommon.route.RouteDefinition;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
import java.util.Objects;
/**
* @author tanghc
@ -14,7 +17,8 @@ public class ServiceApiInfo {
private List<ApiMeta> apis;
private List<RouteDefinition> routeDefinitionList;
@Data
@Getter
@Setter
public static class ApiMeta {
/** 接口名 */
private String name;
@ -45,5 +49,19 @@ public class ServiceApiInfo {
public String fetchNameVersion() {
return this.name + this.version;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ApiMeta apiMeta = (ApiMeta) o;
return name.equals(apiMeta.name) &&
Objects.equals(version, apiMeta.version);
}
@Override
public int hashCode() {
return Objects.hash(name, version);
}
}
}

@ -16,6 +16,7 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -50,6 +51,7 @@ public class ApiMetaBuilder {
Set<RequestMappingInfo> requestMappingInfos = handlerMethods.keySet();
List<String> store = new ArrayList<>();
List<ServiceApiInfo.ApiMeta> apis = new ArrayList<>(requestMappingInfos.size());
Set<ServiceApiInfo.ApiMeta> restfulApis = new HashSet<>(requestMappingInfos.size());
for (Map.Entry<RequestMappingInfo, HandlerMethod> handlerMethodEntry : handlerMethods.entrySet()) {
ServiceApiInfo.ApiMeta apiMeta = this.buildApiMeta(handlerMethodEntry);
@ -57,13 +59,18 @@ public class ApiMetaBuilder {
continue;
}
String key = apiMeta.fetchNameVersion();
if (store.contains(key)) {
throw new IllegalArgumentException("重复申明接口,请检查path和version,path:" + apiMeta.getPath() + ", version:" + apiMeta.getVersion());
if (apiMeta.isOriginalMapping()) {
restfulApis.add(apiMeta);
} else {
store.add(key);
if (store.contains(key)) {
throw new IllegalArgumentException("重复申明接口,请检查path和version,path:" + apiMeta.getPath() + ", version:" + apiMeta.getVersion());
} else {
store.add(key);
}
apis.add(apiMeta);
}
apis.add(apiMeta);
}
apis.addAll(restfulApis);
return apis;
}
@ -93,11 +100,11 @@ public class ApiMetaBuilder {
if (!ServiceContext.getCurrentContext().getBoolean(ServiceContext.RESTFUL_KEY, false)) {
return null;
}
// 如果是restful服务
String path = patterns.iterator().next();
if (path.contains("$") || isIgnorePattern(path)) {
return null;
}
// 如果是restful服务
String name = path;
String prefix = EnvironmentKeys.SOP_RESTFUL_PREFIX.getValue();
if (StringUtils.isEmpty(prefix)) {

@ -17,6 +17,19 @@ import java.lang.reflect.Method;
*/
public class ApiMappingHandlerMapping extends RequestMappingHandlerMapping implements PriorityOrdered {
private static StringValueResolver stringValueResolver = new ApiMappingStringValueResolver();
@Override
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
ApiMapping apiMapping = method.getAnnotation(ApiMapping.class);
StringValueResolver valueResolver = null;
if (apiMapping != null) {
valueResolver = stringValueResolver;
}
this.setEmbeddedValueResolver(valueResolver);
return super.getMappingForMethod(method, handlerType);
}
@Override
protected RequestCondition<?> getCustomMethodCondition(Method method) {
method.setAccessible(true);

@ -7,13 +7,8 @@ import org.springframework.util.StringValueResolver;
*/
public class ApiMappingStringValueResolver implements StringValueResolver {
private static final String END_CHAR = "/";
@Override
public String resolveStringValue(String strVal) {
if (strVal != null && !strVal.endsWith(END_CHAR)) {
return strVal + END_CHAR;
}
return null;
return strVal;
}
}

@ -28,7 +28,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>2.5.5-SNAPSHOT</version>
<version>2.5.6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.gitee.sop</groupId>

@ -29,7 +29,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>2.5.5-SNAPSHOT</version>
<version>2.5.6-SNAPSHOT</version>
</dependency>
<!-- 使用nacos注册中心

@ -20,7 +20,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>2.5.5-SNAPSHOT</version>
<version>2.5.6-SNAPSHOT</version>
</dependency>
<!-- nacos -->
<dependency>

@ -28,7 +28,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>2.5.5-SNAPSHOT</version>
<version>2.5.6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.gitee.sop</groupId>

@ -1,6 +1,8 @@
package com.gitee.sop.storyweb.controller;
import com.gitee.sop.servercommon.util.UploadUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
@ -20,11 +22,13 @@ import java.util.Collection;
*/
@RestController
@RequestMapping("food")
@Api(tags = "食物接口")
public class TraditionalWebappController {
// http://localhost:8081/rest/food/getFoodById?id=1 网关入口
// http://localhost:2222/food/getFoodById/?id=12 本地入口
@ApiOperation(value="获取食物", notes = "根据id获取食物")
@RequestMapping(value = "getFoodById", method = RequestMethod.GET)
public Food getFoodById(Integer id) {
Food food = new Food();

@ -29,7 +29,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-gateway-common</artifactId>
<version>2.5.5-SNAPSHOT</version>
<version>2.5.6-SNAPSHOT</version>
</dependency>
<!-- ↓↓↓ 使用spring cloud zuul ↓↓↓ -->

@ -35,7 +35,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-gateway-common</artifactId>
<version>2.5.5-SNAPSHOT</version>
<version>2.5.6-SNAPSHOT</version>
</dependency>
<dependency>

@ -8,6 +8,7 @@ import com.gitee.sop.websiteserver.bean.DocModule;
import com.gitee.sop.websiteserver.bean.DocParameter;
import com.gitee.sop.websiteserver.bean.DocParserContext;
import com.google.common.collect.Sets;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;
@ -48,6 +49,9 @@ public class SwaggerDocParser implements DocParser {
String method = first.get();
JSONObject docInfo = pathInfo.getJSONObject(method);
DocItem docItem = buildDocItem(docInfo, docRoot);
if (docItem == null) {
continue;
}
if (docItem.isUploadRequest()) {
docItem.setHttpMethodList(Sets.newHashSet("post"));
} else {
@ -103,8 +107,13 @@ public class SwaggerDocParser implements DocParser {
}
protected DocItem buildDocItem(JSONObject docInfo, JSONObject docRoot) {
String apiName = docInfo.getString("sop_name");
// 非开放接口
if (StringUtils.isBlank(apiName)) {
return null;
}
DocItem docItem = new DocItem();
docItem.setName(docInfo.getString("sop_name"));
docItem.setName(apiName);
docItem.setVersion(docInfo.getString("sop_version"));
docItem.setSummary(docInfo.getString("summary"));
docItem.setDescription(docInfo.getString("description"));

Loading…
Cancel
Save