flask-restplus marshal_with()与doc()装饰器位置问题

yourapp.marshal_with(model)必须跟紧youapp.doc()才会在swagger页面上展示model

先看这段代码:

@api.doc('GetList')
@api.param('changenumber', '变更单号')
@api.param('mindate', '起始日期')
@api.param('maxdate', '截至日期')
@api.response(ARGUMENTS_ERROR, 'need at least one argument')
@api.response(HTTP_NOT_FOUND, 'no record found')
@api.response(HTTP_GET_SUCCESS, 'query success')
@api.marshal_with(list_model)
def get(self):
	pass

有没有发现什么异常?
咋一看,该有的都有,很全面呀,可是在swagger页面上:
swagger展示页面

嗯?marshal_with定义的model呢?被天狗吃掉啦???

后来对比了下官方DEMO,发现doc和marshal_with()或者expect()要放到一起写才行:

@api.doc('Get_Plan_List')
@api.marshal_with(record_list_model)
@api.param('changenumber', '变更单号')
@api.param('mindate', '起始日期')
@api.param('maxdate', '截至日期')
@api.response(ARGUMENTS_ERROR, 'need at least one argument')
@api.response(HTTP_NOT_FOUND, 'no record found')
@api.response(HTTP_GET_SUCCESS, 'query success')
def get(self):
	pass

渲染出来的swagger页面:
有model的swagger页面

没啥好说,拧耳朵,按规矩办!

走过的弯路,+1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值