如何使用@ArraySchema定义参数名称

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

我想使用 spring 和 swagger 来描述一个查询参数。 ReceiptStatus 是一个枚举。 我期望使用@ArraySchema中的

arrayschema

定义要解析为模式属性的属性 类型

array

根据文档:https://docs.swagger.io/swagger-core/v2.2.10/apidocs/io/swagger/v3/oas/annotations/media/ArraySchema.html

显然 name 不用于定义参数名称。

@ArraySchema(arraySchema = @Schema(description = "Status of the receipt", name = "status", example = "paid"))
private List<ReceiptStatus> statuses;

产生名称为 statuses 的数组类型参数

@Schema(description = "Status of the receipt", name = "status", example = "paid")
private List<ReceiptStatus> statuses;

产生名称为“status”的字符串类型参数。

有没有办法定义枚举列表并使用自定义参数名称?

spring swagger openapi
1个回答
0
投票

您可以尝试使用@ArraySchema的items属性。然后您可以在其 @Schema 实现属性中使用您想要的枚举类型。

   @ArraySchema(
       arraySchema = @Schema(description = "Status of the receipt", name = "status", example = "paid"),
       items = @Schema(implementation = ReceiptStatus.class)
   )
   private List<ReceiptStatus> statuses;
© www.soinside.com 2019 - 2024. All rights reserved.