java - openapi - 不允许空格或连字符的正则表达式
问题描述
我正在使用 openapi 3.0.3 自动生成基于 Spring Boot 的 REST API ...
内部src/main/resources/openapi/schema/PurchaseOrder.yaml
:
openapi: '3.0.3'
info:
title: 'Purchase Order'
version: '1.0'
paths: {}
components:
schemas:
PurchaseOrder:
title: 'Purchase Order'
type: 'object'
properties:
account:
type: 'string'
description: Identifier for account making the purchase
example: 1
minLength: 1
pattern: '^\s-$'
所以,我需要它包含字母数字值但没有空格(尝试使用 this pattern: '^\s-$'
) - 根本不能有空格......
尝试时:
{
account: 'a b'
}
这是我收到的 JSON 响应:
"validationErrors": [
{
"field": "account",
"message": "must match \"^\\s-$\""
}
]
当我尝试使用有效的 JSON(包含多个字符且没有空格和连字符)时,也会发生同样的验证错误:
{
'account': 'ab'
}
这应该是有效的并且没有抛出任何验证错误......
如何在此 yaml 文件中使用正则表达式完全不强制使用空格和/或连字符?
解决方案
推荐阅读
- c# - 尝试将动态列表转换为 Dataview 时“无法将外部对象添加到此列表”
- elasticsearch - elasticdump - 如何有效地转储大量数据
- clickhouse - Clickhouse-mysql 不运行
- tensorflow - 在 tf.function 中使用复杂的控制流可以吗?
- javascript - Bootstrap表格过滤器控制搜索使用后如何清除输入框
- apache-kafka - Kafka-在复合键上加入 KStream 和 KTable
- delphi - 构建工具宏失败的解决方法?
- python - 在 imshow 和 Legend 中调整散点图大小
- python - cv2.Rodrigues() 在相机校准环境中应用于 rvec 的目的是什么
- c# - 使用实体框架核心更新多条记录