swagger 如何注解页面< Foo>以生成正确的响应

a8jjtwal  于 2023-01-26  发布在  其他
关注(0)|答案(1)|浏览(98)

RestController返回响应

Page<Foo>

我这样注解

@ApiResponses(value = {
    @ApiResponse(
            responseCode = "200",

            content = @Content(
                    mediaType = MediaType.APPLICATION_JSON_VALUE,
                    array = @ArraySchema(
                            schema = @Schema(implementation = Foo.class)
                    )),
            description = "The request has succeeded")

但是我需要生成页面而不是数组。
有没有办法做到这一点
如果应该是这样

schema PageFoo->data-> [{Foo}]

如果我删除注解,它将生成正确架构,但没有内容类型

icnyk63a

icnyk63a1#

@ApiResponses(value = {
    @ApiResponse(
        responseCode = "200",
        content = @Content(
            mediaType = MediaType.APPLICATION_JSON_VALUE,
            schema = @Schema(implementation = PageFoo.class)
        ),
        description = "The request has succeeded"
    )
})

class PageFoo {
    @Schema(name = "data", implementation = Foo.class, type = SchemaType.ARRAY)
    List<Foo> data;
    //...
}

相关问题