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

 pom文件:



    4.0.0

    
        org.springframework.boot
        spring-boot-starter-parent
        2.7.2
         
    

    com.example
    demo
    0.0.1-SNAPSHOT
    2023_demo
    2023_demo

    
        11
    

    
        
            org.springframework.boot
            spring-boot-starter
        

        
            org.projectlombok
            lombok
            true
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        

        
            org.springframework.boot
            spring-boot-starter-web
        

        
            org.springdoc
            springdoc-openapi-ui
            1.6.11
        
        
            com.github.xiaoymin
            knife4j-springdoc-ui
            3.0.3
        


    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
                
                    
                        
                            org.projectlombok
                            lombok
                        
                    
                
            
        
    

    
        
            aliyun-repo
            aliyun
            http://maven.aliyun.com/nexus/content/groups/public/
        
    


yum文件:

server:
  port: 18080

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

swagger配置文件

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:

springdoc-openapi-ui 整合 knife,多模块分组,脚手架_第1张图片

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

springdoc-openapi-ui 整合 knife,多模块分组,脚手架_第2张图片

你可能感兴趣的:(ui)