【问题标题】:Rspec api documentation + apitome request body in json formatjson格式的Rspec api文档+apime请求正文
【发布时间】:2018-07-12 12:38:16
【问题描述】:

我正在使用 rspec api 文档、apime 和 oauth2 协议来为我们的 api 构建验收测试。一切都很好,除了请求正文如下所示:

我从上面生成的文档中注意到的:

Content-Type: application/x-www-form-urlencoded
那应该是 application/json 。我浏览了一些博客文章并建议将其放入:

post "/api/v1/ticket_carts" do
    header "Content-Type", "application/json"

我试图检查服务器上的参数

def create
    render json: params
    # options = set_ticket_cart_protected_params(filter_params)
    # adapter = Adapter::TicketCart.new(options)
    # @handler = adapter.handler
    # @handler.call

    # render json: @handler.order, serializer: adapter.serializer_class
  end

响应看起来像这样:

据我所见,服务器仍然以表单编码格式从客户端获取参数。

我的结论是,rspec api 文档没有将 content-type 作为 application/json 发送到服务器。

我做错了什么或者需要采取哪些其他步骤才能使 rspec api 文档发送正确的内容类型 (application/json)?

【问题讨论】:

    标签: ruby-on-rails rspec-api-documentation apitome


    【解决方案1】:

    我在 rspec api doc config 中找到了这个

    # Change how the post body is formatted by default, you can still override by `raw_post`
      # Can be :json, :xml, or a proc that will be passed the params

    然后我尝试了这个

    # set content type to json
    header "Content-Type", "application/json"
    #override the params to json format
    let(:raw_post) { params.to_json }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-19
      • 1970-01-01
      • 2011-07-02
      • 2020-07-20
      • 2018-01-03
      • 1970-01-01
      • 2017-09-03
      • 1970-01-01
      相关资源
      最近更新 更多