Class: Gitlab::GrapeOpenapi::Models::SecurityScheme

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/grape_openapi/models/security_scheme.rb

Overview

Constant Summary collapse

VALID_TYPES =
%w[apiKey http oauth2 openIdConnect].freeze
VALID_IN_VALUES =
%w[query header cookie].freeze
VALID_HTTP_SCHEMES =
%w[basic bearer oauth].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, **options) ⇒ SecurityScheme

Returns a new instance of SecurityScheme.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/gitlab/grape_openapi/models/security_scheme.rb', line 15

def initialize(type:, **options)
  @type = type
  validate_type!

  @description = options[:description]

  case @type
  when 'apiKey'
    @name = options[:name] || raise(ArgumentError, "name is required for apiKey type")
    @in = options[:in] || raise(ArgumentError, "in is required for apiKey type")
    validate_in!
  when 'http'
    @scheme = options[:scheme] || raise(ArgumentError, "scheme is required for http type")
    validate_http_scheme!
    @bearer_format = options[:bearer_format] if @scheme == 'bearer'
  when 'oauth2'
    @flows = options[:flows] || raise(ArgumentError, "flows is required for oauth2 type")
    validate_oauth2_flows!
  when 'openIdConnect'
    @open_id_connect_url = options[:open_id_connect_url] ||
      raise(ArgumentError, "open_id_connect_url is required for openIdConnect type")
  end
end

Instance Attribute Details

#bearer_formatObject

Returns the value of attribute bearer_format.



12
13
14
# File 'lib/gitlab/grape_openapi/models/security_scheme.rb', line 12

def bearer_format
  @bearer_format
end

#descriptionObject

Returns the value of attribute description.



12
13
14
# File 'lib/gitlab/grape_openapi/models/security_scheme.rb', line 12

def description
  @description
end

#flowsObject

Returns the value of attribute flows.



12
13
14
# File 'lib/gitlab/grape_openapi/models/security_scheme.rb', line 12

def flows
  @flows
end

#inObject

Returns the value of attribute in.



12
13
14
# File 'lib/gitlab/grape_openapi/models/security_scheme.rb', line 12

def in
  @in
end

#nameObject

Returns the value of attribute name.



12
13
14
# File 'lib/gitlab/grape_openapi/models/security_scheme.rb', line 12

def name
  @name
end

#open_id_connect_urlObject

Returns the value of attribute open_id_connect_url.



12
13
14
# File 'lib/gitlab/grape_openapi/models/security_scheme.rb', line 12

def open_id_connect_url
  @open_id_connect_url
end

#schemeObject

Returns the value of attribute scheme.



12
13
14
# File 'lib/gitlab/grape_openapi/models/security_scheme.rb', line 12

def scheme
  @scheme
end

#typeObject

Returns the value of attribute type.



12
13
14
# File 'lib/gitlab/grape_openapi/models/security_scheme.rb', line 12

def type
  @type
end

Instance Method Details

#to_hObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/gitlab/grape_openapi/models/security_scheme.rb', line 39

def to_h
  hash = { 'type' => @type }
  hash['description'] = @description if @description

  case @type
  when 'apiKey'
    hash['name'] = @name
    hash['in'] = @in
  when 'http'
    hash['scheme'] = @scheme
    hash['bearerFormat'] = @bearer_format if @bearer_format
  when 'oauth2'
    hash['flows'] = flows_to_hash(@flows)
  when 'openIdConnect'
    hash['openIdConnectUrl'] = @open_id_connect_url
  end

  hash
end