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

pom文件:

XML 复制代码
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>2023_demo</name>
    <description>2023_demo</description>

    <properties>
        <java.version>11</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-ui</artifactId>
            <version>1.6.11</version>
        </dependency>
        <dependency>
            <groupId>com.github.xiaoymin</groupId>
            <artifactId>knife4j-springdoc-ui</artifactId>
            <version>3.0.3</version>
        </dependency>


    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>aliyun-repo</id>
            <name>aliyun</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
        </repository>
    </repositories>

</project>

yum文件:

java 复制代码
server:
  port: 18080

springdoc:
  swagger-ui:
    enabled: true # 开关
    doc-expansion: none  #关闭展开
  api-docs:
    enabled: true # 开关

swagger配置文件

java 复制代码
package com.example.demo.config;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.models.parameters.Parameter;
import org.springdoc.core.GroupedOpenApi;
import org.springdoc.core.customizers.OperationCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @description
 
 * @author 
 * @since 2023/8/31
 */
@Configuration
@OpenAPIDefinition(info = @Info(title = "springDoc + knife 集成测试", version = "1.0",
        description = "swagger基础项目脚手架")
)
public class SwaggerConfig {

    @Bean
    public GroupedOpenApi usercApi() {
        return GroupedOpenApi.builder()
                .group("用户管理")
                .packagesToScan("com.example.demo.system")
                .pathsToMatch("/**")
                .build();
    }

    @Bean
    public GroupedOpenApi biApi(OperationCustomizer operationCustomizer) {
        return GroupedOpenApi.builder()
                .group("报表管理")
                .packagesToScan("com.example.demo.bi")
                .pathsToMatch("/**")
                .addOperationCustomizer(operationCustomizer)
                .build();
    }

    @Bean
    public OperationCustomizer operationCustomizer() {
        return (operation, handlerMethod) -> operation.addParametersItem(
                new Parameter()
                        .in("header")
                        .required(true)
                        .description("token 验证")
                        .name("token"));
    }

//    @Bean
//    public OpenApiCustomiser customerGlobalHeaderOpenApiCustomise() {
//        Parameter passwordParameter = new Parameter().name("password").description("密码").in(ParameterIn.QUERY.toString()).schema(new Schema<>().type("string"));
//        Parameter usernameParameter = new Parameter().name("username").description("用户名").in(ParameterIn.QUERY.toString()).schema(new Schema<>().type("string"));
//        ApiResponse apiResponse = new ApiResponse().content(new Content().addMediaType("*/*", new MediaType()));
//        PathItem pathItem = new PathItem().post(new Operation().summary("登录").tags(CollUtil.newArrayList("system/auth")).description("系统管理/鉴权接口").responses(new ApiResponses()
//                        .addApiResponse("default", apiResponse))
//                .parameters(CollUtil.newArrayList(usernameParameter, passwordParameter)));
//        return openApi -> openApi.path("/auth/login", pathItem);
//
//    }
}

访问swagger-ui:

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

相关推荐
UI设计兰亭妙微10 小时前
兰亭妙微ui设计公司分享:移动端界面用户友好型设计的核心思路
ui·移动端界面设计
青稞社区.11 小时前
小米大模型 Plus 团队提出BTL-UI:基于直觉-思考-关联的GUI Agent推理
人工智能·ui
weixin_5316518112 小时前
@clack/prompts 命令行终端中构建交互式用户界面
ui
Larry_Yanan12 小时前
Qt多进程(四)QTcpSocket
开发语言·c++·qt·ui
wtrees_松阳16 小时前
【弦断处见真章】:鸿蒙UI三重境之《UIContext》心法探幽
ui·华为·harmonyos
IT古董17 小时前
企业级官网全栈(React·Next.js·Tailwind·Axios·Headless UI·RHF·i18n)实战教程-第四篇:登录与注册系统(核心篇)
javascript·react.js·ui
梦想的旅途217 小时前
基于 UI 驱动(RPA)实现企业微信外部群自动化推送的技术逻辑
ui·自动化·企业微信·rpa
JosieBook18 小时前
【UI设计】智慧政务大屏 UI 设计深度解析:从战略意图到像素级落地
ui·政务
xinyu_Jina2 天前
Info Flow:大规模列表渲染中的UI虚拟化、数据懒-加载与前端性能工程
前端·ui
鼎道开发者联盟2 天前
构建活的界面:AIGUI底板的动态布局
人工智能·ui·ai·aigc·gui