Class: SwaggerYard::Authorization

Inherits:
Object
  • Object
show all
Defined in:
lib/swagger_yard/authorization.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, pass_as, key) ⇒ Authorization

Returns a new instance of Authorization.



10
11
12
# File 'lib/swagger_yard/authorization.rb', line 10

def initialize(type, pass_as, key)
  @type, @pass_as, @key = type, pass_as, key
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



3
4
5
# File 'lib/swagger_yard/authorization.rb', line 3

def key
  @key
end

#nameObject

the spec suggests most auth names are just the type of auth



15
16
17
# File 'lib/swagger_yard/authorization.rb', line 15

def name
  @name ||= [@pass_as, @key].join('_').downcase.gsub('-', '_')
end

#pass_asObject (readonly)

Returns the value of attribute pass_as.



3
4
5
# File 'lib/swagger_yard/authorization.rb', line 3

def pass_as
  @pass_as
end

Class Method Details

.from_yard_object(yard_object) ⇒ Object



6
7
8
# File 'lib/swagger_yard/authorization.rb', line 6

def self.from_yard_object(yard_object)
  new(yard_object.types.first, yard_object.name, yard_object.text)
end

Instance Method Details

#to_hObject



28
29
30
31
32
# File 'lib/swagger_yard/authorization.rb', line 28

def to_h
  { "type" => type,
    "name" => @key,
    "in"   => @pass_as }
end

#typeObject



19
20
21
22
23
24
25
26
# File 'lib/swagger_yard/authorization.rb', line 19

def type
  case @type
  when "api_key"
    "apiKey"
  when "basic_auth"
    "basicAuth"
  end
end