。私のモデルorder.json
はthe model accepts only predefined propertiesように、私は"strict": true
を設定ループバックモデルオブジェクト厳格なフィルタのJSON配列
{
"name": "order",
"base": "PersistedModel",
"strict": true,
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"orderNo": {
"type": "string"
},
"lines": {
"type": [
{
"type": {
"description": "string",
"quantity": "number"
}
}
]
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
です。しかし、このは、アレイlines
にプロパティの動作しません。
I.E.あなたはAPIへのこのオブジェクトを投稿する場合は、予想通りValidationErrorを(コード422)を取得:
{
"orderNo": "xyz",
"someOtherProp": "hello",
"lines": [
{
"description": "abc",
"quantity": 5
}
]
}
をしかし、あなたは、このJSONオブジェクトのループバックを投稿する場合にMongoDBにオブジェクトを保存し
{
"orderNo": "xyz",
"lines": [
{
"description": "abc",
"quantity": 5,
"someOtherProp": "hello"
}
]
}
私の質問はおよそですオブジェクトの配列を検証するためにモデルJSONに設定されるフラグがあれば?または、自分自身でネストされたドキュメントをorder.js
model extension file経由で検証する必要がありますか?
を検証しますgithub.com/epoberezkin/ajv)を使用してモデルのプロパティを検証します。 – Syed