[英]nested “oneOf” issue in json schema draft 4 using tv4.js
I'm using tv4.js to validate some json against a schema (which has nested oneOf properties) but it returns errors when I am using valid data. 我正在使用tv4.js来验证一些json对一个模式(它嵌套了oneOf属性)但是当我使用有效数据时它会返回错误。 Here is the result object I get back from the tv4.js validateMultiple method:
这是我从tv4.js validateMultiple方法返回的结果对象:
{"valid":false,"errors":[{"code":11,"message":"Data does not match any schemas from \"oneOf\"","schemaKey":null,"dataPath":"/shape","subErrors":[{"code":302,"message":"Missing required property: boxname","schemaKey":null,"dataPath":"/shape","subErrors":null},{"code":1,"message":"No enum match for: \"circle\"","schemaKey":null,"dataPath":"/shape/thetype","subErrors":null},{"code":12,"message":"Data is valid against more than one schema from \"oneOf\": indices 0 and 1","schemaKey":null,"dataPath":"/shape","subErrors":null}]}],"missing":[]}
Here is my test schema: 这是我的测试架构:
{
"type": "object",
"properties": {
"shape": {
"oneOf": [
{ "$ref":"#/definitions/squareSchema" },
{ "$ref":"#/definitions/circleSchema" }
]
}
},
"definitions": {
"squareSchema": {
"type": "object",
"properties": {
"thetype": {
"type": "string",
"enum": ["square"]
},
"colour":{},
"shade":{},
"boxname": {
"type":"string"
}
},
"oneOf":[
{ "$ref":"#/definitions/colourSchema" },
{ "$ref":"#/definitions/shadeSchema" }
],
"required": ["thetype", "boxname"],
"additionalProperties":false
},
"circleSchema": {
"type": "object",
"properties": {
"thetype": {
"type": "string",
"enum":["circle"]
},
"colour":{},
"shade":{}
},
"oneOf":[
{ "$ref":"#/definitions/colourSchema" },
{ "$ref":"#/definitions/shadeSchema" }
],
"additionalProperties":false
},
"colourSchema":{
"type":"object",
"properties":{
"colour":{
"type":"string"
},
"shade":{
"type":"null"
}
}
},
"shadeSchema":{
"type":"object",
"properties":{
"shade":{
"type":"string"
},
"colour":{
"type":"null"
}
}
}
}
}
And here is the data I would expect to validate: 以下是我希望验证的数据:
{
"shape": {
"thetype": "circle",
"shade":"red"
}
}
I seem to only encounter this issue when using nested "oneOf". 我似乎只在使用嵌套的“oneOf”时遇到此问题。 Is this an issue with my schema?
这是我的架构的问题吗? Or a bug with tv4.js?
或者是tv4.js的错误? Are there any alternative validators which will do this validation within a web browser?
是否有任何其他验证器可以在Web浏览器中进行此验证?
Any help would be appreciated. 任何帮助,将不胜感激。
It works for me (using the "Try out tv4" demo). 它适用于我 (使用“试用tv4”演示)。
Normally, I'd suggest you file a issue on the GitHub repo if you think you've found an error. 通常情况下,如果您认为发现了错误,我建议您在GitHub仓库上提出问题。 However, the fact that the error output includes
schemaKey
makes me think you're using a fairly old version. 但是,错误输出包含
schemaKey
这一事实让我觉得你使用的是一个相当旧的版本。
Are you using an up-to-date version of tv4? 您使用的是最新版本的tv4吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.