【问题标题】:Flask-Restplus, changing content-type in swaggerFlask-Restplus,大摇大摆地改变内容类型
【发布时间】:2017-12-20 07:55:48
【问题描述】:

我正在使用 flask_restplus 来生成招摇。我必须在 POST 端点之一上接受 Content-Type: application/x-www-form-urlencoded 。但是自动生成的 swagger 文档只显示 applicatin/json。我怎样才能改变这种行为?谢谢。

【问题讨论】:

  • 当我在做类似的事情时:你是如何设置你想接受的Content-Type 的?你能发布一些示例代码吗?

标签: swagger content-type flask-restplus


【解决方案1】:

我自己偶然发现了这个,并找到了解决方法。

解决方法是使用@api.expect 来注释方法,而不是类。

例如,假设您有一个名为 someparser 的解析器,其属性为 location='form'

代替

@api.route('/someroute')
@api.expect(someparser)
class SomeResource(Resource):
    def post(self):
        ...

你应该这样做

@api.route('/someroute')
class SomeResource(Resource):
    @api.expect(someparser)
    def post(self):
        ...

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-05-11
  • 1970-01-01
  • 2022-09-28
  • 2021-09-03
  • 2017-10-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多