Skip to content

Commit

Permalink
fix: Remove content field if no content (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
exoego committed Mar 25, 2024
1 parent 7a98af4 commit efcca3b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
15 changes: 9 additions & 6 deletions lib/rspec/openapi/schema_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ def build(record)
if record.response_body
disposition = normalize_content_disposition(record.response_content_disposition)

response[:content] = {
normalize_content_type(record.response_content_type) => {
schema: build_property(record.response_body, disposition: disposition),
example: response_example(record, disposition: disposition),
}.compact,
}
has_content = !normalize_content_type(record.response_content_type).nil?
if has_content
response[:content] = {
normalize_content_type(record.response_content_type) => {
schema: build_property(record.response_body, disposition: disposition),
example: response_example(record, disposition: disposition),
}.compact,
}
end
end

{
Expand Down
11 changes: 9 additions & 2 deletions spec/rails/doc/smart/expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ paths:
summary: get
tags:
- Page
parameters:
- name: head
in: query
required: false
schema:
type: integer
example: 1
responses:
'200':
description: return HTML
Expand All @@ -27,8 +34,8 @@ paths:
schema:
type: string
example: '<!DOCTYPE html><html lang="en"><head><title>Hello</title></head><body>Hello</body></html>'
# '204':
# description: return no content
'204':
description: return no content
"/tables":
get:
summary: index
Expand Down
5 changes: 5 additions & 0 deletions spec/requests/rails_smart_merge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,10 @@
get '/pages'
expect(response.status).to eq(200)
end

it 'return no content' do
get '/pages?head=1'
expect(response.status).to eq(204)
end
end
end

0 comments on commit efcca3b

Please sign in to comment.