-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #230 from dblock/defensive-from-nils-in-models
Fix: be defensive with nil types in the API documentation.
- Loading branch information
Showing
3 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |