Browse Source

优化swagger

mxd 4 years ago
parent
commit
6356f965e2

+ 5 - 5
src/main/java/org/ssssssss/magicapi/spring/boot/starter/MagicSwaggerConfiguration.java

@@ -13,6 +13,7 @@ import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
 import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
 import org.ssssssss.magicapi.config.MappingHandlerMapping;
 import org.ssssssss.magicapi.provider.GroupServiceProvider;
+import org.ssssssss.magicapi.swagger.SwaggerEntity;
 import org.ssssssss.magicapi.swagger.SwaggerProvider;
 import springfox.documentation.swagger.web.SwaggerResource;
 import springfox.documentation.swagger.web.SwaggerResourcesProvider;
@@ -38,7 +39,7 @@ public class MagicSwaggerConfiguration {
 	@Autowired
 	private ApplicationContext context;
 
-	private MagicAPIProperties properties;
+	private final MagicAPIProperties properties;
 
 	public MagicSwaggerConfiguration(MagicAPIProperties properties) {
 		this.properties = properties;
@@ -54,9 +55,8 @@ public class MagicSwaggerConfiguration {
 		SwaggerProvider swaggerProvider = new SwaggerProvider();
 		swaggerProvider.setGroupServiceProvider(groupServiceProvider);
 		swaggerProvider.setMappingHandlerMapping(handlerMapping);
-		swaggerProvider.setTitle(config.getTitle());
-		swaggerProvider.setDescription(config.getDescription());
-		swaggerProvider.setVersion(config.getVersion());
+		SwaggerEntity.License license = new SwaggerEntity.License("MIT", "https://gitee.com/ssssssss-team/magic-api/blob/master/LICENSE");
+		swaggerProvider.setInfo(new SwaggerEntity.Info(config.getDescription(), config.getVersion(), config.getTitle(), license, config.getConcat()));
 		swaggerProvider.setBasePath(servletContext.getContextPath());
 
 
@@ -69,7 +69,7 @@ public class MagicSwaggerConfiguration {
 			// 获取已定义的文档信息
 			if (beans != null) {
 				for (Map.Entry<String, SwaggerResourcesProvider> entry : beans.entrySet()) {
-					if(!"magicSwaggerResourcesProvider".equalsIgnoreCase(entry.getKey())){
+					if (!"magicSwaggerResourcesProvider".equalsIgnoreCase(entry.getKey())) {
 						resources.addAll(entry.getValue().get());
 					}
 				}

+ 14 - 0
src/main/java/org/ssssssss/magicapi/spring/boot/starter/SwaggerConfig.java

@@ -1,5 +1,8 @@
 package org.ssssssss.magicapi.spring.boot.starter;
 
+import org.springframework.boot.context.properties.NestedConfigurationProperty;
+import org.ssssssss.magicapi.swagger.SwaggerEntity;
+
 /**
  * Swagger 配置
  */
@@ -25,6 +28,9 @@ public class SwaggerConfig {
 	 */
 	private String description = "MagicAPI 接口信息";
 
+	@NestedConfigurationProperty
+	private SwaggerEntity.Concat concat = new SwaggerEntity.Concat();
+
 	/**
 	 * 文档版本
 	 */
@@ -69,4 +75,12 @@ public class SwaggerConfig {
 	public void setVersion(String version) {
 		this.version = version;
 	}
+
+	public SwaggerEntity.Concat getConcat() {
+		return concat;
+	}
+
+	public void setConcat(SwaggerEntity.Concat concat) {
+		this.concat = concat;
+	}
 }