Skip to content

Commit

Permalink
Fix: Document Virtus::Attribute::Boolean as boolean.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Nov 28, 2014
1 parent 95320e8 commit dbe01f6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 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 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
# versions of RuboCop, may require this file to be generated again.

# 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

# Offense count: 13
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 355
Max: 357

# Offense count: 4
Metrics/PerceivedComplexity:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 2 additions & 0 deletions lib/grape-swagger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
30 changes: 30 additions & 0 deletions spec/boolean_params_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit dbe01f6

Please sign in to comment.