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?
如何在flaskRESTX中创建一个只有一个字符串字段而没有其他属性的Enum API模型,以便在swagger.yml中生成以下描述?
definitions:
Colors:
type: string
enum: [black, white, red, green, blue]
Maybe some hacks will help?
Because now it seems like you can create an api model with properties only
也许黑客会有所帮助?因为现在您似乎可以创建仅具有属性的API模型
更多回答
优秀答案推荐
Oh, so I find solution for my question)
哦,所以我找到了我的问题的答案)
Self-answered, lol
自答式,哈哈
You can define api model via json schema description:
https://flask-restx.readthedocs.io/en/latest/marshalling.html#define-model-using-json-schema
您可以通过JSON模式描述定义接口模型: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'
})
For new comers, flask restx now supports an enum property for String type
对于新来者,flaskRESTX现在支持字符串类型的枚举属性
theme_color = api.model( "theme_color", {
"appTheme": fields.String(description="UI primary colour",enum=["theme-red", "theme-pink", "theme-orange", "theme-yellow"])
})
Example documentation here
此处提供了示例文档
更多回答
我是一名优秀的程序员,十分优秀!