mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-23 06:16:42 +00:00
feature remove trailing produces and consumes
This commit is contained in:
parent
f1f8b0ed18
commit
cbc7a33ac3
@ -51,6 +51,9 @@ module Rswag
|
||||
|
||||
def stop(_notification = nil)
|
||||
@config.swagger_docs.each do |url_path, doc|
|
||||
unless doc_version(doc).start_with?('2')
|
||||
remove_invalid_operation_keys!(doc)
|
||||
end
|
||||
## OA3
|
||||
# # remove 2.0 parameters
|
||||
# doc[:paths]&.each_pair do |_k, v|
|
||||
@ -211,6 +214,16 @@ module Rswag
|
||||
swagger_doc[:components][:securitySchemes][name].merge!(flows: { flow => flow_elements })
|
||||
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
|
||||
|
||||
@ -174,17 +174,19 @@ module Rswag
|
||||
before do
|
||||
FileUtils.rm_r(swagger_root) if File.exist?(swagger_root)
|
||||
allow(config).to receive(:swagger_docs).and_return(
|
||||
'v1/swagger.json' => { info: { version: 'v1' } },
|
||||
'v2/swagger.json' => { info: { version: 'v2' } }
|
||||
'v1/swagger.json' => doc_1,
|
||||
'v2/swagger.json' => doc_2
|
||||
)
|
||||
allow(config).to receive(:swagger_format).and_return(swagger_format)
|
||||
subject.stop(notification)
|
||||
end
|
||||
|
||||
let(:doc_1) { { info: { version: 'v1' } } }
|
||||
let(:doc_2) { { info: { version: 'v2' } } }
|
||||
let(:swagger_format) { :json }
|
||||
|
||||
let(:notification) { double('notification') }
|
||||
context 'with default format' do
|
||||
let(:swagger_format) { :json }
|
||||
|
||||
it 'writes the swagger_doc(s) to file' do
|
||||
expect(File).to exist("#{swagger_root}/v1/swagger.json")
|
||||
expect(File).to exist("#{swagger_root}/v2/swagger.json")
|
||||
@ -203,6 +205,24 @@ module Rswag
|
||||
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
|
||||
FileUtils.rm_r(swagger_root) if File.exist?(swagger_root)
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user