Skip to content

Commit 34d8bf0

Browse files
committed
Merge pull request #200 from ypresto/symbol-as-string
Treat Symbol as string in params parsing
2 parents ac11d81 + f180ce6 commit 34d8bf0

File tree

5 files changed

+45
-8
lines changed

5 files changed

+45
-8
lines changed

.rubocop_todo.yml

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
# This configuration was generated by `rubocop --auto-gen-config`
2-
# on 2014-11-29 13:48:01 -0500 using RuboCop version 0.27.0.
2+
# on 2015-02-02 02:04:29 +0900 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: 327
10+
Max: 324
1111

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

1717
# Offense count: 5
1818
Metrics/CyclomaticComplexity:
1919
Max: 93
2020

21-
# Offense count: 195
21+
# Offense count: 220
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: 359
29+
Max: 360
3030

3131
# Offense count: 4
3232
Metrics/PerceivedComplexity:
33-
Max: 96
33+
Max: 94
3434

35-
# Offense count: 7
35+
# Offense count: 8
3636
Style/ClassVars:
3737
Enabled: false
3838

39-
# Offense count: 69
39+
# Offense count: 70
4040
Style/Documentation:
4141
Enabled: false
4242

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
### Next Release
22

33
* [#196](https://github.com/tim-vandecasteele/grape-swagger/pull/196): If `:type` is omitted, see if it's available in `:using` - [@jhollinger](https://github.com/jhollinger).
4+
* [#200](https://github.com/tim-vandecasteele/grape-swagger/pull/200): Treat `type: Symbol` as string form parameter - [@ypresto](https://github.com/ypresto).
45
* Your contribution here.
56

67
### 0.9.0 (December 19, 2014)

lib/grape-swagger.rb

+2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ def parse_params(params, path, method)
8888
'dateTime'
8989
when 'Numeric'
9090
'double'
91+
when 'Symbol'
92+
'string'
9193
else
9294
@@documentation_class.parse_entity_name(raw_data_type)
9395
end

spec/form_params_spec.rb

+15
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ def app
3030
{}
3131
end
3232

33+
params do
34+
requires :id, type: Integer, desc: 'id of item'
35+
requires :name, type: String, desc: 'name of item'
36+
optional :conditions, type: Symbol, desc: 'conditions of item', values: [:one, :two]
37+
end
38+
post '/items/:id' do
39+
{}
40+
end
41+
3342
add_swagger_documentation
3443
end
3544
end
@@ -46,5 +55,11 @@ def app
4655
expect(subject['apis'][1]['path']).to start_with '/items/{id}'
4756
expect(subject['apis'][1]['operations'][0]['method']).to eq 'PUT'
4857
expect(subject['apis'][1]['operations'][1]['method']).to eq 'PATCH'
58+
expect(subject['apis'][1]['operations'][2]['method']).to eq 'POST'
59+
end
60+
61+
it 'treats Symbol parameter as form param' do
62+
expect(subject['apis'][1]['operations'][2]['parameters'][2]['paramType']).to eq 'form'
63+
expect(subject['apis'][1]['operations'][2]['parameters'][2]['type']).to eq 'string'
4964
end
5065
end

spec/grape-swagger_helper_spec.rb

+19
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,25 @@ class HelperTestAPI < Grape::API
6262

6363
end
6464

65+
it 'parses symbol param as string' do
66+
params = {
67+
animal: { type: 'Symbol', desc: 'An animal you like', required: true, values: [:cat, :dog] }
68+
}
69+
path = '/coolness'
70+
method = 'POST'
71+
expect(subject.parse_params(params, path, method)).to eq [
72+
{
73+
paramType: 'form',
74+
name: :animal,
75+
description: 'An animal you like',
76+
type: 'string',
77+
required: true,
78+
allowMultiple: false,
79+
enum: [:cat, :dog]
80+
}
81+
]
82+
end
83+
6584
context 'custom type' do
6685
before :all do
6786
class CustomType

0 commit comments

Comments
 (0)