java如何通过带@annotation的OpenAPI3.0描述我的对象的模式?
对此使用注释可以吗?我不懂如何使用Yaml
例如:
@Operation(summary = "Get page of top by rating articles by title")
@ApiResponses(value = {
@ApiResponse(responseCode = "200 successful operation",
content = @Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(???)))
})
@GetMapping(value = {"/articles/topByRating"})
@JsonView({JsonViews.Short.class})
@ResponseStatus(HttpStatus.OK)
public ItemsDto<Article> getArticlesTopByRating(@RequestParam int numberPage, @RequestParam int sizePage) {
return articleCrud.getTopByRating(numberPage, sizePage);
}
项目至:
public class ItemsDto<E> {
Long total = 0L;
List<E> items;
}
第条:
public class Article{
private Author author;
private String title;
private String body;
}
https://swagger.io/docs/specification/data-models/dictionaries/ 自由形式对象 如果字典值可以是任何类型(也称为自由形式对象),请使用additionalProperties:true:
1. type: object
2. additionalProperties: true
我将尝试使用'ref=myfile'。将“yaml”属性转换为@Schema注释
# 1 楼答案
springdoc openapi会自动将对象转换为模式
请注意,在DTO上,还可以添加@Schema注释以自定义不同的字段