簡體   English   中英

如何在 Flask Restx 中使用 model OneOf?

[英]How to model OneOf in Flask Restx?

我有以下架構文檔

{
    "$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"]
}

我正在嘗試創建 flask restx model,但我不確定如何 model 所需的 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)
)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM