烧瓶restx枚举模型

时间:2020-10-07 22:52:20

标签: flask enums swagger flask-restplus

如何在烧瓶restx 中创建一个带其他属性的字符串字段的Enum api模型,以便在swagger.yml中生成以下描述?

definitions:
    Colors:
      type: string
      enum: [black, white, red, green, blue]

enter image description here 也许一些技巧会有所帮助? 因为现在看来您可以创建仅具有属性的api模型

1 个答案:

答案 0 :(得分:0)

哦,所以我找到了解决问题的方法)

自我回答,大声笑

您可以通过json模式描述定义api模型: https://flask-restx.readthedocs.io/en/latest/marshalling.html#define-model-using-json-schema

colors_api_model = api.schema_model('Colors', {
    'enum':
        ['black', 'white', 'red', 'green', 'blue'],
    'type': 'string'
})
相关问题