Skip to content

Commit efcca3b

Browse files
authored
fix: Remove content field if no content (#193)
1 parent 7a98af4 commit efcca3b

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

lib/rspec/openapi/schema_builder.rb

+9-6
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ def build(record)
1414
if record.response_body
1515
disposition = normalize_content_disposition(record.response_content_disposition)
1616

17-
response[:content] = {
18-
normalize_content_type(record.response_content_type) => {
19-
schema: build_property(record.response_body, disposition: disposition),
20-
example: response_example(record, disposition: disposition),
21-
}.compact,
22-
}
17+
has_content = !normalize_content_type(record.response_content_type).nil?
18+
if has_content
19+
response[:content] = {
20+
normalize_content_type(record.response_content_type) => {
21+
schema: build_property(record.response_body, disposition: disposition),
22+
example: response_example(record, disposition: disposition),
23+
}.compact,
24+
}
25+
end
2326
end
2427

2528
{

spec/rails/doc/smart/expected.yaml

+9-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ paths:
1919
summary: get
2020
tags:
2121
- Page
22+
parameters:
23+
- name: head
24+
in: query
25+
required: false
26+
schema:
27+
type: integer
28+
example: 1
2229
responses:
2330
'200':
2431
description: return HTML
@@ -27,8 +34,8 @@ paths:
2734
schema:
2835
type: string
2936
example: '<!DOCTYPE html><html lang="en"><head><title>Hello</title></head><body>Hello</body></html>'
30-
# '204':
31-
# description: return no content
37+
'204':
38+
description: return no content
3239
"/tables":
3340
get:
3441
summary: index

spec/requests/rails_smart_merge_spec.rb

+5
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,10 @@
117117
get '/pages'
118118
expect(response.status).to eq(200)
119119
end
120+
121+
it 'return no content' do
122+
get '/pages?head=1'
123+
expect(response.status).to eq(204)
124+
end
120125
end
121126
end

0 commit comments

Comments
 (0)