Class: WeakSwaggerParameters::Definitions::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/weak_swagger_parameters/definitions/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_method, action, path, summary, &block) ⇒ Api

Returns a new instance of Api.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/weak_swagger_parameters/definitions/api.rb', line 8

def initialize(http_method, action, path, summary, &block)
  @http_method = http_method
  @action = action
  @path = path
  @summary = summary
  @param_definition = nil
  @response_definitions = []
  @description = nil

  instance_eval(&block) if block.present?
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/weak_swagger_parameters/definitions/api.rb', line 6

def path
  @path
end

Instance Method Details

#apply_docs(controller_class) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/weak_swagger_parameters/definitions/api.rb', line 43

def apply_docs(controller_class)
  this = self
  http_method = @http_method
  operation_params = operation_params(@action, controller_class)

  controller_class.instance_eval do
    swagger_path this.path do
      operation http_method, operation_params do
        this.child_definitions.each { |definition| definition.apply_docs(self) }
      end
    end
  end
end

#apply_validations(controller_class) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/weak_swagger_parameters/definitions/api.rb', line 32

def apply_validations(controller_class)
  child_definitions = validation_definitions
  action = @action

  controller_class.instance_eval do
    validates action do
      child_definitions.each { |definition| definition.apply_validations(self) }
    end
  end
end

#child_definitionsObject



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/weak_swagger_parameters/definitions/api.rb', line 57

def child_definitions
  result = validation_definitions

  if @response_definitions.empty?
    result << WeakSwaggerParameters::Definitions::Response.new(200, 'Success')
  else
    result += @response_definitions
  end

  result
end

#description(description) ⇒ Object



20
21
22
# File 'lib/weak_swagger_parameters/definitions/api.rb', line 20

def description(description)
  @description = description
end

#params(&block) ⇒ Object



24
25
26
# File 'lib/weak_swagger_parameters/definitions/api.rb', line 24

def params(&block)
  @param_definition = WeakSwaggerParameters::Definitions::Params.new(&block)
end

#response(status_code, description = '', &block) ⇒ Object



28
29
30
# File 'lib/weak_swagger_parameters/definitions/api.rb', line 28

def response(status_code, description = '', &block)
  @response_definitions << WeakSwaggerParameters::Definitions::Response.new(status_code, description, &block)
end