JSON模式更深层的对象唯一性 [英] JSON schema deeper object uniqueness
问题描述
我正在尝试进入 JSON模式定义,并希望了解如何实现模式定义中更深层的对象唯一性.请查看以下示例定义,在这种情况下,为模块的简单IO.
I'm trying to get into JSON schema definitions and wanted to find out, how to achieve a deeper object uniqueness in the schema definition. Please look at the following example definition, in this case a simple IO of a module.
{
"$schema": "http://json-schema.org/draft-06/schema#",
"type": "object",
"required": ["modulIOs"],
"properties": {
"modulIOs": {
"type": "array",
"uniqueItems": true,
"items": {
"allOf": [
{
"type": "object",
"required": ["ioPosition","ioType","ioFunction"],
"additionalProperties": false,
"properties": {
"ioPosition": {
"type": "integer"
},
"ioType": {
"type":"string",
"enum": ["in","out"]
},
"ioFunction": {
"type":"string"
}
}
}
]
}
}
}
}
当我通过i.E.验证以下内容时.草稿06我得到了肯定的肯定.
When I validate the following with i.E. draft-06 I get a positive validation.
{"modulIOs":
[
{
"ioPosition":1,
"ioType":"in",
"ioFunction":"240 V AC in"
},
{
"ioPosition":1,
"ioType":"in",
"ioFunction":"24 V DC in"
}
]
}
我知道验证是成功的,因为验证器执行了他打算做的事情-它检查JSON对象的结构,但是可以验证更深层对象中的对象值数据还是我需要执行其他地方的支票?
I'm aware that the validation is successfull because the validator does what he's intended to - it checks the structure of a JSON-object, but is there a possibility to validate object value data in deeper objects or do i need to perform the check elsewhere?
推荐答案
当前无法使用JSON模式(在草案7).
This is not currently possible with JSON Schema (at draft-7).
There is an issue raised on the official spec repo github for this: https://github.com/json-schema-org/json-schema-spec/issues/538
如果您(或阅读此书的任何人)真的想要这个,请竖起第一期评论.
If you (or anyone reading this) really wants this, please thumbsup the first issue comment.
目前不太可能将其纳入下一份草案,即使这样做,实现起来的时间也可能很长.
It's currently unlikely to make it into the next draft, and even if it did, time to impleemntations picking it up may be slow.
您需要在JSON模式验证过程之后执行此验证.
You'll need to do this validation after your JSON Schema validation process.
这篇关于JSON模式更深层的对象唯一性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!