Skip to content

corrects exposing of inline definitions #503

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
Sep 19, 2016
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 .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Metrics/AbcSize:
# Offense count: 3
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 231
Max: 240

# Offense count: 10
Metrics/CyclomaticComplexity:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#### Fixes

* [#503](https://github.com/ruby-grape/grape-swagger/pull/503): Corrects exposing of inline definitions - [@LeFnord](https://github.com/LeFnord).
* [#494](https://github.com/ruby-grape/grape-swagger/pull/494): Header parametes are now included in documentation when body parameters have been defined - [@anakinj](https://github.com/anakinj).
* Your contribution here.

Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ end

group :test do
gem 'ruby-grape-danger', '~> 0.1.0', require: false
gem 'grape-entity'
gem 'grape-swagger-entity'
end
12 changes: 11 additions & 1 deletion lib/grape-swagger/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,17 @@ def expose_params_from_model(model)
end

def model_name(name)
name.respond_to?(:name) ? name.name.demodulize.camelize : name.split('::').last
if name.respond_to?(:entity_name)
name.entity_name
elsif name.to_s.end_with?('Entity', 'Entities')
length = 0
name.to_s.split('::')[0..-2].reverse.take_while do |x|
length += x.length
length < 42
end.reverse.join
else
name.name.demodulize.camelize
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I let it, cause without it, it would be a breaking change

end
end

def hidden?(route, options)
Expand Down
48 changes: 48 additions & 0 deletions spec/issues/430_entity_definitions_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require 'spec_helper'
require 'grape-entity'
require 'grape-swagger-entity'

describe 'definition names' do
before :all do
module TestDefinition
module DummyEntities
module WithVeryLongName
module AnotherGroupingModule
class Class1
class Entity < Grape::Entity
expose :one_thing
end
end

class Class2
class Entity < Grape::Entity
expose :another_thing

def self.entity_name
'FooKlass'
end
end
end
end
end
end

class NameApi < Grape::API
add_swagger_documentation models: [
DummyEntities::WithVeryLongName::AnotherGroupingModule::Class1::Entity,
DummyEntities::WithVeryLongName::AnotherGroupingModule::Class2::Entity
]
end
end
end

let(:app) { TestDefinition::NameApi }

subject do
get '/swagger_doc'
JSON.parse(last_response.body)['definitions']
end

specify { expect(subject).to include 'AnotherGroupingModuleClass1' }
specify { expect(subject).to include 'FooKlass' }
end