Class: Aikido::Zen::Request::Schema::AuthSchemas

Inherits:
Object
  • Object
show all
Defined in:
lib/aikido/zen/request/schema/auth_schemas.rb

Defined Under Namespace

Classes: ApiKey, Authorization

Constant Summary collapse

NONE =
new([])

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schemas) ⇒ AuthSchemas

Returns a new instance of AuthSchemas.



8
9
10
# File 'lib/aikido/zen/request/schema/auth_schemas.rb', line 8

def initialize(schemas)
  @schemas = schemas
end

Instance Attribute Details

#schemasObject (readonly)

Returns the value of attribute schemas.



6
7
8
# File 'lib/aikido/zen/request/schema/auth_schemas.rb', line 6

def schemas
  @schemas
end

Class Method Details

.from_json(schemas_array) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/aikido/zen/request/schema/auth_schemas.rb', line 21

def self.from_json(schemas_array)
  return NONE if !schemas_array || schemas_array.empty?

  AuthSchemas.new(schemas_array.map do |schema|
    case schema["type"]
    when "http"
      Authorization.new(schema["scheme"])
    when "apiKey"
      ApiKey.new(schema["in"], schema["name"])
    else
      raise "Invalid schema type: #{schema["type"]}"
    end
  end)
end

Instance Method Details

#==(other) ⇒ Object



36
37
38
# File 'lib/aikido/zen/request/schema/auth_schemas.rb', line 36

def ==(other)
  other.is_a?(self.class) && schemas == other.schemas
end

#as_jsonObject



17
18
19
# File 'lib/aikido/zen/request/schema/auth_schemas.rb', line 17

def as_json
  @schemas.map(&:as_json) unless @schemas.empty?
end

#merge(other) ⇒ Object Also known as: |



12
13
14
# File 'lib/aikido/zen/request/schema/auth_schemas.rb', line 12

def merge(other)
  self.class.new((schemas + other.schemas).uniq)
end