Skip to content

Commit

Permalink
Use entity_name event if type come from a string
Browse files Browse the repository at this point in the history
  • Loading branch information
frodrigo committed Dec 6, 2016
1 parent 23d0211 commit cb02a5c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#### 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).

### 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{
def self.entity_name
'MyInteger'
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 cb02a5c

Please sign in to comment.