使用 RSpec API 文档生成器,我可以漂亮地打印请求 body JSON 吗?

Using RSpec API Documentation Generator, can I pretty print the request body JSON?

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

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

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

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

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

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

你可以试试这个:

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