[英]Json Meta Schema : How to restrict another Json Schema from having nested objects
所以我使用 Json Meta Schema https://json-schema.org/draft/2019-09/meta/core使用https://github.com/java-json-tools/json-schema-进一步验证 JSONSchema-验证器
我有一个要求,我必须限制架构具有嵌套对象,如下面的架构应该是无效的
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://example.com/product.schema.json",
"title": "test",
"description": "A product from Acme's catalog",
"type": "object",
"properties": {
"productId": {
"description": "Outer",
"type": "object",
"properties": {
"lineId": {
"description": "Outer",
"type": "object"
}
}
}
}
}
由于productId
是一个对象并且它有另一个对象lineId
, productId
只能有 string 或 number 字段,而不能有 object ,如何扩展 MetaSchema 以强制执行此操作。 任何帮助表示赞赏
您的问题存在一些版本不一致,但我假设是 Draft-04,因为您使用的验证器仅支持最多 Draft-04。 如果您需要对其他草稿执行此操作,此过程将与 Draft-07 类似。 2019-09 年草案会更复杂。
type
和与对象相关的任何关键字,例如properties
。id
更改为独一无二的内容,例如https://my-project.com/nested-meta-schema
。{ "$ref": "#" }
) 替换为对您刚刚创建的架构的引用 ( { "$ref": "https://my-project.com/nested-meta-schema" }
)id
更改为独一无二的内容,例如https://my-project.com/flat-meta-schema
。$schema
更改为您为第二个元$schema
提供的 ID。请注意,并非所有实现都支持自定义元模式,因此您的里程可能会有所不同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.