Skip to content

Commit b57259d

Browse files
committed
Fix API blueprint documentation.
- Remove Content-Type header from the Header sections
1 parent 6a86bfe commit b57259d

File tree

2 files changed

+20
-24
lines changed

2 files changed

+20
-24
lines changed

lib/rspec_api_documentation/views/api_blueprint_example.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ def parameters
2020

2121
def requests
2222
super.map do |request|
23-
request[:request_headers_text] = remove_utf8_for_json(request[:request_headers_text])
23+
request[:request_headers_text] = remove_utf8_for_json(remove_content_type(request[:request_headers_text]))
2424
request[:request_headers_text] = indent(request[:request_headers_text])
2525
request[:request_content_type] = content_type(request[:request_headers])
2626
request[:request_content_type] = remove_utf8_for_json(request[:request_content_type])
2727
request[:request_body] = body_to_json(request, :request)
2828
request[:request_body] = indent(request[:request_body])
2929

30-
request[:response_headers_text] = remove_utf8_for_json(request[:response_headers_text])
30+
request[:response_headers_text] = remove_utf8_for_json(remove_content_type(request[:response_headers_text]))
3131
request[:response_headers_text] = indent(request[:response_headers_text])
3232
request[:response_content_type] = content_type(request[:response_headers])
3333
request[:response_content_type] = remove_utf8_for_json(request[:response_content_type])
@@ -78,6 +78,18 @@ def body_to_json(http_call, message_direction)
7878
body
7979
end
8080

81+
# `Content-Type` header is removed because the information would be duplicated
82+
# since it's already present in `request[:request_content_type]`.
83+
def remove_content_type(headers)
84+
return unless headers
85+
headers
86+
.split("\n")
87+
.reject { |header|
88+
header.start_with?('Content-Type:')
89+
}
90+
.join("\n")
91+
end
92+
8193
# JSON requests should use UTF-8 by default according to
8294
# http://www.ietf.org/rfc/rfc4627.txt, so we will remove `charset=utf-8`
8395
# when we find it to remove noise.

spec/views/api_blueprint_example_spec.rb

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,9 @@
5757
describe 'request_headers_text' do
5858
subject { view.requests[0][:request_headers_text] }
5959

60-
context 'when charset=utf-8 is present' do
61-
it "just strips that because it's the default for json" do
62-
expect(subject).to eq "Content-Type: application/json\n Another: header; charset=utf-8"
63-
end
64-
end
65-
66-
context 'when charset=utf-16 is present' do
67-
let(:content_type) { "application/json; charset=utf-16" }
68-
69-
it "keeps that because it's NOT the default for json" do
70-
expect(subject).to eq "Content-Type: application/json; charset=utf-16\n Another: header; charset=utf-8"
60+
context 'when Content-Type is present' do
61+
it "removes it" do
62+
expect(subject).to eq "Another: header; charset=utf-8"
7163
end
7264
end
7365
end
@@ -93,17 +85,9 @@
9385
describe 'response_headers_text' do
9486
subject { view.requests[0][:response_headers_text] }
9587

96-
context 'when charset=utf-8 is present' do
97-
it "just strips that because it's the default for json" do
98-
expect(subject).to eq "Content-Type: application/json\n Another: header; charset=utf-8"
99-
end
100-
end
101-
102-
context 'when charset=utf-16 is present' do
103-
let(:content_type) { "application/json; charset=utf-16" }
104-
105-
it "keeps that because it's NOT the default for json" do
106-
expect(subject).to eq "Content-Type: application/json; charset=utf-16\n Another: header; charset=utf-8"
88+
context 'when Content-Type is present' do
89+
it "removes it" do
90+
expect(subject).to eq "Another: header; charset=utf-8"
10791
end
10892
end
10993
end

0 commit comments

Comments
 (0)