grape 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Appraisals +3 -7
- data/CHANGELOG.md +21 -1
- data/Gemfile.lock +26 -26
- data/README.md +109 -29
- data/UPGRADING.md +45 -0
- data/gemfiles/rack_1.5.2.gemfile.lock +232 -0
- data/gemfiles/rails_3.gemfile +1 -1
- data/gemfiles/rails_3.gemfile.lock +288 -0
- data/gemfiles/rails_4.gemfile +1 -1
- data/gemfiles/rails_4.gemfile.lock +280 -0
- data/gemfiles/rails_5.gemfile +1 -1
- data/gemfiles/rails_5.gemfile.lock +312 -0
- data/lib/grape.rb +1 -0
- data/lib/grape/api.rb +74 -195
- data/lib/grape/api/instance.rb +242 -0
- data/lib/grape/dsl/desc.rb +17 -1
- data/lib/grape/dsl/middleware.rb +7 -0
- data/lib/grape/dsl/parameters.rb +9 -4
- data/lib/grape/dsl/routing.rb +5 -1
- data/lib/grape/endpoint.rb +1 -1
- data/lib/grape/exceptions/base.rb +9 -1
- data/lib/grape/exceptions/invalid_response.rb +9 -0
- data/lib/grape/locale/en.yml +1 -0
- data/lib/grape/middleware/error.rb +8 -2
- data/lib/grape/middleware/versioner/header.rb +2 -2
- data/lib/grape/validations/params_scope.rb +1 -0
- data/lib/grape/validations/validators/multiple_params_base.rb +1 -1
- data/lib/grape/version.rb +1 -1
- data/pkg/grape-1.2.0.gem +0 -0
- data/spec/grape/api/routes_with_requirements_spec.rb +59 -0
- data/spec/grape/api_remount_spec.rb +85 -0
- data/spec/grape/api_spec.rb +70 -1
- data/spec/grape/dsl/desc_spec.rb +17 -1
- data/spec/grape/dsl/middleware_spec.rb +8 -0
- data/spec/grape/dsl/routing_spec.rb +10 -0
- data/spec/grape/exceptions/base_spec.rb +61 -0
- data/spec/grape/exceptions/invalid_response_spec.rb +11 -0
- data/spec/grape/middleware/auth/dsl_spec.rb +3 -3
- data/spec/grape/middleware/exception_spec.rb +1 -1
- data/spec/grape/middleware/versioner/header_spec.rb +6 -0
- data/spec/grape/validations/params_scope_spec.rb +133 -0
- data/spec/spec_helper.rb +3 -1
- metadata +99 -87
- data/gemfiles/rack_1.5.2.gemfile +0 -35
- data/pkg/grape-0.17.0.gem +0 -0
- data/pkg/grape-0.19.0.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4362917201381823e379e97fe0be3964a122a7d56039b34419f811c6cfe3f6e
|
4
|
+
data.tar.gz: 5975d6e356d8487684f9470546e9c3e42027fb4610f879d844f1c9871e614f7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61a0080907f18d90106ee479cba0229aee5e3e500b42310e8c7d78a95632c4f580616dcdc10947ec008ae76cef19029a69f184749de6110a54231e688c104aea
|
7
|
+
data.tar.gz: 586400490332bdd096ef8f299f8ace196788268d505b76beb00a969204819940b4b5d2b1159309206c2826186e65302c19cda4f7ea2aec5ecf14109ed29362ba
|
data/Appraisals
CHANGED
@@ -1,18 +1,14 @@
|
|
1
1
|
appraise 'rails-3' do
|
2
|
-
gem 'rails', '3.2.
|
2
|
+
gem 'rails', '3.2.22.5'
|
3
3
|
gem 'rack-cache', '<= 1.2' # Pin as next rack-cache version (1.3) removes Ruby1.9 support
|
4
4
|
end
|
5
5
|
|
6
6
|
appraise 'rails-4' do
|
7
|
-
gem 'rails', '4.
|
7
|
+
gem 'rails', '4.2.10'
|
8
8
|
end
|
9
9
|
|
10
10
|
appraise 'rails-5' do
|
11
|
-
gem 'rails', '5.
|
12
|
-
end
|
13
|
-
|
14
|
-
appraise 'rack-1.5.2' do
|
15
|
-
gem 'rack', '1.5.2'
|
11
|
+
gem 'rails', '5.2.1'
|
16
12
|
end
|
17
13
|
|
18
14
|
appraise 'rails-edge' do
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,24 @@
|
|
1
|
+
### 1.2.0 (Next)
|
2
|
+
|
3
|
+
#### Features
|
4
|
+
|
5
|
+
* Your contribution here.
|
6
|
+
* [#1813](https://github.com/ruby-grape/grape/pull/1813): Add ruby 2.5 support, drop 2.2. Update rails version in travis - [@darren987469](https://github.com/darren987469).
|
7
|
+
* [#1803](https://github.com/ruby-grape/grape/pull/1803): Adds the ability to re-mount all endpoints in any location - [@myxoh](https://github.com/myxoh).
|
8
|
+
* [#1795](https://github.com/ruby-grape/grape/pull/1795): Fix vendor/subtype parsing of an invalid Accept header - [@bschmeck](https://github.com/bschmeck).
|
9
|
+
* [#1791](https://github.com/ruby-grape/grape/pull/1791): Support `summary`, `hidden`, `deprecated`, `is_array`, `nickname`, `produces`, `consumes`, `tags` options in `desc` block - [@darren987469](https://github.com/darren987469).
|
10
|
+
|
11
|
+
#### Fixes
|
12
|
+
|
13
|
+
* Your contribution here.
|
14
|
+
* [#1796](https://github.com/ruby-grape/grape/pull/1796): Fix crash when available locales are enforced but fallback locale unavailable - [@Morred](https://github.com/Morred).
|
15
|
+
* [#1776](https://github.com/ruby-grape/grape/pull/1776): Validate response returned by the exception handler - [@darren987469](https://github.com/darren987469).
|
16
|
+
* [#1787](https://github.com/ruby-grape/grape/pull/1787): Add documented but not implemented ability to `.insert` a middleware in the stack - [@michaellennox](https://github.com/michaellennox).
|
17
|
+
* [#1788](https://github.com/ruby-grape/grape/pull/1788): Fix route requirements bug - [@darren987469](https://github.com/darren987469), [@darrellnash](https://github.com/darrellnash).
|
18
|
+
* [#1810](https://github.com/ruby-grape/grape/pull/1810): Fix support in `given` for aliased params - [@darren987469](https://github.com/darren987469).
|
19
|
+
* [#1811](https://github.com/ruby-grape/grape/pull/1811): Support nested dependent parameters - [@darren987469](https://github.com/darren987469), [@andreacfm](https://github.com/andreacfm).
|
20
|
+
* [#1822](https://github.com/ruby-grape/grape/pull/1822): Raise validation error when optional hash type parameter is received string type value and exactly_one_of be used - [@woshidan](https://github.com/woshidan).
|
21
|
+
|
1
22
|
### 1.1.0 (8/4/2018)
|
2
23
|
|
3
24
|
#### Features
|
@@ -6,7 +27,6 @@
|
|
6
27
|
|
7
28
|
#### Fixes
|
8
29
|
|
9
|
-
|
10
30
|
* [#1762](https://github.com/ruby-grape/grape/pull/1763): Fix unsafe HTML rendering on errors - [@ctennis](https://github.com/ctennis).
|
11
31
|
* [#1759](https://github.com/ruby-grape/grape/pull/1759): Update appraisal for rails_edge - [@zvkemp](https://github.com/zvkemp).
|
12
32
|
* [#1758](https://github.com/ruby-grape/grape/pull/1758): Fix expanding load_path in gemspec - [@2maz](https://github.com/2maz).
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
grape (1.
|
4
|
+
grape (1.2.0)
|
5
5
|
activesupport
|
6
6
|
builder
|
7
7
|
mustermann-grape (~> 1.0.0)
|
@@ -12,7 +12,7 @@ PATH
|
|
12
12
|
GEM
|
13
13
|
remote: https://rubygems.org/
|
14
14
|
specs:
|
15
|
-
activesupport (5.2.
|
15
|
+
activesupport (5.2.1)
|
16
16
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
17
|
i18n (>= 0.7, < 2)
|
18
18
|
minitest (~> 5.1)
|
@@ -65,7 +65,7 @@ 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.
|
68
|
+
danger-toc (0.1.3)
|
69
69
|
activesupport
|
70
70
|
danger-plugin-api (~> 1.0)
|
71
71
|
kramdown
|
@@ -74,13 +74,13 @@ GEM
|
|
74
74
|
diff-lcs (1.3)
|
75
75
|
docile (1.3.1)
|
76
76
|
equalizer (0.0.11)
|
77
|
-
faraday (0.15.
|
77
|
+
faraday (0.15.3)
|
78
78
|
multipart-post (>= 1.2, < 3)
|
79
79
|
faraday-http-cache (1.3.1)
|
80
80
|
faraday (~> 0.8)
|
81
81
|
ffi (1.9.25)
|
82
82
|
formatador (0.2.5)
|
83
|
-
git (1.
|
83
|
+
git (1.5.0)
|
84
84
|
grape-entity (0.7.1)
|
85
85
|
activesupport (>= 4.0)
|
86
86
|
multi_json (>= 1.3.2)
|
@@ -101,8 +101,8 @@ GEM
|
|
101
101
|
guard-rubocop (1.3.0)
|
102
102
|
guard (~> 2.0)
|
103
103
|
rubocop (~> 0.20)
|
104
|
-
hashie (3.
|
105
|
-
i18n (1.
|
104
|
+
hashie (3.6.0)
|
105
|
+
i18n (1.1.1)
|
106
106
|
concurrent-ruby (~> 1.0)
|
107
107
|
ice_nine (0.11.2)
|
108
108
|
json (2.1.0)
|
@@ -114,13 +114,13 @@ GEM
|
|
114
114
|
lumberjack (1.0.13)
|
115
115
|
maruku (0.7.3)
|
116
116
|
method_source (0.9.0)
|
117
|
-
mime-types (3.
|
117
|
+
mime-types (3.2.2)
|
118
118
|
mime-types-data (~> 3.2015)
|
119
|
-
mime-types-data (3.
|
119
|
+
mime-types-data (3.2018.0812)
|
120
120
|
minitest (5.11.3)
|
121
121
|
multi_json (1.13.1)
|
122
122
|
multipart-post (2.0.0)
|
123
|
-
mustermann (1.0.
|
123
|
+
mustermann (1.0.3)
|
124
124
|
mustermann-grape (1.0.0)
|
125
125
|
mustermann (~> 1.0.0)
|
126
126
|
nap (1.1.0)
|
@@ -128,7 +128,7 @@ GEM
|
|
128
128
|
notiffany (0.1.1)
|
129
129
|
nenv (~> 0.1)
|
130
130
|
shellany (~> 0.0)
|
131
|
-
octokit (4.
|
131
|
+
octokit (4.13.0)
|
132
132
|
sawyer (~> 0.8.0, >= 0.5.3)
|
133
133
|
open4 (1.3.4)
|
134
134
|
parallel (1.12.1)
|
@@ -138,7 +138,7 @@ GEM
|
|
138
138
|
pry (0.11.3)
|
139
139
|
coderay (~> 1.1.0)
|
140
140
|
method_source (~> 0.9.0)
|
141
|
-
public_suffix (3.0.
|
141
|
+
public_suffix (3.0.3)
|
142
142
|
rack (2.0.5)
|
143
143
|
rack-accept (0.4.5)
|
144
144
|
rack (>= 0.4)
|
@@ -152,19 +152,19 @@ GEM
|
|
152
152
|
rb-fsevent (0.10.3)
|
153
153
|
rb-inotify (0.9.10)
|
154
154
|
ffi (>= 0.5.0, < 2)
|
155
|
-
rspec (3.
|
156
|
-
rspec-core (~> 3.
|
157
|
-
rspec-expectations (~> 3.
|
158
|
-
rspec-mocks (~> 3.
|
159
|
-
rspec-core (3.
|
160
|
-
rspec-support (~> 3.
|
161
|
-
rspec-expectations (3.
|
155
|
+
rspec (3.8.0)
|
156
|
+
rspec-core (~> 3.8.0)
|
157
|
+
rspec-expectations (~> 3.8.0)
|
158
|
+
rspec-mocks (~> 3.8.0)
|
159
|
+
rspec-core (3.8.0)
|
160
|
+
rspec-support (~> 3.8.0)
|
161
|
+
rspec-expectations (3.8.2)
|
162
162
|
diff-lcs (>= 1.2.0, < 2.0)
|
163
|
-
rspec-support (~> 3.
|
164
|
-
rspec-mocks (3.
|
163
|
+
rspec-support (~> 3.8.0)
|
164
|
+
rspec-mocks (3.8.0)
|
165
165
|
diff-lcs (>= 1.2.0, < 2.0)
|
166
|
-
rspec-support (~> 3.
|
167
|
-
rspec-support (3.
|
166
|
+
rspec-support (~> 3.8.0)
|
167
|
+
rspec-support (3.8.0)
|
168
168
|
rubocop (0.51.0)
|
169
169
|
parallel (~> 1.10)
|
170
170
|
parser (>= 2.3.3.1, < 3.0)
|
@@ -175,7 +175,7 @@ GEM
|
|
175
175
|
ruby-grape-danger (0.1.1)
|
176
176
|
danger (~> 4.0.1)
|
177
177
|
danger-changelog (~> 0.2.0)
|
178
|
-
ruby-progressbar (1.
|
178
|
+
ruby-progressbar (1.10.0)
|
179
179
|
ruby_dep (1.5.0)
|
180
180
|
sawyer (0.8.1)
|
181
181
|
addressable (>= 2.3.5, < 2.6)
|
@@ -192,7 +192,7 @@ GEM
|
|
192
192
|
unicode-display_width (~> 1.1, >= 1.1.1)
|
193
193
|
thor (0.19.4)
|
194
194
|
thread_safe (0.3.6)
|
195
|
-
tins (1.
|
195
|
+
tins (1.17.0)
|
196
196
|
tzinfo (1.2.5)
|
197
197
|
thread_safe (~> 0.1)
|
198
198
|
unicode-display_width (1.4.0)
|
@@ -228,4 +228,4 @@ DEPENDENCIES
|
|
228
228
|
ruby-grape-danger (~> 0.1.0)
|
229
229
|
|
230
230
|
BUNDLED WITH
|
231
|
-
1.16.
|
231
|
+
1.16.2
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
[](https://gemnasium.com/ruby-grape/grape)
|
6
6
|
[](https://codeclimate.com/github/ruby-grape/grape)
|
7
7
|
[](https://coveralls.io/github/ruby-grape/grape?branch=master)
|
8
|
-
[](https://inch-ci.org/github/ruby-grape/grape)
|
9
9
|
[](https://git.legal/projects/1364)
|
10
10
|
[](https://gitter.im/ruby-grape/grape?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
11
11
|
|
@@ -22,6 +22,8 @@
|
|
22
22
|
- [Alongside Sinatra (or other frameworks)](#alongside-sinatra-or-other-frameworks)
|
23
23
|
- [Rails](#rails)
|
24
24
|
- [Modules](#modules)
|
25
|
+
- [Remounting](#remounting)
|
26
|
+
- [Configuration](#configuration)
|
25
27
|
- [Versioning](#versioning)
|
26
28
|
- [Path](#path)
|
27
29
|
- [Header](#header)
|
@@ -38,35 +40,35 @@
|
|
38
40
|
- [Integer/Fixnum and Coercions](#integerfixnum-and-coercions)
|
39
41
|
- [Custom Types and Coercions](#custom-types-and-coercions)
|
40
42
|
- [Multipart File Parameters](#multipart-file-parameters)
|
41
|
-
- [First-Class
|
43
|
+
- [First-Class JSON Types](#first-class-json-types)
|
42
44
|
- [Multiple Allowed Types](#multiple-allowed-types)
|
43
45
|
- [Validation of Nested Parameters](#validation-of-nested-parameters)
|
44
46
|
- [Dependent Parameters](#dependent-parameters)
|
45
47
|
- [Group Options](#group-options)
|
46
48
|
- [Alias](#alias)
|
47
49
|
- [Built-in Validators](#built-in-validators)
|
48
|
-
- [
|
49
|
-
- [
|
50
|
-
- [
|
51
|
-
- [
|
52
|
-
- [
|
53
|
-
- [
|
54
|
-
- [
|
55
|
-
- [
|
56
|
-
- [Nested
|
50
|
+
- [allow_blank](#allow_blank)
|
51
|
+
- [values](#values)
|
52
|
+
- [except_values](#except_values)
|
53
|
+
- [regexp](#regexp)
|
54
|
+
- [mutually_exclusive](#mutually_exclusive)
|
55
|
+
- [exactly_one_of](#exactly_one_of)
|
56
|
+
- [at_least_one_of](#at_least_one_of)
|
57
|
+
- [all_or_none_of](#all_or_none_of)
|
58
|
+
- [Nested mutually_exclusive, exactly_one_of, at_least_one_of, all_or_none_of](#nested-mutually_exclusive-exactly_one_of-at_least_one_of-all_or_none_of)
|
57
59
|
- [Namespace Validation and Coercion](#namespace-validation-and-coercion)
|
58
60
|
- [Custom Validators](#custom-validators)
|
59
61
|
- [Validation Errors](#validation-errors)
|
60
62
|
- [I18n](#i18n)
|
61
63
|
- [Custom Validation messages](#custom-validation-messages)
|
62
|
-
- [
|
63
|
-
- [
|
64
|
-
- [
|
65
|
-
- [
|
66
|
-
- [
|
67
|
-
- [
|
68
|
-
- [
|
69
|
-
- [
|
64
|
+
- [presence, allow_blank, values, regexp](#presence-allow_blank-values-regexp)
|
65
|
+
- [all_or_none_of](#all_or_none_of-1)
|
66
|
+
- [mutually_exclusive](#mutually_exclusive-1)
|
67
|
+
- [exactly_one_of](#exactly_one_of-1)
|
68
|
+
- [at_least_one_of](#at_least_one_of-1)
|
69
|
+
- [Coerce](#coerce)
|
70
|
+
- [With Lambdas](#with-lambdas)
|
71
|
+
- [Pass symbols for i18n translations](#pass-symbols-for-i18n-translations)
|
70
72
|
- [Overriding Attribute Names](#overriding-attribute-names)
|
71
73
|
- [With Default](#with-default)
|
72
74
|
- [Headers](#headers)
|
@@ -145,8 +147,9 @@ content negotiation, versioning and much more.
|
|
145
147
|
|
146
148
|
## Stable Release
|
147
149
|
|
148
|
-
You're reading the documentation for the
|
150
|
+
You're reading the documentation for the next release of Grape, which should be **1.1.1**.
|
149
151
|
Please read [UPGRADING](UPGRADING.md) when upgrading from a previous version.
|
152
|
+
The current stable release is [1.1.0](https://github.com/ruby-grape/grape/blob/v1.1.0/README.md).
|
150
153
|
|
151
154
|
## Project Resources
|
152
155
|
|
@@ -365,6 +368,57 @@ class Twitter::API < Grape::API
|
|
365
368
|
end
|
366
369
|
```
|
367
370
|
|
371
|
+
## Remounting
|
372
|
+
|
373
|
+
You can mount the same endpoints in two different locations.
|
374
|
+
|
375
|
+
```ruby
|
376
|
+
class Voting::API < Grape::API
|
377
|
+
namespace 'votes' do
|
378
|
+
get do
|
379
|
+
# Your logic
|
380
|
+
end
|
381
|
+
|
382
|
+
post do
|
383
|
+
# Your logic
|
384
|
+
end
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
388
|
+
class Post::API < Grape::API
|
389
|
+
mount Voting::API
|
390
|
+
end
|
391
|
+
|
392
|
+
class Comment::API < Grape::API
|
393
|
+
mount Voting::API
|
394
|
+
end
|
395
|
+
```
|
396
|
+
|
397
|
+
Assuming that the post and comment endpoints are mounted in `/posts` and `/comments`, you should now be able to do `get /posts/votes`, `post /posts/votes`, `get /comments/votes`.
|
398
|
+
|
399
|
+
### Configuration
|
400
|
+
|
401
|
+
You can configure remountable endpoints for small details changing according to where they are mounted.
|
402
|
+
|
403
|
+
```ruby
|
404
|
+
class Voting::API < Grape::API
|
405
|
+
namespace 'votes' do
|
406
|
+
desc "Vote for your #{configuration[:votable]}"
|
407
|
+
get do
|
408
|
+
# Your logic
|
409
|
+
end
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
413
|
+
class Post::API < Grape::API
|
414
|
+
mount Voting::API, with: { votable: 'posts' }
|
415
|
+
end
|
416
|
+
|
417
|
+
class Comment::API < Grape::API
|
418
|
+
mount Voting::API, with: { votable: 'comments' }
|
419
|
+
end
|
420
|
+
```
|
421
|
+
|
368
422
|
## Versioning
|
369
423
|
|
370
424
|
There are four strategies in which clients can reach your API's endpoints: `:path`,
|
@@ -445,10 +499,13 @@ version 'v1', using: :param, parameter: 'v'
|
|
445
499
|
|
446
500
|
## Describing Methods
|
447
501
|
|
448
|
-
You can add a description to API methods and namespaces.
|
502
|
+
You can add a description to API methods and namespaces. The description would be used by [grape-swagger][grape-swagger] to generate swagger compliant documentation.
|
503
|
+
|
504
|
+
Note: Description block is only for documentation and won't affects API behavior.
|
449
505
|
|
450
506
|
```ruby
|
451
507
|
desc 'Returns your public timeline.' do
|
508
|
+
summary 'summary'
|
452
509
|
detail 'more details'
|
453
510
|
params API::Entities::Status.documentation
|
454
511
|
success API::Entities::Entity
|
@@ -462,7 +519,13 @@ desc 'Returns your public timeline.' do
|
|
462
519
|
description: 'Not really needed',
|
463
520
|
required: false
|
464
521
|
}
|
465
|
-
|
522
|
+
hidden false
|
523
|
+
deprecated false
|
524
|
+
is_array true
|
525
|
+
nickname 'nickname'
|
526
|
+
produces ['application/json']
|
527
|
+
consumes ['application/json']
|
528
|
+
tags ['tag1', 'tag2']
|
466
529
|
end
|
467
530
|
get :public_timeline do
|
468
531
|
Status.limit(20)
|
@@ -475,6 +538,9 @@ end
|
|
475
538
|
* `failure`: (former http_codes) A definition of the used failure HTTP Codes and Entities
|
476
539
|
* `named`: A helper to give a route a name and find it with this name in the documentation Hash
|
477
540
|
* `headers`: A definition of the used Headers
|
541
|
+
* Other options can be found in [grape-swagger][grape-swagger]
|
542
|
+
|
543
|
+
[grape-swagger]: https://github.com/ruby-grape/grape-swagger
|
478
544
|
|
479
545
|
## Parameters
|
480
546
|
|
@@ -934,7 +1000,7 @@ parameter, and the return value must match the given `type`.
|
|
934
1000
|
|
935
1001
|
```ruby
|
936
1002
|
params do
|
937
|
-
requires :passwd, type: String, coerce_with: Base64.method(:
|
1003
|
+
requires :passwd, type: String, coerce_with: Base64.method(:decode64)
|
938
1004
|
requires :loud_color, type: Color, coerce_with: ->(c) { Color.parse(c.downcase) }
|
939
1005
|
|
940
1006
|
requires :obj, type: Hash, coerce_with: JSON do
|
@@ -1109,6 +1175,18 @@ params do
|
|
1109
1175
|
end
|
1110
1176
|
```
|
1111
1177
|
|
1178
|
+
You can set alias for parameter:
|
1179
|
+
|
1180
|
+
```ruby
|
1181
|
+
params do
|
1182
|
+
optional :category, as: :type
|
1183
|
+
given type: ->(val) { val == 'foo' } do
|
1184
|
+
requires :description
|
1185
|
+
end
|
1186
|
+
end
|
1187
|
+
```
|
1188
|
+
|
1189
|
+
Note: param in `given` should be the aliased one. In the example, it should be `type`, not `category`.
|
1112
1190
|
|
1113
1191
|
### Group Options
|
1114
1192
|
|
@@ -1546,6 +1624,8 @@ end
|
|
1546
1624
|
Grape supports I18n for parameter-related error messages, but will fallback to English if
|
1547
1625
|
translations for the default locale have not been provided. See [en.yml](lib/grape/locale/en.yml) for message keys.
|
1548
1626
|
|
1627
|
+
In case your app enforces available locales only and :en is not included in your available locales, Grape cannot fall back to English and will return the translation key for the error message. To avoid this behaviour, either provide a translation for your default locale or add :en to your available locales.
|
1628
|
+
|
1549
1629
|
### Custom Validation messages
|
1550
1630
|
|
1551
1631
|
Grape supports custom validation messages for parameter-related and coerce-related error messages.
|
@@ -1587,7 +1667,7 @@ params do
|
|
1587
1667
|
optional :beer
|
1588
1668
|
optional :wine
|
1589
1669
|
optional :juice
|
1590
|
-
exactly_one_of :beer, :wine, :juice, message: {exactly_one: "are missing, exactly one parameter is required", mutual_exclusion: "are mutually exclusive, exactly one parameter is required"}
|
1670
|
+
exactly_one_of :beer, :wine, :juice, message: { exactly_one: "are missing, exactly one parameter is required", mutual_exclusion: "are mutually exclusive, exactly one parameter is required" }
|
1591
1671
|
end
|
1592
1672
|
```
|
1593
1673
|
|
@@ -1606,7 +1686,7 @@ end
|
|
1606
1686
|
|
1607
1687
|
```ruby
|
1608
1688
|
params do
|
1609
|
-
requires :int, type: {value: Integer, message: "type cast is invalid" }
|
1689
|
+
requires :int, type: { value: Integer, message: "type cast is invalid" }
|
1610
1690
|
end
|
1611
1691
|
```
|
1612
1692
|
|
@@ -2182,7 +2262,7 @@ You can also rescue all exceptions with a code block and handle the Rack respons
|
|
2182
2262
|
```ruby
|
2183
2263
|
class Twitter::API < Grape::API
|
2184
2264
|
rescue_from :all do |e|
|
2185
|
-
Rack::Response.new([ e.message ], 500, { 'Content-type' => 'text/error' })
|
2265
|
+
Rack::Response.new([ e.message ], 500, { 'Content-type' => 'text/error' })
|
2186
2266
|
end
|
2187
2267
|
end
|
2188
2268
|
```
|
@@ -2253,9 +2333,9 @@ class Twitter::API < Grape::API
|
|
2253
2333
|
end
|
2254
2334
|
```
|
2255
2335
|
|
2256
|
-
The `rescue_from`
|
2336
|
+
The `rescue_from` handler must return a `Rack::Response` object, call `error!`, or raise an exception (either the original exception or another custom one). The exception raised in `rescue_from` will be handled outside Grape. For example, if you mount Grape in Rails, the exception will be handle by [Rails Action Controller](https://guides.rubyonrails.org/action_controller_overview.html#rescue).
|
2257
2337
|
|
2258
|
-
|
2338
|
+
Alternately, use the `with` option in `rescue_from` to specify a method or a `proc`.
|
2259
2339
|
|
2260
2340
|
```ruby
|
2261
2341
|
class Twitter::API < Grape::API
|
@@ -2893,7 +2973,7 @@ end
|
|
2893
2973
|
|
2894
2974
|
```
|
2895
2975
|
|
2896
|
-
Use [warden-oauth2](https://github.com/opperator/warden-oauth2) or [rack-oauth2](https://github.com/nov/rack-oauth2) for OAuth2 support.
|
2976
|
+
Use [Doorkeeper](https://github.com/doorkeeper-gem/doorkeeper), [warden-oauth2](https://github.com/opperator/warden-oauth2) or [rack-oauth2](https://github.com/nov/rack-oauth2) for OAuth2 support.
|
2897
2977
|
|
2898
2978
|
## Describing and Inspecting an API
|
2899
2979
|
|