Class: OpenAPISourceTools::SecuritySchemeInfo

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/openapi/sourcetools/securityschemes.rb

Overview

Class that contains security scheme objects and what headers and parameters are added to the request when the scheme is used.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(security_scheme = {}, scheme_templates = []) ⇒ SecuritySchemeInfo

Returns a new instance of SecuritySchemeInfo.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/openapi/sourcetools/securityschemes.rb', line 18

def initialize(security_scheme = {}, scheme_templates = [])
  @headers = {}
  @parameters = {}
  @query_parameters = {}
  @cookies = {}
  scheme_templates.each do |template|
    s = template['scheme']
    match = true
    s.each do |k, v|
      unless v == security_scheme[k]
        match = false
        break
      end
    end
    next unless match
    o = template['output']
    fill_in(@headers, o['headers'] || {}, security_scheme)
    fill_in(@parameters, o['parameters'] || {}, security_scheme)
    fill_in(@query_parameters, o['query_parameters'] || {}, security_scheme)
    fill_in(@cookies, o['cookies'] || {}, security_scheme)
    break
  end
end

Instance Attribute Details

#cookiesObject (readonly)

Returns the value of attribute cookies.



16
17
18
# File 'lib/openapi/sourcetools/securityschemes.rb', line 16

def cookies
  @cookies
end

#headersObject (readonly)

Returns the value of attribute headers.



16
17
18
# File 'lib/openapi/sourcetools/securityschemes.rb', line 16

def headers
  @headers
end

#parametersObject (readonly)

Returns the value of attribute parameters.



16
17
18
# File 'lib/openapi/sourcetools/securityschemes.rb', line 16

def parameters
  @parameters
end

#query_parametersObject (readonly)

Returns the value of attribute query_parameters.



16
17
18
# File 'lib/openapi/sourcetools/securityschemes.rb', line 16

def query_parameters
  @query_parameters
end

Instance Method Details

#<=>(other) ⇒ Object



69
70
71
72
# File 'lib/openapi/sourcetools/securityschemes.rb', line 69

def <=>(other)
  # Only really interested in equality.
  @headers <=> other.headers || @parameters <=> other.parameters || @query_parameters <=> other.query_parameters || @cookies <=> other.cookies
end

#fill_in(output, source, scheme) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/openapi/sourcetools/securityschemes.rb', line 42

def fill_in(output, source, scheme)
  source.each do |k, v|
    if k.start_with?('<') && k.end_with?('>')
      scheme_key = k[1..-2]
      scheme_value = scheme[scheme_key]
      raise "Missing security scheme value for #{scheme_key}" if scheme_value.nil?
      output[scheme_value] = v
    else
      output[k] = v
    end
  end
end

#merge(other) ⇒ Object



62
63
64
65
66
67
# File 'lib/openapi/sourcetools/securityschemes.rb', line 62

def merge(other)
  out = SecuritySchemeInfo.new({}, [])
  out.merge!(self)
  out.merge!(other)
  out
end

#merge!(other) ⇒ Object



55
56
57
58
59
60
# File 'lib/openapi/sourcetools/securityschemes.rb', line 55

def merge!(other)
  @headers.merge!(other.headers)
  @parameters.merge!(other.parameters)
  @query_parameters.merge!(other.query_parameters)
  @cookies.merge!(other.cookies)
end