[英]JSON schema + relative JSON-pointers: how to verify “confirm password” field
這是我的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,它說它確實 支持相對JSON指針 。
原來唯一的問題是我忘了將$data
選項設置為true
。 例如
const ajv = new Ajv({
allErrors: true,
$data: true,
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.