| | |
| | | import org.springframework.context.annotation.Bean;
|
| | | import org.springframework.context.annotation.Configuration;
|
| | | import io.swagger.annotations.ApiOperation;
|
| | | import io.swagger.models.auth.In;
|
| | | import springfox.documentation.builders.ApiInfoBuilder;
|
| | | import springfox.documentation.builders.PathSelectors;
|
| | | import springfox.documentation.builders.RequestHandlerSelectors;
|
| | |
| | | import springfox.documentation.service.AuthorizationScope;
|
| | | import springfox.documentation.service.Contact;
|
| | | import springfox.documentation.service.SecurityReference;
|
| | | import springfox.documentation.service.SecurityScheme;
|
| | | import springfox.documentation.spi.DocumentationType;
|
| | | import springfox.documentation.spi.service.contexts.SecurityContext;
|
| | | import springfox.documentation.spring.web.plugins.Docket;
|
| | | import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
| | |
|
| | | /**
|
| | | * Swagger2的接口配置
|
| | |
| | | * @author ruoyi
|
| | | */
|
| | | @Configuration
|
| | | @EnableSwagger2
|
| | | public class SwaggerConfig
|
| | | {
|
| | | /** 系统基础配置 */
|
| | |
| | | @Bean
|
| | | public Docket createRestApi()
|
| | | {
|
| | | return new Docket(DocumentationType.SWAGGER_2)
|
| | | return new Docket(DocumentationType.OAS_30)
|
| | | // 是否启用Swagger
|
| | | .enable(enabled)
|
| | | // 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息)
|
| | |
| | | /**
|
| | | * 安全模式,这里指定token通过Authorization头请求头传递
|
| | | */
|
| | | private List<ApiKey> securitySchemes()
|
| | | private List<SecurityScheme> securitySchemes()
|
| | | {
|
| | | List<ApiKey> apiKeyList = new ArrayList<ApiKey>();
|
| | | apiKeyList.add(new ApiKey("Authorization", "Authorization", "header"));
|
| | | List<SecurityScheme> apiKeyList = new ArrayList<SecurityScheme>();
|
| | | apiKeyList.add(new ApiKey("Authorization", "Authorization", In.HEADER.toValue()));
|
| | | return apiKeyList;
|
| | | }
|
| | |
|
| | |
| | | securityContexts.add(
|
| | | SecurityContext.builder()
|
| | | .securityReferences(defaultAuth())
|
| | | .forPaths(PathSelectors.regex("^(?!auth).*$"))
|
| | | .operationSelector(o -> o.requestMappingPattern().matches("/.*"))
|
| | | .build());
|
| | | return securityContexts;
|
| | | }
|