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.

Constant Summary

Constants included from Base::Attributes

Base::Attributes::DEFAULT_ARRAY, Base::Attributes::DEFAULT_HASH

Instance Method Summary collapse

Methods included from OpenAPI::Extensions

#add_openapi_extension, #openapi_extensions, #openapi_extensions=

Methods inherited from Base

#description

Methods inherited from Base::Model

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

Methods included from Base::Attributes

#attribute, #attribute_names

Constructor Details

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

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.



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

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

#to_openapi(version) ⇒ Object

Returns a hash representing the OpenAPI security scheme object.



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

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

  with_openapi_extensions(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
end