diff --git a/lib/grape-swagger.rb b/lib/grape-swagger.rb index 2d6e5530..d5a9d4d7 100644 --- a/lib/grape-swagger.rb +++ b/lib/grape-swagger.rb @@ -128,7 +128,7 @@ def standalone_sub_namespaces(name, namespaces) def get_non_nested_params(params) # Duplicate the params as we are going to modify them - dup_params = params.each_with_object(Hash.new) do |(param, value), dparams| + dup_params = params.each_with_object({}) do |(param, value), dparams| dparams[param] = value.dup end @@ -599,7 +599,7 @@ def setup(options) type: route.route_is_array ? 'array' : 'void' } operation[:authorizations] = route.route_authorizations unless route.route_authorizations.nil? || route.route_authorizations.empty? - if operation[:parameters].any? { | param | param[:type] == 'File' } + if operation[:parameters].any? { |param| param[:type] == 'File' } operation.merge!(consumes: ['multipart/form-data']) end operation.merge!(responseMessages: http_codes) unless http_codes.empty? diff --git a/spec/api_global_models_spec.rb b/spec/api_global_models_spec.rb index 1f774a60..cf314190 100644 --- a/spec/api_global_models_spec.rb +++ b/spec/api_global_models_spec.rb @@ -43,13 +43,13 @@ def app get '/swagger_doc/thing.json' json = JSON.parse(last_response.body) expect(json['models']).to eq( - 'Some::Thing' => { - 'id' => 'Some::Thing', - 'properties' => { - 'text' => { 'type' => 'string', 'description' => 'Content of something.' }, - 'name' => { 'type' => 'string', 'description' => 'Name of something.' } - } - }) + 'Some::Thing' => { + 'id' => 'Some::Thing', + 'properties' => { + 'text' => { 'type' => 'string', 'description' => 'Content of something.' }, + 'name' => { 'type' => 'string', 'description' => 'Name of something.' } + } + }) end it 'uses global models and route endpoint specific entities together' do @@ -57,21 +57,21 @@ def app json = JSON.parse(last_response.body) expect(json['models']).to include( - 'Some::Thing' => { - 'id' => 'Some::Thing', - 'properties' => { - 'text' => { 'type' => 'string', 'description' => 'Content of something.' }, - 'name' => { 'type' => 'string', 'description' => 'Name of something.' } - } - }) + 'Some::Thing' => { + 'id' => 'Some::Thing', + 'properties' => { + 'text' => { 'type' => 'string', 'description' => 'Content of something.' }, + 'name' => { 'type' => 'string', 'description' => 'Name of something.' } + } + }) expect(json['models']).to include( - 'Some::CombinedThing' => { - 'id' => 'Some::CombinedThing', - 'properties' => { - 'text' => { 'type' => 'string', 'description' => 'Content of something.' }, - 'created_at' => { 'type' => 'dateTime', 'description' => 'Creation of something.' } - } - }) + 'Some::CombinedThing' => { + 'id' => 'Some::CombinedThing', + 'properties' => { + 'text' => { 'type' => 'string', 'description' => 'Content of something.' }, + 'created_at' => { 'type' => 'dateTime', 'description' => 'Creation of something.' } + } + }) end end diff --git a/spec/api_models_spec.rb b/spec/api_models_spec.rb index 0eb93345..c0fa2fb2 100644 --- a/spec/api_models_spec.rb +++ b/spec/api_models_spec.rb @@ -227,68 +227,68 @@ def app }, 'required' => ['parts'] - ) + ) expect(result['models']['ComposedOf']).to include( - 'id' => 'ComposedOf', - 'properties' => { - 'part_text' => { - 'type' => 'string', - 'description' => 'Content of composedof.' - } - } - ) + 'id' => 'ComposedOf', + 'properties' => { + 'part_text' => { + 'type' => 'string', + 'description' => 'Content of composedof.' + } + } + ) expect(result['models']['composed']).to include( - 'id' => 'composed', - 'properties' => { - 'part_text' => { - 'type' => 'string', - 'description' => 'Content of composedof else.' - } - - } - ) + 'id' => 'composed', + 'properties' => { + 'part_text' => { + 'type' => 'string', + 'description' => 'Content of composedof else.' + } + + } + ) end it 'includes enum values in params and documentation.' do get '/swagger_doc/enum_description_in_entity' result = JSON.parse(last_response.body) expect(result['models']['EnumValues']).to eq( - 'id' => 'EnumValues', - 'properties' => { - 'gender' => { 'type' => 'string', 'description' => 'Content of something.', 'enum' => %w(Male Female) }, - 'number' => { 'type' => 'integer', 'description' => 'Content of something.', 'enum' => [1, 2] } - } - ) + 'id' => 'EnumValues', + 'properties' => { + 'gender' => { 'type' => 'string', 'description' => 'Content of something.', 'enum' => %w(Male Female) }, + 'number' => { 'type' => 'integer', 'description' => 'Content of something.', 'enum' => [1, 2] } + } + ) expect(result['apis'][0]['operations'][0]).to include( - 'parameters' => - [ - { 'paramType' => 'query', 'name' => 'gender', 'description' => 'Content of something.', 'type' => 'string', 'required' => false, 'allowMultiple' => false, 'enum' => %w(Male Female) }, - { 'paramType' => 'query', 'name' => 'number', 'description' => 'Content of something.', 'type' => 'integer', 'required' => false, 'allowMultiple' => false, 'format' => 'int32', 'enum' => [1, 2] } - ], - 'type' => 'EnumValues' - ) + 'parameters' => + [ + { 'paramType' => 'query', 'name' => 'gender', 'description' => 'Content of something.', 'type' => 'string', 'required' => false, 'allowMultiple' => false, 'enum' => %w(Male Female) }, + { 'paramType' => 'query', 'name' => 'number', 'description' => 'Content of something.', 'type' => 'integer', 'required' => false, 'allowMultiple' => false, 'format' => 'int32', 'enum' => [1, 2] } + ], + 'type' => 'EnumValues' + ) end it 'includes referenced models in those with aliased references.' do get '/swagger_doc/aliasedthing' result = JSON.parse(last_response.body) expect(result['models']['AliasedThing']).to eq( - 'id' => 'AliasedThing', - 'properties' => { - 'post' => { '$ref' => 'Something', 'description' => 'Reference to something.' } - } - ) + 'id' => 'AliasedThing', + 'properties' => { + 'post' => { '$ref' => 'Something', 'description' => 'Reference to something.' } + } + ) expect(result['models']['Something']).to eq( - 'id' => 'Something', - 'properties' => { - 'text' => { 'type' => 'string', 'description' => 'Content of something.' }, - 'links' => { 'type' => 'array', 'items' => { '$ref' => 'link' } } - } - ) + 'id' => 'Something', + 'properties' => { + 'text' => { 'type' => 'string', 'description' => 'Content of something.' }, + 'links' => { 'type' => 'array', 'items' => { '$ref' => 'link' } } + } + ) end it 'includes all entities with four levels of nesting' do diff --git a/spec/api_with_standalone_namespace_spec.rb b/spec/api_with_standalone_namespace_spec.rb index 97ede29f..77e73fe7 100644 --- a/spec/api_with_standalone_namespace_spec.rb +++ b/spec/api_with_standalone_namespace_spec.rb @@ -47,14 +47,14 @@ def app it 'that contains all api paths' do expect(json_body['apis']).to eq( - [ - { 'path' => '/store.{format}', 'description' => 'Operations about stores' }, - { 'path' => '/store_orders.{format}', 'description' => 'Operations about store/orders' }, - { 'path' => '/store_orders_actions2.{format}', 'description' => 'Operations about store/orders/actions2s' }, - { 'path' => '/specific-store-orders.{format}', 'description' => 'Operations about store/:store_id/orders' }, - { 'path' => '/swagger_doc.{format}', 'description' => 'Operations about swagger_docs' } - ] - ) + [ + { 'path' => '/store.{format}', 'description' => 'Operations about stores' }, + { 'path' => '/store_orders.{format}', 'description' => 'Operations about store/orders' }, + { 'path' => '/store_orders_actions2.{format}', 'description' => 'Operations about store/orders/actions2s' }, + { 'path' => '/specific-store-orders.{format}', 'description' => 'Operations about store/:store_id/orders' }, + { 'path' => '/swagger_doc.{format}', 'description' => 'Operations about swagger_docs' } + ] + ) end end @@ -152,14 +152,14 @@ def app it 'that contains all api paths' do expect(json_body['apis']).to eq( - [ - { 'path' => '/store.{format}', 'description' => 'Operations about stores' }, - { 'path' => '/store_orders.{format}', 'description' => 'Operations about store/orders' }, - { 'path' => '/store_orders_actions2.{format}', 'description' => 'Operations about store/orders/actions2s' }, - { 'path' => '/specific-store-orders.{format}', 'description' => 'Operations about store/:store_id/orders' }, - { 'path' => '/swagger_doc.{format}', 'description' => 'Operations about swagger_docs' } - ] - ) + [ + { 'path' => '/store.{format}', 'description' => 'Operations about stores' }, + { 'path' => '/store_orders.{format}', 'description' => 'Operations about store/orders' }, + { 'path' => '/store_orders_actions2.{format}', 'description' => 'Operations about store/orders/actions2s' }, + { 'path' => '/specific-store-orders.{format}', 'description' => 'Operations about store/:store_id/orders' }, + { 'path' => '/swagger_doc.{format}', 'description' => 'Operations about swagger_docs' } + ] + ) end end diff --git a/spec/mounted_target_class_spec.rb b/spec/mounted_target_class_spec.rb index b4404c46..ae043ec0 100644 --- a/spec/mounted_target_class_spec.rb +++ b/spec/mounted_target_class_spec.rb @@ -34,7 +34,7 @@ def app 'info' => {}, 'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq, 'apis' => [ - { 'path' => '/simple.{format}', 'description' => 'Operations about simples' }, + { 'path' => '/simple.{format}', 'description' => 'Operations about simples' } ] ) end