Skip to content

pretty json in request + pretty api.vnd+json #236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/rspec_api_documentation/client_base.rb
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ def document_example(method, path)

request_metadata[:request_method] = method
request_metadata[:request_path] = path
request_metadata[:request_body] = request_body.empty? ? nil : request_body.force_encoding("UTF-8")
request_metadata[:request_body] = record_request_body(request_content_type, request_body)
request_metadata[:request_headers] = request_headers
request_metadata[:request_query_parameters] = query_hash
request_metadata[:request_content_type] = request_content_type
@@ -89,13 +89,22 @@ def record_response_body(response_content_type, response_body)
return nil if response_body.empty?
if response_body.encoding == Encoding::ASCII_8BIT
"[binary data]"
elsif response_content_type =~ /application\/json/
elsif response_content_type =~ /application\/(vnd\.api\+)?json/
JSON.pretty_generate(JSON.parse(response_body))
else
response_body
end
end

def record_request_body(request_content_type, request_body)
return nil if request_body.empty?
if request_content_type =~ /application\/(vnd\.api\+)?json/
JSON.pretty_generate(JSON.parse(request_body.force_encoding("UTF-8")))
else
request_body.force_encoding("UTF-8")
end
end

def clean_out_uploaded_data(params, request_body)
params.each do |_, value|
if value.is_a?(Hash)