From cb02a5c006724c95dab703a6fe663691606b781f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Rodrigo?= Date: Tue, 6 Dec 2016 10:48:09 +0100 Subject: [PATCH 1/3] Use entity_name event if type come from a string --- CHANGELOG.md | 1 + lib/grape-swagger/doc_methods/data_type.rb | 7 ++++++- spec/lib/data_type_spec.rb | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9ccc313..4f126cf1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/lib/grape-swagger/doc_methods/data_type.rb b/lib/grape-swagger/doc_methods/data_type.rb index aed9b956..3669af54 100644 --- a/lib/grape-swagger/doc_methods/data_type.rb +++ b/lib/grape-swagger/doc_methods/data_type.rb @@ -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 diff --git a/spec/lib/data_type_spec.rb b/spec/lib/data_type_spec.rb index 63895085..bf91ca3e 100644 --- a/spec/lib/data_type_spec.rb +++ b/spec/lib/data_type_spec.rb @@ -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 @@ -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 } } From a2e022883a873b064587409a1227e2d57b25c741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Rodrigo?= Date: Thu, 8 Dec 2016 12:16:41 +0100 Subject: [PATCH 2/3] Fix CHANGELOG.md format --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f126cf1..f3cf4317 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ * [#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) From 0fafbdc13e3f520cc154e0ff5c01be80bcef56b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Rodrigo?= Date: Thu, 8 Dec 2016 12:22:40 +0100 Subject: [PATCH 3/3] Make rubocup happy --- spec/lib/data_type_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/lib/data_type_spec.rb b/spec/lib/data_type_spec.rb index bf91ca3e..a1297af7 100644 --- a/spec/lib/data_type_spec.rb +++ b/spec/lib/data_type_spec.rb @@ -3,11 +3,11 @@ describe GrapeSwagger::DocMethods::DataType do before do stub_const 'MyEntity', Class.new - MyEntity.class_eval{ + MyEntity.class_eval do def self.entity_name 'MyInteger' end - } + end end subject { described_class.call(value) }