Skip to content

Commit 2e7a985

Browse files
committed
Fix: Document as boolean.
1 parent 95320e8 commit 2e7a985

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

.rubocop_todo.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
# This configuration was generated by `rubocop --auto-gen-config`
2-
# on 2014-11-20 15:23:00 +0200 using RuboCop version 0.27.0.
2+
# on 2014-11-28 11:04:19 -0500 using RuboCop version 0.27.0.
33
# The point is for the user to remove these configuration records
44
# one by one as the offenses are removed from the code base.
55
# Note that changes in the inspected code, or installation of new
66
# versions of RuboCop, may require this file to be generated again.
77

88
# Offense count: 8
99
Metrics/AbcSize:
10-
Max: 330
10+
Max: 331
1111

1212
# Offense count: 1
1313
# Configuration parameters: CountComments.
1414
Metrics/ClassLength:
15-
Max: 390
15+
Max: 392
1616

1717
# Offense count: 4
1818
Metrics/CyclomaticComplexity:
19-
Max: 92
19+
Max: 93
2020

21-
# Offense count: 203
21+
# Offense count: 204
2222
# Configuration parameters: AllowURI, URISchemes.
2323
Metrics/LineLength:
2424
Max: 254
2525

2626
# Offense count: 13
2727
# Configuration parameters: CountComments.
2828
Metrics/MethodLength:
29-
Max: 355
29+
Max: 357
3030

3131
# Offense count: 4
3232
Metrics/PerceivedComplexity:

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* [#166](https://github.com/tim-vandecasteele/grape-swagger/pull/166): Ensure compatibility with Grape 0.8.0 or newer - [@dblock](https://github.com/dblock).
88
* [#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).
99
* [#176](https://github.com/tim-vandecasteele/grape-swagger/pull/176): Added ability to load nested models recursively - [@sergey-verevkin](https://github.com/sergey-verevkin).
10+
* [#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).
1011

1112
* Your contribution here.
1213

lib/grape-swagger.rb

+2
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ def parse_params(params, path, method)
243243

244244
raw_data_type = value.is_a?(Hash) ? (value[:type] || 'string').to_s : 'string'
245245
data_type = case raw_data_type
246+
when 'Virtus::Attribute::Boolean'
247+
'boolean'
246248
when 'Boolean', 'Date', 'Integer', 'String'
247249
raw_data_type.downcase
248250
when 'BigDecimal'

spec/boolean_params_spec.rb

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require 'spec_helper'
2+
3+
describe 'Boolean Params' do
4+
def app
5+
Class.new(Grape::API) do
6+
format :json
7+
8+
params do
9+
requires :a_boolean, type: Virtus::Attribute::Boolean
10+
end
11+
post :splines do
12+
end
13+
14+
add_swagger_documentation
15+
end
16+
end
17+
18+
subject do
19+
get '/swagger_doc/splines.json'
20+
expect(last_response.status).to eq 200
21+
body = JSON.parse last_response.body
22+
body['apis'].first['operations'].first['parameters']
23+
end
24+
25+
it 'converts boolean types' do
26+
expect(subject).to eq [
27+
{ 'paramType' => 'form', 'name' => 'a_boolean', 'description' => nil, 'type' => 'boolean', 'required' => true, 'allowMultiple' => false }
28+
]
29+
end
30+
end

0 commit comments

Comments
 (0)