我正在从 Swagger 2.x 迁移到 OpenAPI 3.0,并遇到了一些麻烦:我使用 ApiModel 和 ApiModelProperties 将 dto 字段显示为方法的参数,但现在它仅显示为没有字段描述的 JSON 对象。 现在看起来像: 但我想要它:
@RequestMapping("/smth")
@RequiredArgsConstructor
@RestController
public class Controller {
@GetMapping
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "Filtered values")
public List<GD> findAll(Parameter(explode = Explode.TRUE) final PageFilter pageFilter) {
return baseAdapter.findAll(pageFilter);
}
D对:
@NoArgsConstructor
@AllArgsConstructor
@Data
@Builder
@Schema(type = "object")
public class PageFilter {
@Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE)
private static final String DELIMITER = ";";
@Schema(
name = "page",
description = "Results page you want to retrieve (0..N)",
example = DEFAULT_PAGE_STRING,
type = "integer")
private Integer page;
@Schema(
description = "Number of records per page",
example = DEFAULT_SIZE_STRING,
type = "integer")
private Integer size;
@Schema(
description =
"Sorting criteria in the format: property(propertyName;asc|desc). "
+ "Default sort order is ascending. Multiple sort criteria are supported.")
private String[] sort;
}
答案在问题的评论中,但我将其添加到此处以获得更多可见性。
要解决这个问题,只需在 Dto 对象的字段上添加 @Parameter 注释,并在控制器的参数上添加 @ParameterObject 注释即可!
感谢@Shamil Mukhetdinov 的修复!