Class: WestfieldSwagger::SwaggerController

Inherits:
ApplicationController show all
Defined in:
app/controllers/westfield_swagger/swagger_controller.rb

Constant Summary collapse

ENV_PREFIX =
%w(uat production).include?(Rails.env) ? "#{Rails.env}_" : ''

Instance Method Summary collapse

Instance Method Details

#indexObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/westfield_swagger/swagger_controller.rb', line 8

def index
  if params[:service]
    # Access service swagger
    env_prefix = ''
    @service = "#{params[:service]}/"
  else
    # Access roll-up swagger
    env_prefix = ENV_PREFIX
    @service = ""
  end

  @spec = WestfieldSwagger::ApiSpecification.new(params[:version], binding, request, env_prefix)

  respond_to do |format|
    format.html
    format.json { render json: @spec.read }
    format.all {
      render text: "Format '#{params[:format]}' not supported", status: 404
    }
  end
end

#specification_missing(exception) ⇒ Object



35
36
37
38
# File 'app/controllers/westfield_swagger/swagger_controller.rb', line 35

def specification_missing(exception)
  data = { error: exception.message }
  render json: data, status: 404
end

#specification_parse_error(exception) ⇒ Object



30
31
32
33
# File 'app/controllers/westfield_swagger/swagger_controller.rb', line 30

def specification_parse_error(exception)
  data = { error: exception.message }
  render json: data, status: 500
end