urls = new LinkedHashMap<>();
38 | urls.put("github", SWAGGER_SPRING_BOOT_GITHUB_URL);
39 | urls.put("issues", SWAGGER_SPRING_BOOT_ISSUES_URL);
40 |
41 | metaData.put("versions", versions);
42 | metaData.put("urls", urls);
43 | metaData.put("email", "1837307557@qq.com");
44 | return metaData;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/swagger-spring-boot-actuator/src/main/resources/META-INF/spring.factories:
--------------------------------------------------------------------------------
1 | # Auto Configure
2 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
3 | com.battcn.boot.swagger.actuate.autoconfigure.SwaggerEndpointsAutoConfiguration
--------------------------------------------------------------------------------
/swagger-spring-boot-actuator/src/main/resources/META-INF/swagger-endpoins-default.properties:
--------------------------------------------------------------------------------
1 |
2 | management.endpoint.dubbo.enabled=true
3 |
4 | management.endpoints.web.exposure.include=swagger
--------------------------------------------------------------------------------
/swagger-spring-boot-autoconfigure/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.battcn
8 | swagger-spring-boot
9 | 2.1.5-RELEASE
10 |
11 | swagger-spring-boot-autoconfigure
12 | swagger-spring-boot-autoconfigure
13 | jar
14 | ${parent.version}
15 |
16 |
17 |
18 | org.springframework.boot
19 | spring-boot-starter-web
20 | true
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-configuration-processor
25 | true
26 |
27 |
28 | io.springfox
29 | springfox-swagger2
30 |
31 |
32 | io.springfox
33 | springfox-bean-validators
34 |
35 |
36 | com.battcn
37 | swagger-vue-ui
38 |
39 |
40 | org.projectlombok
41 | lombok
42 | provided
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/swagger-spring-boot-autoconfigure/src/main/java/com/battcn/boot/swagger/annotation/ApiOrder.java:
--------------------------------------------------------------------------------
1 | package com.battcn.boot.swagger.annotation;
2 |
3 | import org.springframework.core.Ordered;
4 |
5 | import java.lang.annotation.*;
6 |
7 | @Retention(RetentionPolicy.RUNTIME)
8 | @Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
9 | @Documented
10 | public @interface ApiOrder {
11 |
12 | /**
13 | * The order value.
14 | * Default is {@link Ordered#LOWEST_PRECEDENCE}.
15 | * @see Ordered#getOrder()
16 | */
17 | int value() default Ordered.LOWEST_PRECEDENCE;
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/swagger-spring-boot-autoconfigure/src/main/java/com/battcn/boot/swagger/configuration/CustomSwagger2DocumentationConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.battcn.boot.swagger.configuration;
2 |
3 | import org.springframework.context.annotation.ComponentScan;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | /**
7 | * @author Levin
8 | * @since 2018/7/6 0006
9 | */
10 | @Configuration
11 | @ComponentScan("com.battcn.boot.swagger.web")
12 | public class CustomSwagger2DocumentationConfiguration {
13 |
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/swagger-spring-boot-autoconfigure/src/main/java/com/battcn/boot/swagger/configuration/SwaggerBeanValidatorPluginsConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.battcn.boot.swagger.configuration;
2 |
3 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
4 | import org.springframework.context.annotation.Configuration;
5 | import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
6 |
7 | /**
8 | * @author Levin
9 | * @since 2.0.2
10 | */
11 | @Configuration
12 | @ConditionalOnProperty(name = {"spring.swagger.enabled", "spring.swagger.validator-plugin"}, havingValue = "true")
13 | public class SwaggerBeanValidatorPluginsConfiguration extends BeanValidatorPluginsConfiguration {
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/swagger-spring-boot-autoconfigure/src/main/java/com/battcn/boot/swagger/configuration/SwaggerSecurityFilterPluginsConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.battcn.boot.swagger.configuration;
2 |
3 | import com.battcn.boot.swagger.utils.RequestUtils;
4 | import org.slf4j.Logger;
5 | import org.slf4j.LoggerFactory;
6 |
7 | import javax.servlet.*;
8 | import javax.servlet.http.HttpServletRequest;
9 | import javax.servlet.http.HttpServletResponse;
10 | import javax.servlet.http.HttpSession;
11 | import java.io.IOException;
12 |
13 | /**
14 | * @author Levin
15 | * @since 2.0.2
16 | */
17 | public class SwaggerSecurityFilterPluginsConfiguration implements Filter {
18 |
19 | private static Logger logger = LoggerFactory.getLogger(SwaggerSecurityFilterPluginsConfiguration.class);
20 |
21 | @Override
22 | public void init(FilterConfig filterConfig) throws ServletException {
23 | logger.info("==================== init swagger security filter plugin ====================");
24 | }
25 |
26 | @Override
27 | public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
28 | final HttpServletResponse response = (HttpServletResponse) servletResponse;
29 | final HttpServletRequest request = (HttpServletRequest) servletRequest;
30 | final HttpSession session = request.getSession();
31 | if (session == null || session.getAttribute(session.getId()) == null) {
32 | RequestUtils.writeForbidden(response);
33 | }
34 | filterChain.doFilter(servletRequest, servletResponse);
35 | }
36 |
37 | @Override
38 | public void destroy() {
39 | logger.info("==================== destroy swagger security filter plugin ====================");
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/swagger-spring-boot-autoconfigure/src/main/java/com/battcn/boot/swagger/model/DataType.java:
--------------------------------------------------------------------------------
1 | package com.battcn.boot.swagger.model;
2 |
3 |
4 | /**
5 | * 方便Swagger 中 @ApiImplicitParam(paramType = DataType.HEADER)
6 | *
7 | * @author Levin
8 | * @since 2.0.2
9 | */
10 | public final class DataType {
11 |
12 | public final static String STRING = "String";
13 | public final static String INT = "int";
14 | public final static String LONG = "long";
15 | public final static String DOUBLE = "double";
16 | public final static String FLOAT = "float";
17 | public final static String BYTE = "byte";
18 | public final static String BOOLEAN = "boolean";
19 | public final static String ARRAY = "array";
20 | public final static String BINARY = "binary";
21 | public final static String DATETIME = "dateTime";
22 | public final static String PASSWORD = "password";
23 |
24 | }
25 |
26 |
--------------------------------------------------------------------------------
/swagger-spring-boot-autoconfigure/src/main/java/com/battcn/boot/swagger/model/Order.java:
--------------------------------------------------------------------------------
1 | package com.battcn.boot.swagger.model;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * @author Levin
9 | * @since 2018/12/6 0006
10 | */
11 | @Data
12 | public class Order {
13 |
14 | private List tags;
15 | private int order = 0;
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/swagger-spring-boot-autoconfigure/src/main/java/com/battcn/boot/swagger/model/ParamType.java:
--------------------------------------------------------------------------------
1 | package com.battcn.boot.swagger.model;
2 |
3 | /**
4 | * 方便Swagger 中 @ApiImplicitParam(paramType = ApiParamType.HEADER)
5 | *
6 | * @author Levin
7 | */
8 | public final class ParamType {
9 |
10 | public final static String QUERY = "query";
11 | public final static String HEADER = "header";
12 | public final static String PATH = "path";
13 | public final static String BODY = "body";
14 | public final static String FORM = "form";
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/swagger-spring-boot-autoconfigure/src/main/java/com/battcn/boot/swagger/properties/SwaggerProperties.java:
--------------------------------------------------------------------------------
1 | package com.battcn.boot.swagger.properties;
2 |
3 | import com.google.common.collect.Maps;
4 | import lombok.Data;
5 | import lombok.NoArgsConstructor;
6 | import org.springframework.boot.context.properties.ConfigurationProperties;
7 | import org.springframework.web.bind.annotation.RequestMethod;
8 |
9 | import java.util.ArrayList;
10 | import java.util.LinkedHashMap;
11 | import java.util.List;
12 | import java.util.Map;
13 |
14 |
15 | /**
16 | * @author Levin
17 | */
18 | @Data
19 | @ConfigurationProperties("spring.swagger")
20 | public class SwaggerProperties {
21 |
22 |
23 | private static final String DEFAULT_VALUE = "";
24 |
25 | /**
26 | * 是否开启swagger
27 | */
28 | private Boolean enabled;
29 | /**
30 | * 标题
31 | */
32 | private String title = DEFAULT_VALUE;
33 | /**
34 | * 描述
35 | */
36 | private String description = DEFAULT_VALUE;
37 | /**
38 | * 版本
39 | */
40 | private String version = DEFAULT_VALUE;
41 | /**
42 | * 许可证
43 | */
44 | private String license = DEFAULT_VALUE;
45 | /**
46 | * 许可证URL
47 | */
48 | private String licenseUrl = DEFAULT_VALUE;
49 | /**
50 | * 服务条款URL
51 | */
52 | private String termsOfServiceUrl = DEFAULT_VALUE;
53 |
54 | /**
55 | * swagger会解析的包路径
56 | */
57 | private String basePackage = DEFAULT_VALUE;
58 |
59 | /**
60 | * host信息
61 | */
62 | private String host = DEFAULT_VALUE;
63 |
64 | /**
65 | * 联系人信息
66 | */
67 | private Contact contact = new Contact();
68 |
69 | /**
70 | * swagger会解析的url规则
71 | */
72 | private List basePath = new ArrayList<>();
73 | /**
74 | * 在basePath基础上需要排除的url规则
75 | */
76 | private List excludePath = new ArrayList<>();
77 |
78 | /**
79 | * 分组文档
80 | */
81 | private Map groups = new LinkedHashMap<>();
82 |
83 |
84 | /**
85 | * 全局参数配置
86 | */
87 | private List globalOperationParameters;
88 |
89 | /**
90 | * 全局响应配置
91 | */
92 | private Map> globalResponseMessages = Maps.newLinkedHashMap();
93 |
94 | /**
95 | * 是否开启验证插件支持(默认关闭)
96 | */
97 | private boolean validatorPlugin = false;
98 |
99 | public boolean isValidatorPlugin() {
100 | return validatorPlugin;
101 | }
102 |
103 | public void setValidatorPlugin(boolean validatorPlugin) {
104 | this.validatorPlugin = validatorPlugin;
105 | }
106 |
107 |
108 | private ApiKey apiKey;
109 |
110 | @Data
111 | public static class ApiKey {
112 |
113 | /**
114 | * 鉴权策略ID;对应 SecurityReferences ID
115 | */
116 | private String name = "X-Authorization";
117 |
118 | /**
119 | * 传递的鉴权参数字段名
120 | */
121 | private String keyName = "token";
122 |
123 |
124 | /**
125 | * 自定义匹配路径的正则(如:/anyPath.* 或者 ^.*$) 默认匹配所有
126 | */
127 | private String authRegex = "^.*$";
128 |
129 | /**
130 | * 传递参数的类型;默认 header 存放
131 | */
132 | private String paramType = "header";
133 | }
134 |
135 | @Data
136 | public static class ResponseMessageBody {
137 | /**
138 | * 状态码
139 | */
140 | private int code;
141 | /**
142 | * 响应的消息内容
143 | */
144 | private String message;
145 | /**
146 | * 响应体(对象)
147 | */
148 | private String modelRef;
149 | }
150 |
151 | @Data
152 | public static class GlobalOperationParameter {
153 |
154 | /**
155 | * 参数名
156 | */
157 | private String name;
158 |
159 | /**
160 | * 描述信息
161 | */
162 | private String description;
163 |
164 | /**
165 | * 指定参数类型
166 | */
167 | private String modelRef;
168 |
169 | /**
170 | * 参数存放位置:
171 | *
172 | * @see ParamType
173 | */
174 | private String parameterType;
175 |
176 | /**
177 | * 是否必须传
178 | */
179 | private Boolean required = false;
180 |
181 | }
182 |
183 | @Data
184 | @NoArgsConstructor
185 | @ConfigurationProperties("spring.swagger.groups")
186 | public static class GroupInfo {
187 |
188 | /**
189 | * 标题
190 | */
191 | private String title = DEFAULT_VALUE;
192 | /**
193 | * 描述
194 | */
195 | private String description = DEFAULT_VALUE;
196 |
197 | /**
198 | * 版本
199 | */
200 | private String version = DEFAULT_VALUE;
201 |
202 | /**
203 | * 许可证
204 | */
205 | private String license = DEFAULT_VALUE;
206 |
207 | /**
208 | * 许可证URL
209 | */
210 | private String licenseUrl = DEFAULT_VALUE;
211 |
212 | /**
213 | * 服务条款URL
214 | */
215 | private String termsOfServiceUrl = DEFAULT_VALUE;
216 |
217 | private Contact contact = new Contact();
218 |
219 | /**
220 | * swagger会解析的包路径
221 | */
222 | private String basePackage = DEFAULT_VALUE;
223 |
224 | /**
225 | * swagger会解析的url规则
226 | */
227 | private List basePath = new ArrayList<>();
228 | /**
229 | * 在basePath基础上需要排除的url规则
230 | */
231 | private List excludePath = new ArrayList<>();
232 |
233 | /**
234 | * 分组里的全局参数
235 | */
236 | private List globalOperationParameters;
237 |
238 | }
239 |
240 | @Data
241 | @NoArgsConstructor
242 | public static class Contact {
243 | /**
244 | * 联系人
245 | */
246 | private String name = DEFAULT_VALUE;
247 | /**
248 | * 联系人url
249 | */
250 | private String url = DEFAULT_VALUE;
251 | /**
252 | * 联系人email
253 | */
254 | private String email = DEFAULT_VALUE;
255 |
256 | }
257 |
258 | }
--------------------------------------------------------------------------------
/swagger-spring-boot-autoconfigure/src/main/java/com/battcn/boot/swagger/properties/SwaggerSecurityProperties.java:
--------------------------------------------------------------------------------
1 | package com.battcn.boot.swagger.properties;
2 |
3 | import org.springframework.boot.context.properties.ConfigurationProperties;
4 |
5 |
6 | /**
7 | * @author Levin
8 | */
9 | @ConfigurationProperties("spring.swagger.security")
10 | public class SwaggerSecurityProperties {
11 |
12 | /**
13 | * 安全过滤器插件开关
14 | */
15 | private boolean filterPlugin;
16 | /**
17 | * 用户名
18 | */
19 | private String username;
20 | /**
21 | * 密码
22 | */
23 | private String password;
24 |
25 | public boolean isFilterPlugin() {
26 | return filterPlugin;
27 | }
28 |
29 | public void setFilterPlugin(boolean filterPlugin) {
30 | this.filterPlugin = filterPlugin;
31 | }
32 |
33 | public String getUsername() {
34 | return username;
35 | }
36 |
37 | public void setUsername(String username) {
38 | this.username = username;
39 | }
40 |
41 | public String getPassword() {
42 | return password;
43 | }
44 |
45 | public void setPassword(String password) {
46 | this.password = password;
47 | }
48 | }
--------------------------------------------------------------------------------
/swagger-spring-boot-autoconfigure/src/main/java/com/battcn/boot/swagger/security/GlobalAccess.java:
--------------------------------------------------------------------------------
1 | package com.battcn.boot.swagger.security;
2 |
3 | import com.battcn.boot.swagger.properties.SwaggerProperties;
4 | import springfox.documentation.builders.PathSelectors;
5 | import springfox.documentation.service.ApiKey;
6 | import springfox.documentation.service.AuthorizationScope;
7 | import springfox.documentation.service.SecurityReference;
8 | import springfox.documentation.spi.service.contexts.SecurityContext;
9 |
10 | import java.util.List;
11 |
12 | import static com.google.common.collect.Lists.newArrayList;
13 |
14 | /**
15 | * 安全相关
16 | *
17 | * @author Levin
18 | * @since 2018/6/14 0014
19 | */
20 | public class GlobalAccess {
21 |
22 | private final SwaggerProperties swaggerProperties;
23 |
24 | public GlobalAccess(SwaggerProperties swaggerProperties) {
25 | this.swaggerProperties = swaggerProperties;
26 | }
27 |
28 |
29 | public ApiKey apiKey() {
30 | final SwaggerProperties.ApiKey apiKey = swaggerProperties.getApiKey();
31 | return new ApiKey(apiKey.getName(), apiKey.getKeyName(), apiKey.getParamType());
32 | }
33 |
34 | /**
35 | * 采用正则表达式进行 HTTP API 全局鉴权接口配置;默认 any 所有接口都授权
36 | * 其中 securityReferences 为配置启用的鉴权策略
37 | *
38 | * @return SecurityContext
39 | */
40 | public SecurityContext securityContext() {
41 | final SwaggerProperties.ApiKey apiKey = swaggerProperties.getApiKey();
42 | return SecurityContext.builder()
43 | .securityReferences(defaultAuth(apiKey))
44 | .forPaths(PathSelectors.regex(apiKey.getAuthRegex())).build();
45 | }
46 |
47 | /**
48 | * 配置默认的全局鉴权策略; SecurityReference 中 reference 参数需要与 ApiKey.name 保持一致
49 | *
50 | * @return List
51 | */
52 | private List defaultAuth(SwaggerProperties.ApiKey apiKey) {
53 | AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
54 | return newArrayList(new SecurityReference(apiKey.getName(), new AuthorizationScope[]{authorizationScope}));
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/swagger-spring-boot-autoconfigure/src/main/java/com/battcn/boot/swagger/utils/HostNameProvider.java:
--------------------------------------------------------------------------------
1 | package com.battcn.boot.swagger.utils;
2 |
3 | import org.springframework.http.server.ServletServerHttpRequest;
4 | import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
5 | import org.springframework.web.util.UriComponents;
6 | import org.springframework.web.util.UriComponentsBuilder;
7 | import org.springframework.web.util.UrlPathHelper;
8 |
9 | import javax.servlet.http.HttpServletRequest;
10 |
11 | import static org.springframework.util.StringUtils.hasText;
12 | import static org.springframework.web.servlet.support.ServletUriComponentsBuilder.fromContextPath;
13 |
14 | /**
15 | * @author Levin
16 | * @since 2018/12/6 0006
17 | */
18 | public class HostNameProvider {
19 | public HostNameProvider() {
20 | throw new UnsupportedOperationException();
21 | }
22 |
23 | public static UriComponents componentsFrom(
24 | HttpServletRequest request,
25 | String basePath) {
26 |
27 | ServletUriComponentsBuilder builder = fromServletMapping(request, basePath);
28 |
29 | UriComponents components = UriComponentsBuilder.fromHttpRequest(
30 | new ServletServerHttpRequest(request))
31 | .build();
32 |
33 | String host = components.getHost();
34 | if (!hasText(host)) {
35 | return builder.build();
36 | }
37 |
38 | builder.host(host);
39 | builder.port(components.getPort());
40 |
41 | return builder.build();
42 | }
43 |
44 | private static ServletUriComponentsBuilder fromServletMapping(
45 | HttpServletRequest request,
46 | String basePath) {
47 |
48 | ServletUriComponentsBuilder builder = fromContextPath(request);
49 |
50 | builder.replacePath(prependForwardedPrefix(request, basePath));
51 | if (hasText(new UrlPathHelper().getPathWithinServletMapping(request))) {
52 | builder.path(request.getServletPath());
53 | }
54 |
55 | return builder;
56 | }
57 |
58 | private static String prependForwardedPrefix(
59 | HttpServletRequest request,
60 | String path) {
61 |
62 | String prefix = request.getHeader("X-Forwarded-Prefix");
63 | if (prefix != null) {
64 | return prefix + path;
65 | } else {
66 | return path;
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/swagger-spring-boot-autoconfigure/src/main/java/com/battcn/boot/swagger/utils/RequestUtils.java:
--------------------------------------------------------------------------------
1 | package com.battcn.boot.swagger.utils;
2 |
3 | import com.battcn.boot.swagger.web.CustomSwagger2Controller;
4 | import org.slf4j.Logger;
5 | import org.slf4j.LoggerFactory;
6 | import org.springframework.http.HttpStatus;
7 | import org.springframework.http.MediaType;
8 |
9 | import javax.servlet.ServletOutputStream;
10 | import javax.servlet.http.HttpServletResponse;
11 | import java.io.IOException;
12 |
13 | /**
14 | * @author Levin
15 | * @since 2018/7/6 0006
16 | */
17 | public class RequestUtils {
18 |
19 | private RequestUtils() {
20 | }
21 |
22 | public static boolean SWAGGER_IS_LOGIN = false;
23 |
24 | private static final Logger logger = LoggerFactory.getLogger(CustomSwagger2Controller.class);
25 |
26 | public static void writeForbidden(HttpServletResponse response) throws IOException {
27 | final HttpStatus status = HttpStatus.UNAUTHORIZED;
28 | response.setStatus(status.value());
29 | response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
30 | ServletOutputStream outputStream = response.getOutputStream();
31 | String error = "{\"code\":%d,\"message\":\"%s\"}";
32 | final String format = String.format(error, status.value(), status.getReasonPhrase());
33 | logger.error(format);
34 | outputStream.write(format.getBytes());
35 | outputStream.flush();
36 | outputStream.close();
37 | }
38 |
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/swagger-spring-boot-autoconfigure/src/main/java/com/battcn/boot/swagger/web/CustomSwagger2Controller.java:
--------------------------------------------------------------------------------
1 | package com.battcn.boot.swagger.web;
2 |
3 | import com.battcn.boot.swagger.annotation.ApiOrder;
4 | import com.battcn.boot.swagger.model.Order;
5 | import com.battcn.boot.swagger.properties.SwaggerSecurityProperties;
6 | import com.battcn.boot.swagger.utils.HostNameProvider;
7 | import com.battcn.boot.swagger.utils.RequestUtils;
8 | import com.google.common.base.Strings;
9 | import com.google.common.collect.Lists;
10 | import io.swagger.annotations.Api;
11 | import io.swagger.models.Swagger;
12 | import io.swagger.models.Tag;
13 | import org.springframework.beans.factory.annotation.Autowired;
14 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
15 | import org.springframework.core.annotation.AnnotationUtils;
16 | import org.springframework.core.env.Environment;
17 | import org.springframework.http.HttpStatus;
18 | import org.springframework.http.MediaType;
19 | import org.springframework.http.ResponseEntity;
20 | import org.springframework.util.StringUtils;
21 | import org.springframework.web.bind.annotation.GetMapping;
22 | import org.springframework.web.bind.annotation.PostMapping;
23 | import org.springframework.web.bind.annotation.RequestParam;
24 | import org.springframework.web.bind.annotation.RestController;
25 | import org.springframework.web.method.HandlerMethod;
26 | import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
27 | import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
28 | import org.springframework.web.util.UriComponents;
29 | import springfox.documentation.annotations.ApiIgnore;
30 | import springfox.documentation.service.Documentation;
31 | import springfox.documentation.spring.web.DocumentationCache;
32 | import springfox.documentation.spring.web.json.Json;
33 | import springfox.documentation.spring.web.json.JsonSerializer;
34 | import springfox.documentation.spring.web.plugins.Docket;
35 | import springfox.documentation.swagger2.mappers.ServiceModelToSwagger2Mapper;
36 |
37 | import javax.servlet.http.HttpServletRequest;
38 | import javax.servlet.http.HttpServletResponse;
39 | import javax.servlet.http.HttpSession;
40 | import java.io.IOException;
41 | import java.util.HashMap;
42 | import java.util.List;
43 | import java.util.Map;
44 | import java.util.Optional;
45 |
46 | import static com.google.common.base.Strings.isNullOrEmpty;
47 |
48 | /**
49 | * @author Levin
50 | * @since 2018/7/6 0006
51 | */
52 | @ConditionalOnProperty(name = "spring.swagger.enabled", havingValue = "true", matchIfMissing = true)
53 | @RestController
54 | @ApiIgnore
55 | public class CustomSwagger2Controller {
56 |
57 | private static final String DEFAULT = "DEFAULT";
58 | private static final String V3_SWAGGER_API_DOCS = "/v3/api-docs";
59 | private static final String V3_SWAGGER_SECURITY_URL = "/v3/swagger-security";
60 | private static final String V3_SWAGGER_SECURITY_LOGIN_URL = "/v3/swagger-login";
61 | private final SwaggerSecurityProperties swaggerSecurityProperties;
62 |
63 | private final String hostNameOverride;
64 | private final DocumentationCache documentationCache;
65 | private final ServiceModelToSwagger2Mapper mapper;
66 | private final JsonSerializer jsonSerializer;
67 | private final RequestMappingHandlerMapping requestMappingHandlerMapping;
68 |
69 | @Autowired
70 | public CustomSwagger2Controller(SwaggerSecurityProperties swaggerSecurityProperties, Environment environment,
71 | DocumentationCache documentationCache,
72 | ServiceModelToSwagger2Mapper mapper,
73 | JsonSerializer jsonSerializer, RequestMappingHandlerMapping requestMappingHandlerMapping) {
74 | this.hostNameOverride = environment.getProperty("springfox.documentation.swagger.v2.host", "DEFAULT");
75 | this.documentationCache = documentationCache;
76 | this.mapper = mapper;
77 | this.jsonSerializer = jsonSerializer;
78 | this.swaggerSecurityProperties = swaggerSecurityProperties;
79 | this.requestMappingHandlerMapping = requestMappingHandlerMapping;
80 | }
81 |
82 | @GetMapping(value = V3_SWAGGER_SECURITY_URL, produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
83 | public ResponseEntity