class SwaggerApi::Operations::Base

Attributes

action[RW]
controller[RW]

Public Instance Methods

create() click to toggle source
# File lib/swagger_api/operations/base.rb, line 12
def create
  {
    summary: "#{readable_action} #{model_name}",
    description: "#{readable_action} #{model_name.downcase}'s information",
    parameters: parameters,
    responses: responses,
    tags: [model_name]
  }
end
error_responses() click to toggle source
# File lib/swagger_api/operations/base.rb, line 66
def error_responses
  [
    {
      '404' => { '$ref' => '#/components/responses/NotFound' }
    },
    {
      '401' => { '$ref' => '#/components/responses/Unauthorized' }
    },
    {
      '422' => { '$ref' => '#/components/responses/BadRequest' }
    }
  ]
end
model() click to toggle source
# File lib/swagger_api/operations/base.rb, line 88
def model
  @model ||= model_name.constantize
end
model_name() click to toggle source
# File lib/swagger_api/operations/base.rb, line 84
def model_name
  @model_name ||= controller.model
end
parameters() click to toggle source
# File lib/swagger_api/operations/base.rb, line 22
def parameters
  [
    {
      name: 'id',
      in: 'path',
      description: "ID of #{model_name}",
      required: true,
      schema: {
        type: :integer,
        format: :int64,
        minimum: 1
      }
    }
  ]
end
readable_action() click to toggle source
# File lib/swagger_api/operations/base.rb, line 80
def readable_action
  @readable_action ||= self.class.name.demodulize.downcase
end
request_body() click to toggle source
# File lib/swagger_api/operations/base.rb, line 38
def request_body
  {
    '$ref' => "#/components/requestBodies/#{model_name}"
  }
end
responses() click to toggle source
# File lib/swagger_api/operations/base.rb, line 44
def responses
  return @responses unless @responses.nil?
  @responses = success_response
  error_responses.each do |error_response|
    @responses.merge!(error_response)
  end
  @responses
end
success_response() click to toggle source
# File lib/swagger_api/operations/base.rb, line 53
def success_response
  {
    '200' => {
      description: "#{readable_action} #{model_name.downcase}'s information",
      content: {
        'application/json; charset=utf-8' => {
          schema: schema(model)
        }
      }
    }
  }
end