Class: Swagger::Grape::Entity
- Inherits:
-
Object
- Object
- Swagger::Grape::Entity
- Defined in:
- lib/ruby-swagger/grape/entity.rb
Instance Method Summary collapse
-
#initialize(type) ⇒ Entity
constructor
A new instance of Entity.
- #sub_types ⇒ Object
- #to_swagger ⇒ Object
Constructor Details
#initialize(type) ⇒ Entity
Returns a new instance of Entity.
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_types ⇒ Object
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_swagger ⇒ Object
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 |