Skip to content

Commit

Permalink
corrects exposing of inline definitions (#503)
Browse files Browse the repository at this point in the history
- adds changelog entry
- adds option to set definition name
  • Loading branch information
peter scholz authored Sep 19, 2016
1 parent ef1d5cd commit 054c54f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 2 deletions.
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
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

0 comments on commit 054c54f

Please sign in to comment.