Skip to content

Commit cb02a5c

Browse files
committed
Use entity_name event if type come from a string
1 parent 23d0211 commit cb02a5c

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#### Fixes
88

99
* [#546](https://github.com/ruby-grape/grape-swagger/pull/546): Move development dependencies to Gemfile - [@olleolleolle](https://github.com/olleolleolle).
10+
* [#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).
1011

1112
### 0.25.2 (November 30, 2016)
1213

lib/grape-swagger/doc_methods/data_type.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ def call(value)
3232
def parse_multi_type(raw_data_type)
3333
case raw_data_type
3434
when /\A\[.*\]\z/
35-
raw_data_type.gsub(/[\[\s+\]]/, '').split(',').first
35+
type_as_string = raw_data_type.gsub(/[\[\s+\]]/, '').split(',').first
36+
begin
37+
Object.const_get(type_as_string)
38+
rescue NameError
39+
type_as_string
40+
end
3641
when Array
3742
raw_data_type.first
3843
else

spec/lib/data_type_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
require 'spec_helper'
22

33
describe GrapeSwagger::DocMethods::DataType do
4+
before do
5+
stub_const 'MyEntity', Class.new
6+
MyEntity.class_eval{
7+
def self.entity_name
8+
'MyInteger'
9+
end
10+
}
11+
end
12+
413
subject { described_class.call(value) }
514

615
describe 'standards' do
@@ -36,6 +45,12 @@
3645
it { expect(subject).to eql 'string' }
3746
end
3847

48+
describe 'Types in array with entity_name' do
49+
let(:value) { { type: '[MyEntity]' } }
50+
51+
it { expect(subject).to eql 'MyInteger' }
52+
end
53+
3954
describe 'Rack::Multipart::UploadedFile' do
4055
let(:value) { { type: Rack::Multipart::UploadedFile } }
4156

0 commit comments

Comments
 (0)