diff --git a/changelog.md b/changelog.md
index 50362f4e..27ea95c3 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,5 +1,9 @@
# changelog
+## 4.0.2
+
+- 支持swagger排序(position属性)
+
## 4.0.1
- 修复超大文本无法请求BUG(设置`spring.codec.max-in-memory-size`无效)
diff --git a/pom.xml b/pom.xml
index c760cfd0..23e2d066 100644
--- a/pom.xml
+++ b/pom.xml
@@ -65,6 +65,7 @@
27.1-jre
1.5.21
2.9.2
+ 2.9.2
1.16.9
@@ -121,6 +122,11 @@
swagger-annotations
${swagger.version}
+
+ io.springfox
+ springfox-swagger2
+ ${springfox-swagger2.version}
+
net.oschina.durcframework
diff --git a/sop-auth/pom.xml b/sop-auth/pom.xml
index f03ca5b4..b01d416f 100644
--- a/sop-auth/pom.xml
+++ b/sop-auth/pom.xml
@@ -25,7 +25,7 @@
com.gitee.sop
sop-service-common
- 4.0.1-SNAPSHOT
+ 4.0.2-SNAPSHOT
diff --git a/sop-common/sop-bridge-eureka/pom.xml b/sop-common/sop-bridge-eureka/pom.xml
index a62bcc41..f367b7a9 100644
--- a/sop-common/sop-bridge-eureka/pom.xml
+++ b/sop-common/sop-bridge-eureka/pom.xml
@@ -10,7 +10,7 @@
4.0.0
- 4.0.1-SNAPSHOT
+ 4.0.2-SNAPSHOT
sop-bridge-eureka
@@ -18,7 +18,7 @@
com.gitee.sop
sop-gateway-common
- 4.0.1-SNAPSHOT
+ 4.0.2-SNAPSHOT
diff --git a/sop-common/sop-bridge-nacos/pom.xml b/sop-common/sop-bridge-nacos/pom.xml
index 49d7125f..822b8234 100644
--- a/sop-common/sop-bridge-nacos/pom.xml
+++ b/sop-common/sop-bridge-nacos/pom.xml
@@ -10,7 +10,7 @@
4.0.0
- 4.0.1-SNAPSHOT
+ 4.0.2-SNAPSHOT
sop-bridge-nacos
@@ -18,7 +18,7 @@
com.gitee.sop
sop-gateway-common
- 4.0.1-SNAPSHOT
+ 4.0.2-SNAPSHOT
diff --git a/sop-common/sop-gateway-common/pom.xml b/sop-common/sop-gateway-common/pom.xml
index 58801797..0346be41 100644
--- a/sop-common/sop-gateway-common/pom.xml
+++ b/sop-common/sop-gateway-common/pom.xml
@@ -11,7 +11,7 @@
4.0.0
sop-gateway-common
- 4.0.1-SNAPSHOT
+ 4.0.2-SNAPSHOT
jar
diff --git a/sop-common/sop-service-common/pom.xml b/sop-common/sop-service-common/pom.xml
index 34f7df4e..91d00021 100644
--- a/sop-common/sop-service-common/pom.xml
+++ b/sop-common/sop-service-common/pom.xml
@@ -12,7 +12,7 @@
4.0.0
sop-service-common
- 4.0.1-SNAPSHOT
+ 4.0.2-SNAPSHOT
jar
@@ -60,7 +60,7 @@
io.springfox
- springfox-spring-web
+ springfox-swagger2
true
diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/swagger/CustomModelToSwaggerMapper.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/swagger/CustomModelToSwaggerMapper.java
new file mode 100644
index 00000000..0f2c9a64
--- /dev/null
+++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/swagger/CustomModelToSwaggerMapper.java
@@ -0,0 +1,20 @@
+package com.gitee.sop.servercommon.swagger;
+
+import io.swagger.models.parameters.Parameter;
+import springfox.documentation.swagger2.mappers.ServiceModelToSwagger2MapperImpl;
+
+import java.util.Comparator;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class CustomModelToSwaggerMapper extends ServiceModelToSwagger2MapperImpl {
+
+ @Override
+ protected List parameterListToParameterList(List list) {
+ // list需要根据order|postion排序
+ list = list.stream()
+ .sorted(Comparator.comparingInt(springfox.documentation.service.Parameter::getOrder))
+ .collect(Collectors.toList());
+ return super.parameterListToParameterList(list);
+ }
+}
diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/swagger/CustomSwaggerParameterBuilder.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/swagger/CustomSwaggerParameterBuilder.java
new file mode 100644
index 00000000..b3e4974b
--- /dev/null
+++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/swagger/CustomSwaggerParameterBuilder.java
@@ -0,0 +1,127 @@
+package com.gitee.sop.servercommon.swagger;
+
+import com.google.common.base.Function;
+import com.google.common.base.Optional;
+import com.google.common.base.Strings;
+import com.google.common.collect.Lists;
+import io.swagger.annotations.ApiModelProperty;
+import io.swagger.annotations.ApiParam;
+import springfox.documentation.builders.ParameterBuilder;
+import springfox.documentation.service.AllowableListValues;
+import springfox.documentation.service.AllowableValues;
+import springfox.documentation.spi.DocumentationType;
+import springfox.documentation.spi.schema.EnumTypeDeterminer;
+import springfox.documentation.spi.service.ExpandedParameterBuilderPlugin;
+import springfox.documentation.spi.service.contexts.ParameterExpansionContext;
+import springfox.documentation.spring.web.DescriptionResolver;
+import springfox.documentation.swagger.common.SwaggerPluginSupport;
+import springfox.documentation.swagger.readers.parameter.Examples;
+import springfox.documentation.swagger.schema.ApiModelProperties;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static springfox.documentation.swagger.common.SwaggerPluginSupport.SWAGGER_PLUGIN_ORDER;
+
+/**
+ * Created by wujie on 2019/2/16.
+ * 自定义ExpandedParameterBuilderPlugin,主要是修正源码query传入请求参数postion无效
+ * 这里,将postion赋值给order
+ *
+ * https://blog.csdn.net/qq_38316721/article/details/103908793
+ */
+public class CustomSwaggerParameterBuilder implements ExpandedParameterBuilderPlugin {
+
+ private final DescriptionResolver descriptions;
+ private final EnumTypeDeterminer enumTypeDeterminer;
+
+ public CustomSwaggerParameterBuilder(
+ DescriptionResolver descriptions,
+ EnumTypeDeterminer enumTypeDeterminer) {
+ this.descriptions = descriptions;
+ this.enumTypeDeterminer = enumTypeDeterminer;
+ }
+
+ @Override
+ public void apply(ParameterExpansionContext context) {
+ Optional apiModelPropertyOptional = context.findAnnotation(ApiModelProperty.class);
+ if (apiModelPropertyOptional.isPresent()) {
+ fromApiModelProperty(context, apiModelPropertyOptional.get());
+ }
+ Optional apiParamOptional = context.findAnnotation(ApiParam.class);
+ if (apiParamOptional.isPresent()) {
+ fromApiParam(context, apiParamOptional.get());
+ }
+ }
+
+ @Override
+ public boolean supports(DocumentationType delimiter) {
+ return SwaggerPluginSupport.pluginDoesApply(delimiter);
+ }
+
+ private void fromApiParam(ParameterExpansionContext context, ApiParam apiParam) {
+ String allowableProperty = Strings.emptyToNull(apiParam.allowableValues());
+ AllowableValues allowable = allowableValues(
+ Optional.fromNullable(allowableProperty),
+ context.getFieldType().getErasedType());
+
+ maybeSetParameterName(context, apiParam.name())
+ .description(descriptions.resolve(apiParam.value()))
+ .defaultValue(apiParam.defaultValue())
+ .required(apiParam.required())
+ .allowMultiple(apiParam.allowMultiple())
+ .allowableValues(allowable)
+ .parameterAccess(apiParam.access())
+ .hidden(apiParam.hidden())
+ .scalarExample(apiParam.example())
+ .complexExamples(Examples.examples(apiParam.examples()))
+ .order(SWAGGER_PLUGIN_ORDER)
+ .build();
+ }
+
+ private void fromApiModelProperty(ParameterExpansionContext context, ApiModelProperty apiModelProperty) {
+ String allowableProperty = Strings.emptyToNull(apiModelProperty.allowableValues());
+ AllowableValues allowable = allowableValues(
+ Optional.fromNullable(allowableProperty),
+ context.getFieldType().getErasedType());
+
+ maybeSetParameterName(context, apiModelProperty.name())
+ .description(descriptions.resolve(apiModelProperty.value()))
+ .required(apiModelProperty.required())
+ .allowableValues(allowable)
+ .parameterAccess(apiModelProperty.access())
+ .hidden(apiModelProperty.hidden())
+ .scalarExample(apiModelProperty.example())
+ //源码这里是: SWAGGER_PLUGIN_ORDER,需要修正
+ .order(apiModelProperty.position())
+ .build();
+ }
+
+ private ParameterBuilder maybeSetParameterName(ParameterExpansionContext context, String parameterName) {
+ if (!Strings.isNullOrEmpty(parameterName)) {
+ context.getParameterBuilder().name(parameterName);
+ }
+ return context.getParameterBuilder();
+ }
+
+ private AllowableValues allowableValues(final Optional optionalAllowable, Class> fieldType) {
+
+ AllowableValues allowable = null;
+ if (enumTypeDeterminer.isEnum(fieldType)) {
+ allowable = new AllowableListValues(getEnumValues(fieldType), "LIST");
+ } else if (optionalAllowable.isPresent()) {
+ allowable = ApiModelProperties.allowableValueFromString(optionalAllowable.get());
+ }
+ return allowable;
+ }
+
+ private List getEnumValues(final Class> subject) {
+ return Lists.transform(Arrays.asList(subject.getEnumConstants()), new Function