flask restx枚举模型 [英] flask restx enum model

查看:90
本文介绍了flask restx枚举模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How to create an Enum api model in flask restx with one string field without other properties so that the following description is generated in swagger.yml?

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

也许一些技巧会有所帮助?因为现在看来您只能创建仅具有属性的api模型

Maybe some hacks will help? Because now it seems like you can create an api model with properties only

推荐答案

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

Oh, so I find solution for my question)

自我回答,大声笑

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

You can define api model via json schema description: 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'
})

这篇关于flask restx枚举模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆