diff --git a/changelog.md b/changelog.md
index edb75ef8..fca5cf17 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,5 +1,10 @@
# changelog
+## 2.5.6
+
+- 优化文档显示
+- 修复路由拉取接口重复BUG
+
## 2.5.5
- 优化文档显示
diff --git a/sop-auth/pom.xml b/sop-auth/pom.xml
index 66b23fbd..56a660cd 100644
--- a/sop-auth/pom.xml
+++ b/sop-auth/pom.xml
@@ -26,7 +26,7 @@
com.gitee.sop
sop-service-common
- 2.5.5-SNAPSHOT
+ 2.5.6-SNAPSHOT
diff --git a/sop-common/pom.xml b/sop-common/pom.xml
index 3e8e634c..04bd8b38 100644
--- a/sop-common/pom.xml
+++ b/sop-common/pom.xml
@@ -5,7 +5,7 @@
4.0.0
com.gitee.sop
sop-common
- 2.5.5-SNAPSHOT
+ 2.5.6-SNAPSHOT
pom
diff --git a/sop-common/sop-gateway-common/pom.xml b/sop-common/sop-gateway-common/pom.xml
index c8f6c86a..0b8cc65f 100644
--- a/sop-common/sop-gateway-common/pom.xml
+++ b/sop-common/sop-gateway-common/pom.xml
@@ -5,11 +5,11 @@
com.gitee.sop
sop-common
- 2.5.5-SNAPSHOT
+ 2.5.6-SNAPSHOT
../pom.xml
sop-gateway-common
- 2.5.5-SNAPSHOT
+ 2.5.6-SNAPSHOT
jar
sop-gateway-common
diff --git a/sop-common/sop-service-common/pom.xml b/sop-common/sop-service-common/pom.xml
index 747d9757..42fe1731 100644
--- a/sop-common/sop-service-common/pom.xml
+++ b/sop-common/sop-service-common/pom.xml
@@ -6,11 +6,11 @@
com.gitee.sop
sop-common
- 2.5.5-SNAPSHOT
+ 2.5.6-SNAPSHOT
../pom.xml
sop-service-common
- 2.5.5-SNAPSHOT
+ 2.5.6-SNAPSHOT
jar
sop-service-common
diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/ServiceApiInfo.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/ServiceApiInfo.java
index 7998d941..85d1f9a3 100644
--- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/ServiceApiInfo.java
+++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/ServiceApiInfo.java
@@ -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 apis;
private List 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);
+ }
}
}
diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/manager/ApiMetaBuilder.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/manager/ApiMetaBuilder.java
index 215db872..8f3ecb17 100644
--- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/manager/ApiMetaBuilder.java
+++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/manager/ApiMetaBuilder.java
@@ -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 requestMappingInfos = handlerMethods.keySet();
List store = new ArrayList<>();
List apis = new ArrayList<>(requestMappingInfos.size());
+ Set restfulApis = new HashSet<>(requestMappingInfos.size());
for (Map.Entry 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)) {
diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingHandlerMapping.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingHandlerMapping.java
index 8506f015..506704b6 100644
--- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingHandlerMapping.java
+++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingHandlerMapping.java
@@ -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);
diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingStringValueResolver.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingStringValueResolver.java
index d17ce61a..da448bab 100644
--- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingStringValueResolver.java
+++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingStringValueResolver.java
@@ -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;
}
}
diff --git a/sop-example/sop-book/sop-book-web/pom.xml b/sop-example/sop-book/sop-book-web/pom.xml
index 3b963552..6a18e083 100644
--- a/sop-example/sop-book/sop-book-web/pom.xml
+++ b/sop-example/sop-book/sop-book-web/pom.xml
@@ -28,7 +28,7 @@
com.gitee.sop
sop-service-common
- 2.5.5-SNAPSHOT
+ 2.5.6-SNAPSHOT
com.gitee.sop
diff --git a/sop-example/sop-easyopen/pom.xml b/sop-example/sop-easyopen/pom.xml
index 71ffdf9c..5ea622ef 100644
--- a/sop-example/sop-easyopen/pom.xml
+++ b/sop-example/sop-easyopen/pom.xml
@@ -29,7 +29,7 @@
com.gitee.sop
sop-service-common
- 2.5.5-SNAPSHOT
+ 2.5.6-SNAPSHOT
diff --git a/sop-example/sop-story/sop-story-web/pom.xml b/sop-example/sop-story/sop-story-web/pom.xml
index d0ea4606..fee0925e 100644
--- a/sop-example/sop-story/sop-story-web/pom.xml
+++ b/sop-example/sop-story/sop-story-web/pom.xml
@@ -28,7 +28,7 @@
com.gitee.sop
sop-service-common
- 2.5.5-SNAPSHOT
+ 2.5.6-SNAPSHOT
com.gitee.sop
diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/TraditionalWebappController.java b/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/TraditionalWebappController.java
index 64752165..7cf77b49 100644
--- a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/TraditionalWebappController.java
+++ b/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/TraditionalWebappController.java
@@ -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();
diff --git a/sop-gateway/pom.xml b/sop-gateway/pom.xml
index 1fa42884..7b52f8dc 100644
--- a/sop-gateway/pom.xml
+++ b/sop-gateway/pom.xml
@@ -29,7 +29,7 @@
com.gitee.sop
sop-gateway-common
- 2.5.5-SNAPSHOT
+ 2.5.6-SNAPSHOT
diff --git a/sop-website/pom.xml b/sop-website/pom.xml
index c496a577..b11423ee 100644
--- a/sop-website/pom.xml
+++ b/sop-website/pom.xml
@@ -35,7 +35,7 @@
com.gitee.sop
sop-gateway-common
- 2.5.5-SNAPSHOT
+ 2.5.6-SNAPSHOT
diff --git a/sop-website/src/main/java/com/gitee/sop/websiteserver/manager/SwaggerDocParser.java b/sop-website/src/main/java/com/gitee/sop/websiteserver/manager/SwaggerDocParser.java
index bb822cbf..ff845789 100644
--- a/sop-website/src/main/java/com/gitee/sop/websiteserver/manager/SwaggerDocParser.java
+++ b/sop-website/src/main/java/com/gitee/sop/websiteserver/manager/SwaggerDocParser.java
@@ -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"));