grape 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grape might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/Appraisals +1 -1
- data/CHANGELOG.md +18 -0
- data/Dangerfile +1 -0
- data/Gemfile +9 -10
- data/Gemfile.lock +42 -40
- data/LICENSE +1 -1
- data/README.md +89 -40
- data/Rakefile +1 -46
- data/gemfiles/multi_json.gemfile +9 -10
- data/gemfiles/multi_xml.gemfile +9 -10
- data/gemfiles/rack_1.5.2.gemfile +9 -10
- data/gemfiles/rack_edge.gemfile +9 -10
- data/gemfiles/rails_3.gemfile +9 -10
- data/gemfiles/rails_4.gemfile +9 -10
- data/gemfiles/rails_5.gemfile +9 -10
- data/gemfiles/rails_edge.gemfile +9 -10
- data/grape.gemspec +3 -3
- data/lib/grape/api.rb +2 -2
- data/lib/grape/dsl/inside_route.rb +30 -10
- data/lib/grape/dsl/routing.rb +1 -1
- data/lib/grape/dsl/settings.rb +6 -6
- data/lib/grape/endpoint.rb +1 -1
- data/lib/grape/exceptions/incompatible_option_values.rb +0 -1
- data/lib/grape/exceptions/invalid_accept_header.rb +0 -1
- data/lib/grape/exceptions/invalid_formatter.rb +0 -1
- data/lib/grape/exceptions/invalid_message_body.rb +0 -1
- data/lib/grape/exceptions/invalid_version_header.rb +0 -1
- data/lib/grape/exceptions/invalid_versioner_option.rb +0 -1
- data/lib/grape/exceptions/invalid_with_option_for_represent.rb +0 -1
- data/lib/grape/exceptions/method_not_allowed.rb +0 -1
- data/lib/grape/exceptions/missing_group_type.rb +0 -1
- data/lib/grape/exceptions/missing_mime_type.rb +0 -1
- data/lib/grape/exceptions/missing_option.rb +0 -1
- data/lib/grape/exceptions/missing_vendor_option.rb +0 -1
- data/lib/grape/exceptions/unknown_options.rb +0 -1
- data/lib/grape/exceptions/unknown_parameter.rb +0 -1
- data/lib/grape/exceptions/unknown_validator.rb +0 -1
- data/lib/grape/exceptions/unsupported_group_type.rb +0 -1
- data/lib/grape/namespace.rb +1 -1
- data/lib/grape/router.rb +2 -0
- data/lib/grape/router/pattern.rb +1 -1
- data/lib/grape/router/route.rb +14 -14
- data/lib/grape/validations/params_scope.rb +3 -4
- data/lib/grape/validations/types.rb +14 -1
- data/lib/grape/validations/types/build_coercer.rb +8 -0
- data/lib/grape/validations/types/custom_type_coercer.rb +1 -1
- data/lib/grape/validations/types/custom_type_collection_coercer.rb +71 -0
- data/lib/grape/validations/validators/allow_blank.rb +1 -1
- data/lib/grape/validations/validators/base.rb +1 -0
- data/lib/grape/validations/validators/coerce.rb +6 -0
- data/lib/grape/version.rb +1 -1
- data/pkg/grape-1.0.1.gem +0 -0
- data/spec/grape/api_spec.rb +22 -12
- data/spec/grape/dsl/inside_route_spec.rb +1 -1
- data/spec/grape/dsl/parameters_spec.rb +5 -5
- data/spec/grape/dsl/settings_spec.rb +2 -2
- data/spec/grape/endpoint_spec.rb +25 -12
- data/spec/grape/entity_spec.rb +1 -1
- data/spec/grape/exceptions/invalid_formatter_spec.rb +0 -1
- data/spec/grape/exceptions/invalid_versioner_option_spec.rb +0 -1
- data/spec/grape/exceptions/missing_option_spec.rb +0 -1
- data/spec/grape/exceptions/unknown_options_spec.rb +1 -2
- data/spec/grape/exceptions/unknown_validator_spec.rb +0 -1
- data/spec/grape/exceptions/validation_errors_spec.rb +1 -1
- data/spec/grape/middleware/exception_spec.rb +36 -12
- data/spec/grape/middleware/formatter_spec.rb +1 -1
- data/spec/grape/middleware/versioner/header_spec.rb +1 -1
- data/spec/grape/middleware/versioner/param_spec.rb +1 -1
- data/spec/grape/middleware/versioner/path_spec.rb +1 -1
- data/spec/grape/path_spec.rb +3 -3
- data/spec/grape/util/inheritable_setting_spec.rb +2 -2
- data/spec/grape/util/reverse_stackable_values_spec.rb +13 -13
- data/spec/grape/util/stackable_values_spec.rb +13 -13
- data/spec/grape/util/strict_hash_configuration_spec.rb +1 -1
- data/spec/grape/validations/params_scope_spec.rb +19 -7
- data/spec/grape/validations/validators/all_or_none_spec.rb +1 -1
- data/spec/grape/validations/validators/at_least_one_of_spec.rb +1 -1
- data/spec/grape/validations/validators/coerce_spec.rb +94 -13
- data/spec/grape/validations/validators/default_spec.rb +40 -0
- data/spec/grape/validations/validators/exactly_one_of_spec.rb +1 -1
- data/spec/grape/validations/validators/mutual_exclusion_spec.rb +1 -1
- data/spec/grape/validations/validators/values_spec.rb +3 -3
- data/spec/grape/validations_spec.rb +9 -9
- data/spec/shared/versioning_examples.rb +58 -0
- data/spec/support/content_type_helpers.rb +1 -1
- metadata +26 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 22167fc7407088f03f9c85cc9e9ab6f63186e30a9c41cff89ca042a71a7dbdf7
|
4
|
+
data.tar.gz: 9ba03eae4067052f0d10dcefb032bc15f8844221e31397ed03398b4a4dbcda5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a206dba0bd582138f92d3020c98b4019095175d3c4412d650b4a994f3b2881a2f24867a32c6c7163c5fd589a3b2ccbfdef9453ca3d70b726c62bcdf094a463f7
|
7
|
+
data.tar.gz: 92c1e9d3c7d89a93c5ce8c9bb9a28baed795f99de0d495dfac9968dabd810621665162d78fdcd0ed846f0a9b83bd02b163de768bc7059843d0bea67fd65d6502
|
data/Appraisals
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
### 1.0.2 (1/10/2018)
|
2
|
+
|
3
|
+
#### Features
|
4
|
+
|
5
|
+
* [#1686](https://github.com/ruby-grape/grape/pull/1686): Avoid coercion of a value if it is valid - [@timothysu](https://github.com/timothysu).
|
6
|
+
* [#1688](https://github.com/ruby-grape/grape/pull/1688): Removes yard docs - [@ramkumar-kr](https://github.com/ramkumar-kr).
|
7
|
+
* [#1702](https://github.com/ruby-grape/grape/pull/1702): Added danger-toc, verify correct TOC in README - [@dblock](https://github.com/dblock).
|
8
|
+
* [#1711](https://github.com/ruby-grape/grape/pull/1711): Automatically coerce arrays and sets of types that implement a `parse` method - [@dslh](https://github.com/dslh).
|
9
|
+
|
10
|
+
#### Fixes
|
11
|
+
|
12
|
+
* [#1710](https://github.com/ruby-grape/grape/pull/1710): Fix wrong transformation of empty Array in declared params - [@pablonahuelgomez](https://github.com/pablonahuelgomez).
|
13
|
+
* [#1722](https://github.com/ruby-grape/grape/pull/1722): Fix catch-all hiding multiple versions of an endpoint after the first definition - [@zherr](https://github.com/zherr).
|
14
|
+
* [#1724](https://github.com/ruby-grape/grape/pull/1724): Optional nested array validation - [@ericproulx](https://github.com/ericproulx).
|
15
|
+
* [#1725](https://github.com/ruby-grape/grape/pull/1725): Fix `rescue_from :all` documentation - [@Jelkster](https://github.com/Jelkster).
|
16
|
+
* [#1726](https://github.com/ruby-grape/grape/pull/1726): Improved startup performance during API method generation - [@jkowens](https://github.com/jkowens).
|
17
|
+
* [#1727](https://github.com/ruby-grape/grape/pull/1727): Fix infinite loop when mounting endpoint with same superclass - [@jkowens](https://github.com/jkowens).
|
18
|
+
|
1
19
|
### 1.0.1 (9/8/2017)
|
2
20
|
|
3
21
|
#### Features
|
data/Dangerfile
CHANGED
data/Gemfile
CHANGED
@@ -6,29 +6,28 @@ gemspec
|
|
6
6
|
|
7
7
|
group :development, :test do
|
8
8
|
gem 'bundler'
|
9
|
-
gem 'rake'
|
10
|
-
gem 'rubocop', '0.47.0'
|
11
9
|
gem 'hashie'
|
10
|
+
gem 'rake'
|
11
|
+
gem 'rubocop', '0.51.0'
|
12
12
|
end
|
13
13
|
|
14
14
|
group :development do
|
15
|
+
gem 'appraisal'
|
16
|
+
gem 'benchmark-ips'
|
15
17
|
gem 'guard'
|
16
18
|
gem 'guard-rspec'
|
17
19
|
gem 'guard-rubocop'
|
18
|
-
gem 'yard'
|
19
|
-
gem 'appraisal'
|
20
|
-
gem 'benchmark-ips'
|
21
|
-
gem 'redcarpet'
|
22
20
|
end
|
23
21
|
|
24
22
|
group :test do
|
23
|
+
gem 'cookiejar'
|
24
|
+
gem 'coveralls', '~> 0.8.17', require: false
|
25
|
+
gem 'danger-toc', '~> 0.1.0'
|
25
26
|
gem 'grape-entity', '~> 0.6'
|
26
27
|
gem 'maruku'
|
28
|
+
gem 'mime-types'
|
29
|
+
gem 'rack-jsonp', require: 'rack/jsonp'
|
27
30
|
gem 'rack-test', '~> 0.6.3'
|
28
31
|
gem 'rspec', '~> 3.0'
|
29
|
-
gem 'cookiejar'
|
30
|
-
gem 'rack-jsonp', require: 'rack/jsonp'
|
31
|
-
gem 'mime-types'
|
32
32
|
gem 'ruby-grape-danger', '~> 0.1.0', require: false
|
33
|
-
gem 'coveralls', '~> 0.8.17', require: false
|
34
33
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
grape (1.0.
|
4
|
+
grape (1.0.2)
|
5
5
|
activesupport
|
6
6
|
builder
|
7
7
|
mustermann-grape (~> 1.0.0)
|
@@ -65,6 +65,10 @@ GEM
|
|
65
65
|
danger-plugin-api (~> 1.0)
|
66
66
|
danger-plugin-api (1.0.0)
|
67
67
|
danger (> 2.0)
|
68
|
+
danger-toc (0.1.0)
|
69
|
+
activesupport
|
70
|
+
danger-plugin-api (~> 1.0)
|
71
|
+
kramdown
|
68
72
|
descendants_tracker (0.0.4)
|
69
73
|
thread_safe (~> 0.3, >= 0.3.1)
|
70
74
|
diff-lcs (1.3)
|
@@ -80,10 +84,10 @@ GEM
|
|
80
84
|
grape-entity (0.6.1)
|
81
85
|
activesupport (>= 5.0.0)
|
82
86
|
multi_json (>= 1.3.2)
|
83
|
-
guard (2.14.
|
87
|
+
guard (2.14.2)
|
84
88
|
formatador (>= 0.2.4)
|
85
89
|
listen (>= 2.7, < 4.0)
|
86
|
-
lumberjack (
|
90
|
+
lumberjack (>= 1.0.12, < 2.0)
|
87
91
|
nenv (~> 0.1)
|
88
92
|
notiffany (~> 0.0)
|
89
93
|
pry (>= 0.9.12)
|
@@ -97,23 +101,24 @@ GEM
|
|
97
101
|
guard-rubocop (1.3.0)
|
98
102
|
guard (~> 2.0)
|
99
103
|
rubocop (~> 0.20)
|
100
|
-
hashie (3.5.
|
101
|
-
i18n (0.
|
104
|
+
hashie (3.5.7)
|
105
|
+
i18n (0.9.1)
|
106
|
+
concurrent-ruby (~> 1.0)
|
102
107
|
ice_nine (0.11.2)
|
103
108
|
json (2.1.0)
|
104
|
-
kramdown (1.
|
109
|
+
kramdown (1.16.2)
|
105
110
|
listen (3.1.5)
|
106
111
|
rb-fsevent (~> 0.9, >= 0.9.4)
|
107
112
|
rb-inotify (~> 0.9, >= 0.9.7)
|
108
113
|
ruby_dep (~> 1.2)
|
109
114
|
lumberjack (1.0.12)
|
110
115
|
maruku (0.7.3)
|
111
|
-
method_source (0.
|
116
|
+
method_source (0.9.0)
|
112
117
|
mime-types (3.1)
|
113
118
|
mime-types-data (~> 3.2015)
|
114
119
|
mime-types-data (3.2016.0521)
|
115
|
-
minitest (5.
|
116
|
-
multi_json (1.
|
120
|
+
minitest (5.11.1)
|
121
|
+
multi_json (1.13.1)
|
117
122
|
multipart-post (2.0.0)
|
118
123
|
mustermann (1.0.1)
|
119
124
|
mustermann-grape (1.0.0)
|
@@ -123,17 +128,17 @@ GEM
|
|
123
128
|
notiffany (0.1.1)
|
124
129
|
nenv (~> 0.1)
|
125
130
|
shellany (~> 0.0)
|
126
|
-
octokit (4.
|
131
|
+
octokit (4.8.0)
|
127
132
|
sawyer (~> 0.8.0, >= 0.5.3)
|
128
133
|
open4 (1.3.4)
|
129
|
-
|
130
|
-
|
134
|
+
parallel (1.12.1)
|
135
|
+
parser (2.4.0.2)
|
136
|
+
ast (~> 2.3)
|
131
137
|
powerpack (0.1.1)
|
132
|
-
pry (0.
|
138
|
+
pry (0.11.3)
|
133
139
|
coderay (~> 1.1.0)
|
134
|
-
method_source (~> 0.
|
135
|
-
|
136
|
-
public_suffix (3.0.0)
|
140
|
+
method_source (~> 0.9.0)
|
141
|
+
public_suffix (3.0.1)
|
137
142
|
rack (2.0.3)
|
138
143
|
rack-accept (0.4.5)
|
139
144
|
rack (>= 0.4)
|
@@ -143,34 +148,34 @@ GEM
|
|
143
148
|
rack (>= 1.0)
|
144
149
|
rainbow (2.2.2)
|
145
150
|
rake
|
146
|
-
rake (12.
|
151
|
+
rake (12.3.0)
|
147
152
|
rb-fsevent (0.10.2)
|
148
153
|
rb-inotify (0.9.10)
|
149
154
|
ffi (>= 0.5.0, < 2)
|
150
|
-
|
151
|
-
|
152
|
-
rspec-
|
153
|
-
rspec-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
rspec-expectations (3.6.0)
|
155
|
+
rspec (3.7.0)
|
156
|
+
rspec-core (~> 3.7.0)
|
157
|
+
rspec-expectations (~> 3.7.0)
|
158
|
+
rspec-mocks (~> 3.7.0)
|
159
|
+
rspec-core (3.7.1)
|
160
|
+
rspec-support (~> 3.7.0)
|
161
|
+
rspec-expectations (3.7.0)
|
158
162
|
diff-lcs (>= 1.2.0, < 2.0)
|
159
|
-
rspec-support (~> 3.
|
160
|
-
rspec-mocks (3.
|
163
|
+
rspec-support (~> 3.7.0)
|
164
|
+
rspec-mocks (3.7.0)
|
161
165
|
diff-lcs (>= 1.2.0, < 2.0)
|
162
|
-
rspec-support (~> 3.
|
163
|
-
rspec-support (3.
|
164
|
-
rubocop (0.
|
166
|
+
rspec-support (~> 3.7.0)
|
167
|
+
rspec-support (3.7.0)
|
168
|
+
rubocop (0.51.0)
|
169
|
+
parallel (~> 1.10)
|
165
170
|
parser (>= 2.3.3.1, < 3.0)
|
166
171
|
powerpack (~> 0.1)
|
167
|
-
rainbow (>=
|
172
|
+
rainbow (>= 2.2.2, < 3.0)
|
168
173
|
ruby-progressbar (~> 1.7)
|
169
174
|
unicode-display_width (~> 1.0, >= 1.0.1)
|
170
175
|
ruby-grape-danger (0.1.1)
|
171
176
|
danger (~> 4.0.1)
|
172
177
|
danger-changelog (~> 0.2.0)
|
173
|
-
ruby-progressbar (1.
|
178
|
+
ruby-progressbar (1.9.0)
|
174
179
|
ruby_dep (1.5.0)
|
175
180
|
sawyer (0.8.1)
|
176
181
|
addressable (>= 2.3.5, < 2.6)
|
@@ -181,15 +186,14 @@ GEM
|
|
181
186
|
json (>= 1.8, < 3)
|
182
187
|
simplecov-html (~> 0.10.0)
|
183
188
|
simplecov-html (0.10.2)
|
184
|
-
slop (3.6.0)
|
185
189
|
term-ansicolor (1.6.0)
|
186
190
|
tins (~> 1.0)
|
187
191
|
terminal-table (1.8.0)
|
188
192
|
unicode-display_width (~> 1.1, >= 1.1.1)
|
189
193
|
thor (0.19.4)
|
190
194
|
thread_safe (0.3.6)
|
191
|
-
tins (1.
|
192
|
-
tzinfo (1.2.
|
195
|
+
tins (1.16.3)
|
196
|
+
tzinfo (1.2.4)
|
193
197
|
thread_safe (~> 0.1)
|
194
198
|
unicode-display_width (1.3.0)
|
195
199
|
virtus (1.0.5)
|
@@ -197,7 +201,6 @@ GEM
|
|
197
201
|
coercible (~> 1.0)
|
198
202
|
descendants_tracker (~> 0.0, >= 0.0.3)
|
199
203
|
equalizer (~> 0.0, >= 0.0.9)
|
200
|
-
yard (0.9.9)
|
201
204
|
|
202
205
|
PLATFORMS
|
203
206
|
ruby
|
@@ -208,6 +211,7 @@ DEPENDENCIES
|
|
208
211
|
bundler
|
209
212
|
cookiejar
|
210
213
|
coveralls (~> 0.8.17)
|
214
|
+
danger-toc (~> 0.1.0)
|
211
215
|
grape!
|
212
216
|
grape-entity (~> 0.6)
|
213
217
|
guard
|
@@ -219,11 +223,9 @@ DEPENDENCIES
|
|
219
223
|
rack-jsonp
|
220
224
|
rack-test (~> 0.6.3)
|
221
225
|
rake
|
222
|
-
redcarpet
|
223
226
|
rspec (~> 3.0)
|
224
|
-
rubocop (= 0.
|
227
|
+
rubocop (= 0.51.0)
|
225
228
|
ruby-grape-danger (~> 0.1.0)
|
226
|
-
yard
|
227
229
|
|
228
230
|
BUNDLED WITH
|
229
|
-
1.
|
231
|
+
1.16.0
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -31,6 +31,7 @@
|
|
31
31
|
- [Parameters](#parameters)
|
32
32
|
- [Params Class](#params-class)
|
33
33
|
- [Declared](#declared)
|
34
|
+
- [Include Parent Namespaces](#include-parent-namespaces)
|
34
35
|
- [Include Missing](#include-missing)
|
35
36
|
- [Parameter Validation and Coercion](#parameter-validation-and-coercion)
|
36
37
|
- [Supported Parameter Types](#supported-parameter-types)
|
@@ -44,12 +45,24 @@
|
|
44
45
|
- [Group Options](#group-options)
|
45
46
|
- [Alias](#alias)
|
46
47
|
- [Built-in Validators](#built-in-validators)
|
48
|
+
- [`allow_blank`](#allowblank)
|
49
|
+
- [`values`](#values)
|
50
|
+
- [`except_values`](#exceptvalues)
|
51
|
+
- [`regexp`](#regexp)
|
52
|
+
- [`mutually_exclusive`](#mutuallyexclusive)
|
53
|
+
- [`exactly_one_of`](#exactlyoneof)
|
54
|
+
- [`at_least_one_of`](#atleastoneof)
|
55
|
+
- [`all_or_none_of`](#allornoneof)
|
56
|
+
- [Nested `mutually_exclusive`, `exactly_one_of`, `at_least_one_of`, `all_or_none_of`](#nested-mutuallyexclusive-exactlyoneof-atleastoneof-allornoneof)
|
47
57
|
- [Namespace Validation and Coercion](#namespace-validation-and-coercion)
|
48
58
|
- [Custom Validators](#custom-validators)
|
49
59
|
- [Validation Errors](#validation-errors)
|
50
60
|
- [I18n](#i18n)
|
51
|
-
- [Custom Validation
|
52
|
-
- [
|
61
|
+
- [Custom Validation messages](#custom-validation-messages)
|
62
|
+
- [`presence`, `allow_blank`, `values`, `regexp`](#presence-allowblank-values-regexp)
|
63
|
+
- [`mutually_exclusive`](#mutuallyexclusive-1)
|
64
|
+
- [Overriding Attribute Names](#overriding-attribute-names)
|
65
|
+
- [With Default](#with-default)
|
53
66
|
- [Routes](#routes)
|
54
67
|
- [Helpers](#helpers)
|
55
68
|
- [Path Helpers](#path-helpers)
|
@@ -63,6 +76,8 @@
|
|
63
76
|
- [Default Error HTTP Status Code](#default-error-http-status-code)
|
64
77
|
- [Handling 404](#handling-404)
|
65
78
|
- [Exception Handling](#exception-handling)
|
79
|
+
- [Rescuing exceptions inside namespaces](#rescuing-exceptions-inside-namespaces)
|
80
|
+
- [Unrescuable Exceptions](#unrescuable-exceptions)
|
66
81
|
- [Rails 3.x](#rails-3x)
|
67
82
|
- [Logging](#logging)
|
68
83
|
- [API Formats](#api-formats)
|
@@ -78,6 +93,8 @@
|
|
78
93
|
- [Active Model Serializers](#active-model-serializers)
|
79
94
|
- [Sending Raw or No Data](#sending-raw-or-no-data)
|
80
95
|
- [Authentication](#authentication)
|
96
|
+
- [Basic and Digest Auth](#basic-and-digest-auth)
|
97
|
+
- [Register custom middleware for authentication](#register-custom-middleware-for-authentication)
|
81
98
|
- [Describing and Inspecting an API](#describing-and-inspecting-an-api)
|
82
99
|
- [Current Route and Endpoint](#current-route-and-endpoint)
|
83
100
|
- [Before and After](#before-and-after)
|
@@ -88,13 +105,22 @@
|
|
88
105
|
- [Remote IP](#remote-ip)
|
89
106
|
- [Writing Tests](#writing-tests)
|
90
107
|
- [Writing Tests with Rack](#writing-tests-with-rack)
|
108
|
+
- [RSpec](#rspec)
|
109
|
+
- [Airborne](#airborne)
|
110
|
+
- [MiniTest](#minitest)
|
91
111
|
- [Writing Tests with Rails](#writing-tests-with-rails)
|
112
|
+
- [RSpec](#rspec-1)
|
113
|
+
- [MiniTest](#minitest-1)
|
92
114
|
- [Stubbing Helpers](#stubbing-helpers)
|
93
115
|
- [Reloading API Changes in Development](#reloading-api-changes-in-development)
|
94
116
|
- [Reloading in Rack Applications](#reloading-in-rack-applications)
|
95
117
|
- [Reloading in Rails Applications](#reloading-in-rails-applications)
|
96
118
|
- [Performance Monitoring](#performance-monitoring)
|
97
119
|
- [Active Support Instrumentation](#active-support-instrumentation)
|
120
|
+
- [endpoint_run.grape](#endpointrungrape)
|
121
|
+
- [endpoint_render.grape](#endpointrendergrape)
|
122
|
+
- [endpoint_run_filters.grape](#endpointrunfiltersgrape)
|
123
|
+
- [endpoint_run_validators.grape](#endpointrunvalidatorsgrape)
|
98
124
|
- [Monitoring Products](#monitoring-products)
|
99
125
|
- [Contributing to Grape](#contributing-to-grape)
|
100
126
|
- [License](#license)
|
@@ -110,12 +136,13 @@ content negotiation, versioning and much more.
|
|
110
136
|
|
111
137
|
## Stable Release
|
112
138
|
|
113
|
-
You're reading the documentation for the stable release of Grape, 1.0.
|
139
|
+
You're reading the documentation for the stable release of Grape, **1.0.2**.
|
114
140
|
Please read [UPGRADING](UPGRADING.md) when upgrading from a previous version.
|
115
141
|
|
116
142
|
## Project Resources
|
117
143
|
|
118
144
|
* [Grape Website](http://www.ruby-grape.org)
|
145
|
+
* [Documentation](http://www.rubydoc.info/gems/grape)
|
119
146
|
* Need help? Try [Grape Google Group](http://groups.google.com/group/ruby-grape) or [Gitter](https://gitter.im/ruby-grape/grape)
|
120
147
|
* [Follow us on Twitter](https://twitter.com/grapeframework)
|
121
148
|
|
@@ -294,13 +321,6 @@ Modify `config/routes`:
|
|
294
321
|
mount Twitter::API => '/'
|
295
322
|
```
|
296
323
|
|
297
|
-
Additionally, if the version of your Rails is 4.0+ and the application uses the default model layer of ActiveRecord, you will want to use the [hashie-forbidden_attributes gem](https://github.com/Maxim-Filimonov/hashie-forbidden_attributes). This gem disables the security feature of `strong_params` at the model layer, allowing you the use of Grape's own params validation instead.
|
298
|
-
|
299
|
-
```ruby
|
300
|
-
# Gemfile
|
301
|
-
gem 'hashie-forbidden_attributes'
|
302
|
-
```
|
303
|
-
|
304
324
|
See [below](#reloading-api-changes-in-development) for additional code that enables reloading of API changes in development.
|
305
325
|
|
306
326
|
### Modules
|
@@ -643,7 +663,7 @@ curl -X GET -H "Content-Type: application/json" localhost:9292/parent/foo/bar
|
|
643
663
|
}
|
644
664
|
````
|
645
665
|
|
646
|
-
### Include
|
666
|
+
### Include Missing
|
647
667
|
|
648
668
|
By default `declared(params)` includes parameters that have `nil` values. If you want to return only the parameters that are not `nil`, you can use the `include_missing` option. By default, `include_missing` is set to `true`. Consider the following API:
|
649
669
|
|
@@ -868,7 +888,7 @@ get '/int' integers: { int: '45' }
|
|
868
888
|
### Custom Types and Coercions
|
869
889
|
|
870
890
|
Aside from the default set of supported types listed above, any class can be
|
871
|
-
used as a type
|
891
|
+
used as a type as long as an explicit coercion method is supplied. If the type
|
872
892
|
implements a class-level `parse` method, Grape will use it automatically.
|
873
893
|
This method must take one string argument and return an instance of the correct
|
874
894
|
type, or raise an exception to indicate the value was invalid. E.g.,
|
@@ -886,10 +906,10 @@ class Color
|
|
886
906
|
end
|
887
907
|
end
|
888
908
|
|
889
|
-
# ...
|
890
|
-
|
891
909
|
params do
|
892
910
|
requires :color, type: Color, default: Color.new('blue')
|
911
|
+
requires :more_colors, type: Array[Color] # Collections work
|
912
|
+
optional :unique_colors, type: Set[Color] # Duplicates discarded
|
893
913
|
end
|
894
914
|
|
895
915
|
get '/stuff' do
|
@@ -924,6 +944,26 @@ params do
|
|
924
944
|
end
|
925
945
|
```
|
926
946
|
|
947
|
+
Grape will assert that coerced values match the given `type`, and will reject the request
|
948
|
+
if they do not. To override this behaviour, custom types may implement a `parsed?` method
|
949
|
+
that should accept a single argument and return `true` if the value passes type validation.
|
950
|
+
|
951
|
+
```ruby
|
952
|
+
class SecureUri
|
953
|
+
def self.parse(value)
|
954
|
+
URI.parse value
|
955
|
+
end
|
956
|
+
|
957
|
+
def self.parsed?(value)
|
958
|
+
value.is_a? URI::HTTPS
|
959
|
+
end
|
960
|
+
end
|
961
|
+
|
962
|
+
params do
|
963
|
+
requires :secure_uri, type: SecureUri
|
964
|
+
end
|
965
|
+
```
|
966
|
+
|
927
967
|
### Multipart File Parameters
|
928
968
|
|
929
969
|
Grape makes use of `Rack::Request`'s built-in support for multipart file parameters. Such parameters can be declared with `type: File`:
|
@@ -934,7 +974,7 @@ params do
|
|
934
974
|
end
|
935
975
|
post '/' do
|
936
976
|
params[:avatar][:filename] # => 'avatar.png'
|
937
|
-
params[:avatar][:
|
977
|
+
params[:avatar][:type] # => 'image/png'
|
938
978
|
params[:avatar][:tempfile] # => #<File>
|
939
979
|
end
|
940
980
|
```
|
@@ -955,8 +995,6 @@ get '/' do
|
|
955
995
|
params[:json].inspect
|
956
996
|
end
|
957
997
|
|
958
|
-
# ...
|
959
|
-
|
960
998
|
client.get('/', json: '{"int":1}') # => "{:int=>1}"
|
961
999
|
client.get('/', json: '[{"int":"1"}]') # => "[{:int=>1}]"
|
962
1000
|
|
@@ -992,8 +1030,6 @@ get '/' do
|
|
992
1030
|
params[:status_code].inspect
|
993
1031
|
end
|
994
1032
|
|
995
|
-
# ...
|
996
|
-
|
997
1033
|
client.get('/', status_code: 'OK_GOOD') # => "OK_GOOD"
|
998
1034
|
client.get('/', status_code: 300) # => 300
|
999
1035
|
client.get('/', status_code: %w(404 NOT FOUND)) # => [404, "NOT", "FOUND"]
|
@@ -1010,15 +1046,13 @@ get '/' do
|
|
1010
1046
|
params[:status_codes].inspect
|
1011
1047
|
end
|
1012
1048
|
|
1013
|
-
# ...
|
1014
|
-
|
1015
1049
|
client.get('/', status_codes: %w(1 two)) # => [1, "two"]
|
1016
1050
|
```
|
1017
1051
|
|
1018
1052
|
### Validation of Nested Parameters
|
1019
1053
|
|
1020
1054
|
Parameters can be nested using `group` or by calling `requires` or `optional` with a block.
|
1021
|
-
In the above example, this means `params[:media][:url]` is required along with `params[:id]`,
|
1055
|
+
In the [above example](#parameter-validation-and-coercion), this means `params[:media][:url]` is required along with `params[:id]`,
|
1022
1056
|
and `params[:audio][:format]` is required only if `params[:audio]` is present.
|
1023
1057
|
With a block, `group`, `requires` and `optional` accept an additional option `type` which can
|
1024
1058
|
be either `Array` or `Hash`, and defaults to `Array`. Depending on the value, the nested
|
@@ -1055,7 +1089,7 @@ end
|
|
1055
1089
|
|
1056
1090
|
In the example above Grape will use `blank?` to check whether the `shelf_id` param is present.
|
1057
1091
|
|
1058
|
-
|
1092
|
+
`given` also takes a `Proc` with custom code. Below, the param `description` is required only if the value of `category` is equal `foo`:
|
1059
1093
|
|
1060
1094
|
```ruby
|
1061
1095
|
params do
|
@@ -1264,6 +1298,8 @@ params do
|
|
1264
1298
|
end
|
1265
1299
|
```
|
1266
1300
|
|
1301
|
+
Note that using `:default` with `mutually_exclusive` will cause multiple parameters to always have a default value and raise a `Grape::Exceptions::Validation` mutually exclusive exception.
|
1302
|
+
|
1267
1303
|
#### `at_least_one_of`
|
1268
1304
|
|
1269
1305
|
Parameters can be defined as 'at_least_one_of', ensuring that at least one parameter gets selected.
|
@@ -1587,7 +1623,7 @@ en:
|
|
1587
1623
|
name_required: 'must be present'
|
1588
1624
|
```
|
1589
1625
|
|
1590
|
-
####
|
1626
|
+
#### Overriding Attribute Names
|
1591
1627
|
|
1592
1628
|
You can also override attribute names.
|
1593
1629
|
|
@@ -1605,7 +1641,7 @@ en:
|
|
1605
1641
|
```
|
1606
1642
|
Will produce 'Oops! Name must be present'
|
1607
1643
|
|
1608
|
-
####
|
1644
|
+
#### With Default
|
1609
1645
|
|
1610
1646
|
You cannot set a custom message option for Default as it requires interpolation `%{option1}: %{value1} is incompatible with %{option2}: %{value2}`. You can change the default error message for Default by changing the `incompatible_option_values` message key inside [en.yml](lib/grape/locale/en.yml)
|
1611
1647
|
|
@@ -2034,7 +2070,7 @@ literally accepts every request.
|
|
2034
2070
|
|
2035
2071
|
## Exception Handling
|
2036
2072
|
|
2037
|
-
Grape can be told to rescue all exceptions and return them in the API format.
|
2073
|
+
Grape can be told to rescue all `StandardError` exceptions and return them in the API format.
|
2038
2074
|
|
2039
2075
|
```ruby
|
2040
2076
|
class Twitter::API < Grape::API
|
@@ -2081,7 +2117,7 @@ Custom error formatters for existing and additional types can be defined with a
|
|
2081
2117
|
|
2082
2118
|
```ruby
|
2083
2119
|
class Twitter::API < Grape::API
|
2084
|
-
error_formatter :txt, ->(message, backtrace, options, env) {
|
2120
|
+
error_formatter :txt, ->(message, backtrace, options, env, original_exception) {
|
2085
2121
|
"error: #{message} from #{backtrace}"
|
2086
2122
|
}
|
2087
2123
|
end
|
@@ -2091,7 +2127,7 @@ You can also use a module or class.
|
|
2091
2127
|
|
2092
2128
|
```ruby
|
2093
2129
|
module CustomFormatter
|
2094
|
-
def self.call(message, backtrace, options, env)
|
2130
|
+
def self.call(message, backtrace, options, env, original_exception)
|
2095
2131
|
{ message: message, backtrace: backtrace }
|
2096
2132
|
end
|
2097
2133
|
end
|
@@ -2140,8 +2176,8 @@ class Twitter::API < Grape::API
|
|
2140
2176
|
error!("ArgumentError: #{e.message}")
|
2141
2177
|
end
|
2142
2178
|
|
2143
|
-
rescue_from
|
2144
|
-
error!("
|
2179
|
+
rescue_from NoMethodError do |e|
|
2180
|
+
error!("NoMethodError: #{e.message}")
|
2145
2181
|
end
|
2146
2182
|
end
|
2147
2183
|
```
|
@@ -2280,7 +2316,6 @@ class API < Grape::API
|
|
2280
2316
|
end
|
2281
2317
|
end
|
2282
2318
|
post '/statuses' do
|
2283
|
-
# ...
|
2284
2319
|
logger.info "#{current_user} has statused"
|
2285
2320
|
end
|
2286
2321
|
end
|
@@ -2923,9 +2958,7 @@ If a request for a resource is made that triggers the built-in `OPTIONS` handler
|
|
2923
2958
|
only `before` and `after` callbacks will be executed. The remaining callbacks will
|
2924
2959
|
be bypassed.
|
2925
2960
|
|
2926
|
-
|
2927
|
-
|
2928
|
-
Using a simple `before` block to set a header
|
2961
|
+
For example, using a simple `before` block to set a header.
|
2929
2962
|
|
2930
2963
|
```ruby
|
2931
2964
|
before do
|
@@ -2961,7 +2994,7 @@ class MyAPI < Grape::API
|
|
2961
2994
|
end
|
2962
2995
|
```
|
2963
2996
|
|
2964
|
-
The
|
2997
|
+
The behavior is then:
|
2965
2998
|
|
2966
2999
|
```bash
|
2967
3000
|
GET / # 'root - '
|
@@ -2989,7 +3022,7 @@ class MyAPI < Grape::API
|
|
2989
3022
|
end
|
2990
3023
|
```
|
2991
3024
|
|
2992
|
-
The
|
3025
|
+
The behavior is then:
|
2993
3026
|
|
2994
3027
|
```bash
|
2995
3028
|
GET /123 # 'Integer'
|
@@ -3024,7 +3057,7 @@ class Test < Grape::API
|
|
3024
3057
|
end
|
3025
3058
|
```
|
3026
3059
|
|
3027
|
-
The
|
3060
|
+
The behavior is then:
|
3028
3061
|
|
3029
3062
|
```bash
|
3030
3063
|
GET /foo/v1 # 'v1-hello'
|
@@ -3049,7 +3082,7 @@ class MyAPI < Grape::API
|
|
3049
3082
|
end
|
3050
3083
|
```
|
3051
3084
|
|
3052
|
-
The
|
3085
|
+
The behavior is then:
|
3053
3086
|
|
3054
3087
|
```bash
|
3055
3088
|
GET /greeting # {"greeting":"Hello!"}
|
@@ -3337,7 +3370,7 @@ describe 'an endpoint that needs helpers stubbed' do
|
|
3337
3370
|
end
|
3338
3371
|
|
3339
3372
|
it 'stubs the helper' do
|
3340
|
-
|
3373
|
+
|
3341
3374
|
end
|
3342
3375
|
end
|
3343
3376
|
```
|
@@ -3374,6 +3407,22 @@ if Rails.env.development?
|
|
3374
3407
|
end
|
3375
3408
|
```
|
3376
3409
|
|
3410
|
+
For Rails >= 5.1.4, change this:
|
3411
|
+
|
3412
|
+
```ruby
|
3413
|
+
ActionDispatch::Callbacks.to_prepare do
|
3414
|
+
api_reloader.execute_if_updated
|
3415
|
+
end
|
3416
|
+
```
|
3417
|
+
|
3418
|
+
to this:
|
3419
|
+
|
3420
|
+
```ruby
|
3421
|
+
ActiveSupport::Reloader.to_prepare do
|
3422
|
+
api_reloader.execute_if_updated
|
3423
|
+
end
|
3424
|
+
```
|
3425
|
+
|
3377
3426
|
See [StackOverflow #3282655](http://stackoverflow.com/questions/3282655/ruby-on-rails-3-reload-lib-directory-for-each-request/4368838#4368838) for more information.
|
3378
3427
|
|
3379
3428
|
## Performance Monitoring
|
@@ -3434,4 +3483,4 @@ MIT License. See LICENSE for details.
|
|
3434
3483
|
|
3435
3484
|
## Copyright
|
3436
3485
|
|
3437
|
-
Copyright (c) 2010-
|
3486
|
+
Copyright (c) 2010-2018 Michael Bleigh, Intridea Inc. and Contributors.
|