knife4j api文件使用說明

漠孤烟發表於2024-04-19

1、引入依賴:

        <dependency>
            <groupId>com.github.xiaoymin</groupId>
            <artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
            <version>4.5.0</version>
        </dependency>

2、Configuration

@Configuration
public class SwaggerDocConfig {

    @Bean
    public OpenAPI customOpenAPI() {
        return new OpenAPI()
                .components(new Components().addSecuritySchemes("basicScheme", new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic"))
                        .addParameters("X-Author", new Parameter().in("header").schema(new StringSchema()).name("X-Copyright-Schema"))
                        .addHeaders("X-Copyright-Start", new Header().description("Source Code Copyright declare").schema(new StringSchema())))
                .info(new Info()
                        .title("title")
                        .version("1.0.0")
                        .description("description")
                        .termsOfService("http://swagger.io/terms/")
                        .license(new License().name("Apache 2.0").url("http://springdoc.org")));
    }

}

3、配置

springdoc:
  swagger-ui:
    path: /swagger-ui.html
    tags-sorter: alpha
    operations-sorter: alpha
  api-docs:
    path: /v3/api-docs
  group-configs:
    - group: 'default'
      paths-to-match: '/**'
      packages-to-scan: com.abc.controller
# knife4j的增強配置,不需要增強可以不配
knife4j:
  enable: true
  setting:
    language: zh_cn

相關文章