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

发布了25 篇原创文章 · 获赞 24 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/arnolan/article/details/84801653
今日推荐