只允许在JSON模式中声明的属性 [英] Only allow properties that are declared in JSON schema
本文介绍了只允许在JSON模式中声明的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用json-schema,并且只想允许在此文件中声明的属性通过验证.例如,如果用户在其json对象中传递名称"属性,则该模式将失败,因为此处没有将名称"作为属性列出.
I am using json-schema and wanting to only allow properties that are declared in this file to pass validation. For instance if a user passes a "name" property in their json object it will fail this schema because "name" is not listed here as a property.
是否有一些类似于"required"的功能仅允许列出的属性通过?
Is there some function similar to "required" that will only allow the listed properties to pass?
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Accounting Resource - Add Item",
"type": "object",
"properties": {
"itemNumber": {
"type":"string",
"minimum": 3
},
"title": {
"type":"string",
"minimum": 5
},
"description": {
"type":"string",
"minimum": 5
}
},
"required": [
"itemNumber",
"title",
"description"
]
}
推荐答案
我相信将additionalProperties
设置为false可以实现此目的.请参见此处
I believe what you need to do to achieve this is set additionalProperties
to false. See the specification here
这篇关于只允许在JSON模式中声明的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文