swagger 注解忽略字段、类、方法

文章目录

    • 1. 忽略字段
    • 2.忽略类
    • 3.忽略方法

Swagger 注解提供了多种忽略注解来控制 API 文档的生成。

1. 忽略字段

在字段上添加 @ApiModelProperty(hidden=true) 注解可以忽略该字段,例如:

public class User {
    private Long id;

    @ApiModelProperty(hidden=true)
    private String password;

    private String name;
    ...
}

2.忽略类

在类上添加 @ApiIgnore 注解可以忽略该类,例如:

@ApiIgnore
@RestController
public class TestController {
   ...
}

3.忽略方法

在方法上添加 @ApiOperation(hidden=true) 注解可以忽略该方法,例如:

@Api(tags = "用户管理")
public class UserController {

    @ApiOperation(value="获取用户列表", hidden=true)
    @GetMapping("/users")
    public List<User> getUsers() {
        // ...
    }

    @ApiOperation(value="获取单个用户信息")
    @GetMapping("/users/{id}")
    public User getUser(@PathVariable Long id) {
        // ...
    }
}

你可能感兴趣的:(swagger,java)