add rewrite for securitySchemes into swagger_doc

This commit is contained in:
Greg Myers 2020-03-24 14:56:05 +00:00
parent e9aebe6221
commit 231a2d135c
3 changed files with 15 additions and 12 deletions

View File

@ -56,11 +56,11 @@ module Rswag
else # Openapi3 else # Openapi3
if swagger_doc.has_key?(:securityDefinitions) if swagger_doc.has_key?(:securityDefinitions)
ActiveSupport::Deprecation.warn('Rswag::Specs: WARNING: securityDefinitions is replaced in OpenAPI3! Rename to components/securitySchemes (in swagger_helper.rb)') ActiveSupport::Deprecation.warn('Rswag::Specs: WARNING: securityDefinitions is replaced in OpenAPI3! Rename to components/securitySchemes (in swagger_helper.rb)')
(swagger_doc[:securityDefinitions] || {}).slice(*scheme_names).values swagger_doc[:components] ||= { securitySchemes: swagger_doc[:securityDefinitions] }
else swagger_doc.delete(:securityDefinitions)
components = swagger_doc[:components] || {}
(components[:securitySchemes] || {}).slice(*scheme_names).values
end end
components = swagger_doc[:components] || {}
(components[:securitySchemes] || {}).slice(*scheme_names).values
end end
end end

View File

@ -242,6 +242,7 @@ module Rswag
expect(request[:headers]).to eq('HTTP_AUTHORIZATION' => 'Basic foobar') expect(request[:headers]).to eq('HTTP_AUTHORIZATION' => 'Basic foobar')
expect(ActiveSupport::Deprecation).to have_received(:warn) expect(ActiveSupport::Deprecation).to have_received(:warn)
.with('Rswag::Specs: WARNING: securityDefinitions is replaced in OpenAPI3! Rename to components/securitySchemes (in swagger_helper.rb)') .with('Rswag::Specs: WARNING: securityDefinitions is replaced in OpenAPI3! Rename to components/securitySchemes (in swagger_helper.rb)')
expect(swagger_doc[:components]).to have_key(:securitySchemes)
end end
end end
end end

View File

@ -286,14 +286,16 @@
] ]
} }
}, },
"securityDefinitions": { "components": {
"basic_auth": { "securitySchemes": {
"type": "basic" "basic_auth": {
}, "type": "basic"
"api_key": { },
"type": "apiKey", "api_key": {
"name": "api_key", "type": "apiKey",
"in": "query" "name": "api_key",
"in": "query"
}
} }
} }
} }