![](/img/trans.png)
[英]Form validation using javascript, validates only the first field even though it should be validating both
[英]JSON payload validates against schema even though field is missing
我假设我在定义模式时遗漏了一些东西。 注意form
属性下需要id
属性,但是JSON中没有提供,但是JSON根据多个在线JSON验证器正确验证。
架构
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://example.biz",
"type": "object",
"properties": {
"form": {
"type": "object",
"nullable": false,
"properties": {
"id": {
"type": "number",
"description": "The unique identifier of the form.",
"nullable": false
},
"name": {
"type": "string",
"description": "The name of the form.",
"nullable": false
}
}
}
}
}
JSON 有效载荷
{
"form": {
"name": "Test 2"
}
}
您的架构没有指定required
哪些属性。 您需要将required
设置为您想要在那里的字段。 您可能还希望将additionalProperties
设置为false
。
文档: https://json-schema.org/understanding-json-schema/reference/object.html#required-properties
我在 json 架构文档中的任何地方都没有将nullable
视为键。
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://example.biz",
"type": "object",
"properties": {
"form": {
"type": "object",
"properties": {
"id": {
"type": "number",
"description": "The unique identifier of the form."
},
"name": {
"type": "string",
"description": "The name of the form."
}
},
"required": ["id", "name"],
"additionalProperties": false
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.