OpenAPI 3.0 如何将 dto 字段显示为查询参数

问题描述 投票:0回答:1

我正在从 Swagger 2.x 迁移到 OpenAPI 3.0,并遇到了一些麻烦:我使用 ApiModel 和 ApiModelProperties 将 dto 字段显示为方法的参数,但现在它仅显示为没有字段描述的 JSON 对象。 现在看起来像: enter image description here 但我想要它: enter image description here

@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;

}
java swagger openapi
1个回答
0
投票

答案在问题的评论中,但我将其添加到此处以获得更多可见性。

要解决这个问题,只需在 Dto 对象的字段上添加 @Parameter 注释,并在控制器的参数上添加 @ParameterObject 注释即可!

感谢@Shamil Mukhetdinov 的修复!

© www.soinside.com 2019 - 2024. All rights reserved.