implementation 'com.github.xiaoymin:swagger-bootstrap-ui:1.9.6'
implementation 'com.spring4all:swagger-spring-boot-starter:1.9.1.RELEASE'
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
@Import({BeanValidatorPluginsConfiguration.class})
@EnableConfigurationProperties({SwaggerProperties.class})
@ConditionalOnProperty(
name = {"swagger.enabled"},
matchIfMissing = true
)
public class SwaggerAutoConfig {
public SwaggerAutoConfig() {
}
@Bean
@Order(1)
public Docket groupRestApi(SwaggerProperties swaggerProperties) {
return (new Docket(DocumentationType.SWAGGER_2)).host(swaggerProperties.getHost()).apiInfo(this.groupApiInfo(swaggerProperties)).select().apis(RequestHandlerSelectors.basePackage(swaggerProperties.getBasePackage())).paths(PathSelectors.any()).build().securityContexts(Lists.newArrayList(new SecurityContext[]{this.securityContext()})).securitySchemes(Lists.newArrayList(new SecurityScheme[]{this.apiKey()}));
}
private ApiInfo groupApiInfo(SwaggerProperties swaggerProperties) {
Contact contact = new Contact(swaggerProperties.getContact().getName(), "https://www.dqgs.fun", swaggerProperties.getContact().getEmail());
return (new ApiInfoBuilder()).title(swaggerProperties.getTitle()).description(swaggerProperties.getDescription()).termsOfServiceUrl("http://www.dqgs.fun/").version(swaggerProperties.getVersion()).contact(contact).build();
}
private ApiKey apiKey() {
return new ApiKey("BearerToken", "Authorization", "header");
}
private SecurityContext securityContext() {
return SecurityContext.builder().securityReferences(this.defaultAuth()).forPaths(PathSelectors.regex("/.*")).build();
}
private List<SecurityReference> defaultAuth() {
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
AuthorizationScope[] authorizationScopes = new AuthorizationScope[]{authorizationScope};
return Lists.newArrayList(new SecurityReference[]{new SecurityReference("BearerToken", authorizationScopes)});
}
}
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有