Class: Swagger::Grape::Entity

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-swagger/grape/entity.rb

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ Entity

Returns a new instance of Entity.

Raises:

  • (ArgumentError)


3
4
5
6
7
8
# 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

Instance Method Details

#sub_typesObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# 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_swaggerObject



10
11
12
13
14
15
# 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