Class: OpenAPISourceTools::ApiObjects::SecurityRequirementObject

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

Overview

Simple holder that determines where parameters are placed.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reqs, schemes) ⇒ SecurityRequirementObject

Returns a new instance of SecurityRequirementObject.



277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/openapi/sourcetools/apiobjects.rb', line 277

def initialize(reqs, schemes)
  @reqs = reqs
  @extras = {}
  @reqs.each do |name, scopes|
    scheme = schemes[name].scheme
    case scheme['type']
    when 'apiKey'
      if scheme['in'] == 'header'
        h = @extras[:headers] || {}
        h[scheme['name']] = scopes
        @extras[:headers] = h
      elsif scheme['in'] == 'query'
        q = @extras[:query] || {}
        q[scheme['name']] = scopes
        @extras[:query] = q
      end
    when 'http', 'oauth2', 'openIdConnect'
      h = @extras[:headers] || {}
      h['authorization'] = scopes
      @extras[:headers] = h
    else
      raise "Unknown security type: #{scheme['type']} for #{name}"
    end
  end
end

Instance Attribute Details

#extrasObject (readonly)

Returns the value of attribute extras.



275
276
277
# File 'lib/openapi/sourcetools/apiobjects.rb', line 275

def extras
  @extras
end

#reqsObject (readonly)

Returns the value of attribute reqs.



275
276
277
# File 'lib/openapi/sourcetools/apiobjects.rb', line 275

def reqs
  @reqs
end

Instance Method Details

#<=>(other) ⇒ Object



303
304
305
306
307
308
309
310
311
312
313
# File 'lib/openapi/sourcetools/apiobjects.rb', line 303

def <=>(other)
  d = @reqs.size <=> other.reqs.size
  return d unless d.zero?
  d = @reqs.keys.sort! <=> other.reqs.keys.sort!
  return d unless d.zero?
  @reqs.keys.sort!.each do |name|
    d = @reqs[name].sort <=> other.reqs[name].sort
    return d unless d.zero?
  end
  0
end