Module: Rails::Swagger::Controller

Defined in:
lib/rails/swagger/controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Injects swagger-related code into the controller when included



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rails/swagger/controller.rb', line 14

def self.included base

  # Add controller hooks
  # base.class_eval do
  #   before_action :swagger_validate_params
  # end

  # Returns the swagger spec definition for the endpoint serving
  # the current request.
  def swagger_endpoint
    key = "#{params[:controller]}##{params[:action]}"
    swagger_engine.endpoints[key]
  end

  # Validates request parameters against the Swagger API spec
  # associated with this controller.
  # def swagger_validate_params
  #   if METHODS_WITH_BODIES.include? request.method_symbol
  #     body = request.POST
  #     # TODO: add validation here
  #   end
  # end

end

Instance Method Details

#swagger_endpointObject

Returns the swagger spec definition for the endpoint serving the current request.



23
24
25
26
# File 'lib/rails/swagger/controller.rb', line 23

def swagger_endpoint
  key = "#{params[:controller]}##{params[:action]}"
  swagger_engine.endpoints[key]
end