mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-25 07:16:40 +00:00
Parse defined security requirements correctly
This commit is contained in:
parent
312f68ae72
commit
23f4120fe3
@ -65,9 +65,13 @@ module Rswag
|
|||||||
|
|
||||||
def resolve_api_key_parameters
|
def resolve_api_key_parameters
|
||||||
@api_key_params ||= begin
|
@api_key_params ||= begin
|
||||||
global_requirements = (@global_metadata[:security] || {})
|
# First figure out the security requirement applicable to the operation
|
||||||
requirements = global_requirements.merge(@api_metadata[:operation][:security] || {})
|
global_requirements = (@global_metadata[:security] || [] ).map { |r| r.keys.first }
|
||||||
definitions = (@global_metadata[:securityDefinitions] || {}).slice(*requirements.keys)
|
operation_requirements = (@api_metadata[:operation][:security] || [] ).map { |r| r.keys.first }
|
||||||
|
requirements = global_requirements | operation_requirements
|
||||||
|
|
||||||
|
# Then obtain the scheme definitions for those requirements
|
||||||
|
definitions = (@global_metadata[:securityDefinitions] || {}).slice(*requirements)
|
||||||
definitions.values.select { |d| d[:type] == :apiKey }
|
definitions.values.select { |d| d[:type] == :apiKey }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -26,9 +26,9 @@ module Rswag
|
|||||||
{ name: 'q1', in: :query, type: 'string' },
|
{ name: 'q1', in: :query, type: 'string' },
|
||||||
{ name: :blog, in: :body, schema: { type: 'object' } }
|
{ name: :blog, in: :body, schema: { type: 'object' } }
|
||||||
],
|
],
|
||||||
security: {
|
security: [
|
||||||
api_key: []
|
{ api_key: [] }
|
||||||
}
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|||||||
@ -102,7 +102,7 @@ module Rswag
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'global requirement' do
|
context 'global requirement' do
|
||||||
before { global_metadata[:security] = { api_key: [] } }
|
before { global_metadata[:security] = [ { api_key: [] } ] }
|
||||||
|
|
||||||
it "appends the api_key using metadata and example value" do
|
it "appends the api_key using metadata and example value" do
|
||||||
expect(path).to eq('/blogs/1/comments/2?api_key=fookey')
|
expect(path).to eq('/blogs/1/comments/2?api_key=fookey')
|
||||||
@ -110,7 +110,7 @@ module Rswag
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'operation-specific requirement' do
|
context 'operation-specific requirement' do
|
||||||
before { api_metadata[:operation][:security] = { api_key: [] } }
|
before { api_metadata[:operation][:security] = [ { api_key: [] } ] }
|
||||||
|
|
||||||
it "appends the api_key using metadata and example value" do
|
it "appends the api_key using metadata and example value" do
|
||||||
expect(path).to eq('/blogs/1/comments/2?api_key=fookey')
|
expect(path).to eq('/blogs/1/comments/2?api_key=fookey')
|
||||||
|
|||||||
@ -51,9 +51,9 @@ RSpec.configure do |config|
|
|||||||
in: :query
|
in: :query
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
security: {
|
security: [
|
||||||
api_key: []
|
{ api_key: [] }
|
||||||
}
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|||||||
@ -145,9 +145,11 @@
|
|||||||
"in": "query"
|
"in": "query"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"security": {
|
"security": [
|
||||||
"api_key": [
|
{
|
||||||
|
"api_key": [
|
||||||
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user