【问题标题】:Using RSpec API Documentation Generator, can I pretty print the request body JSON?使用 RSpec API 文档生成器,我可以漂亮地打印请求正文 JSON 吗?
【发布时间】:2019-06-18 03:37:40
【问题描述】:

我将RSpec API Documentation Generator Gem 用于我的rails 应用程序,当我生成文档时,请求正文(JSON 格式)的格式如下:

{"user":{"email":"person1@example.com","password":"z5x6c7v8!@!"}}

有没有办法像下面这样漂亮地打印它?

{
    "user": {
        "email":"person1@example.com",
        "password":"password"
    }
}

我似乎找不到任何配置选项来执行此操作。我正在使用以下两个标题:

header 'Content-Type', 'application/json'
header 'Accept', 'application/json'

【问题讨论】:

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


    【解决方案1】:

    你可以试试这个:

    RspecApiDocumentation.configure do |config|
      config.request_body_formatter = proc do |params|
        JSON.pretty_generate(params)
      end
    end
    

    【讨论】:

      猜你喜欢
      • 2013-08-08
      • 2011-02-27
      • 2017-08-13
      • 2012-10-08
      • 1970-01-01
      • 2015-07-03
      • 2015-08-26
      相关资源
      最近更新 更多