grape 2.4.0 → 3.0.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 +40 -0
- data/CONTRIBUTING.md +1 -9
- data/README.md +72 -31
- data/UPGRADING.md +34 -0
- data/grape.gemspec +4 -4
- data/lib/grape/api/instance.rb +49 -72
- data/lib/grape/api.rb +24 -34
- data/lib/grape/dry_types.rb +48 -4
- data/lib/grape/dsl/callbacks.rb +8 -58
- data/lib/grape/dsl/desc.rb +8 -67
- data/lib/grape/dsl/helpers.rb +59 -64
- data/lib/grape/dsl/inside_route.rb +20 -43
- data/lib/grape/dsl/logger.rb +3 -6
- data/lib/grape/dsl/middleware.rb +22 -40
- data/lib/grape/dsl/parameters.rb +7 -16
- data/lib/grape/dsl/request_response.rb +136 -139
- data/lib/grape/dsl/routing.rb +229 -201
- data/lib/grape/dsl/settings.rb +22 -134
- data/lib/grape/dsl/validations.rb +37 -45
- data/lib/grape/endpoint.rb +64 -96
- data/lib/grape/error_formatter/base.rb +2 -0
- data/lib/grape/exceptions/base.rb +1 -1
- data/lib/grape/exceptions/missing_group_type.rb +0 -2
- data/lib/grape/exceptions/unsupported_group_type.rb +0 -2
- data/lib/grape/middleware/auth/dsl.rb +5 -6
- data/lib/grape/middleware/error.rb +1 -11
- data/lib/grape/middleware/formatter.rb +4 -2
- data/lib/grape/middleware/stack.rb +2 -2
- data/lib/grape/middleware/versioner/accept_version_header.rb +1 -1
- data/lib/grape/middleware/versioner/base.rb +24 -42
- data/lib/grape/middleware/versioner/header.rb +1 -1
- data/lib/grape/middleware/versioner/param.rb +2 -2
- data/lib/grape/middleware/versioner/path.rb +1 -1
- data/lib/grape/namespace.rb +11 -0
- data/lib/grape/params_builder/base.rb +2 -0
- data/lib/grape/router.rb +4 -3
- data/lib/grape/util/api_description.rb +56 -0
- data/lib/grape/util/base_inheritable.rb +5 -2
- data/lib/grape/util/inheritable_setting.rb +7 -0
- data/lib/grape/util/media_type.rb +1 -1
- data/lib/grape/util/registry.rb +1 -1
- data/lib/grape/validations/contract_scope.rb +2 -2
- data/lib/grape/validations/params_documentation.rb +50 -0
- data/lib/grape/validations/params_scope.rb +38 -53
- data/lib/grape/validations/types/array_coercer.rb +2 -3
- data/lib/grape/validations/types/dry_type_coercer.rb +4 -11
- data/lib/grape/validations/types/primitive_coercer.rb +1 -28
- data/lib/grape/validations/types.rb +10 -25
- data/lib/grape/validations/validators/base.rb +0 -7
- data/lib/grape/version.rb +1 -1
- data/lib/grape.rb +7 -10
- metadata +24 -14
- data/lib/grape/api/helpers.rb +0 -9
- data/lib/grape/dsl/api.rb +0 -17
- data/lib/grape/dsl/configuration.rb +0 -15
- data/lib/grape/types/invalid_value.rb +0 -8
- data/lib/grape/util/strict_hash_configuration.rb +0 -108
- data/lib/grape/validations/attributes_doc.rb +0 -60
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: grape
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 3.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Michael Bleigh
|
|
@@ -15,14 +15,28 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: '
|
|
18
|
+
version: '7.0'
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: '
|
|
25
|
+
version: '7.0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: dry-configurable
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
26
40
|
- !ruby/object:Gem::Dependency
|
|
27
41
|
name: dry-types
|
|
28
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -95,14 +109,11 @@ files:
|
|
|
95
109
|
- grape.png
|
|
96
110
|
- lib/grape.rb
|
|
97
111
|
- lib/grape/api.rb
|
|
98
|
-
- lib/grape/api/helpers.rb
|
|
99
112
|
- lib/grape/api/instance.rb
|
|
100
113
|
- lib/grape/content_types.rb
|
|
101
114
|
- lib/grape/cookies.rb
|
|
102
115
|
- lib/grape/dry_types.rb
|
|
103
|
-
- lib/grape/dsl/api.rb
|
|
104
116
|
- lib/grape/dsl/callbacks.rb
|
|
105
|
-
- lib/grape/dsl/configuration.rb
|
|
106
117
|
- lib/grape/dsl/desc.rb
|
|
107
118
|
- lib/grape/dsl/headers.rb
|
|
108
119
|
- lib/grape/dsl/helpers.rb
|
|
@@ -199,7 +210,7 @@ files:
|
|
|
199
210
|
- lib/grape/serve_stream/file_body.rb
|
|
200
211
|
- lib/grape/serve_stream/sendfile_response.rb
|
|
201
212
|
- lib/grape/serve_stream/stream_response.rb
|
|
202
|
-
- lib/grape/
|
|
213
|
+
- lib/grape/util/api_description.rb
|
|
203
214
|
- lib/grape/util/base_inheritable.rb
|
|
204
215
|
- lib/grape/util/cache.rb
|
|
205
216
|
- lib/grape/util/endpoint_configuration.rb
|
|
@@ -215,12 +226,11 @@ files:
|
|
|
215
226
|
- lib/grape/util/registry.rb
|
|
216
227
|
- lib/grape/util/reverse_stackable_values.rb
|
|
217
228
|
- lib/grape/util/stackable_values.rb
|
|
218
|
-
- lib/grape/util/strict_hash_configuration.rb
|
|
219
229
|
- lib/grape/validations.rb
|
|
220
|
-
- lib/grape/validations/attributes_doc.rb
|
|
221
230
|
- lib/grape/validations/attributes_iterator.rb
|
|
222
231
|
- lib/grape/validations/contract_scope.rb
|
|
223
232
|
- lib/grape/validations/multiple_attributes_iterator.rb
|
|
233
|
+
- lib/grape/validations/params_documentation.rb
|
|
224
234
|
- lib/grape/validations/params_scope.rb
|
|
225
235
|
- lib/grape/validations/single_attribute_iterator.rb
|
|
226
236
|
- lib/grape/validations/types.rb
|
|
@@ -260,9 +270,9 @@ licenses:
|
|
|
260
270
|
- MIT
|
|
261
271
|
metadata:
|
|
262
272
|
bug_tracker_uri: https://github.com/ruby-grape/grape/issues
|
|
263
|
-
changelog_uri: https://github.com/ruby-grape/grape/blob/
|
|
264
|
-
documentation_uri: https://www.rubydoc.info/gems/grape/
|
|
265
|
-
source_code_uri: https://github.com/ruby-grape/grape/tree/
|
|
273
|
+
changelog_uri: https://github.com/ruby-grape/grape/blob/v3.0.0/CHANGELOG.md
|
|
274
|
+
documentation_uri: https://www.rubydoc.info/gems/grape/3.0.0
|
|
275
|
+
source_code_uri: https://github.com/ruby-grape/grape/tree/v3.0.0
|
|
266
276
|
rubygems_mfa_required: 'true'
|
|
267
277
|
rdoc_options: []
|
|
268
278
|
require_paths:
|
|
@@ -271,14 +281,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
271
281
|
requirements:
|
|
272
282
|
- - ">="
|
|
273
283
|
- !ruby/object:Gem::Version
|
|
274
|
-
version:
|
|
284
|
+
version: '3.0'
|
|
275
285
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
276
286
|
requirements:
|
|
277
287
|
- - ">="
|
|
278
288
|
- !ruby/object:Gem::Version
|
|
279
289
|
version: '0'
|
|
280
290
|
requirements: []
|
|
281
|
-
rubygems_version: 3.
|
|
291
|
+
rubygems_version: 3.7.1
|
|
282
292
|
specification_version: 4
|
|
283
293
|
summary: A simple Ruby framework for building REST-like APIs.
|
|
284
294
|
test_files: []
|
data/lib/grape/api/helpers.rb
DELETED
data/lib/grape/dsl/api.rb
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Grape
|
|
4
|
-
module DSL
|
|
5
|
-
module API
|
|
6
|
-
extend ActiveSupport::Concern
|
|
7
|
-
|
|
8
|
-
include Grape::DSL::Validations
|
|
9
|
-
include Grape::DSL::Callbacks
|
|
10
|
-
include Grape::DSL::Configuration
|
|
11
|
-
include Grape::DSL::Helpers
|
|
12
|
-
include Grape::DSL::Middleware
|
|
13
|
-
include Grape::DSL::RequestResponse
|
|
14
|
-
include Grape::DSL::Routing
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Grape
|
|
4
|
-
module DSL
|
|
5
|
-
module Configuration
|
|
6
|
-
extend ActiveSupport::Concern
|
|
7
|
-
|
|
8
|
-
module ClassMethods
|
|
9
|
-
include Grape::DSL::Settings
|
|
10
|
-
include Grape::DSL::Logger
|
|
11
|
-
include Grape::DSL::Desc
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Grape
|
|
4
|
-
module Util
|
|
5
|
-
module StrictHashConfiguration
|
|
6
|
-
extend ActiveSupport::Concern
|
|
7
|
-
|
|
8
|
-
module DSL
|
|
9
|
-
extend ActiveSupport::Concern
|
|
10
|
-
|
|
11
|
-
module ClassMethods
|
|
12
|
-
def settings
|
|
13
|
-
config_context.to_hash
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def configure(&block)
|
|
17
|
-
config_context.instance_exec(&block)
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
class SettingsContainer
|
|
23
|
-
def initialize
|
|
24
|
-
@settings = {}
|
|
25
|
-
@contexts = {}
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def to_hash
|
|
29
|
-
@settings.to_hash
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def self.config_class(*args)
|
|
34
|
-
new_config_class = Class.new(SettingsContainer)
|
|
35
|
-
|
|
36
|
-
args.each do |setting_name|
|
|
37
|
-
if setting_name.respond_to? :values
|
|
38
|
-
nested_settings_methods(setting_name, new_config_class)
|
|
39
|
-
else
|
|
40
|
-
simple_settings_methods(setting_name, new_config_class)
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
new_config_class
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def self.simple_settings_methods(setting_name, new_config_class)
|
|
48
|
-
setting_name_sym = setting_name.to_sym
|
|
49
|
-
new_config_class.class_eval do
|
|
50
|
-
define_method setting_name do |new_value|
|
|
51
|
-
@settings[setting_name_sym] = new_value
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def self.nested_settings_methods(setting_name, new_config_class)
|
|
57
|
-
new_config_class.class_eval do
|
|
58
|
-
setting_name.each_pair do |key, value|
|
|
59
|
-
define_method :"#{key}_context" do
|
|
60
|
-
@contexts[key] ||= Grape::Util::StrictHashConfiguration.config_class(*value).new
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
define_method key do |&block|
|
|
64
|
-
send(:"#{key}_context").instance_exec(&block)
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
define_method :to_hash do
|
|
69
|
-
@settings.to_hash.merge(
|
|
70
|
-
setting_name.each_key.with_object({}) do |k, merge_hash|
|
|
71
|
-
merge_hash[k] = send(:"#{k}_context").to_hash
|
|
72
|
-
end
|
|
73
|
-
)
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def self.module(*args)
|
|
79
|
-
new_module = Module.new do
|
|
80
|
-
extend ActiveSupport::Concern
|
|
81
|
-
include DSL
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
new_module.tap do |mod|
|
|
85
|
-
class_mod = create_class_mod(args)
|
|
86
|
-
|
|
87
|
-
mod.const_set(:ClassMethods, class_mod)
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
def self.create_class_mod(args)
|
|
92
|
-
new_module = Module.new do
|
|
93
|
-
def config_context
|
|
94
|
-
@config_context ||= config_class.new
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
new_module.tap do |class_mod|
|
|
99
|
-
new_config_class = config_class(*args)
|
|
100
|
-
|
|
101
|
-
class_mod.send(:define_method, :config_class) do
|
|
102
|
-
@config_class ||= new_config_class
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
end
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Grape
|
|
4
|
-
module Validations
|
|
5
|
-
# Documents parameters of an endpoint. If documentation isn't needed (for instance, it is an
|
|
6
|
-
# internal API), the class only cleans up attributes to avoid junk in RAM.
|
|
7
|
-
|
|
8
|
-
class AttributesDoc
|
|
9
|
-
attr_accessor :type, :values
|
|
10
|
-
|
|
11
|
-
# @param api [Grape::API::Instance]
|
|
12
|
-
# @param scope [Validations::ParamsScope]
|
|
13
|
-
def initialize(api, scope)
|
|
14
|
-
@api = api
|
|
15
|
-
@scope = scope
|
|
16
|
-
@type = type
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def extract_details(validations)
|
|
20
|
-
details[:required] = validations.key?(:presence)
|
|
21
|
-
|
|
22
|
-
desc = validations.delete(:desc) || validations.delete(:description)
|
|
23
|
-
|
|
24
|
-
details[:desc] = desc if desc
|
|
25
|
-
|
|
26
|
-
documentation = validations.delete(:documentation)
|
|
27
|
-
|
|
28
|
-
details[:documentation] = documentation if documentation
|
|
29
|
-
|
|
30
|
-
details[:default] = validations[:default] if validations.key?(:default)
|
|
31
|
-
|
|
32
|
-
details[:min_length] = validations[:length][:min] if validations.key?(:length) && validations[:length].key?(:min)
|
|
33
|
-
details[:max_length] = validations[:length][:max] if validations.key?(:length) && validations[:length].key?(:max)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def document(attrs)
|
|
37
|
-
return if @api.namespace_inheritable(:do_not_document)
|
|
38
|
-
|
|
39
|
-
details[:type] = type.to_s if type
|
|
40
|
-
details[:values] = values if values
|
|
41
|
-
|
|
42
|
-
documented_attrs = attrs.each_with_object({}) do |name, memo|
|
|
43
|
-
memo[@scope.full_name(name)] = details
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
@api.namespace_stackable(:params, documented_attrs)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def required
|
|
50
|
-
details[:required]
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
protected
|
|
54
|
-
|
|
55
|
-
def details
|
|
56
|
-
@details ||= {}
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|