在选择子模式时与oneOf发生冲突



我只是有一个非常困难的时间让一个工作。阅读似乎很简单,但要让它发挥作用似乎很难。我只是不知道为什么它不适合这个设置。这是我想要完成的。首先,我有一个模式,它应该能够根据数据结构的类型产生不同的名称。如果它是一个简单数组,那么它应该是productCodesList和它的属性,否则它应该是productsArray和它的属性。

{
"productCodesList":{
"codesIndex": 0,
"productCodes": [1]
}
}
{
"productsArray": {
"productsListIndex":0,
"productCodesArray": [ [] ]
} 
}

//This works, don't really know what's going on!
{
"productCodesList": {
"productCodes":0,
"productCodesArray": [ [] ]
} 
}
//This works though, I specify minItems:1
{
"productCodesList": {
"codesIndex":0,
"productCodes": [  ]
} 
}

{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "This my my attempt",
"additionalProperties":false,
"type": "object",
"required": ["productCodes"],
"properties": {
"productCodesList": {
"type":"object",
"additionalProperties":false,
"codesIndex": {
"type": "integer"
},
"productCodes": {
"type": "array",
"minItems": 1,
"items": {
"type": "integer"
}
}
},
"productsArray": {
"required":["productCodesArray"],
"type": "object",
"productsListIndex": {
"type": "integer"
},
"productCodesArray": {
"type": "array",
"minItems": 1,
"items": {
"type": "array",
"minItems": 1,
"items": {
"type": "integer"
}
}
}
}
},
"oneOf": [
{ "type": "object", "required": ["productCodesList"] },
{ "type": "object", "required": ["productsArray"] }
]
}

我只是想选择一种格式,但它抱怨我错过了objectproductcodes中缺少必需的属性。

您的模式顶部有"required": ["productCodes"]

最新更新