Skip to content

Commit

Permalink
Use entity_name event if type come from a string (ruby-grape#547)
Browse files Browse the repository at this point in the history
* Use entity_name event if type come from a string

* Fix CHANGELOG.md format

* Make rubocup happy
  • Loading branch information
frodrigo authored and LeFnord committed Dec 18, 2016
1 parent 5e19659 commit 046057f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#### Fixes

* [#546](https://github.com/ruby-grape/grape-swagger/pull/546): Move development dependencies to Gemfile - [@olleolleolle](https://github.com/olleolleolle).
* [#547](https://github.com/ruby-grape/grape-swagger/pull/547): Use entity_name event if type come from a string - [@frodrigo](https://github.com/frodrigo).
* Your contribution here.

### 0.25.2 (November 30, 2016)

Expand Down
7 changes: 6 additions & 1 deletion lib/grape-swagger/doc_methods/data_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ def call(value)
def parse_multi_type(raw_data_type)
case raw_data_type
when /\A\[.*\]\z/
raw_data_type.gsub(/[\[\s+\]]/, '').split(',').first
type_as_string = raw_data_type.gsub(/[\[\s+\]]/, '').split(',').first
begin
Object.const_get(type_as_string)
rescue NameError
type_as_string
end
when Array
raw_data_type.first
else
Expand Down
15 changes: 15 additions & 0 deletions spec/lib/data_type_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
require 'spec_helper'

describe GrapeSwagger::DocMethods::DataType do
before do
stub_const 'MyEntity', Class.new
MyEntity.class_eval do
def self.entity_name
'MyInteger'
end
end
end

subject { described_class.call(value) }

describe 'standards' do
Expand Down Expand Up @@ -36,6 +45,12 @@
it { expect(subject).to eql 'string' }
end

describe 'Types in array with entity_name' do
let(:value) { { type: '[MyEntity]' } }

it { expect(subject).to eql 'MyInteger' }
end

describe 'Rack::Multipart::UploadedFile' do
let(:value) { { type: Rack::Multipart::UploadedFile } }

Expand Down

0 comments on commit 046057f

Please sign in to comment.