简体   繁体   English

如何使用 OpenAPI 3 Swagger 注释指定列表

[英]How to specify a list using OpenAPI 3 Swagger annotations

For my API I'm making a meta annotation for handling Pagable parameters and for it I need to annotate a list of strings as a parameter that will show up in Swagger UI.对于我的 API,我正在制作一个元注释来处理Pagable参数,为此我需要将字符串列表注释为将显示在 Swagger UI 中的参数。

import io.swagger.v3.oas.annotations.Parameter;

@Parameter(name = "sort", in = ParameterIn.QUERY, schema = @Schema(implementation = String.class, type = "query"))
public @interface PageableQueryParameters {}

In order to sort by multiple criteria in Spring's Pageable the sort parameter needs to be provided as a list of strings.为了在 Spring 的Pageable按多个条件进行排序,需要将 sort 参数作为字符串列表提供。 Unfortunately I don't know how to declare the sort parameter as a list.不幸的是,我不知道如何将 sort 参数声明为列表。

How can I document a list of strings using Swagger's OpenAPI 3 annotations?如何使用 Swagger 的 OpenAPI 3 注释记录字符串列表?

If I'm understanding you correctly, to indicate that the "sort" parameter is a list, you need to use the parameters array like the following:如果我对你的理解正确,为了表明"sort"参数是一个列表,你需要使用如下所示的参数array

schema = @Schema(implementation = String.class, type = "query"

should be changed to应该改为

array = @ArraySchema(implementation = String.class)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Java 注释,有没有办法在其他模式中指定 Swagger/OpenAPI 模式? - Using Java annotations, is there a way to specify Swagger/OpenAPI schemas inside other schemas? Swagger / Openapi-Annotations:如何使用$ ref生成allOf? - Swagger/Openapi-Annotations: How to produce allOf with $ref? Swagger/OpenAPI 注释 V3 - 在 swagger 注释中使用枚举值 - Swagger/OpenAPI annotations V3 - use Enum values in swagger annotations OpenAPI / Swagger-UI注释和@BeanParam - OpenAPI/Swagger-UI Annotations & @BeanParam Swagger(OpenAPI):如何指定从自定义对象动态生成的示例字符串? - Swagger (OpenAPI) : how to specify example String dynamically generated from a custom Object? 如何使用JPA Annotations指定字段的类? - How to specify a class of a field using JPA Annotations? 如何传递列表<string>在 swagger 注释中 java with paramType="body"</string> - How to pass a List<String> in swagger annotations in java with paramType="body" 使用 Quarkus 时如何在 OpenAPI 中指定服务器 url 和描述? - How to specify server url and description in OpenAPI when using Quarkus? 使用带有 Lombok 注释的 OpenAPI 生成器生成 POJO - Generating POJOs using OpenAPI generator with Lombok Annotations 如何在 Gradle for OpenAPI 3.0 中使用 Swagger Codegen? - How to use Swagger Codegen in Gradle for OpenAPI 3.0?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM