【问题标题】:flask restx enum model烧瓶restx枚举模型
【发布时间】:2020-10-07 22:52:20
【问题描述】:

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

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

也许一些黑客会有所帮助? 因为现在看起来你可以创建一个只有属性的 api 模型

【问题讨论】:

    标签: flask enums swagger flask-restplus


    【解决方案1】:

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

    自答,哈哈

    您可以通过 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'
    })
    

    【讨论】:

      猜你喜欢
      • 2022-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-02
      • 2022-01-16
      • 2015-12-14
      • 1970-01-01
      • 2019-02-10
      相关资源
      最近更新 更多