Json模式-如何表示混合类型(字符串和对象)的字段?
我在数据中有一个字段,可以多次键入: 它可以是type=string,具有以下架构:Json模式-如何表示混合类型(字符串和对象)的字段?,json,jsonschema,json-schema-validator,Json,Jsonschema,Json Schema Validator,我在数据中有一个字段,可以多次键入: 它可以是type=string,具有以下架构: {"mixed_field" : {"type":"string"} } 其他情况下,它可能是type=object,架构如下所示: {"mixed_field" : { "properties": { "access_token": { "type": "string" }, "created_at": { "type": "integer" }
{"mixed_field" : {"type":"string"} }
其他情况下,它可能是type=object,架构如下所示:
{"mixed_field" : {
"properties": {
"access_token": {
"type": "string"
},
"created_at": {
"type": "integer"
}
},
"type": "object"
}
}
如何表示“混合_字段”可以是类型字符串或类型对象?我应该使用下面的“oneOf”关键字吗
{
"mixed_field": {
"oneOf": [
{
"type": "string"
},
{
"properties": {
"access_token": {
"type": "string"
},
"created_at": {
"type": "integer"
}
},
"type": "object"
}
]
}
}
您可以使用/anyOf或
“type”:[“string”,“object”]
,如果是字符串,“properties”关键字将被忽略。不知道如果type是基元,“properties”将被忽略!谢谢你的提醒。使用关键字与枚举类型字段相比,是否有特定的偏好?