diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d4bad096..74ab613e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,5 +1,5 @@ # This configuration was generated by `rubocop --auto-gen-config` -# on 2014-11-20 15:23:00 +0200 using RuboCop version 0.27.0. +# on 2014-11-28 11:04:19 -0500 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 @@ -7,18 +7,18 @@ # Offense count: 8 Metrics/AbcSize: - Max: 330 + Max: 331 # Offense count: 1 # Configuration parameters: CountComments. Metrics/ClassLength: - Max: 390 + Max: 392 # Offense count: 4 Metrics/CyclomaticComplexity: - Max: 92 + Max: 93 -# Offense count: 203 +# Offense count: 204 # Configuration parameters: AllowURI, URISchemes. Metrics/LineLength: Max: 254 @@ -26,7 +26,7 @@ Metrics/LineLength: # Offense count: 13 # Configuration parameters: CountComments. Metrics/MethodLength: - Max: 355 + Max: 357 # Offense count: 4 Metrics/PerceivedComplexity: diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f732f2e..45829ea2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * [#166](https://github.com/tim-vandecasteele/grape-swagger/pull/166): Ensure compatibility with Grape 0.8.0 or newer - [@dblock](https://github.com/dblock). * [#174](https://github.com/tim-vandecasteele/grape-swagger/pull/172): Fix problem with using prefix name somewhere in api paths - [@grzesiek](https://github.com/grzesiek). * [#176](https://github.com/tim-vandecasteele/grape-swagger/pull/176): Added ability to load nested models recursively - [@sergey-verevkin](https://github.com/sergey-verevkin). +* [#179](https://github.com/tim-vandecasteele/grape-swagger/pull/179): Document `Virtus::Attribute::Boolean` as boolean - [@eashman](https://github.com/eashman), [@dblock](https://github.com/dblock). * Your contribution here. diff --git a/lib/grape-swagger.rb b/lib/grape-swagger.rb index 70bba592..7b16061e 100644 --- a/lib/grape-swagger.rb +++ b/lib/grape-swagger.rb @@ -243,6 +243,8 @@ def parse_params(params, path, method) raw_data_type = value.is_a?(Hash) ? (value[:type] || 'string').to_s : 'string' data_type = case raw_data_type + when 'Virtus::Attribute::Boolean' + 'boolean' when 'Boolean', 'Date', 'Integer', 'String' raw_data_type.downcase when 'BigDecimal' diff --git a/spec/boolean_params_spec.rb b/spec/boolean_params_spec.rb new file mode 100644 index 00000000..e94d4449 --- /dev/null +++ b/spec/boolean_params_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' + +describe 'Boolean Params' do + def app + Class.new(Grape::API) do + format :json + + params do + requires :a_boolean, type: Virtus::Attribute::Boolean + end + post :splines do + end + + add_swagger_documentation + end + end + + subject do + get '/swagger_doc/splines.json' + expect(last_response.status).to eq 200 + body = JSON.parse last_response.body + body['apis'].first['operations'].first['parameters'] + end + + it 'converts boolean types' do + expect(subject).to eq [ + { 'paramType' => 'form', 'name' => 'a_boolean', 'description' => nil, 'type' => 'boolean', 'required' => true, 'allowMultiple' => false } + ] + end +end