我在JSON项目的每个键上都出现“不允许其他属性”错误。下面是架构和项目。
架构:
{ "additionalProperties": false, "category": { "admin": {"type": "boolean"} }, "username": {"type": "string"}, "password": {"type": "string"}, "name": {"type": "string"}, "email": {"type": "string", "format": "email"}, "phone": {"type": "string"}, "hours": { "type": "array", "items": { "start": {"type": "string", "format": "date-time"}, "end": {"type": "string", "format": "date-time"} } } }
档案:
{ "username": "emanb29", "password": "$2a$10$THISISAPASSWORDHASH", "name": "Ethan Bell", "email": "eb@ethanbell.me", "phone": "5555555555", "hours": [ { "start": "1998-05-29T04:00:00Z", "end": "1999-05-29T04:00:00Z" }, { "start": "2001-05-29T10:20:00Z", "end": "2001-05-29T22:20:00Z" } ], "category": { "admin": true } }
答案 0 :(得分:2)
您的架构似乎很可疑。使用jsonschemalint.com上的示例,我在根目录中为您的属性创建了一个properties
容器,在根目录中添加了description
和type
,并将additionalProperties
移动到根目录好。
这会在jsonschemalint.com上验证您的项目:
{
"description": "StackOverflow test schema",
"type": "object",
"additionalProperties": false,
"properties": {
"category": {
"admin": {"type": "boolean"}
},
"username": {"type": "string"},
"password": {"type": "string"},
"name": {"type": "string"},
"email": {"type": "string", "format": "email"},
"phone": {"type": "string"},
"hours": {
"type": "array",
"items": {
"start": {"type": "string", "format": "date-time"},
"end": {"type": "string", "format": "date-time"}
}
}
}
}