annotations - 定义openapi/swagger注解的常用参数
问题描述
在https://swagger.io/docs/specification/describing-parameters/ (OAS3) 上有一个通用参数的示例,可以通过 $ref 在路径和操作中引用:
components:
parameters:
offsetParam: # <-- Arbitrary name for the definition that will be used to refer to it.
# Not necessarily the same as the parameter name.
in: query
name: offset
required: false
schema:
type: integer
minimum: 0
description: The number of items to skip before starting to collect the result set.
limitParam:
in: query
name: limit
required: false
schema:
type: integer
minimum: 1
maximum: 50
default: 20
description: The numbers of items to return.
paths:
/users:
get:
summary: Gets a list of users.
parameters:
- $ref: '#/components/parameters/offsetParam'
- $ref: '#/components/parameters/limitParam'
responses:
'200':
description: OK
/teams:
get:
summary: Gets a list of teams.
parameters:
- $ref: '#/components/parameters/offsetParam'
- $ref: '#/components/parameters/limitParam'
responses:
'200':
description: OK
我将如何声明 Swagger Annotations 以产生此输出,尤其是在参数是原始类型的情况下?
我试过了
@Schema(type = "int")
@OpenAPIDefinition(info = @Info(description = "descr"))
public class OffsetParam {
public static final String DESCRIPTION =
"The number of items to skip before starting to collect the result set.";
@Parameter(description = "desc1")
public static OffsetParam valueOf(String value) {
return null;
}
}
但我只得到
"components" : {
"schemas" : {
"OffsetParam" : {
"type" : "object"
},...
您知道要向 JAX-RS 2.1 资源添加哪些 v3 注释吗?我的目标是一次性定义这些常用参数,并在我的应用程序的所有资源中引用它们。
解决方案
推荐阅读
- windows - WinAPI:可等待计时器在睡眠状态后是否恢复?
- ionic-framework - 如何在 Ionic/Angular 中自动刷新页面
- android - 如何使用 volley 从 getMethod() 返回值?
- ms-access - Access 中的 OpenQuery 宏 - 更新参数
- jsf - 警告:尽管有一些未处理的 FacesMessages
- python - 如何使用python在几个不同的行中找到一个模式
- swiftui - 形状的条件创建 - SwiftUI
- gnuplot - 带有 Gnuplot 的希腊字母
- c++ - 无效矩形背景
- tensorflow - ValueError:检查目标时出错:预期 conv2d_transpose_6 的形状为 (258, 258, 19) 但得到的数组形状为 (258, 258, 3)