我正在阅读有关flask-restx的swagger文档的the documentation,并遵循以下示例。我知道为了生成API参数的swagger文档,我应该这样做。
@api.doc(params={'id': 'An ID'})但是,我找不到如何记录API响应正文的解释。不是响应代码,而是get-method返回的结果。我要找的东西如下所示:
class MyResource(Resource):
@api.doc(returns={"info": "Some very interesting information"})
def get(self, id):
res = some_function_of_id(id)
return {"info": res}有没有人知道这是否可能,如果可能,是如何实现的?
发布于 2021-11-09 08:10:22
试用api.response装饰器
model = api.model('Model', {
'name': fields.String,
})
@api.route('/my-resource/')
class MyResource(Resource):
@api.response(200, 'Success', model)
@api.response(400, 'Validation Error')
def get(self):
pass请注意,@api.marshal_with()装饰器会自动记录响应。
https://stackoverflow.com/questions/69104988
复制相似问题