mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-22 22:06:43 +00:00
add upgrade for basepath and host to server urls
This commit is contained in:
parent
da230a4f3e
commit
eb58fe687a
@ -36,6 +36,7 @@ module Rswag
|
||||
|
||||
if !doc_version(swagger_doc).start_with?('2')
|
||||
upgrade_request_type!(metadata)
|
||||
upgrade_servers!(swagger_doc)
|
||||
end
|
||||
|
||||
swagger_doc.deep_merge!(metadata_to_swagger(metadata))
|
||||
@ -136,6 +137,20 @@ module Rswag
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def upgrade_servers!(swagger_doc)
|
||||
if swagger_doc[:servers].nil? && swagger_doc.has_key?(:schemes)
|
||||
|
||||
swagger_doc[:servers] = { urls: [] }
|
||||
swagger_doc[:schemes].each do |scheme|
|
||||
swagger_doc[:servers][:urls] << scheme + '://' + swagger_doc[:host] + swagger_doc[:basePath]
|
||||
end
|
||||
|
||||
swagger_doc.delete(:schemes)
|
||||
swagger_doc.delete(:host)
|
||||
swagger_doc.delete(:basePath)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -22,7 +22,6 @@ module Rswag
|
||||
allow(config).to receive(:get_swagger_doc).and_return(swagger_doc)
|
||||
subject.example_group_finished(notification)
|
||||
end
|
||||
let(:swagger_doc) { { swagger: '2.0' } }
|
||||
let(:notification) { OpenStruct.new(group: OpenStruct.new(metadata: api_metadata)) }
|
||||
let(:api_metadata) do
|
||||
{
|
||||
@ -34,6 +33,7 @@ module Rswag
|
||||
end
|
||||
|
||||
context 'with the document tag set to false' do
|
||||
let(:swagger_doc) { { swagger: '2.0' } }
|
||||
let(:document) { false }
|
||||
|
||||
it 'does not update the swagger doc' do
|
||||
@ -42,6 +42,7 @@ module Rswag
|
||||
end
|
||||
|
||||
context 'with the document tag set to anything but false' do
|
||||
let(:swagger_doc) { { swagger: '2.0' } }
|
||||
# anything works, including its absence when specifying responses.
|
||||
let(:document) { nil }
|
||||
|
||||
@ -67,13 +68,21 @@ module Rswag
|
||||
end
|
||||
end
|
||||
|
||||
context 'upgrades to 3.0' do
|
||||
let(:swagger_doc) { { openapi: '3.0.1'} }
|
||||
context 'with metadata upgrades for 3.0' do
|
||||
let(:swagger_doc) { {
|
||||
openapi: '3.0.1',
|
||||
basePath: '/foo',
|
||||
schemes: ['http', 'https'],
|
||||
host: 'api.example.com'
|
||||
} }
|
||||
let(:document) { nil }
|
||||
|
||||
it 'converts query and path params, type: to schema: { type: }' do
|
||||
expect(swagger_doc).to match(
|
||||
openapi: '3.0.1',
|
||||
servers: {
|
||||
urls: ['http://api.example.com/foo', 'https://api.example.com/foo']
|
||||
},
|
||||
paths: {
|
||||
'/blogs' => {
|
||||
parameters: [{ schema: { type: :string } }],
|
||||
|
||||
@ -21,10 +21,14 @@
|
||||
],
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "Valid credentials"
|
||||
"description": "Valid credentials",
|
||||
"headers": {
|
||||
}
|
||||
},
|
||||
"401": {
|
||||
"description": "Invalid credentials"
|
||||
"description": "Invalid credentials",
|
||||
"headers": {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -45,10 +49,14 @@
|
||||
],
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "Valid credentials"
|
||||
"description": "Valid credentials",
|
||||
"headers": {
|
||||
}
|
||||
},
|
||||
"401": {
|
||||
"description": "Invalid credentials"
|
||||
"description": "Invalid credentials",
|
||||
"headers": {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -72,10 +80,14 @@
|
||||
],
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "Valid credentials"
|
||||
"description": "Valid credentials",
|
||||
"headers": {
|
||||
}
|
||||
},
|
||||
"401": {
|
||||
"description": "Invalid credentials"
|
||||
"description": "Invalid credentials",
|
||||
"headers": {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -105,12 +117,16 @@
|
||||
],
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": "blog created"
|
||||
"description": "blog created",
|
||||
"headers": {
|
||||
}
|
||||
},
|
||||
"422": {
|
||||
"description": "invalid request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/errors_object"
|
||||
},
|
||||
"headers": {
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -136,7 +152,9 @@
|
||||
],
|
||||
"responses": {
|
||||
"406": {
|
||||
"description": "unsupported accept header"
|
||||
"description": "unsupported accept header",
|
||||
"headers": {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -189,7 +207,9 @@
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "blog not found"
|
||||
"description": "blog not found",
|
||||
"headers": {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -227,7 +247,9 @@
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "blog updated"
|
||||
"description": "blog updated",
|
||||
"headers": {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user