grape 2.1.1 → 2.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/README.md +1 -1
- data/lib/grape/api/instance.rb +1 -1
- data/lib/grape/api.rb +2 -2
- data/lib/grape/dsl/inside_route.rb +5 -3
- data/lib/grape/dsl/parameters.rb +1 -1
- data/lib/grape/endpoint.rb +2 -2
- data/lib/grape/exceptions/validation_errors.rb +1 -1
- data/lib/grape/middleware/base.rb +1 -1
- data/lib/grape/middleware/error.rb +2 -2
- data/lib/grape/middleware/stack.rb +2 -2
- data/lib/grape/validations/attributes_iterator.rb +1 -0
- data/lib/grape/validations/params_scope.rb +12 -10
- data/lib/grape/validations/validators/exactly_one_of_validator.rb +1 -1
- data/lib/grape/version.rb +1 -1
- metadata +5 -6
- data/lib/grape/util/accept/header.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 172d51f08cb655e030afc83ecc06cb13ad5c72c9ad1d6f63d6f87d8b45a52772
|
4
|
+
data.tar.gz: 2d946a6526a7cc848e441fac2d4e0169a0762025d34445307f3945abeeef2b72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb1ec3cd146f8e4a3f12314159e68177b92548fb7ea3eeac47a425addc3fa04a38c61c566ed3a0655d325bd5d24044b020449aa5702f997d746eef2c5d493928
|
7
|
+
data.tar.gz: 8c44c721a9e0acbb00997ac40ea4b491c4a3c0315e6f4cc1432a2ea5cff102887e028e10df883eba0b50645219918a3fc5a3a66f36068a9d6abc81b29b75c61f
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
### 2.1.3 (2024-07-13)
|
2
|
+
|
3
|
+
#### Fixes
|
4
|
+
|
5
|
+
* [#2467](https://github.com/ruby-grape/grape/pull/2467): Fix repo coverage - [@ericproulx](https://github.com/ericproulx).
|
6
|
+
* [#2468](https://github.com/ruby-grape/grape/pull/2468): Align `error!` method signatures across different places - [@numbata](https://github.com/numbata).
|
7
|
+
* [#2469](https://github.com/ruby-grape/grape/pull/2469): Fix full path building for lateral scopes - [@numbata](https://github.com/numbata).
|
8
|
+
|
9
|
+
### 2.1.2 (2024-06-28)
|
10
|
+
|
11
|
+
#### Fixes
|
12
|
+
|
13
|
+
* [#2459](https://github.com/ruby-grape/grape/pull/2459): Autocorrect cops - [@ericproulx](https://github.com/ericproulx).
|
14
|
+
* [#3458](https://github.com/ruby-grape/grape/pull/2458): Remove unused Grape::Util::Accept::Header - [@ericproulx](https://github.com/ericproulx).
|
15
|
+
* [#2463](https://github.com/ruby-grape/grape/pull/2463): Fix error message indices - [@ericproulx](https://github.com/ericproulx).
|
16
|
+
|
1
17
|
### 2.1.1 (2024-06-22)
|
2
18
|
|
3
19
|
#### Features
|
data/README.md
CHANGED
@@ -157,7 +157,7 @@ Grape is a REST-like API framework for Ruby. It's designed to run on Rack or com
|
|
157
157
|
|
158
158
|
## Stable Release
|
159
159
|
|
160
|
-
You're reading the documentation for the stable release of Grape, **2.1.
|
160
|
+
You're reading the documentation for the stable release of Grape, **2.1.3**.
|
161
161
|
Please read [UPGRADING](UPGRADING.md) when upgrading from a previous version.
|
162
162
|
|
163
163
|
## Project Resources
|
data/lib/grape/api/instance.rb
CHANGED
@@ -46,7 +46,7 @@ module Grape
|
|
46
46
|
# Parses the API's definition and compiles it into an instance of
|
47
47
|
# Grape::API.
|
48
48
|
def compile
|
49
|
-
@instance ||= new
|
49
|
+
@instance ||= new # rubocop:disable Naming/MemoizedInstanceVariableName
|
50
50
|
end
|
51
51
|
|
52
52
|
# Wipe the compiled API so we can recompile after changes were made.
|
data/lib/grape/api.rb
CHANGED
@@ -32,7 +32,7 @@ module Grape
|
|
32
32
|
def inherited(api)
|
33
33
|
super
|
34
34
|
|
35
|
-
api.initial_setup(Grape::API
|
35
|
+
api.initial_setup(self == Grape::API ? Grape::API::Instance : @base_instance)
|
36
36
|
api.override_all_methods!
|
37
37
|
end
|
38
38
|
|
@@ -108,7 +108,7 @@ module Grape
|
|
108
108
|
end
|
109
109
|
|
110
110
|
def respond_to?(method, include_private = false)
|
111
|
-
super
|
111
|
+
super || base_instance.respond_to?(method, include_private)
|
112
112
|
end
|
113
113
|
|
114
114
|
def respond_to_missing?(method, include_private = false)
|
@@ -163,12 +163,14 @@ module Grape
|
|
163
163
|
# end user with the specified message.
|
164
164
|
#
|
165
165
|
# @param message [String] The message to display.
|
166
|
-
# @param status [Integer]
|
166
|
+
# @param status [Integer] The HTTP Status Code. Defaults to default_error_status, 500 if not set.
|
167
167
|
# @param additional_headers [Hash] Addtional headers for the response.
|
168
|
-
|
168
|
+
# @param backtrace [Array<String>] The backtrace of the exception that caused the error.
|
169
|
+
# @param original_exception [Exception] The original exception that caused the error.
|
170
|
+
def error!(message, status = nil, additional_headers = nil, backtrace = nil, original_exception = nil)
|
169
171
|
status = self.status(status || namespace_inheritable(:default_error_status))
|
170
172
|
headers = additional_headers.present? ? header.merge(additional_headers) : header
|
171
|
-
throw :error, message: message, status: status, headers: headers
|
173
|
+
throw :error, message: message, status: status, headers: headers, backtrace: backtrace, original_exception: original_exception
|
172
174
|
end
|
173
175
|
|
174
176
|
# Creates a Rack response based on the provided message, status, and headers.
|
data/lib/grape/dsl/parameters.rb
CHANGED
data/lib/grape/endpoint.rb
CHANGED
@@ -231,8 +231,8 @@ module Grape
|
|
231
231
|
options[:app].endpoints if options[:app].respond_to?(:endpoints)
|
232
232
|
end
|
233
233
|
|
234
|
-
def equals?(
|
235
|
-
(options ==
|
234
|
+
def equals?(endpoint)
|
235
|
+
(options == endpoint.options) && (inheritable_setting.to_hash == endpoint.inheritable_setting.to_hash)
|
236
236
|
end
|
237
237
|
|
238
238
|
protected
|
@@ -74,7 +74,7 @@ module Grape
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def mime_types
|
77
|
-
@
|
77
|
+
@mime_types ||= content_types.each_pair.with_object({}) do |(k, v), types_without_params|
|
78
78
|
types_without_params[v.split(';').first] = k
|
79
79
|
end
|
80
80
|
end
|
@@ -74,8 +74,8 @@ module Grape
|
|
74
74
|
rack_response(status, headers, format_message(message, backtrace, original_exception))
|
75
75
|
end
|
76
76
|
|
77
|
-
def default_rescue_handler(
|
78
|
-
error_response(message:
|
77
|
+
def default_rescue_handler(exception)
|
78
|
+
error_response(message: exception.message, backtrace: exception.backtrace, original_exception: exception)
|
79
79
|
end
|
80
80
|
|
81
81
|
def rescue_handler_for_base_only_class(klass)
|
@@ -21,6 +21,7 @@ module Grape
|
|
21
21
|
private
|
22
22
|
|
23
23
|
def do_each(params_to_process, parent_indicies = [], &block)
|
24
|
+
@scope.reset_index # gets updated depending on the size of params_to_process
|
24
25
|
params_to_process.each_with_index do |resource_params, index|
|
25
26
|
# when we get arrays of arrays it means that target element located inside array
|
26
27
|
# we need this because we want to know parent arrays indicies
|
@@ -93,9 +93,7 @@ module Grape
|
|
93
93
|
|
94
94
|
def meets_dependency?(params, request_params)
|
95
95
|
return true unless @dependent_on
|
96
|
-
|
97
96
|
return false if @parent.present? && !@parent.meets_dependency?(@parent.params(request_params), request_params)
|
98
|
-
|
99
97
|
return params.any? { |param| meets_dependency?(param, request_params) } if params.is_a?(Array)
|
100
98
|
|
101
99
|
meets_hash_dependency?(params)
|
@@ -103,7 +101,6 @@ module Grape
|
|
103
101
|
|
104
102
|
def attr_meets_dependency?(params)
|
105
103
|
return true unless @dependent_on
|
106
|
-
|
107
104
|
return false if @parent.present? && !@parent.attr_meets_dependency?(params)
|
108
105
|
|
109
106
|
meets_hash_dependency?(params)
|
@@ -169,6 +166,10 @@ module Grape
|
|
169
166
|
!@optional
|
170
167
|
end
|
171
168
|
|
169
|
+
def reset_index
|
170
|
+
@index = nil
|
171
|
+
end
|
172
|
+
|
172
173
|
protected
|
173
174
|
|
174
175
|
# Adds a parameter declaration to our list of validations.
|
@@ -189,7 +190,13 @@ module Grape
|
|
189
190
|
#
|
190
191
|
# @return [Array<Symbol>] the nesting/path of the current parameter scope
|
191
192
|
def full_path
|
192
|
-
nested?
|
193
|
+
if nested?
|
194
|
+
(@parent.full_path + [@element])
|
195
|
+
elsif lateral?
|
196
|
+
@parent.full_path
|
197
|
+
else
|
198
|
+
[]
|
199
|
+
end
|
193
200
|
end
|
194
201
|
|
195
202
|
private
|
@@ -297,12 +304,7 @@ module Grape
|
|
297
304
|
# `optional` invocation that opened this scope.
|
298
305
|
# @yield parameter scope
|
299
306
|
def new_group_scope(attrs, &block)
|
300
|
-
self.class.new(
|
301
|
-
api: @api,
|
302
|
-
parent: self,
|
303
|
-
group: attrs.first,
|
304
|
-
&block
|
305
|
-
)
|
307
|
+
self.class.new(api: @api, parent: self, group: attrs.first, &block)
|
306
308
|
end
|
307
309
|
|
308
310
|
# Pushes declared params to parent or settings
|
@@ -7,7 +7,7 @@ module Grape
|
|
7
7
|
def validate_params!(params)
|
8
8
|
keys = keys_in_common(params)
|
9
9
|
return if keys.length == 1
|
10
|
-
raise Grape::Exceptions::Validation.new(params: all_keys, message: message(:exactly_one)) if keys.
|
10
|
+
raise Grape::Exceptions::Validation.new(params: all_keys, message: message(:exactly_one)) if keys.empty?
|
11
11
|
|
12
12
|
raise Grape::Exceptions::Validation.new(params: keys, message: message(:mutual_exclusion))
|
13
13
|
end
|
data/lib/grape/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Bleigh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -189,7 +189,6 @@ files:
|
|
189
189
|
- lib/grape/serve_stream/sendfile_response.rb
|
190
190
|
- lib/grape/serve_stream/stream_response.rb
|
191
191
|
- lib/grape/types/invalid_value.rb
|
192
|
-
- lib/grape/util/accept/header.rb
|
193
192
|
- lib/grape/util/accept_header_handler.rb
|
194
193
|
- lib/grape/util/base_inheritable.rb
|
195
194
|
- lib/grape/util/cache.rb
|
@@ -252,9 +251,9 @@ licenses:
|
|
252
251
|
- MIT
|
253
252
|
metadata:
|
254
253
|
bug_tracker_uri: https://github.com/ruby-grape/grape/issues
|
255
|
-
changelog_uri: https://github.com/ruby-grape/grape/blob/v2.1.
|
256
|
-
documentation_uri: https://www.rubydoc.info/gems/grape/2.1.
|
257
|
-
source_code_uri: https://github.com/ruby-grape/grape/tree/v2.1.
|
254
|
+
changelog_uri: https://github.com/ruby-grape/grape/blob/v2.1.3/CHANGELOG.md
|
255
|
+
documentation_uri: https://www.rubydoc.info/gems/grape/2.1.3
|
256
|
+
source_code_uri: https://github.com/ruby-grape/grape/tree/v2.1.3
|
258
257
|
post_install_message:
|
259
258
|
rdoc_options: []
|
260
259
|
require_paths:
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Grape
|
4
|
-
module Util
|
5
|
-
module Accept
|
6
|
-
module Header
|
7
|
-
ALLOWED_CHARACTERS = %r{^([a-z*]+)/([a-z0-9*&\^\-_#{$ERROR_INFO}.+]+)(?:;([a-z0-9=;]+))?$}.freeze
|
8
|
-
class << self
|
9
|
-
# Corrected version of https://github.com/mjackson/rack-accept/blob/master/lib/rack/accept/header.rb#L40-L44
|
10
|
-
def parse_media_type(media_type)
|
11
|
-
# see http://tools.ietf.org/html/rfc6838#section-4.2 for allowed characters in media type names
|
12
|
-
m = media_type&.match(ALLOWED_CHARACTERS)
|
13
|
-
m ? [m[1], m[2], m[3] || ''] : []
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|