【发布时间】:2017-02-15 15:12:36
【问题描述】:
我有以下两种模式:
A.json
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type":"object",
"properties":
{
"ArgumentChoice":{
"type" : "array",
"items" : {"$ref" : "B.json"}
}
}
}
B.json
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title" : "ArgumentChoiceType",
"type":"object",
"properties":{
"ArgumentInt" : {
"type" : "object",
"properties":{
"Value":{
"type" : "integer"
}
}
},
"ArgumentString" : {
"type" : "object",
"properties":{
"Value":{
"type" : "string"
}
}
}
}
}
下面是针对 A.json 验证的 json 请求:
{
"ArgumentChoice" : [
{
"ArgumentInt" : {
"Value" : 1
}
},
{
"ArgumentString" :
{
"Name" : "JOB_NAME",
"Value" : "test"
}
}
]
}
我的问题是,当我将 ArgumentInt 的值作为字符串传递时,它会失败,因为它接受整数值,我可以在报告消息中看到它。
但是,当我将 ArgumentString 的值作为整数传递时,它仍然失败,但我在消息中看不到由于输入错误类型而失败。
我猜只有ArgumentChoice 中的第一个数组元素会针对模式进行验证,因为如果我将ArgumentString 放在ArgumentInt 上方并且ArgumentString 中的值类型错误,它会失败。
我做错了吗?
【问题讨论】: