Class: Jsapi::Meta::SecurityScheme::OAuth2
- Inherits:
-
Base
- Object
- Model::Base
- Base
- Jsapi::Meta::SecurityScheme::OAuth2
- 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 Model::Attributes
Model::Attributes::DEFAULT_ARRAY, Model::Attributes::DEFAULT_HASH
Instance Method Summary collapse
-
#oauth2_metadata_url ⇒ Object
:attr: oauth2_metadata_url The URL of the OAuth2 authorization server metadata.
-
#oauth_flows ⇒ Object
:attr: oauth_flows Maps one or more of the following keys to OAuthFlow objects.
-
#to_openapi(version) ⇒ Object
Returns a hash representing the OpenAPI security scheme object.
Methods included from OpenAPI::Extensions
Methods inherited from Base
Methods inherited from Model::Base
#initialize, #inspect, #merge!, #reference?, #resolve
Methods included from Model::Attributes
Constructor Details
This class inherits a constructor from Jsapi::Meta::Model::Base
Instance Method Details
#oauth2_metadata_url ⇒ Object
:attr: oauth2_metadata_url The URL of the OAuth2 authorization server metadata. Applies to OpenAPI 3.2 and higher.
32 |
# File 'lib/jsapi/meta/security_scheme/oauth2.rb', line 32 attribute :oauth2_metadata_url, String |
#oauth_flows ⇒ Object
: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.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/jsapi/meta/security_scheme/oauth2.rb', line 35 def to_openapi(version, *) version = OpenAPI::Version.from(version) with_openapi_extensions( base_openapi_fields('oauth2', version).tap do |fields| flows = oauth_flows flows = flows.except('device_authorization') unless version >= OpenAPI::V3_2 if version >= OpenAPI::V3_0 fields[:flows] = flows.to_h do |key, value| [key.to_s.camelize(:lower).to_sym, value.to_openapi(version)] end if flows.any? fields[:oauth2MetadataUrl] = if version >= OpenAPI::V3_2 elsif flows.one? key, flow = flows.first fields[:flow] = key.to_s fields.merge!(flow.to_openapi(version)) end end ) end |