我有以下架构文档
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "foo",
"definitions": {
"stuff": {
"type": "object",
"properties": {
"id": {
"description": "the id",
"type": "string"
},
"type": {
"description": "the type",
"type": "string"
}
},
"oneOf": [{
"required": ["id"]
}, {
"required": ["type"]
}],
},
},
"type": "object",
"properties": {
"bar": {
"description": "blah",
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/stuff"
}
}
},
"required": ["bar"]
}
我正在尝试创建烧瓶 restx 模型,但我不确定如何为所需的 OneOf 字段建模?
我认为以下将起作用,但随后它忽略了 oneof 要求。
stuff_model = (
"Stuff Model",
"id": fields.String(description="the id", required=False),
"type": fields.String(description="the type", required=False)
)
bar_model = (
"Bar Model",
"bar": fields.Nested(stuff_model, required=True)
)