Skip to content

Commit

Permalink
additions to #515 (#518)
Browse files Browse the repository at this point in the history
  • Loading branch information
peter scholz authored Oct 12, 2016
1 parent 197103e commit 10ed0b8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#### Fixes

* [#515](https://github.com/ruby-grape/grape-swagger/pull/515): Removes limit on model names, updates README - [@LeFnord](https://github.com/LeFnord).
* [#515](https://github.com/ruby-grape/grape-swagger/pull/515): Removes limit on model names - [@LeFnord](https://github.com/LeFnord).
* Your contribution here.

### 0.24.0 (September 23, 2016)
Expand Down
3 changes: 1 addition & 2 deletions lib/grape-swagger/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,12 @@ def expose_params_from_model(model)
end

def model_name(entity)
if entity.respond_to?(:entity_name)
if entity.methods(false).include?(:entity_name)
entity.entity_name
elsif entity.to_s.end_with?('::Entity', '::Entities')
entity.to_s.split('::')[-2]
else
entity.name.demodulize.camelize
# entity.respond_to?(:name) ? entity.name.demodulize.camelize : entity.split('::').last
end
end

Expand Down
32 changes: 26 additions & 6 deletions spec/issues/430_entity_definitions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ module WithVeryLongName
module AnotherGroupingModule
class Class1
class Entity < Grape::Entity
expose :one_thing
expose :first_thing
end
end

class Class2
class Entities < Grape::Entity
expose :one_thing
expose :second_thing
end
end

class Class3
class Entity < Grape::Entity
expose :another_thing
expose :third_thing

def self.entity_name
'FooKlass'
Expand All @@ -32,13 +32,29 @@ def self.entity_name

class Class4
class FourthEntity < Grape::Entity
expose :another_thing
expose :fourth_thing
end
end

class Class5
class FithEntity < Class4::FourthEntity
expose :another_thing
expose :fith_thing
end
end

class Class6
class SixthEntity < Grape::Entity
expose :sixth_thing

def self.entity_name
'BarKlass'
end
end
end

class Class7
class SeventhEntity < Class6::SixthEntity
expose :seventh_thing
end
end
end
Expand All @@ -51,7 +67,9 @@ class NameApi < Grape::API
DummyEntities::WithVeryLongName::AnotherGroupingModule::Class2::Entities,
DummyEntities::WithVeryLongName::AnotherGroupingModule::Class3::Entity,
DummyEntities::WithVeryLongName::AnotherGroupingModule::Class4::FourthEntity,
DummyEntities::WithVeryLongName::AnotherGroupingModule::Class5::FithEntity
DummyEntities::WithVeryLongName::AnotherGroupingModule::Class5::FithEntity,
DummyEntities::WithVeryLongName::AnotherGroupingModule::Class6::SixthEntity,
DummyEntities::WithVeryLongName::AnotherGroupingModule::Class7::SeventhEntity
]
end
end
Expand All @@ -69,4 +87,6 @@ class NameApi < Grape::API
specify { expect(subject).to include 'FooKlass' }
specify { expect(subject).to include 'FourthEntity' }
specify { expect(subject).to include 'FithEntity' }
specify { expect(subject).to include 'BarKlass' }
specify { expect(subject).to include 'SeventhEntity' }
end

0 comments on commit 10ed0b8

Please sign in to comment.