如何解决OpenAPI 不验证字符串数组查询参数值
端点不再接受单个 id 参数
- name: id
in: query
schema:
$ref: "#/components/schemas/id"
接受一个数组:
- name: id
in: query
schema:
type: array
items:
$ref: "#/components/schemas/id"
id 定义为:
id:
type: string
pattern: "^[1-9][0-9]{0,9}$"
description: Identifies a Location within the EDDI API (has no wider interpretation).
example: "1"
但似乎模式验证在此过程中丢失了。阅读https://github.com/OpenAPITools/openapi-generator/issues/4947的内容后,我尝试这样实现:
- name: id
in: query
schema:
type: array
items:
type: object
properties:
item:
$ref: "#/components/schemas/id"
生成的 Id 对象甚至在 getter 上有 @Pattern(regexp="^[1-9][0-9]{0,9}$")
,在它的唯一字段 @Valid
上有 private @Valid String item;
,但 Jersey 似乎没有调用验证:约束列表中为空org.hibernate.validator.internal.engine.ValidatorImpl#validateMetaConstraints。看起来为了验证对象,我需要让 OpenApiGenerator 在自动生成的界面中的查询参数上放置 @Valid 约束...
有没有办法在 Jersey/Jetty 上强制执行 OpenApi 规范中定义的验证,而无需编写代码来手动验证后端参数?
附言正如错误(上面的链接)中所写的那样,将数组项定义为字符串不会产生@Valid ad @Pattern 注释
- name: id
in: query
schema:
type: array
items:
type: string
properties:
item:
$ref: "#/components/schemas/id"
P.P.S OpenApiGenerator 版本:4.3.1,Jersey 版本=2.29.1,Jetty 版本=9.4.6.v20170531
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。