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

Inherits:
Base show all
Includes:
OpenAPI::Extensions
Defined in:
lib/jsapi/meta/security_scheme/oauth2.rb

Overview

Specifies a security scheme based on OAuth2.

Instance Method Summary collapse

Methods included from OpenAPI::Extensions

included

Methods inherited from Base

#deprecated, #description

Methods inherited from Model::Base

#initialize, #inspect, #merge!, #reference?, #resolve

Methods included from Model::Attributes

#attributes_frozen?, #freeze_attributes, included

Constructor Details

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

Instance Method Details

#oauth2_metadata_urlObject

:attr: oauth2_metadata_url The URL of the OAuth2 authorization server metadata.

Applies to OpenAPI 3.2 and higher.



34
# File 'lib/jsapi/meta/security_scheme/oauth2.rb', line 34

attribute :oauth2_metadata_url, String

#oauth_flowsObject

:attr: oauth_flows Maps one or more of the following keys to OAuthFlow objects.

  • "authorization_code"

  • "client_credentials"

  • "device_authorization"

  • "implicit"

  • "password"

Note that "device_authorization" was introduced with OpenAPI 3.2. This entry is omitted when generating an OpenAPI document with a lower version.



22
23
24
25
26
27
# File 'lib/jsapi/meta/security_scheme/oauth2.rb', line 22

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

#to_openapi(version) ⇒ Object

Returns a hash representing the OpenAPI security scheme object.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/jsapi/meta/security_scheme/oauth2.rb', line 37

def to_openapi(version, *)
  version = OpenAPI::Version.from(version)

  flows = oauth_flows
  flows = flows.except('device_authorization') if version < OpenAPI::V3_2

  openapi_security_scheme_object(
    'oauth2',
    version,
    **if version >= OpenAPI::V3_0
        {
          flows:
            flows.to_h do |key, value|
              [key.to_s.camelize(:lower), value.to_openapi(version)]
            end.presence,
          oauth2MetadataUrl: ( if version >= OpenAPI::V3_2)
        }
      elsif flows.one?
        key, flow = flows.first
        { flow: key, **flow.to_openapi(version) }
      else
        {}
      end
  )
end