![](/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.