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

Fix: be defensive with nil types in the API documentation. #230

Merged
merged 1 commit into from
Mar 11, 2015
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### 0.10.1 (Next)

* [#227](https://github.com/tim-vandecasteele/grape-swagger/issues/227): Fix: nested routes under prefix not documented - [@dblock](https://github.com/dblock).
* [#226](https://github.com/tim-vandecasteele/grape-swagger/issues/226): Fix: be defensive with nil exposure types - [@dblock](https://github.com/dblock).
* Your contribution here.

### 0.10.0 (March 10, 2015)
Expand Down
5 changes: 3 additions & 2 deletions lib/grape-swagger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,9 @@ def parse_entity_models(models)

type = if p[:type]
p.delete(:type)
elsif (entity = model.exposures[property_name][:using])
parse_entity_name(entity)
else
exposure = model.exposures[property_name]
parse_entity_name(exposure[:using]) if exposure
end

if p.delete(:is_array)
Expand Down
50 changes: 50 additions & 0 deletions spec/api_with_nil_types.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require 'spec_helper'

describe 'API with minimally documented models' do
def app
entity_klass = Class.new do
def self.exposures
{}
end

def self.documentation
{
bar: { type: String },
foo: {}
}
end

def self.entity_name
'Foo'
end
end

Class.new(Grape::API) do
format :json

get :foo do
end

add_swagger_documentation \
format: :json,
models: [Class.new(entity_klass)]
end
end

subject do
get '/swagger_doc/foo'
JSON.parse(last_response.body)['models']
end

it 'returns model' do
expect(subject).to eq(
'Foo' => {
'id' => 'Foo',
'properties' => {
'bar' => { 'type' => 'string' },
'foo' => { '$ref' => nil }
}
}
)
end
end