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
标签:knife4j,description,Copyright,api,文档,new,swagger
From: https://www.cnblogs.com/jiayuan2006/p/18146820