1.导入依赖
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
<version>4.5.0</version>
</dependency>
2.配置类
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class Knife4jConfig {
@Bean
public OpenAPI openAPI() {
return new OpenAPI().info(new Info()
.title("Cloud-platform-api-service Service Api")
.description("管理页面API")
.contact(new Contact().name("jjj"))
.version("1.0.0"));
}
}
3.application.yaml
# springdoc-openapi
springdoc:
swagger-ui:
path: /swagger-ui.html
tags-sorter: alpha
operations-sorter: order
api-docs:
path: /v3/api-docs
group-configs:
- group: 'api页面'
paths-to-match: '/organization-structure/**'
packages-to-scan: com.cloudservice
- group: '老版本'
paths-to-match: '/organization-manage/**'
packages-to-scan: com.cloudservice.organizationmanage
knife4j:
enable: true
setting:
language: zh_cn
4.常用注解
@Tag(name = "组织Tree的页面接口")
public class OrganizationTreeApiController
@Operation(summary = "获取多级分类")
public List<OrganizationVo> getTreeOfCompany(@Parameter(name = "orgId", description = "公司ID", required = true) @PathVariable("orgId") String orgId)
public class UpdateOrganizationVo {
/**
* id
*/
@Schema(description = "组织ID",requiredMode = Schema.RequiredMode.REQUIRED)
private Long id;