zipmark/rspec_api_documentation

JSON outputting with newlines in request body

qortex opened this issue · 1 comments

The generated JSON is fine for response body, such as:

{
  "id": 1,
  "firstname": null,
  "lastname": null,
  "created_at": "2018-10-26T16:27:32.335Z",
  "updated_at": "2018-10-26T16:27:32.335Z",
  "email": "test@email.com"
}

But it is on only one line when in a request body:

{"user":{"grant_type":"password","email":"test@email.com","password":"passwordtest"}}

How would I enable multi-line JSON in request body?

Fixed it with that in config:

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

Looks like by default JSON.generate is called, whereas I needed pretty_generate to get it more pretty.