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 b81f24f
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 8 deletions.
12 changes: 6 additions & 6 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
# This configuration was generated by `rubocop --auto-gen-config`
# on 2015-02-26 15:04:26 +0100 using RuboCop version 0.27.0.
# on 2015-03-11 10:53:03 -0400 using RuboCop version 0.27.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 9
# Offense count: 10
Metrics/AbcSize:
Max: 347

# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 485
Max: 486

# Offense count: 6
Metrics/CyclomaticComplexity:
Max: 99

# Offense count: 289
# Offense count: 294
# Configuration parameters: AllowURI, URISchemes.
Metrics/LineLength:
Max: 254

# Offense count: 17
# Offense count: 20
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 368
Max: 369

# Offense count: 5
Metrics/PerceivedComplexity:
Expand Down
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 b81f24f

Please sign in to comment.