| | |
| | | import springfox.documentation.spi.DocumentationType; |
| | | import springfox.documentation.spring.web.plugins.Docket; |
| | | |
| | | /** |
| | | * Knife4j配置类 |
| | | * |
| | | * @author WWW |
| | | * @date 2024-09-12 |
| | | */ |
| | | @Configuration |
| | | @EnableKnife4j |
| | | @SuppressWarnings("ALL") |
| | | public class Knife4jConfig extends WebMvcConfigurationSupport { |
| | | @Value("${server.port}") |
| | | String serverPort; |
| | |
| | | @Bean |
| | | public Docket createRestApi() { |
| | | return new Docket(new DocumentationType("openApi", "3.0")) |
| | | // 是否启用Swagger |
| | | .enable(enabled) |
| | | // 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息) |
| | | .apiInfo(apiInfo()) |
| | | // 分组名称 |
| | | .groupName("服务") |
| | | // 设置哪些接口暴露给Swagger展示 |
| | | .select() |
| | | // 扫描所有有注解的api,用这种方式更灵活 |
| | | .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) |
| | | // 扫描指定包中的swagger注解 |
| | | // .apis(RequestHandlerSelectors.basePackage("com.cn.project.tool.swagger")) |
| | | // 扫描所有 .apis(RequestHandlerSelectors.any()) |
| | | .paths(PathSelectors.any()) |
| | | .build() |
| | | /* 设置安全模式,swagger可以设置访问token */ |
| | | // .securitySchemes(securitySchemes()) |
| | | .pathMapping(pathMapping); |
| | | } |
| | | |
| | | private ApiInfo apiInfo() { |
| | | return new ApiInfoBuilder() |
| | | //描述字段支持Markdown语法 |
| | | .description("接口文档") |
| | | .contact(new Contact("WuWeiwei", "http://127.0.0.1:" + serverPort + contextPath + "/doc.html", "252740454@qq.com")) |
| | | .version("0.2") |