我使用的SpringBoot具有以下依赖项
<dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-ui</artifactId> <version>1.5.12</version> </dependency>
控制器类(@RestController)有一个入口点(@ return ),这个入口点应该返回对象的列表:MyClass.java。我在方法上面添加了Swagger注释,以便通过swagger页面创建API文档。
swagger文档应指示返回对象的类型。
List< MyClass>
但我该怎么做呢?如果我做了
@Schema(implementation= List< MyClass >.class)
编译错误。
摆动注释:
@operation(.)@ApiResponse(value={ @ApiResponse(responseCode = "200",description = "successful“),content ={ @Content(mediaType = "application/json",schema = @Schema(implementation =?) }),@ApiResponse(.),@ApiResponse(.)@/aaa,MediaType.APPLICATION_JSON_VALUE)公共列表getAaa(.){返回.}
发布于 2021-11-01 17:26:42
为此,您需要使用ArraySchema注释,并将其分配给array
属性,而不是@Content
注释的schema
属性。您不需要只指定List.class
的类型参数MyClass.class
。
@Operation(
summary = "Get a list of users",
description = "Get a list of users registered in the system",
responses = {@ApiResponse(
responseCode = "200",
description = "The response for the user request",
content = {
@Content(
mediaType = "application/json",
array = @ArraySchema(schema = @Schema(implementation = User.class))
)
})
}
)
@GET
@SecurityRequirement(name = "JWT")
@Path("/user")
public List<User> getUsers() {
return null;
}
https://stackoverflow.com/questions/69799828
复制相似问题