Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use entity_name event if type come from a string #547

Merged
merged 4 commits into from
Dec 8, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think you have to add: * Your contribution here. in line 11

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with the lines is that they have a period before the - towards the end.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok @dblock … think now it would be nice to know how it should looks like …
sorry, but yhe syntax of the changelog hasn't my first priority 😉

### 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