|
|
|
@ -35,13 +35,14 @@ import java.util.List;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 做个测试
|
|
|
|
|
* @Author scott
|
|
|
|
|
*/
|
|
|
|
|
@Configuration
|
|
|
|
|
@EnableSwagger2 //开启 Swagger2
|
|
|
|
|
@Import(BeanValidatorPluginsConfiguration.class)
|
|
|
|
|
public class SwaggerFlowableConfig implements WebMvcConfigurer {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 导入配置文件中的值
|
|
|
|
|
*/
|
|
|
|
@ -59,7 +60,7 @@ public class SwaggerFlowableConfig implements WebMvcConfigurer {
|
|
|
|
|
registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
|
|
|
|
|
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* swagger2的配置文件,这里可以配置swagger2的一些基本的内容,比如扫描的包等等
|
|
|
|
|
*
|
|
|
|
@ -82,7 +83,7 @@ public class SwaggerFlowableConfig implements WebMvcConfigurer {
|
|
|
|
|
.securityContexts(securityContexts())
|
|
|
|
|
.globalOperationParameters(setHeaderToken());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
* oauth2配置
|
|
|
|
|
* 需要增加swagger授权回调地址
|
|
|
|
@ -104,7 +105,7 @@ public class SwaggerFlowableConfig implements WebMvcConfigurer {
|
|
|
|
|
pars.add(tokenPar.build());
|
|
|
|
|
return pars;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* api文档的详细信息函数,注意这里的注解引用的是哪个
|
|
|
|
|
*
|
|
|
|
@ -125,7 +126,7 @@ public class SwaggerFlowableConfig implements WebMvcConfigurer {
|
|
|
|
|
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html")
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 新增 securityContexts 保持登录状态
|
|
|
|
|
*/
|
|
|
|
@ -137,7 +138,7 @@ public class SwaggerFlowableConfig implements WebMvcConfigurer {
|
|
|
|
|
.build())
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<SecurityReference> defaultAuth() {
|
|
|
|
|
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
|
|
|
|
|
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
|
|
|
|
@ -145,7 +146,7 @@ public class SwaggerFlowableConfig implements WebMvcConfigurer {
|
|
|
|
|
return new ArrayList(
|
|
|
|
|
Collections.singleton(new SecurityReference(SystemConstants.X_ACCESS_TOKEN, authorizationScopes)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 解决springboot2.6 和springfox不兼容问题
|
|
|
|
|
* @return
|
|
|
|
@ -153,7 +154,7 @@ public class SwaggerFlowableConfig implements WebMvcConfigurer {
|
|
|
|
|
@Bean
|
|
|
|
|
public static BeanPostProcessor springfoxHandlerProviderBeanPostProcessor() {
|
|
|
|
|
return new BeanPostProcessor() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
|
|
|
|
if (bean instanceof WebMvcRequestHandlerProvider || bean instanceof WebFluxRequestHandlerProvider) {
|
|
|
|
@ -161,7 +162,7 @@ public class SwaggerFlowableConfig implements WebMvcConfigurer {
|
|
|
|
|
}
|
|
|
|
|
return bean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private <T extends RequestMappingInfoHandlerMapping> void customizeSpringfoxHandlerMappings(List<T> mappings) {
|
|
|
|
|
List<T> copy = mappings.stream()
|
|
|
|
|
.filter(mapping -> mapping.getPatternParser() == null)
|
|
|
|
@ -169,7 +170,7 @@ public class SwaggerFlowableConfig implements WebMvcConfigurer {
|
|
|
|
|
mappings.clear();
|
|
|
|
|
mappings.addAll(copy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
private List<RequestMappingInfoHandlerMapping> getHandlerMappings(Object bean) {
|
|
|
|
|
try {
|
|
|
|
|