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.



381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
# File 'lib/openapi/sourcetools/apiobjects.rb', line 381

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.



379
380
381
# File 'lib/openapi/sourcetools/apiobjects.rb', line 379

def extras
  @extras
end

#reqsObject (readonly)

Returns the value of attribute reqs.



379
380
381
# File 'lib/openapi/sourcetools/apiobjects.rb', line 379

def reqs
  @reqs
end

Instance Method Details

#<=>(other) ⇒ Object



407
408
409
410
411
412
413
414
415
416
417
# File 'lib/openapi/sourcetools/apiobjects.rb', line 407

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