Merge branch 'master' into eureka

# Conflicts:
#	sop-admin/sop-admin-server/pom.xml
#	sop-gateway/pom.xml
#	sop-website/pom.xml
eureka
tanghc 4 years ago
commit 1385bce33d
  1. 4
      changelog.md
  2. 6
      pom.xml
  3. 2
      sop-auth/pom.xml
  4. 4
      sop-common/sop-bridge-eureka/pom.xml
  5. 4
      sop-common/sop-bridge-nacos/pom.xml
  6. 2
      sop-common/sop-gateway-common/pom.xml
  7. 4
      sop-common/sop-service-common/pom.xml
  8. 20
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/swagger/CustomModelToSwaggerMapper.java
  9. 127
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/swagger/CustomSwaggerParameterBuilder.java
  10. 8
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/swagger/DocumentationPluginsManagerExt.java
  11. 16
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/swagger/SwaggerSupport.java
  12. 2
      sop-example/sop-springmvc/pom.xml
  13. 2
      sop-example/sop-story/pom.xml
  14. 4
      sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/Example1001_BaseController.java
  15. 5
      sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/param/StoryParam.java
  16. 4
      sop-website/src/main/java/com/gitee/sop/websiteserver/bean/DocItem.java
  17. 3
      sop-website/src/main/java/com/gitee/sop/websiteserver/manager/SwaggerDocParser.java
  18. 1947
      sop-website/src/main/resources/api.json

@ -1,5 +1,9 @@
# changelog
## 4.0.2
- 支持swagger排序(position属性)
## 4.0.1
- 修复超大文本无法请求BUG(设置`spring.codec.max-in-memory-size`无效)

@ -65,6 +65,7 @@
<guava.version>27.1-jre</guava.version>
<swagger.version>1.5.21</swagger.version>
<springfox-spring-web.version>2.9.2</springfox-spring-web.version>
<springfox-swagger2.version>2.9.2</springfox-swagger2.version>
<easyopen.version>1.16.9</easyopen.version>
</properties>
@ -121,6 +122,11 @@
<artifactId>swagger-annotations</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox-swagger2.version}</version>
</dependency>
<dependency>
<groupId>net.oschina.durcframework</groupId>

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

@ -10,7 +10,7 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<version>4.0.1-SNAPSHOT</version>
<version>4.0.2-SNAPSHOT</version>
<artifactId>sop-bridge-eureka</artifactId>
@ -18,7 +18,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-gateway-common</artifactId>
<version>4.0.1-SNAPSHOT</version>
<version>4.0.2-SNAPSHOT</version>
</dependency>
<dependency>

@ -10,7 +10,7 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<version>4.0.1-SNAPSHOT</version>
<version>4.0.2-SNAPSHOT</version>
<artifactId>sop-bridge-nacos</artifactId>
@ -18,7 +18,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-gateway-common</artifactId>
<version>4.0.1-SNAPSHOT</version>
<version>4.0.2-SNAPSHOT</version>
</dependency>
<dependency>

@ -11,7 +11,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>sop-gateway-common</artifactId>
<version>4.0.1-SNAPSHOT</version>
<version>4.0.2-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>

@ -12,7 +12,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>sop-service-common</artifactId>
<version>4.0.1-SNAPSHOT</version>
<version>4.0.2-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
@ -60,7 +60,7 @@
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-spring-web</artifactId>
<artifactId>springfox-swagger2</artifactId>
<optional>true</optional>
</dependency>
<dependency>

@ -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<Parameter> parameterListToParameterList(List<springfox.documentation.service.Parameter> list) {
// list需要根据order|postion排序
list = list.stream()
.sorted(Comparator.comparingInt(springfox.documentation.service.Parameter::getOrder))
.collect(Collectors.toList());
return super.parameterListToParameterList(list);
}
}

@ -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<ApiModelProperty> apiModelPropertyOptional = context.findAnnotation(ApiModelProperty.class);
if (apiModelPropertyOptional.isPresent()) {
fromApiModelProperty(context, apiModelPropertyOptional.get());
}
Optional<ApiParam> 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<String> 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<String> getEnumValues(final Class<?> subject) {
return Lists.transform(Arrays.asList(subject.getEnumConstants()), new Function<Object, String>() {
@Override
public String apply(final Object input) {
return input.toString();
}
});
}
}

@ -4,6 +4,7 @@ import com.gitee.sop.servercommon.annotation.Open;
import com.gitee.sop.servercommon.bean.ServiceConfig;
import com.google.common.base.Optional;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.core.annotation.Order;
import springfox.documentation.service.Operation;
import springfox.documentation.service.StringVendorExtension;
@ -21,6 +22,7 @@ public class DocumentationPluginsManagerExt extends DocumentationPluginsManager
private static final String SOP_NAME = "sop_name";
private static final String SOP_VERSION = "sop_version";
private static final String MODULE_ORDER = "module_order";
private static final String API_ORDER = "api_order";
@Override
public Operation operation(OperationContext operationContext) {
@ -50,6 +52,12 @@ public class DocumentationPluginsManagerExt extends DocumentationPluginsManager
}
}
vendorExtensions.add(new StringVendorExtension(MODULE_ORDER, String.valueOf(order)));
Optional<ApiOperation> apiOperationOptional = operationContext.findAnnotation(ApiOperation.class);
int methodOrder = 0;
if (apiOperationOptional.isPresent()) {
methodOrder = apiOperationOptional.get().position();
}
vendorExtensions.add(new StringVendorExtension(API_ORDER, String.valueOf(methodOrder)));
}
private String buildVersion(String version) {

@ -8,6 +8,8 @@ import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.schema.EnumTypeDeterminer;
import springfox.documentation.spring.web.DescriptionResolver;
import springfox.documentation.spring.web.plugins.Docket;
/**
@ -27,6 +29,20 @@ public abstract class SwaggerSupport {
return new DocumentationPluginsManagerExt();
}
@Bean
@Primary
public CustomModelToSwaggerMapper customModelToSwaggerMapper() {
return new CustomModelToSwaggerMapper();
}
@Bean
@Primary
public CustomSwaggerParameterBuilder customSwaggerParameterBuilder(
DescriptionResolver descriptions,
EnumTypeDeterminer enumTypeDeterminer) {
return new CustomSwaggerParameterBuilder(descriptions, enumTypeDeterminer);
}
@Bean
public Docket createRestApi() {
return getDocket();

@ -26,7 +26,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>4.0.1-SNAPSHOT</version>
<version>4.0.2-SNAPSHOT</version>
</dependency>
<!-- nacos -->
<dependency>

@ -19,7 +19,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>4.0.1-SNAPSHOT</version>
<version>4.0.2-SNAPSHOT</version>
</dependency>
<dependency>

@ -41,7 +41,7 @@ public class Example1001_BaseController {
}
// 基础用法
@ApiOperation(value = "获取故事信息", notes = "获取故事信息的详细信息")
@ApiOperation(value = "获取故事信息(首位)", notes = "获取故事信息的详细信息", position = -100/* position默认0,值越小越靠前 */)
@Open("story.get")
@RequestMapping("/get/v1")
public StoryResult get_v1(StoryParam param) {
@ -81,7 +81,7 @@ public class Example1001_BaseController {
}
// 返回数组结果
@ApiOperation(value = "返回数组结果", notes = "返回数组结果")
@ApiOperation(value = "返回数组结果(第二)", notes = "返回数组结果", position = -99)
@Open("story.list")
@RequestMapping("/list/v1")
public List<StoryResult> getStory3(StoryParam story) {

@ -13,6 +13,9 @@ public class StoryParam {
@NotBlank(message = "name不能为空")
@Length(max = 20, message = "name长度不能超过20")
@ApiModelProperty(value = "故事名称", required = true, example = "白雪公主")
@ApiModelProperty(value = "故事名称", required = true, example = "白雪公主", position = 3)
private String name;
@ApiModelProperty(value = "备注 (第二)", example = "xx", position = 2)
private String remark;
}

@ -22,8 +22,12 @@ public class DocItem {
private Collection<String> produces;
/** 模块顺序 */
private int moduleOrder;
/** 文档顺序 */
private int apiOrder;
List<DocParameter> requestParameters;
List<DocParameter> responseParameters;

@ -61,7 +61,7 @@ public class SwaggerDocParser implements DocParser {
}
}
docItems.sort(Comparator.comparing(DocItem::getNameVersion));
docItems.sort(Comparator.comparing(DocItem::getApiOrder).thenComparing(DocItem::getNameVersion));
List<DocModule> docModuleList = docItems.stream()
.collect(Collectors.groupingBy(DocItem::getModule))
@ -122,6 +122,7 @@ public class SwaggerDocParser implements DocParser {
docItem.setMultiple(docInfo.getString("multiple") != null);
docItem.setProduces(docInfo.getJSONArray("produces").toJavaList(String.class));
docItem.setModuleOrder(NumberUtils.toInt(docInfo.getString("module_order"), 0));
docItem.setApiOrder(NumberUtils.toInt(docInfo.getString("api_order"), 0));
String moduleName = this.buildModuleName(docInfo, docRoot);
docItem.setModule(moduleName);
List<DocParameter> docParameterList = this.buildRequestParameterList(docInfo, docRoot);

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save