mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-24 23:06:41 +00:00
enable swagger empty body responses
This commit is contained in:
parent
bec4f16676
commit
347f9da32e
@ -129,9 +129,9 @@ module Rswag
|
|||||||
end
|
end
|
||||||
|
|
||||||
def upgrade_content!(mime_list, target_node)
|
def upgrade_content!(mime_list, target_node)
|
||||||
target_node.merge!(content: {})
|
|
||||||
schema = target_node[:schema]
|
schema = target_node[:schema]
|
||||||
return if mime_list.empty? || schema.nil?
|
return if mime_list.empty? || schema.nil?
|
||||||
|
target_node.merge!(content: {})
|
||||||
|
|
||||||
mime_list.each do |mime_type|
|
mime_list.each do |mime_type|
|
||||||
# TODO upgrade to have content-type specific schema
|
# TODO upgrade to have content-type specific schema
|
||||||
|
|||||||
@ -127,6 +127,56 @@ module Rswag
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with empty content' do
|
||||||
|
let(:swagger_doc) do
|
||||||
|
{
|
||||||
|
openapi: '3.0.1',
|
||||||
|
basePath: '/foo',
|
||||||
|
schemes: ['http', 'https'],
|
||||||
|
host: 'api.example.com',
|
||||||
|
components: {
|
||||||
|
securitySchemes: {
|
||||||
|
myClientCredentials: {
|
||||||
|
type: :oauth2,
|
||||||
|
flow: :application,
|
||||||
|
token_url: :somewhere
|
||||||
|
},
|
||||||
|
myAuthorizationCode: {
|
||||||
|
type: :oauth2,
|
||||||
|
flow: :accessCode,
|
||||||
|
token_url: :somewhere
|
||||||
|
},
|
||||||
|
myImplicit: {
|
||||||
|
type: :oauth2,
|
||||||
|
flow: :implicit,
|
||||||
|
token_url: :somewhere
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'converts query and path params, type: to schema: { type: }' do
|
||||||
|
expect(swagger_doc.slice(:paths)).to match(
|
||||||
|
paths: {
|
||||||
|
'/blogs' => {
|
||||||
|
parameters: [{ schema: { type: :string } }],
|
||||||
|
post: {
|
||||||
|
parameters: [{ schema: { type: :string } }],
|
||||||
|
summary: 'Creates a blog',
|
||||||
|
responses: {
|
||||||
|
'201' => {
|
||||||
|
description: 'blog created',
|
||||||
|
headers: { schema: { type: :string } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it 'converts basePath, schemas and host to urls' do
|
it 'converts basePath, schemas and host to urls' do
|
||||||
expect(swagger_doc.slice(:servers)).to match(
|
expect(swagger_doc.slice(:servers)).to match(
|
||||||
servers: {
|
servers: {
|
||||||
|
|||||||
@ -21,14 +21,10 @@
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"204": {
|
"204": {
|
||||||
"description": "Valid credentials",
|
"description": "Valid credentials"
|
||||||
"content": {
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"401": {
|
"401": {
|
||||||
"description": "Invalid credentials",
|
"description": "Invalid credentials"
|
||||||
"content": {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -49,14 +45,10 @@
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"204": {
|
"204": {
|
||||||
"description": "Valid credentials",
|
"description": "Valid credentials"
|
||||||
"content": {
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"401": {
|
"401": {
|
||||||
"description": "Invalid credentials",
|
"description": "Invalid credentials"
|
||||||
"content": {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -80,14 +72,10 @@
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"204": {
|
"204": {
|
||||||
"description": "Valid credentials",
|
"description": "Valid credentials"
|
||||||
"content": {
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"401": {
|
"401": {
|
||||||
"description": "Invalid credentials",
|
"description": "Invalid credentials"
|
||||||
"content": {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -105,9 +93,7 @@
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"201": {
|
"201": {
|
||||||
"description": "blog created",
|
"description": "blog created"
|
||||||
"content": {
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"422": {
|
"422": {
|
||||||
"description": "invalid request",
|
"description": "invalid request",
|
||||||
@ -148,9 +134,7 @@
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"406": {
|
"406": {
|
||||||
"description": "unsupported accept header",
|
"description": "unsupported accept header"
|
||||||
"content": {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -252,9 +236,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"404": {
|
"404": {
|
||||||
"description": "blog not found",
|
"description": "blog not found"
|
||||||
"content": {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -282,9 +264,7 @@
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "blog updated",
|
"description": "blog updated"
|
||||||
"content": {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"requestBody": {
|
"requestBody": {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user