【问题标题】:How to represent List of Strings in Springdoc Swagger v3?如何在 Springdoc Swagger v3 中表示字符串列表?
【发布时间】:2020-11-12 02:49:24
【问题描述】:

下面是和我的情况类似的代码

@ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "OK", content = {@Content(schema = @Schema(
                implementation =  // <-- What to specify here?
            ))})
})
@GetMapping(value = "/user")
public ResponseEntity<List<User>> getUsers() {
    return ResponseEntity.ok().body(Arrays.asList(new User(), new User()));
}

如何在ApiResponse() 中指定从端点返回的用户列表?

请注意,Open-API-Definition 不是项目的一部分,而是在另一个项目中指定的。

【问题讨论】:

    标签: springdoc swagger-3.0


    【解决方案1】:

    使用以下方法解决

    @ApiResponses(value = {
                @ApiResponse(responseCode = "200", description = "OK", content = {
                    @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))
                })
    })
    @GetMapping(value = "/user")
    public ResponseEntity<List<User>> getUsers() {
        return ResponseEntity.ok().body(Arrays.asList(new User(), new User()));
    }
    

    【讨论】:

    • 你知道如何向 List 添加模式吗?我尝试做@Schema(implementation = User.class, pattern = "pattern"),但它没有在 swagger 文档中生成。
    • 我没有遵循你所指的模式。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-18
    • 1970-01-01
    • 1970-01-01
    • 2023-01-15
    • 1970-01-01
    • 1970-01-01
    • 2022-11-05
    相关资源
    最近更新 更多