| | |
| | | |
| | | /** |
| | | * Swagger2的接口配置 |
| | | * |
| | | * @author ruoyi |
| | | * |
| | | * @author Lion Li |
| | | */ |
| | | @Configuration |
| | | @EnableSwagger2WebMvc |
| | | @EnableKnife4j |
| | | public class SwaggerConfig |
| | | { |
| | | /** 系统基础配置 */ |
| | | public class SwaggerConfig { |
| | | /** |
| | | * 系统基础配置 |
| | | */ |
| | | @Autowired |
| | | private RuoYiConfig ruoyiConfig; |
| | | |
| | | /** 是否开启swagger */ |
| | | /** |
| | | * 是否开启swagger |
| | | */ |
| | | @Value("${swagger.enabled}") |
| | | private boolean enabled; |
| | | |
| | | /** 设置请求的统一前缀 */ |
| | | /** |
| | | * 设置请求的统一前缀 |
| | | */ |
| | | @Value("${swagger.pathMapping}") |
| | | private String pathMapping; |
| | | |
| | | /** |
| | | * 标题 |
| | | */ |
| | | @Value("${swagger.title}") |
| | | private String title; |
| | | |
| | | /** |
| | | * 描述 |
| | | */ |
| | | @Value("${swagger.description}") |
| | | private String description; |
| | | |
| | | /** |
| | | * 版本 |
| | | */ |
| | | @Value("${swagger.version}") |
| | | private String version; |
| | | |
| | | /** |
| | | * 创建API |
| | | */ |
| | | @Bean |
| | | public Docket createRestApi() |
| | | { |
| | | public Docket createRestApi() { |
| | | return new Docket(DocumentationType.SWAGGER_2) |
| | | // 是否启用Swagger |
| | | .enable(enabled) |
| | |
| | | /** |
| | | * 安全模式,这里指定token通过Authorization头请求头传递 |
| | | */ |
| | | private List<ApiKey> securitySchemes() |
| | | { |
| | | private List<ApiKey> securitySchemes() { |
| | | List<ApiKey> apiKeyList = new ArrayList<ApiKey>(); |
| | | apiKeyList.add(new ApiKey("Authorization", "Authorization", "header")); |
| | | return apiKeyList; |
| | |
| | | /** |
| | | * 安全上下文 |
| | | */ |
| | | private List<SecurityContext> securityContexts() |
| | | { |
| | | private List<SecurityContext> securityContexts() { |
| | | List<SecurityContext> securityContexts = new ArrayList<>(); |
| | | securityContexts.add( |
| | | SecurityContext.builder() |
| | |
| | | /** |
| | | * 默认的安全上引用 |
| | | */ |
| | | private List<SecurityReference> defaultAuth() |
| | | { |
| | | private List<SecurityReference> defaultAuth() { |
| | | AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything"); |
| | | AuthorizationScope[] authorizationScopes = new AuthorizationScope[1]; |
| | | authorizationScopes[0] = authorizationScope; |
| | |
| | | /** |
| | | * 添加摘要信息 |
| | | */ |
| | | private ApiInfo apiInfo() |
| | | { |
| | | private ApiInfo apiInfo() { |
| | | // 用ApiInfoBuilder进行定制 |
| | | return new ApiInfoBuilder() |
| | | // 设置标题 |
| | | .title("标题:若依管理系统_接口文档") |
| | | .title(title) |
| | | // 描述 |
| | | .description("描述:用于管理集团旗下公司的人员信息,具体包括XXX,XXX模块...") |
| | | .description(description) |
| | | // 作者信息 |
| | | .contact(new Contact(ruoyiConfig.getName(), null, null)) |
| | | // 版本 |
| | | .version("版本号:" + ruoyiConfig.getVersion()) |
| | | .version(version) |
| | | .build(); |
| | | } |
| | | } |