Skip to content

Fix: Document Virtus::Attribute::Boolean as boolean. #179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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