Skip to content

Use full entity name as a default (fixes #779) #786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Your contribution here.
* [#785](https://github.com/ruby-grape/grape-swagger/pull/785): Add extensions for params - [@MaximeRDY](https://github.com/MaximeRDY).
* [#782](https://github.com/ruby-grape/grape-swagger/pull/782): Allow passing class name as string for rake task initializer - [@misdoro](https://github.com/misdoro).

* [#786](https://github.com/ruby-grape/grape-swagger/pull/786): Use full entity name as a default - [@mrexox](https://github.com/mrexox)

#### Fixes

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.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).

### Upgrading to >= 0.26.1

The format can now be specified,
Expand Down
8 changes: 4 additions & 4 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('::')[-2]
elsif model.respond_to?(:name)
model.name.demodulize.camelize
model.to_s.split('::')[0..-2].join('::')
elsif model.to_s.start_with?('Entity::', 'Entities::', 'Representable::')
model.to_s.split('::')[1..-1].join('::')
else
model.to_s.split('::').last
model.to_s
end
end

Expand Down
1 change: 0 additions & 1 deletion lib/grape-swagger/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ def expose_params_from_model(model)
raise GrapeSwagger::Errors::SwaggerSpec,
"Empty model #{model_name}, swagger 2.0 doesn't support empty definitions."
end

@definitions[model_name] = GrapeSwagger::DocMethods::BuildModelDefinition.build(model, properties, required)

model_name
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', '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 'Class1' }
specify { expect(subject).to include '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 'FourthEntity' }
specify { expect(subject).to include '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 '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/ApiResponse',
'$ref' => '#/definitions/NestedModule::ApiResponse',
'description' => 'request data'
}
},
Expand All @@ -207,7 +207,7 @@ def app
end

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

specify do
Expand Down