java - 如何允许请求参数有多个预定义(枚举)值?

标签 java springdoc springdoc-openapi-ui

我想接收查询字符串参数的多个值,例如:

/api/assets?category=light&category=heavy

同时将允许的值限制为预定义的集合。

我已经找到how to limit the allowed values ,现在我怎样才能允许输入多个值?

这是我当前的代码:

public ApiRespSuccess<List<AssetApi>, ApiMetadataPagination> getAssets(
        @RequestParam @Parameter(schema=@Schema(description="param-desc", type="string", allowableValues= {"positioning", "energyReport"})) List<String> withExtFeature,
        @ParameterObject RequestPagination pagination) {
        // ...

如果我删除 @Parameter 注释,swagger-ui 会显示“添加项目”按钮。

最佳答案

这是实现目标的语法:

@GetMapping("/test")
public SampleDTO getFile(@RequestParam @Parameter(array = @ArraySchema(schema = @Schema(type = "string", allowableValues= {"positioning", "energyReport"})), description="param-desc") List<String> withExtFeature){
    return null;
}

关于java - 如何允许请求参数有多个预定义(枚举)值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62684380/

相关文章:

spring-boot - Swagger ui 使用 ip 和端口而不是域名

java - 是否有必要在 `volatile` 关键字之外添加 `synchronized` 关键字以使此类成为线程安全的?

java - 在大型应用程序中使用更好的方法

java - env.getProperty 不工作 Spring PropertyPlaceholderConfigurer

spring-boot - Springdoc 与多模块 gradle

java - springdoc-openapi 应用默认的全局 SecurityScheme 可能吗?

java - Spring:附件的 MimeMessageHelper 编码

spring - 如何在 springdoc Schema 中描述标准的 Spring 错误响应?

spring-boot - Spring-Doc open api 无法与 Spring cloud 配置服务器 @EnableConfigServer 一起使用

spring-boot - 如何使用 OpenApi 自定义 swagger-ui.html url