add oauth flow renaming and warnings

This commit is contained in:
Greg Myers 2020-04-04 20:55:04 +01:00
parent d66be41d04
commit 96fc5276c4
2 changed files with 38 additions and 4 deletions

View File

@ -197,6 +197,14 @@ module Rswag
ActiveSupport::Deprecation.warn("Rswag::Specs: WARNING: securityDefinitions flow is replaced in OpenAPI3! Rename to components/securitySchemes/#{name}/flows[] (in swagger_helper.rb)")
flow = swagger_doc[:components][:securitySchemes][name].delete(:flow)
if flow == :accessCode
ActiveSupport::Deprecation.warn("Rswag::Specs: WARNING: securityDefinitions accessCode is replaced in OpenAPI3! Rename to clientCredentials (in swagger_helper.rb)")
flow = :clientCredentials
end
if flow == :application
ActiveSupport::Deprecation.warn("Rswag::Specs: WARNING: securityDefinitions application is replaced in OpenAPI3! Rename to authorizationCode (in swagger_helper.rb)")
flow = :authorizationCode
end
flow_elements = swagger_doc[:components][:securitySchemes][name].except(:type).each_with_object({}) do |(k, _v), a|
a[k] = swagger_doc[:components][:securitySchemes][name].delete(k)
end

View File

@ -78,9 +78,19 @@ module Rswag
produces: ['application/vnd.my_mime', 'application/json'],
components: {
securitySchemes: {
my_oauth: {
myClientCredentials: {
type: :oauth2,
flow: :anything,
flow: :accessCode,
token_url: :somewhere
},
myAuthorizationCode: {
type: :oauth2,
flow: :application,
token_url: :somewhere
},
myImplicit: {
type: :oauth2,
flow: :implicit,
token_url: :somewhere
}
}
@ -129,10 +139,26 @@ module Rswag
expect(swagger_doc.slice(:components)).to match(
components: {
securitySchemes: {
my_oauth: {
myClientCredentials: {
type: :oauth2,
flows: {
anything: {
clientCredentials: {
token_url: :somewhere
}
}
},
myAuthorizationCode: {
type: :oauth2,
flows: {
authorizationCode: {
token_url: :somewhere
}
}
},
myImplicit: {
type: :oauth2,
flows: {
implicit: {
token_url: :somewhere
}
}