grape 1.7.1 → 1.8.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/CHANGELOG.md +22 -1
- data/CONTRIBUTING.md +1 -1
- data/README.md +12 -4
- data/grape.gemspec +2 -2
- data/lib/grape/api.rb +2 -2
- data/lib/grape/content_types.rb +2 -8
- data/lib/grape/dsl/desc.rb +1 -1
- data/lib/grape/dsl/inside_route.rb +5 -5
- data/lib/grape/dsl/request_response.rb +2 -1
- data/lib/grape/dsl/settings.rb +2 -6
- data/lib/grape/endpoint.rb +19 -17
- data/lib/grape/error_formatter/base.rb +1 -1
- data/lib/grape/exceptions/base.rb +2 -2
- data/lib/grape/exceptions/missing_group_type.rb +1 -6
- data/lib/grape/exceptions/unsupported_group_type.rb +1 -6
- data/lib/grape/exceptions/validation_errors.rb +1 -6
- data/lib/grape/extensions/active_support/hash_with_indifferent_access.rb +3 -3
- data/lib/grape/extensions/hash.rb +4 -7
- data/lib/grape/extensions/hashie/mash.rb +3 -3
- data/lib/grape/formatter/serializable_hash.rb +7 -7
- data/lib/grape/middleware/auth/base.rb +1 -1
- data/lib/grape/middleware/error.rb +1 -1
- data/lib/grape/middleware/formatter.rb +1 -1
- data/lib/grape/middleware/versioner/header.rb +11 -19
- data/lib/grape/router/route.rb +1 -3
- data/lib/grape/util/lazy_value.rb +3 -11
- data/lib/grape/util/strict_hash_configuration.rb +3 -4
- data/lib/grape/validations/multiple_attributes_iterator.rb +1 -1
- data/lib/grape/validations/params_scope.rb +8 -2
- data/lib/grape/validations/single_attribute_iterator.rb +3 -1
- data/lib/grape/validations/types/custom_type_coercer.rb +2 -16
- data/lib/grape/validations/validators/base.rb +9 -20
- data/lib/grape/validations/validators/default_validator.rb +2 -20
- data/lib/grape/validations/validators/multiple_params_base.rb +4 -8
- data/lib/grape/validations/validators/values_validator.rb +14 -5
- data/lib/grape/version.rb +1 -1
- data/lib/grape.rb +11 -3
- data/spec/grape/api/custom_validations_spec.rb +14 -57
- data/spec/grape/api_remount_spec.rb +36 -0
- data/spec/grape/api_spec.rb +10 -1
- data/spec/grape/dsl/desc_spec.rb +84 -87
- data/spec/grape/dsl/inside_route_spec.rb +6 -10
- data/spec/grape/dsl/request_response_spec.rb +21 -2
- data/spec/grape/endpoint_spec.rb +8 -8
- data/spec/grape/exceptions/body_parse_errors_spec.rb +40 -0
- data/spec/grape/exceptions/missing_group_type_spec.rb +5 -9
- data/spec/grape/exceptions/unsupported_group_type_spec.rb +5 -9
- data/spec/grape/grape_spec.rb +9 -0
- data/spec/grape/middleware/formatter_spec.rb +1 -1
- data/spec/grape/request_spec.rb +4 -14
- data/spec/grape/validations/multiple_attributes_iterator_spec.rb +6 -8
- data/spec/grape/validations/single_attribute_iterator_spec.rb +8 -9
- data/spec/grape/validations/validators/base_spec.rb +38 -0
- data/spec/grape/validations/validators/values_spec.rb +37 -0
- data/spec/grape/validations_spec.rb +7 -6
- data/spec/shared/deprecated_class_examples.rb +16 -0
- metadata +17 -22
- data/lib/grape/config.rb +0 -34
- data/lib/grape/extensions/deep_mergeable_hash.rb +0 -21
- data/lib/grape/extensions/deep_symbolize_hash.rb +0 -32
- data/spec/grape/config_spec.rb +0 -17
@@ -30,6 +30,10 @@ describe Grape::Validations::Validators::ValuesValidator do
|
|
30
30
|
def include?(value)
|
31
31
|
values.include?(value)
|
32
32
|
end
|
33
|
+
|
34
|
+
def even?(value)
|
35
|
+
value.to_i.even?
|
36
|
+
end
|
33
37
|
end
|
34
38
|
end
|
35
39
|
end
|
@@ -241,6 +245,18 @@ describe Grape::Validations::Validators::ValuesValidator do
|
|
241
245
|
end
|
242
246
|
get '/proc/message'
|
243
247
|
|
248
|
+
params do
|
249
|
+
requires :number, values: { value: ->(v) { ValuesModel.even? v }, message: 'must be even' }
|
250
|
+
end
|
251
|
+
get '/proc/custom_message' do
|
252
|
+
{ message: 'success' }
|
253
|
+
end
|
254
|
+
|
255
|
+
params do
|
256
|
+
requires :input_one, :input_two, values: { value: ->(v1, v2) { v1 + v2 > 10 } }
|
257
|
+
end
|
258
|
+
get '/proc/arity2'
|
259
|
+
|
244
260
|
params do
|
245
261
|
optional :name, type: String, values: %w[a b], allow_blank: true
|
246
262
|
end
|
@@ -692,5 +708,26 @@ describe Grape::Validations::Validators::ValuesValidator do
|
|
692
708
|
expect(last_response.status).to eq 400
|
693
709
|
expect(last_response.body).to eq({ error: 'type failed check' }.to_json)
|
694
710
|
end
|
711
|
+
|
712
|
+
context 'when proc has an arity of 1' do
|
713
|
+
it 'accepts a valid value' do
|
714
|
+
get '/proc/custom_message', number: 4
|
715
|
+
expect(last_response.status).to eq 200
|
716
|
+
expect(last_response.body).to eq({ message: 'success' }.to_json)
|
717
|
+
end
|
718
|
+
|
719
|
+
it 'rejects an invalid value' do
|
720
|
+
get '/proc/custom_message', number: 5
|
721
|
+
expect(last_response.status).to eq 400
|
722
|
+
expect(last_response.body).to eq({ error: 'number must be even' }.to_json)
|
723
|
+
end
|
724
|
+
end
|
725
|
+
|
726
|
+
context 'when arity is > 1' do
|
727
|
+
it 'returns an error status code' do
|
728
|
+
get '/proc/arity2', input_one: 2, input_two: 3
|
729
|
+
expect(last_response.status).to eq 400
|
730
|
+
end
|
731
|
+
end
|
695
732
|
end
|
696
733
|
end
|
@@ -179,11 +179,12 @@ describe Grape::Validations do
|
|
179
179
|
context 'requires :all using Grape::Entity documentation' do
|
180
180
|
def define_requires_all
|
181
181
|
documentation = {
|
182
|
-
required_field: { type: String },
|
183
|
-
optional_field: { type: String }
|
182
|
+
required_field: { type: String, required: true, param_type: 'query' },
|
183
|
+
optional_field: { type: String },
|
184
|
+
optional_array_field: { type: Array[String], is_array: true }
|
184
185
|
}
|
185
186
|
subject.params do
|
186
|
-
requires :all, except:
|
187
|
+
requires :all, except: %i[optional_field optional_array_field], using: documentation
|
187
188
|
end
|
188
189
|
end
|
189
190
|
before do
|
@@ -195,7 +196,7 @@ describe Grape::Validations do
|
|
195
196
|
|
196
197
|
it 'adds entity documentation to declared params' do
|
197
198
|
define_requires_all
|
198
|
-
expect(Grape::Validations::ParamsScope::Attr.attrs_keys(declared_params)).to eq(%i[required_field optional_field])
|
199
|
+
expect(Grape::Validations::ParamsScope::Attr.attrs_keys(declared_params)).to eq(%i[required_field optional_field optional_array_field])
|
199
200
|
end
|
200
201
|
|
201
202
|
it 'errors when required_field is not present' do
|
@@ -214,8 +215,8 @@ describe Grape::Validations do
|
|
214
215
|
context 'requires :none using Grape::Entity documentation' do
|
215
216
|
def define_requires_none
|
216
217
|
documentation = {
|
217
|
-
required_field: { type: String },
|
218
|
-
optional_field: { type:
|
218
|
+
required_field: { type: String, example: 'Foo' },
|
219
|
+
optional_field: { type: Integer, format: 'int64' }
|
219
220
|
}
|
220
221
|
subject.params do
|
221
222
|
requires :none, except: :required_field, using: documentation
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.shared_examples 'deprecated class' do
|
4
|
+
subject { deprecated_class.new }
|
5
|
+
|
6
|
+
around do |example|
|
7
|
+
old_deprec_behavior = ActiveSupport::Deprecation.behavior
|
8
|
+
ActiveSupport::Deprecation.behavior = :raise
|
9
|
+
example.run
|
10
|
+
ActiveSupport::Deprecation.behavior = old_deprec_behavior
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'raises an ActiveSupport::DeprecationException' do
|
14
|
+
expect { subject }.to raise_error(ActiveSupport::DeprecationException)
|
15
|
+
end
|
16
|
+
end
|
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: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Bleigh
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: builder
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,9 +73,6 @@ dependencies:
|
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: 1.3.0
|
76
|
-
- - "<"
|
77
|
-
- !ruby/object:Gem::Version
|
78
|
-
version: '3'
|
79
76
|
type: :runtime
|
80
77
|
prerelease: false
|
81
78
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -83,9 +80,6 @@ dependencies:
|
|
83
80
|
- - ">="
|
84
81
|
- !ruby/object:Gem::Version
|
85
82
|
version: 1.3.0
|
86
|
-
- - "<"
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
version: '3'
|
89
83
|
- !ruby/object:Gem::Dependency
|
90
84
|
name: rack-accept
|
91
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -118,7 +112,6 @@ files:
|
|
118
112
|
- lib/grape/api.rb
|
119
113
|
- lib/grape/api/helpers.rb
|
120
114
|
- lib/grape/api/instance.rb
|
121
|
-
- lib/grape/config.rb
|
122
115
|
- lib/grape/content_types.rb
|
123
116
|
- lib/grape/cookies.rb
|
124
117
|
- lib/grape/dry_types.rb
|
@@ -167,8 +160,6 @@ files:
|
|
167
160
|
- lib/grape/exceptions/validation_array_errors.rb
|
168
161
|
- lib/grape/exceptions/validation_errors.rb
|
169
162
|
- lib/grape/extensions/active_support/hash_with_indifferent_access.rb
|
170
|
-
- lib/grape/extensions/deep_mergeable_hash.rb
|
171
|
-
- lib/grape/extensions/deep_symbolize_hash.rb
|
172
163
|
- lib/grape/extensions/hash.rb
|
173
164
|
- lib/grape/extensions/hashie/mash.rb
|
174
165
|
- lib/grape/formatter.rb
|
@@ -281,7 +272,6 @@ files:
|
|
281
272
|
- spec/grape/api/shared_helpers_spec.rb
|
282
273
|
- spec/grape/api_remount_spec.rb
|
283
274
|
- spec/grape/api_spec.rb
|
284
|
-
- spec/grape/config_spec.rb
|
285
275
|
- spec/grape/dsl/callbacks_spec.rb
|
286
276
|
- spec/grape/dsl/desc_spec.rb
|
287
277
|
- spec/grape/dsl/headers_spec.rb
|
@@ -314,6 +304,7 @@ files:
|
|
314
304
|
- spec/grape/extensions/param_builders/hash_spec.rb
|
315
305
|
- spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb
|
316
306
|
- spec/grape/extensions/param_builders/hashie/mash_spec.rb
|
307
|
+
- spec/grape/grape_spec.rb
|
317
308
|
- spec/grape/integration/global_namespace_function_spec.rb
|
318
309
|
- spec/grape/integration/rack_sendfile_spec.rb
|
319
310
|
- spec/grape/integration/rack_spec.rb
|
@@ -354,6 +345,7 @@ files:
|
|
354
345
|
- spec/grape/validations/validators/all_or_none_spec.rb
|
355
346
|
- spec/grape/validations/validators/allow_blank_spec.rb
|
356
347
|
- spec/grape/validations/validators/at_least_one_of_spec.rb
|
348
|
+
- spec/grape/validations/validators/base_spec.rb
|
357
349
|
- spec/grape/validations/validators/coerce_spec.rb
|
358
350
|
- spec/grape/validations/validators/default_spec.rb
|
359
351
|
- spec/grape/validations/validators/exactly_one_of_spec.rb
|
@@ -368,6 +360,7 @@ files:
|
|
368
360
|
- spec/integration/eager_load/eager_load_spec.rb
|
369
361
|
- spec/integration/multi_json/json_spec.rb
|
370
362
|
- spec/integration/multi_xml/xml_spec.rb
|
363
|
+
- spec/shared/deprecated_class_examples.rb
|
371
364
|
- spec/shared/versioning_examples.rb
|
372
365
|
- spec/spec_helper.rb
|
373
366
|
- spec/support/basic_auth_encode_helpers.rb
|
@@ -382,10 +375,10 @@ licenses:
|
|
382
375
|
- MIT
|
383
376
|
metadata:
|
384
377
|
bug_tracker_uri: https://github.com/ruby-grape/grape/issues
|
385
|
-
changelog_uri: https://github.com/ruby-grape/grape/blob/v1.
|
386
|
-
documentation_uri: https://www.rubydoc.info/gems/grape/1.
|
387
|
-
source_code_uri: https://github.com/ruby-grape/grape/tree/v1.
|
388
|
-
post_install_message:
|
378
|
+
changelog_uri: https://github.com/ruby-grape/grape/blob/v1.8.0/CHANGELOG.md
|
379
|
+
documentation_uri: https://www.rubydoc.info/gems/grape/1.8.0
|
380
|
+
source_code_uri: https://github.com/ruby-grape/grape/tree/v1.8.0
|
381
|
+
post_install_message:
|
389
382
|
rdoc_options: []
|
390
383
|
require_paths:
|
391
384
|
- lib
|
@@ -400,8 +393,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
400
393
|
- !ruby/object:Gem::Version
|
401
394
|
version: '0'
|
402
395
|
requirements: []
|
403
|
-
rubygems_version: 3.
|
404
|
-
signing_key:
|
396
|
+
rubygems_version: 3.1.6
|
397
|
+
signing_key:
|
405
398
|
specification_version: 4
|
406
399
|
summary: A simple Ruby framework for building REST-like APIs.
|
407
400
|
test_files:
|
@@ -410,6 +403,7 @@ test_files:
|
|
410
403
|
- spec/integration/multi_xml/xml_spec.rb
|
411
404
|
- spec/integration/multi_json/json_spec.rb
|
412
405
|
- spec/shared/versioning_examples.rb
|
406
|
+
- spec/shared/deprecated_class_examples.rb
|
413
407
|
- spec/support/basic_auth_encode_helpers.rb
|
414
408
|
- spec/support/endpoint_faker.rb
|
415
409
|
- spec/support/chunks.rb
|
@@ -431,7 +425,6 @@ test_files:
|
|
431
425
|
- spec/grape/middleware/versioner/path_spec.rb
|
432
426
|
- spec/grape/middleware/versioner/param_spec.rb
|
433
427
|
- spec/grape/middleware/base_spec.rb
|
434
|
-
- spec/grape/config_spec.rb
|
435
428
|
- spec/grape/loading_spec.rb
|
436
429
|
- spec/grape/endpoint_spec.rb
|
437
430
|
- spec/grape/api_spec.rb
|
@@ -482,6 +475,7 @@ test_files:
|
|
482
475
|
- spec/grape/validations/validators/at_least_one_of_spec.rb
|
483
476
|
- spec/grape/validations/validators/coerce_spec.rb
|
484
477
|
- spec/grape/validations/validators/zh-CN.yml
|
478
|
+
- spec/grape/validations/validators/base_spec.rb
|
485
479
|
- spec/grape/extensions/param_builders/hashie/mash_spec.rb
|
486
480
|
- spec/grape/extensions/param_builders/hash_spec.rb
|
487
481
|
- spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb
|
@@ -506,6 +500,7 @@ test_files:
|
|
506
500
|
- spec/grape/api/custom_validations_spec.rb
|
507
501
|
- spec/grape/api/optional_parameters_in_route_spec.rb
|
508
502
|
- spec/grape/api/documentation_spec.rb
|
503
|
+
- spec/grape/grape_spec.rb
|
509
504
|
- spec/grape/api_remount_spec.rb
|
510
505
|
- spec/grape/named_api_spec.rb
|
511
506
|
- spec/grape/dsl/request_response_spec.rb
|
data/lib/grape/config.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Grape
|
4
|
-
module Config
|
5
|
-
class Configuration
|
6
|
-
ATTRIBUTES = %i[
|
7
|
-
param_builder
|
8
|
-
].freeze
|
9
|
-
|
10
|
-
attr_accessor(*ATTRIBUTES)
|
11
|
-
|
12
|
-
def initialize
|
13
|
-
reset
|
14
|
-
end
|
15
|
-
|
16
|
-
def reset
|
17
|
-
self.param_builder = Grape::Extensions::ActiveSupport::HashWithIndifferentAccess::ParamBuilder
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.extended(base)
|
22
|
-
def base.configure
|
23
|
-
block_given? ? yield(config) : config
|
24
|
-
end
|
25
|
-
|
26
|
-
def base.config
|
27
|
-
@configuration ||= Grape::Config::Configuration.new
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
Grape.extend Grape::Config
|
34
|
-
Grape.config.reset
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Grape
|
4
|
-
module Extensions
|
5
|
-
class DeepMergeableHash < ::Hash
|
6
|
-
def deep_merge!(other_hash)
|
7
|
-
other_hash.each_pair do |current_key, other_value|
|
8
|
-
this_value = self[current_key]
|
9
|
-
|
10
|
-
self[current_key] = if this_value.is_a?(::Hash) && other_value.is_a?(::Hash)
|
11
|
-
this_value.deep_merge(other_value)
|
12
|
-
else
|
13
|
-
other_value
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
self
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Grape
|
4
|
-
module Extensions
|
5
|
-
module DeepSymbolizeHash
|
6
|
-
def self.deep_symbolize_keys_in(object)
|
7
|
-
case object
|
8
|
-
when ::Hash
|
9
|
-
object.each_with_object({}) do |(key, value), new_hash|
|
10
|
-
new_hash[symbolize_key(key)] = deep_symbolize_keys_in(value)
|
11
|
-
end
|
12
|
-
when ::Array
|
13
|
-
object.map { |element| deep_symbolize_keys_in(element) }
|
14
|
-
else
|
15
|
-
object
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.symbolize_key(key)
|
20
|
-
if key.is_a?(Symbol)
|
21
|
-
key
|
22
|
-
elsif key.is_a?(String)
|
23
|
-
key.to_sym
|
24
|
-
elsif key.respond_to?(:to_sym)
|
25
|
-
key.to_sym
|
26
|
-
else
|
27
|
-
key
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
data/spec/grape/config_spec.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
describe '.configure' do
|
4
|
-
before do
|
5
|
-
Grape.configure do |config|
|
6
|
-
config.param_builder = 42
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
after do
|
11
|
-
Grape.config.reset
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'is configured to the new value' do
|
15
|
-
expect(Grape.config.param_builder).to eq 42
|
16
|
-
end
|
17
|
-
end
|