当前位置:   article > 正文

【Openapi-ui+Knife】springdoc-openapi-ui 整合 knife,多模块分组,脚手架

springdoc-openapi-ui

 pom文件:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <parent>
  6. <groupId>org.springframework.boot</groupId>
  7. <artifactId>spring-boot-starter-parent</artifactId>
  8. <version>2.7.2</version>
  9. <relativePath/> <!-- lookup parent from repository -->
  10. </parent>
  11. <groupId>com.example</groupId>
  12. <artifactId>demo</artifactId>
  13. <version>0.0.1-SNAPSHOT</version>
  14. <name>2023_demo</name>
  15. <description>2023_demo</description>
  16. <properties>
  17. <java.version>11</java.version>
  18. </properties>
  19. <dependencies>
  20. <dependency>
  21. <groupId>org.springframework.boot</groupId>
  22. <artifactId>spring-boot-starter</artifactId>
  23. </dependency>
  24. <dependency>
  25. <groupId>org.projectlombok</groupId>
  26. <artifactId>lombok</artifactId>
  27. <optional>true</optional>
  28. </dependency>
  29. <dependency>
  30. <groupId>org.springframework.boot</groupId>
  31. <artifactId>spring-boot-starter-test</artifactId>
  32. <scope>test</scope>
  33. </dependency>
  34. <dependency>
  35. <groupId>org.springframework.boot</groupId>
  36. <artifactId>spring-boot-starter-web</artifactId>
  37. </dependency>
  38. <dependency>
  39. <groupId>org.springdoc</groupId>
  40. <artifactId>springdoc-openapi-ui</artifactId>
  41. <version>1.6.11</version>
  42. </dependency>
  43. <dependency>
  44. <groupId>com.github.xiaoymin</groupId>
  45. <artifactId>knife4j-springdoc-ui</artifactId>
  46. <version>3.0.3</version>
  47. </dependency>
  48. </dependencies>
  49. <build>
  50. <plugins>
  51. <plugin>
  52. <groupId>org.springframework.boot</groupId>
  53. <artifactId>spring-boot-maven-plugin</artifactId>
  54. <configuration>
  55. <excludes>
  56. <exclude>
  57. <groupId>org.projectlombok</groupId>
  58. <artifactId>lombok</artifactId>
  59. </exclude>
  60. </excludes>
  61. </configuration>
  62. </plugin>
  63. </plugins>
  64. </build>
  65. <repositories>
  66. <repository>
  67. <id>aliyun-repo</id>
  68. <name>aliyun</name>
  69. <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
  70. </repository>
  71. </repositories>
  72. </project>

yum文件:

  1. server:
  2. port: 18080
  3. springdoc:
  4. swagger-ui:
  5. enabled: true # 开关
  6. doc-expansion: none #关闭展开
  7. api-docs:
  8. enabled: true # 开关

swagger配置文件

  1. package com.example.demo.config;
  2. import io.swagger.v3.oas.annotations.OpenAPIDefinition;
  3. import io.swagger.v3.oas.annotations.info.Info;
  4. import io.swagger.v3.oas.models.parameters.Parameter;
  5. import org.springdoc.core.GroupedOpenApi;
  6. import org.springdoc.core.customizers.OperationCustomizer;
  7. import org.springframework.context.annotation.Bean;
  8. import org.springframework.context.annotation.Configuration;
  9. /**
  10. * @description
  11. * @author
  12. * @since 2023/8/31
  13. */
  14. @Configuration
  15. @OpenAPIDefinition(info = @Info(title = "springDoc + knife 集成测试", version = "1.0",
  16. description = "swagger基础项目脚手架")
  17. )
  18. public class SwaggerConfig {
  19. @Bean
  20. public GroupedOpenApi usercApi() {
  21. return GroupedOpenApi.builder()
  22. .group("用户管理")
  23. .packagesToScan("com.example.demo.system")
  24. .pathsToMatch("/**")
  25. .build();
  26. }
  27. @Bean
  28. public GroupedOpenApi biApi(OperationCustomizer operationCustomizer) {
  29. return GroupedOpenApi.builder()
  30. .group("报表管理")
  31. .packagesToScan("com.example.demo.bi")
  32. .pathsToMatch("/**")
  33. .addOperationCustomizer(operationCustomizer)
  34. .build();
  35. }
  36. @Bean
  37. public OperationCustomizer operationCustomizer() {
  38. return (operation, handlerMethod) -> operation.addParametersItem(
  39. new Parameter()
  40. .in("header")
  41. .required(true)
  42. .description("token 验证")
  43. .name("token"));
  44. }
  45. // @Bean
  46. // public OpenApiCustomiser customerGlobalHeaderOpenApiCustomise() {
  47. // Parameter passwordParameter = new Parameter().name("password").description("密码").in(ParameterIn.QUERY.toString()).schema(new Schema<>().type("string"));
  48. // Parameter usernameParameter = new Parameter().name("username").description("用户名").in(ParameterIn.QUERY.toString()).schema(new Schema<>().type("string"));
  49. // ApiResponse apiResponse = new ApiResponse().content(new Content().addMediaType("*/*", new MediaType()));
  50. // PathItem pathItem = new PathItem().post(new Operation().summary("登录").tags(CollUtil.newArrayList("system/auth")).description("系统管理/鉴权接口").responses(new ApiResponses()
  51. // .addApiResponse("default", apiResponse))
  52. // .parameters(CollUtil.newArrayList(usernameParameter, passwordParameter)));
  53. // return openApi -> openApi.path("/auth/login", pathItem);
  54. //
  55. // }
  56. }

访问swagger-ui

访问doc.html: http://localhost:18080/doc.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/616039
推荐阅读
相关标签
  

闽ICP备14008679号