我在flask中使用flask_restplus swagger获取api文档。我想为将数据发布到数据库的api创建一个模型定义。我的问题是,数据是数组形式的。我正在用post请求发送以下格式的数据。
{
"user_id" : 3,
"product" : [
{
"product_id" : 33,
"total_price" : 50,
"quantity": 2
},
{
"product_id" : 18,
"total_price" : 40,
"quantity": 2
}
]
}我们如何为这种类型的结构定义模型?我在正文中发送数据。
发布于 2019-03-13 17:56:56
如果您仍在寻找答案,请访问以下帮助https://github.com/noirbizarre/flask-restplus/issues/18链接
我有类似的问题,我使用这个链接来解决我的问题
解决方案的一部分可能是这个帮助
{"product" : [
{
"product_id" : 33,
"total_price" : 50,
"quantity": 2
},
{
"product_id" : 18,
"total_price" : 40,
"quantity": 2
}
]
}
order = api.model( "product" : { "product_id" : fields.String, "total_price" : fields.Integer, "quantity": fields.Integer } })
@api.route('/somewhere')
class MyAPI(Resource):
@api.expect([order])
def post(self):
pass
or
@api.route('/somewhere')
class MyAPI(Resource):
@api.doc(body=[order])
def post(self):
pass对于"user_id“,我将使用@api.extend来扩展我的模型并尝试,因为我还没有尝试过,所以我无法评论,你需要检查这部分并更新
https://stackoverflow.com/questions/54263231
复制相似问题