Skip to content

Commit 561552d

Browse files
committed
Warning Duplicate definition of 'Content-Type' header
- Remove Content-Type header from the Header sections
1 parent 2f0a216 commit 561552d

File tree

3 files changed

+20
-35
lines changed

3 files changed

+20
-35
lines changed

Diff for: features/api_blueprint_documentation.feature

-11
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ Feature: Generate API Blueprint documentation from test examples
269269
270270
+ Headers
271271
272-
Content-Type: text/html;charset=utf-8
273272
Content-Length: 57
274273
275274
+ Body
@@ -288,7 +287,6 @@ Feature: Generate API Blueprint documentation from test examples
288287
289288
+ Headers
290289
291-
Content-Type: application/json
292290
Host: example.org
293291
294292
+ Body
@@ -308,7 +306,6 @@ Feature: Generate API Blueprint documentation from test examples
308306
309307
+ Headers
310308
311-
Content-Type: application/json
312309
Content-Length: 73
313310
314311
+ Body
@@ -333,7 +330,6 @@ Feature: Generate API Blueprint documentation from test examples
333330
334331
+ Headers
335332
336-
Content-Type: application/vnd.api+json
337333
Content-Length: 137
338334
339335
+ Body
@@ -372,13 +368,11 @@ Feature: Generate API Blueprint documentation from test examples
372368
+ Headers
373369
374370
Host: example.org
375-
Content-Type: application/x-www-form-urlencoded
376371
377372
+ Response 200 (text/html;charset=utf-8)
378373
379374
+ Headers
380375
381-
Content-Type: text/html;charset=utf-8
382376
Content-Length: 0
383377
384378
### Returns a single order [GET]
@@ -393,7 +387,6 @@ Feature: Generate API Blueprint documentation from test examples
393387
394388
+ Headers
395389
396-
Content-Type: application/json
397390
Content-Length: 73
398391
399392
+ Body
@@ -412,21 +405,18 @@ Feature: Generate API Blueprint documentation from test examples
412405
413406
+ Headers
414407
415-
Content-Type: application/json; charset=utf-16
416408
Host: example.org
417409
418410
+ Response 400 (application/json)
419411
420412
+ Headers
421413
422-
Content-Type: application/json
423414
Content-Length: 0
424415
425416
+ Request Update an order (application/json; charset=utf-16)
426417
427418
+ Headers
428419
429-
Content-Type: application/json; charset=utf-16
430420
Host: example.org
431421
432422
+ Body
@@ -445,7 +435,6 @@ Feature: Generate API Blueprint documentation from test examples
445435
446436
+ Headers
447437
448-
Content-Type: application/json
449438
Content-Length: 111
450439
451440
+ Body

Diff for: lib/rspec_api_documentation/views/api_blueprint_example.rb

+14-2
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])
@@ -46,6 +46,18 @@ def extension
4646

4747
private
4848

49+
# `Content-Type` header is removed because the information would be duplicated
50+
# since it's already present in `request[:request_content_type]`.
51+
def remove_content_type(headers)
52+
return unless headers
53+
headers
54+
.split("\n")
55+
.reject { |header|
56+
header.start_with?('Content-Type:')
57+
}
58+
.join("\n")
59+
end
60+
4961
def has_request?(metadata)
5062
metadata.any? do |key, value|
5163
[:request_body, :request_headers, :request_content_type].include?(key) && value

Diff for: spec/views/api_blueprint_example_spec.rb

+6-22
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)