• springdoc-openapi-ui 整合 knife,多模块分组,脚手架


     pom文件:

    1. "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.0modelVersion>
    5. <parent>
    6. <groupId>org.springframework.bootgroupId>
    7. <artifactId>spring-boot-starter-parentartifactId>
    8. <version>2.7.2version>
    9. <relativePath/>
    10. parent>
    11. <groupId>com.examplegroupId>
    12. <artifactId>demoartifactId>
    13. <version>0.0.1-SNAPSHOTversion>
    14. <name>2023_demoname>
    15. <description>2023_demodescription>
    16. <properties>
    17. <java.version>11java.version>
    18. properties>
    19. <dependencies>
    20. <dependency>
    21. <groupId>org.springframework.bootgroupId>
    22. <artifactId>spring-boot-starterartifactId>
    23. dependency>
    24. <dependency>
    25. <groupId>org.projectlombokgroupId>
    26. <artifactId>lombokartifactId>
    27. <optional>trueoptional>
    28. dependency>
    29. <dependency>
    30. <groupId>org.springframework.bootgroupId>
    31. <artifactId>spring-boot-starter-testartifactId>
    32. <scope>testscope>
    33. dependency>
    34. <dependency>
    35. <groupId>org.springframework.bootgroupId>
    36. <artifactId>spring-boot-starter-webartifactId>
    37. dependency>
    38. <dependency>
    39. <groupId>org.springdocgroupId>
    40. <artifactId>springdoc-openapi-uiartifactId>
    41. <version>1.6.11version>
    42. dependency>
    43. <dependency>
    44. <groupId>com.github.xiaoymingroupId>
    45. <artifactId>knife4j-springdoc-uiartifactId>
    46. <version>3.0.3version>
    47. dependency>
    48. dependencies>
    49. <build>
    50. <plugins>
    51. <plugin>
    52. <groupId>org.springframework.bootgroupId>
    53. <artifactId>spring-boot-maven-pluginartifactId>
    54. <configuration>
    55. <excludes>
    56. <exclude>
    57. <groupId>org.projectlombokgroupId>
    58. <artifactId>lombokartifactId>
    59. exclude>
    60. excludes>
    61. configuration>
    62. plugin>
    63. plugins>
    64. build>
    65. <repositories>
    66. <repository>
    67. <id>aliyun-repoid>
    68. <name>aliyunname>
    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

  • 相关阅读:
    Leetcode 206反转链表、3无重复字符的最长子串、912排序数组(快排)、215数组中的第k个最大元素、53最大子数组和、152乘积最大子数组
    Mysql操作数据库查询数据
    2022年5月20日最全摸鱼游戏导航
    【白盒测试】单元测试的理论基础及用例设计技术(6种)详解
    typescript43-类型兼容性说明
    Hibernate JPA中的N+1 选择问题以及如何避免它
    平面设计实验四 绘制工具和修饰工具
    85智慧楼宇建设解决方案
    使用Webpack打包TS代码
    k8s-服务网格实战-入门Istio
  • 原文地址:https://blog.csdn.net/niuchenliang524/article/details/132619079