如何验证JSON模式中的整数长度?
模拟器: https://www.jsonschemavalidator.net/sschemavalidator.net/s/l3fmjnoe </
l3fmjnoe 验证不会检查整数的正则方式。 如何验证整数的长度?
JSON Schema-
{
"$schema": "http://json-schema.org/draft/2019-09/schema",
"title": "title",
"type": "object",
"properties": {
"amount": {
"type": "integer",
"example": 199,
"maxLength": 1,
"pattern": "^[0-9]{1}$"
}
}
}
我的JSON应该失败验证但没有 -
{
"amount": 343434343434343434334343434343434
}
Simulator: https://www.jsonschemavalidator.net/s/L3FmJnoE
It looks like json schema validation does not check for regex patterns for integers.
How to validate for length of an integer?
Json Schema -
{
"$schema": "http://json-schema.org/draft/2019-09/schema",
"title": "title",
"type": "object",
"properties": {
"amount": {
"type": "integer",
"example": 199,
"maxLength": 1,
"pattern": "^[0-9]{1}quot;
}
}
}
My Json which should fail validation but does not -
{
"amount": 343434343434343434334343434343434
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看
最大
(“规范” )关键字和相关的值,以设置数字的最大值。正则表达式仅应用于字符串值(在这里)。(
maxlength
也仅应用于字符串值)Take a look at the
maximum
(specification) keyword and the related ones to set a maximum value for numbers. Regular expressions are only applied to string values (more details here).(
maxLength
is also only applied to string values)