Skip to content

Commit

Permalink
Modify full entity name to be RFC3986 compliant #797 (#798)
Browse files Browse the repository at this point in the history
* Modify full entity name to be RFC3986 compliant #797

Signed-off-by: Garrett Blehm <garrett.blehm@cerner.com>

* Update changelog and upgrading files

Signed-off-by: Garrett Blehm <garrett.blehm@cerner.com>

* Update Changelog

* Corrects next version

* Modified ineritance and discriminator spec

Signed-off-by: Garrett Blehm <garrett.blehm@cerner.com>

Co-authored-by: Garrett Blehm <garrett.blehm@cerner.com>
Co-authored-by: peter scholz <pscholz.le@gmail.com>
  • Loading branch information
3 people authored Jun 30, 2020
1 parent e86c9ba commit 961e7ca
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#### Fixes

* Your contribution here.
* [#798](https://github.com/ruby-grape/grape-swagger/pull/798): Modify full entity name separator - [@GarrettB71](https://github.com/GarrettB71).
* [#796](https://github.com/ruby-grape/grape-swagger/pull/796): Support grape 1.4.0 - [@thedanielhanke](https://github.com/thedanielhanke).


Expand Down
4 changes: 4 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Upgrading Grape-swagger

### Upgrading to >= 1.2.0

Full class name is modified to use `_` separator (e.g. `A_B_C` instead of `A::B::C`).

### Upgrading to >= 1.1.0

Full class name is used for referencing entity by default (e.g. `A::B::C` instead of just `C`). `Entity` and `Entities` suffixes and prefixes are omitted (e.g. if entity name is `Entities::SomeScope::MyFavourite::Entity` only `SomeScope::MyFavourite` will be used).
Expand Down
6 changes: 3 additions & 3 deletions lib/grape-swagger/doc_methods/data_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ def parse_entity_name(model)
if model.methods(false).include?(:entity_name)
model.entity_name
elsif model.to_s.end_with?('::Entity', '::Entities')
model.to_s.split('::')[0..-2].join('::')
model.to_s.split('::')[0..-2].join('_')
elsif model.to_s.start_with?('Entity::', 'Entities::', 'Representable::')
model.to_s.split('::')[1..-1].join('::')
model.to_s.split('::')[1..-1].join('_')
else
model.to_s
model.to_s.split('::').join('_')
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/issues/427_entity_as_string_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ class RoleEntity < Grape::Entity
JSON.parse(last_response.body)['definitions']
end

specify { expect(subject.keys).to include 'RoleEntity', 'Permission::WithoutRole' }
specify { expect(subject.keys).to include 'RoleEntity', 'Permission_WithoutRole' }
end
10 changes: 5 additions & 5 deletions spec/issues/430_entity_definitions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ class NameApi < Grape::API
JSON.parse(last_response.body)['definitions']
end

specify { expect(subject).to include 'TestDefinition::DummyEntities::WithVeryLongName::AnotherGroupingModule::Class1' }
specify { expect(subject).to include 'TestDefinition::DummyEntities::WithVeryLongName::AnotherGroupingModule::Class2' }
specify { expect(subject).to include 'TestDefinition_DummyEntities_WithVeryLongName_AnotherGroupingModule_Class1' }
specify { expect(subject).to include 'TestDefinition_DummyEntities_WithVeryLongName_AnotherGroupingModule_Class2' }
specify { expect(subject).to include 'FooKlass' }
specify { expect(subject).to include 'TestDefinition::DummyEntities::WithVeryLongName::AnotherGroupingModule::Class4::FourthEntity' }
specify { expect(subject).to include 'TestDefinition::DummyEntities::WithVeryLongName::AnotherGroupingModule::Class5::FithEntity' }
specify { expect(subject).to include 'TestDefinition_DummyEntities_WithVeryLongName_AnotherGroupingModule_Class4_FourthEntity' }
specify { expect(subject).to include 'TestDefinition_DummyEntities_WithVeryLongName_AnotherGroupingModule_Class5_FithEntity' }
specify { expect(subject).to include 'BarKlass' }
specify { expect(subject).to include 'TestDefinition::DummyEntities::WithVeryLongName::AnotherGroupingModule::Class7::SeventhEntity' }
specify { expect(subject).to include 'TestDefinition_DummyEntities_WithVeryLongName_AnotherGroupingModule_Class7_SeventhEntity' }
end
4 changes: 2 additions & 2 deletions spec/swagger_v2/api_swagger_v2_param_type_body_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def app
'type' => 'object',
'properties' => {
'data' => {
'$ref' => '#/definitions/NestedModule::ApiResponse',
'$ref' => '#/definitions/NestedModule_ApiResponse',
'description' => 'request data'
}
},
Expand All @@ -207,7 +207,7 @@ def app
end

specify do
expect(subject['definitions']['NestedModule::ApiResponse']).not_to be_nil
expect(subject['definitions']['NestedModule_ApiResponse']).not_to be_nil
end

specify do
Expand Down
6 changes: 3 additions & 3 deletions spec/swagger_v2/inheritance_and_discriminator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ class NameApi < Grape::API
end

specify do
subject['InheritanceTest::Entities::Pet'].key?('discriminator')
subject['InheritanceTest::Entities::Pet']['discriminator'] = 'type'
subject['InheritanceTest::Entities::Cat'].key?('allOf')
subject['InheritanceTest_Entities_Pet'].key?('discriminator')
subject['InheritanceTest_Entities_Pet']['discriminator'] = 'type'
subject['InheritanceTest_Entities_Cat'].key?('allOf')
end
end
end

0 comments on commit 961e7ca

Please sign in to comment.