class Swagger::Grape::Entity

Public Class Methods

new(type) click to toggle source
# File lib/ruby-swagger/grape/entity.rb, line 3
def initialize(type)
  raise ArgumentError.new("Expecting a Grape::Entity - Can't translate this!") unless Object.const_get(type) < Grape::Entity

  @type = type
  @swagger_type = { 'type' => 'object', 'properties' => {} }
end

Public Instance Methods

sub_types() click to toggle source
# File lib/ruby-swagger/grape/entity.rb, line 17
def sub_types
  collection = []
  root_exposures.each do |exposure|
    exposure = Swagger::Grape::EntityExposure.new(exposure)
    collection << exposure.sub_type if exposure.sub_type

    exposure.nested_exposures.each do |nested_exposure|
      nested_exposure = Swagger::Grape::EntityExposure.new(nested_exposure)
      collection << nested_exposure.sub_type if nested_exposure.sub_type
    end if exposure.nested?
  end
  collection.uniq
end
to_swagger() click to toggle source
# File lib/ruby-swagger/grape/entity.rb, line 10
def to_swagger
  root_exposures.each do |exposure|
    @swagger_type['properties'].merge!(Swagger::Grape::EntityExposure.new(exposure).to_swagger)
  end
  @swagger_type
end

Private Instance Methods

entity_class() click to toggle source
# File lib/ruby-swagger/grape/entity.rb, line 37
def entity_class
  Object.const_get(@type)
end
root_exposures() click to toggle source
# File lib/ruby-swagger/grape/entity.rb, line 33
def root_exposures
  entity_class.root_exposures
end