mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-25 15:22:56 +00:00
add upgrade for basepath and host to server urls
This commit is contained in:
@@ -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 } }],
|
||||
|
||||
Reference in New Issue
Block a user