mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-25 07:16:40 +00:00
feature remove trailing produces and consumes
This commit is contained in:
@@ -51,6 +51,9 @@ module Rswag
|
|||||||
|
|
||||||
def stop(_notification = nil)
|
def stop(_notification = nil)
|
||||||
@config.swagger_docs.each do |url_path, doc|
|
@config.swagger_docs.each do |url_path, doc|
|
||||||
|
unless doc_version(doc).start_with?('2')
|
||||||
|
remove_invalid_operation_keys!(doc)
|
||||||
|
end
|
||||||
## OA3
|
## OA3
|
||||||
# # remove 2.0 parameters
|
# # remove 2.0 parameters
|
||||||
# doc[:paths]&.each_pair do |_k, v|
|
# doc[:paths]&.each_pair do |_k, v|
|
||||||
@@ -211,6 +214,16 @@ module Rswag
|
|||||||
swagger_doc[:components][:securitySchemes][name].merge!(flows: { flow => flow_elements })
|
swagger_doc[:components][:securitySchemes][name].merge!(flows: { flow => flow_elements })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def remove_invalid_operation_keys!(swagger_doc)
|
||||||
|
swagger_doc[:paths]&.each_pair do |_k, v|
|
||||||
|
v.each_pair do |_verb, value|
|
||||||
|
is_hash = value.is_a?(Hash)
|
||||||
|
value.delete(:consumes) if is_hash && value.dig(:consumes)
|
||||||
|
value.delete(:produces) if is_hash && value.dig(:produces)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -174,17 +174,19 @@ module Rswag
|
|||||||
before do
|
before do
|
||||||
FileUtils.rm_r(swagger_root) if File.exist?(swagger_root)
|
FileUtils.rm_r(swagger_root) if File.exist?(swagger_root)
|
||||||
allow(config).to receive(:swagger_docs).and_return(
|
allow(config).to receive(:swagger_docs).and_return(
|
||||||
'v1/swagger.json' => { info: { version: 'v1' } },
|
'v1/swagger.json' => doc_1,
|
||||||
'v2/swagger.json' => { info: { version: 'v2' } }
|
'v2/swagger.json' => doc_2
|
||||||
)
|
)
|
||||||
allow(config).to receive(:swagger_format).and_return(swagger_format)
|
allow(config).to receive(:swagger_format).and_return(swagger_format)
|
||||||
subject.stop(notification)
|
subject.stop(notification)
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:notification) { double('notification') }
|
let(:doc_1) { { info: { version: 'v1' } } }
|
||||||
context 'with default format' do
|
let(:doc_2) { { info: { version: 'v2' } } }
|
||||||
let(:swagger_format) { :json }
|
let(:swagger_format) { :json }
|
||||||
|
|
||||||
|
let(:notification) { double('notification') }
|
||||||
|
context 'with default format' do
|
||||||
it 'writes the swagger_doc(s) to file' do
|
it 'writes the swagger_doc(s) to file' do
|
||||||
expect(File).to exist("#{swagger_root}/v1/swagger.json")
|
expect(File).to exist("#{swagger_root}/v1/swagger.json")
|
||||||
expect(File).to exist("#{swagger_root}/v2/swagger.json")
|
expect(File).to exist("#{swagger_root}/v2/swagger.json")
|
||||||
@@ -203,6 +205,24 @@ module Rswag
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with oauth3 upgrades' do
|
||||||
|
let(:doc_2) do
|
||||||
|
{ paths: { '/paths/{path_id}/nested_paths' => { get: {
|
||||||
|
summary: 'Retrieve Nested Paths',
|
||||||
|
tags: ['nested Paths'],
|
||||||
|
produces: ['application/json'],
|
||||||
|
consumes: ['application/xml']
|
||||||
|
} } } }
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'removes remaining consumes/produces' do
|
||||||
|
expect(doc_2).to eql({ paths: { '/paths/{path_id}/nested_paths' => { get: {
|
||||||
|
summary: 'Retrieve Nested Paths',
|
||||||
|
tags: ['nested Paths']
|
||||||
|
} } } })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
after do
|
after do
|
||||||
FileUtils.rm_r(swagger_root) if File.exist?(swagger_root)
|
FileUtils.rm_r(swagger_root) if File.exist?(swagger_root)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user