我正在构建一个API,并且所有列表操作都返回我从Paged
调用的同一对象:
public class Paged<T> {
public static <J> Paged<J> of(int offset, int limit, long total, List<J> results) {
return new Paged<>(offset, limit, total, results);
}
public Paged() {
}
private Paged(int offset, int limit, long total, List<T> results) {
this.offset = offset;
this.limit = limit;
this.total = total;
this.results = results;
}
private int offset;
private int limit;
private long total;
private List<T> results;
public int getOffset() {
return offset;
}
public void setOffset(int offset) {
this.offset = offset;
}
public int getLimit() {
return limit;
}
public void setLimit(int limit) {
this.limit = limit;
}
public long getTotal() {
return total;
}
public void setTotal(long total) {
this.total = total;
}
public List<T> getResults() {
return results;
}
public void setResults(List<T> results) {
this.results = results;
}
}
如何告诉Microprofile OpenApi来自Paged
的响应是User
的列表?
@Operation(summary = "List all users", description = "List all users")
@APIResponse(responseCode = "200", description = "All Users", content = { @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = Paged.class, type = SchemaType.OBJECT)) })
使用上面的注释,我有以下文档:
content:
application/json:
schema:
type: object
properties:
limit:
format: int32
type: integer
offset:
format: int32
type: integer
results:
type: array
items:
type: object
total:
format: int64
type: integer
当我期待类似的东西时:
content:
application/json:
schema:
type: object
properties:
limit:
format: int32
type: integer
offset:
format: int32
type: integer
results:
type: array
items:
$ref: '#/components/schemas/User'
total:
format: int64
type: integer