Updates specs to add 3.0 compliant structure and tests around the new schema/structure

This commit is contained in:
Jay Danielian
2019-07-20 12:29:44 -04:00
parent 04564d933f
commit 4baf5efd11
6 changed files with 33 additions and 23 deletions

View File

@@ -16,11 +16,13 @@ module Rswag
let(:config) { double('config') }
let(:swagger_doc) do
{
securityDefinitions: {
api_key: {
type: :apiKey,
name: 'api_key',
in: :query
components: {
securitySchemes: {
api_key: {
type: :apiKey,
name: 'api_key',
in: :query
}
}
}
}

View File

@@ -204,7 +204,10 @@ module Rswag
context 'basic auth' do
before do
swagger_doc[:securityDefinitions] = { basic: { type: :basic } }
swagger_doc[:components] = { securitySchemes: {
basic: { type: :basic }
}
}
metadata[:operation][:security] = [basic: []]
allow(example).to receive(:Authorization).and_return('Basic foobar')
end
@@ -216,7 +219,10 @@ module Rswag
context 'apiKey' do
before do
swagger_doc[:securityDefinitions] = { apiKey: { type: :apiKey, name: 'api_key', in: key_location } }
swagger_doc[:components] = { securitySchemes: {
apiKey: { type: :apiKey, name: 'api_key', in: key_location }
}
}
metadata[:operation][:security] = [apiKey: []]
allow(example).to receive(:api_key).and_return('foobar')
end
@@ -257,7 +263,10 @@ module Rswag
context 'oauth2' do
before do
swagger_doc[:securityDefinitions] = { oauth2: { type: :oauth2, scopes: ['read:blogs'] } }
swagger_doc[:components] = { securitySchemes: {
oauth2: { type: :oauth2, scopes: ['read:blogs'] }
}
}
metadata[:operation][:security] = [oauth2: ['read:blogs']]
allow(example).to receive(:Authorization).and_return('Bearer foobar')
end
@@ -269,9 +278,10 @@ module Rswag
context 'paired security requirements' do
before do
swagger_doc[:securityDefinitions] = {
basic: { type: :basic },
api_key: { type: :apiKey, name: 'api_key', in: :query }
swagger_doc[:components] = { securitySchemes: {
basic: { type: :basic },
api_key: { type: :apiKey, name: 'api_key', in: :query }
}
}
metadata[:operation][:security] = [{ basic: [], api_key: [] }]
allow(example).to receive(:Authorization).and_return('Basic foobar')
@@ -327,7 +337,7 @@ module Rswag
context 'global security requirements' do
before do
swagger_doc[:securityDefinitions] = { apiKey: { type: :apiKey, name: 'api_key', in: :query } }
swagger_doc[:components] = {securitySchemes: { apiKey: { type: :apiKey, name: 'api_key', in: :query } }}
swagger_doc[:security] = [apiKey: []]
allow(example).to receive(:api_key).and_return('foobar')
end

View File

@@ -11,7 +11,7 @@ module Rswag
allow(config).to receive(:get_swagger_doc).and_return(swagger_doc)
end
let(:config) { double('config') }
let(:swagger_doc) { {:components => {}} }
let(:swagger_doc) {{}}
let(:example) { double('example') }
let(:metadata) do
{
@@ -58,13 +58,7 @@ module Rswag
context 'referenced schemas' do
before do
# swagger_doc[:definitions] = {
# 'blog' => {
# type: :object,
# properties: { foo: { type: :string } },
# required: ['foo']
# }
# }
swagger_doc[:components] = {}
swagger_doc[:components][:schemas] = {
'blog' => {
type: :object,