【发布时间】:2019-09-09 00:56:11
【问题描述】:
我的一个项目接受“插件”。这些插件需要提供一个特殊的 JSON 文件,其中包含一些元信息,并使用JSON Schema 描述事件对象。例如:
{
"name": "My component",
"description": "My super awesome component",
"documentation": "docs/main.md",
"maintainer": "john.doe@example.com",
"events": [{
"name": "click",
"description": "Occurs when the element is clicked.",
"data": [{
"name": "xPos",
"description": "The horizontal position of the click.",
"schema": {
"type": "integer",
"minimum": 0
}
}
]
}]
}
此元文件将根据 JSON 架构进行验证。现在我的问题是,如何验证 events[0].data[0].schema 条目的内容?在这种情况下,预期的字段是一个整数,但它也可以是任何其他类型。是否有 "type":"schema" 或 JSON Schema 中定义的类似内容?
(无论如何,我使用ajv 作为验证器。)
【问题讨论】:
标签: javascript json schema jsonschema