Module: Jsapi::Meta::SecurityScheme

Defined in:
lib/jsapi/meta/security_scheme.rb,
lib/jsapi/meta/security_scheme/base.rb,
lib/jsapi/meta/security_scheme/http.rb,
lib/jsapi/meta/security_scheme/oauth2.rb,
lib/jsapi/meta/security_scheme/api_key.rb,
lib/jsapi/meta/security_scheme/http/basic.rb,
lib/jsapi/meta/security_scheme/http/other.rb,
lib/jsapi/meta/security_scheme/http/bearer.rb,
lib/jsapi/meta/security_scheme/open_id_connect.rb

Defined Under Namespace

Modules: HTTP Classes: APIKey, Base, OAuth2, OpenIDConnect

Class Method Summary collapse

Class Method Details

.new(keywords = {}) ⇒ Object

Creates a security scheme. The :type keyword specifies the type of the security scheme to be created. Possible types are:

  • "api_key"

  • "basic"

  • "http"

  • "oauth2"

  • "open_id_connect"

Raises an InvalidArgumentError if the given type is invalid.



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

def new(keywords = {})
  type = keywords[:type]
  keywords = keywords.except(:type)

  case type&.to_s
  when 'api_key'
    APIKey.new(keywords)
  when 'basic' # OpenAPI 2.0
    HTTP.new(keywords.merge(scheme: 'basic'))
  when 'http' # OpenAPI 3.0 and higher
    HTTP.new(keywords)
  when 'oauth2'
    OAuth2.new(keywords)
  when 'open_id_connect' # OpenAPI 3.0 and higher
    OpenIDConnect.new(keywords)
  else
    raise InvalidArgumentError.new(
      'type',
      type,
      valid_values: %w[api_key basic http oauth2 open_id_connect]
    )
  end
end