Class: Swagger::Docs::SwaggerDSL

Inherits:
Object
  • Object
show all
Defined in:
lib/swagger/docs/dsl.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(action, caller, &block) ⇒ Object


5
6
7
8
9
10
11
12
13
14
# File 'lib/swagger/docs/dsl.rb', line 5

def self.call(action, caller, &block)
  # Create a new SwaggerDSL instance, and instance_eval the block to it
  instance = new
  instance.instance_eval(&block)
  # Now return all of the set instance variables as a Hash
  instance.instance_variables.inject({}) { |result_hash, instance_variable|
    result_hash[instance_variable] = instance.instance_variable_get(instance_variable)
    result_hash # Gotta have the block return the result_hash
  }
end

Instance Method Details

#consumes(mime_types) ⇒ Object


36
37
38
# File 'lib/swagger/docs/dsl.rb', line 36

def consumes(mime_types)
  @consumes = mime_types
end

#items(items) ⇒ Object


32
33
34
# File 'lib/swagger/docs/dsl.rb', line 32

def items(items)
  @items = items
end

#method(method) ⇒ Object


24
25
26
# File 'lib/swagger/docs/dsl.rb', line 24

def method(method)
  @method = method
end

#nickname(nickname) ⇒ Object


40
41
42
# File 'lib/swagger/docs/dsl.rb', line 40

def nickname(nickname)
  @nickname = nickname
end

#notes(text) ⇒ Object


20
21
22
# File 'lib/swagger/docs/dsl.rb', line 20

def notes(text)
  @notes = text
end

#param(param_type, name, type, required, description = nil, hash = {}) ⇒ Object


48
49
50
51
# File 'lib/swagger/docs/dsl.rb', line 48

def param(param_type, name, type, required, description = nil, hash={})
  parameters << {:param_type => param_type, :name => name, :type => type,
    :description => description, :required => required == :required}.merge(hash)
end

#param_list(param_type, name, type, required, description = nil, allowed_values = [], hash = {}) ⇒ Object

helper method to generate enums


54
55
56
57
# File 'lib/swagger/docs/dsl.rb', line 54

def param_list(param_type, name, type, required, description = nil, allowed_values = [], hash = {})
  hash.merge!({allowable_values: {value_type: "LIST", values: allowed_values}})
  param(param_type, name, type, required, description, hash)
end

#parametersObject


44
45
46
# File 'lib/swagger/docs/dsl.rb', line 44

def parameters
  @parameters ||= []
end

#response(status, text = nil, model = nil) ⇒ Object


63
64
65
66
67
68
69
70
71
72
# File 'lib/swagger/docs/dsl.rb', line 63

def response(status, text = nil, model = nil)
  if status.is_a? Symbol
    status == :ok if status == :success
    status_code = Rack::Utils.status_code(status)
    response_messages << {:code => status_code, :responseModel => model, :message => text || status.to_s.titleize}
  else
    response_messages << {:code => status, :responseModel => model, :message => text}
  end
  response_messages.sort_by!{|i| i[:code]}
end

#response_messagesObject


59
60
61
# File 'lib/swagger/docs/dsl.rb', line 59

def response_messages
  @response_messages ||= []
end

#summary(text) ⇒ Object


16
17
18
# File 'lib/swagger/docs/dsl.rb', line 16

def summary(text)
  @summary = text
end

#type(type) ⇒ Object


28
29
30
# File 'lib/swagger/docs/dsl.rb', line 28

def type(type)
  @type = type
end