Skip to content

Commit

Permalink
Merge pull request #230 from dblock/defensive-from-nils-in-models
Browse files Browse the repository at this point in the history
Fix: be defensive with nil types in the API documentation.
  • Loading branch information
dblock committed Mar 11, 2015
2 parents 05395ce + aed79f0 commit df11872
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
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

0 comments on commit df11872

Please sign in to comment.