Class: Jsapi::Meta::OpenAPI::SecurityScheme::OAuth2

Inherits:
Base
  • Object
show all
Defined in:
lib/jsapi/meta/openapi/security_scheme/oauth2.rb

Overview

Represents a security scheme based on OAuth2.

Instance Method Summary collapse

Methods inherited from Base

#description

Methods inherited from Base

#initialize, #inspect, #reference?, #resolve

Methods included from Attributes::ClassMethods

#attribute, #attribute_names

Constructor Details

This class inherits a constructor from Jsapi::Meta::Base

Instance Method Details

#oauth_flowsObject

:attr: oauth_flows The hash containing the OAuth flows. Possible keys are:

  • "authorization_code"

  • "client_credentials"

  • "implicit"

  • "password"

Values are OAuthFlow objects.



19
20
21
# File 'lib/jsapi/meta/openapi/security_scheme/oauth2.rb', line 19

attribute :oauth_flows,
{ String => OAuthFlow },
keys: %w[authorization_code client_credentials implicit password]

#to_openapi(version) ⇒ Object

Returns a hash representing the security scheme object.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/jsapi/meta/openapi/security_scheme/oauth2.rb', line 24

def to_openapi(version)
  version = Version.from(version)
  {
    type: 'oauth2',
    description: description
  }.tap do |h|
    if oauth_flows&.any?
      if version.major == 2
        key, oauth_flow = oauth_flows.first
        h[:flow] = key.to_s
        h.merge!(oauth_flow.to_openapi(version))
      else
        h[:flows] = oauth_flows.to_h do |key, value|
          [key.to_s.camelize(:lower).to_sym, value.to_openapi(version)]
        end
      end
    end
  end.compact
end