diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e3de2c94..6b2febef 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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: diff --git a/CHANGELOG.md b/CHANGELOG.md index fd06c9c3..b10f54ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/lib/grape-swagger.rb b/lib/grape-swagger.rb index 5fc50c5c..b34e79b3 100644 --- a/lib/grape-swagger.rb +++ b/lib/grape-swagger.rb @@ -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) diff --git a/spec/api_with_nil_types.rb b/spec/api_with_nil_types.rb new file mode 100644 index 00000000..f69beef0 --- /dev/null +++ b/spec/api_with_nil_types.rb @@ -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