接入
引入依赖
引用 Knife4j 的 starter
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
<version>4.4.0</version>
</dependency>
修改配置
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.ftl.xtrack
# knife4j的增强配置,不需要增强可以不配
knife4j:
enable: false
setting:
language: zh_cn
使用示例
接口示例
@RestController
@Tag(name = "用户 API", description = "用户相关接口")
public class UserController {
@Operation(summary = "普通body请求", description = "普通body请求")
@PostMapping("/body")
public ResponseEntity<User> body(@RequestBody User user) {
return ResponseEntity.ok(user);
}
@Operation(summary = "普通body请求+Param+Header+Path")
@Parameters({
@Parameter(name = "id", description = "文件id", in = ParameterIn.PATH),
@Parameter(name = "token", description = "请求token", required = true, in = ParameterIn.HEADER),
@Parameter(name = "name", description = "文件名称", required = true, in = ParameterIn.QUERY)
})
@PostMapping("/bodyParamHeaderPath/{id}")
public ResponseEntity<User> bodyParamHeaderPath(
@PathVariable("id") String id,
@RequestHeader("token") String token,
@RequestParam("name") String name,
@RequestBody User user) {
user.setName(user.getName() + ",receiveName:" + name + ",token:" + token + ",pathID:" + id);
return ResponseEntity.ok(user);
}
}
实体示例
@Getter
@Setter
@ApiModel( value = "用户", description = "用户信息实体")
public class User {
@ApiModelProperty(value = "姓名", required = true, example = "张三")
private String name;
@ApiModelProperty(value = "年龄", required = true, example = "20")
private Integer age;
@ApiModelProperty(hidden = true)
private LocalDateTime createdAt;
}
标签:body,Swgger3,name,接入,token,user,id,description
From: https://www.cnblogs.com/booleandev/p/18413409/swgger3-access-z1ijs9w