这是我的JSON 架构:
{
"required": [
"username",
"password",
"confirmPassword"
],
"properties": {
"username": {
"minLength": 3,
"type": "string"
},
"password": {
"minLength": 6,
"type": "string"
},
"confirmPassword": {
"const": {
"$data": "1/password"
},
"type": "string"
}
},
"type": "object"
}
这是我的数据:
{
"username": "abc",
"password": "asdfasdf",
"confirmPassword": "asdfasdf"
}
你可以将它们复制粘贴到这个在线验证器中,看看会发生什么。
该confirmPassword
字段验证失败并显示错误消息:
值“asdfasdf”与 const 不匹配。
我相信我的相对 JSON 指针有问题,但我不知道正确的语法是什么。
AFAICT,1/password
意思是“上一层,然后检查password
属性”,但似乎并非如此。什么是正确的语法?
我正在使用的具体实现是 AJV,它表示它确实 支持 relative-JSON-pointers。