From 961e7ca927d867dc359426e2da5fd4e086fc295a Mon Sep 17 00:00:00 2001 From: Garrett Blehm Date: Tue, 30 Jun 2020 09:20:34 -0500 Subject: [PATCH] Modify full entity name to be RFC3986 compliant #797 (#798) * Modify full entity name to be RFC3986 compliant #797 Signed-off-by: Garrett Blehm * Update changelog and upgrading files Signed-off-by: Garrett Blehm * Update Changelog * Corrects next version * Modified ineritance and discriminator spec Signed-off-by: Garrett Blehm Co-authored-by: Garrett Blehm Co-authored-by: peter scholz --- CHANGELOG.md | 1 + UPGRADING.md | 4 ++++ lib/grape-swagger/doc_methods/data_type.rb | 6 +++--- spec/issues/427_entity_as_string_spec.rb | 2 +- spec/issues/430_entity_definitions_spec.rb | 10 +++++----- spec/swagger_v2/api_swagger_v2_param_type_body_spec.rb | 4 ++-- spec/swagger_v2/inheritance_and_discriminator_spec.rb | 6 +++--- 7 files changed, 19 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3c47ede..1b8b5118 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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). diff --git a/UPGRADING.md b/UPGRADING.md index 47790dd9..e9f25386 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -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). diff --git a/lib/grape-swagger/doc_methods/data_type.rb b/lib/grape-swagger/doc_methods/data_type.rb index 2e45a778..a3bd7986 100644 --- a/lib/grape-swagger/doc_methods/data_type.rb +++ b/lib/grape-swagger/doc_methods/data_type.rb @@ -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 diff --git a/spec/issues/427_entity_as_string_spec.rb b/spec/issues/427_entity_as_string_spec.rb index 3a00ebda..2c377591 100644 --- a/spec/issues/427_entity_as_string_spec.rb +++ b/spec/issues/427_entity_as_string_spec.rb @@ -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 diff --git a/spec/issues/430_entity_definitions_spec.rb b/spec/issues/430_entity_definitions_spec.rb index 6de6515c..346bce92 100644 --- a/spec/issues/430_entity_definitions_spec.rb +++ b/spec/issues/430_entity_definitions_spec.rb @@ -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 diff --git a/spec/swagger_v2/api_swagger_v2_param_type_body_spec.rb b/spec/swagger_v2/api_swagger_v2_param_type_body_spec.rb index 197510fb..1a539e85 100644 --- a/spec/swagger_v2/api_swagger_v2_param_type_body_spec.rb +++ b/spec/swagger_v2/api_swagger_v2_param_type_body_spec.rb @@ -189,7 +189,7 @@ def app 'type' => 'object', 'properties' => { 'data' => { - '$ref' => '#/definitions/NestedModule::ApiResponse', + '$ref' => '#/definitions/NestedModule_ApiResponse', 'description' => 'request data' } }, @@ -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 diff --git a/spec/swagger_v2/inheritance_and_discriminator_spec.rb b/spec/swagger_v2/inheritance_and_discriminator_spec.rb index 189c3016..8486ffd6 100644 --- a/spec/swagger_v2/inheritance_and_discriminator_spec.rb +++ b/spec/swagger_v2/inheritance_and_discriminator_spec.rb @@ -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