grape 1.7.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +37 -1
- data/CONTRIBUTING.md +1 -1
- data/README.md +30 -25
- data/UPGRADING.md +35 -0
- data/grape.gemspec +3 -6
- 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 +11 -11
- data/lib/grape/dsl/request_response.rb +2 -1
- data/lib/grape/dsl/settings.rb +2 -6
- data/lib/grape/endpoint.rb +28 -18
- 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/http/headers.rb +12 -2
- data/lib/grape/middleware/auth/base.rb +1 -1
- data/lib/grape/middleware/auth/strategies.rb +1 -2
- data/lib/grape/middleware/error.rb +5 -5
- data/lib/grape/middleware/formatter.rb +6 -6
- data/lib/grape/middleware/versioner/header.rb +11 -19
- data/lib/grape/railtie.rb +9 -0
- data/lib/grape/request.rb +8 -2
- 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 +26 -5
- metadata +13 -253
- 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/api/custom_validations_spec.rb +0 -256
- data/spec/grape/api/deeply_included_options_spec.rb +0 -56
- data/spec/grape/api/defines_boolean_in_params_spec.rb +0 -38
- data/spec/grape/api/documentation_spec.rb +0 -59
- data/spec/grape/api/inherited_helpers_spec.rb +0 -114
- data/spec/grape/api/instance_spec.rb +0 -103
- data/spec/grape/api/invalid_format_spec.rb +0 -45
- data/spec/grape/api/namespace_parameters_in_route_spec.rb +0 -38
- data/spec/grape/api/nested_helpers_spec.rb +0 -50
- data/spec/grape/api/optional_parameters_in_route_spec.rb +0 -43
- data/spec/grape/api/parameters_modification_spec.rb +0 -41
- data/spec/grape/api/patch_method_helpers_spec.rb +0 -79
- data/spec/grape/api/recognize_path_spec.rb +0 -21
- data/spec/grape/api/required_parameters_in_route_spec.rb +0 -37
- data/spec/grape/api/required_parameters_with_invalid_method_spec.rb +0 -26
- data/spec/grape/api/routes_with_requirements_spec.rb +0 -59
- data/spec/grape/api/shared_helpers_exactly_one_of_spec.rb +0 -41
- data/spec/grape/api/shared_helpers_spec.rb +0 -36
- data/spec/grape/api_remount_spec.rb +0 -473
- data/spec/grape/api_spec.rb +0 -4347
- data/spec/grape/config_spec.rb +0 -17
- data/spec/grape/dsl/callbacks_spec.rb +0 -45
- data/spec/grape/dsl/desc_spec.rb +0 -101
- data/spec/grape/dsl/headers_spec.rb +0 -62
- data/spec/grape/dsl/helpers_spec.rb +0 -100
- data/spec/grape/dsl/inside_route_spec.rb +0 -535
- data/spec/grape/dsl/logger_spec.rb +0 -24
- data/spec/grape/dsl/middleware_spec.rb +0 -60
- data/spec/grape/dsl/parameters_spec.rb +0 -180
- data/spec/grape/dsl/request_response_spec.rb +0 -206
- data/spec/grape/dsl/routing_spec.rb +0 -275
- data/spec/grape/dsl/settings_spec.rb +0 -261
- data/spec/grape/dsl/validations_spec.rb +0 -55
- data/spec/grape/endpoint/declared_spec.rb +0 -846
- data/spec/grape/endpoint_spec.rb +0 -1085
- data/spec/grape/entity_spec.rb +0 -336
- data/spec/grape/exceptions/base_spec.rb +0 -81
- data/spec/grape/exceptions/body_parse_errors_spec.rb +0 -145
- data/spec/grape/exceptions/invalid_accept_header_spec.rb +0 -358
- data/spec/grape/exceptions/invalid_formatter_spec.rb +0 -15
- data/spec/grape/exceptions/invalid_response_spec.rb +0 -11
- data/spec/grape/exceptions/invalid_versioner_option_spec.rb +0 -15
- data/spec/grape/exceptions/missing_group_type_spec.rb +0 -21
- data/spec/grape/exceptions/missing_mime_type_spec.rb +0 -17
- data/spec/grape/exceptions/missing_option_spec.rb +0 -15
- data/spec/grape/exceptions/unknown_options_spec.rb +0 -15
- data/spec/grape/exceptions/unknown_validator_spec.rb +0 -15
- data/spec/grape/exceptions/unsupported_group_type_spec.rb +0 -23
- data/spec/grape/exceptions/validation_errors_spec.rb +0 -92
- data/spec/grape/exceptions/validation_spec.rb +0 -19
- data/spec/grape/extensions/param_builders/hash_spec.rb +0 -83
- data/spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb +0 -105
- data/spec/grape/extensions/param_builders/hashie/mash_spec.rb +0 -79
- data/spec/grape/integration/global_namespace_function_spec.rb +0 -29
- data/spec/grape/integration/rack_sendfile_spec.rb +0 -48
- data/spec/grape/integration/rack_spec.rb +0 -51
- data/spec/grape/loading_spec.rb +0 -44
- data/spec/grape/middleware/auth/base_spec.rb +0 -31
- data/spec/grape/middleware/auth/dsl_spec.rb +0 -60
- data/spec/grape/middleware/auth/strategies_spec.rb +0 -120
- data/spec/grape/middleware/base_spec.rb +0 -221
- data/spec/grape/middleware/error_spec.rb +0 -85
- data/spec/grape/middleware/exception_spec.rb +0 -294
- data/spec/grape/middleware/formatter_spec.rb +0 -461
- data/spec/grape/middleware/globals_spec.rb +0 -30
- data/spec/grape/middleware/stack_spec.rb +0 -155
- data/spec/grape/middleware/versioner/accept_version_header_spec.rb +0 -122
- data/spec/grape/middleware/versioner/header_spec.rb +0 -345
- data/spec/grape/middleware/versioner/param_spec.rb +0 -171
- data/spec/grape/middleware/versioner/path_spec.rb +0 -62
- data/spec/grape/middleware/versioner_spec.rb +0 -21
- data/spec/grape/named_api_spec.rb +0 -19
- data/spec/grape/parser_spec.rb +0 -86
- data/spec/grape/path_spec.rb +0 -252
- data/spec/grape/presenters/presenter_spec.rb +0 -71
- data/spec/grape/request_spec.rb +0 -136
- data/spec/grape/util/inheritable_setting_spec.rb +0 -242
- data/spec/grape/util/inheritable_values_spec.rb +0 -79
- data/spec/grape/util/reverse_stackable_values_spec.rb +0 -134
- data/spec/grape/util/stackable_values_spec.rb +0 -128
- data/spec/grape/util/strict_hash_configuration_spec.rb +0 -38
- data/spec/grape/validations/attributes_doc_spec.rb +0 -153
- data/spec/grape/validations/instance_behaivour_spec.rb +0 -43
- data/spec/grape/validations/multiple_attributes_iterator_spec.rb +0 -40
- data/spec/grape/validations/params_scope_spec.rb +0 -1420
- data/spec/grape/validations/single_attribute_iterator_spec.rb +0 -57
- data/spec/grape/validations/types/array_coercer_spec.rb +0 -33
- data/spec/grape/validations/types/primitive_coercer_spec.rb +0 -150
- data/spec/grape/validations/types/set_coercer_spec.rb +0 -32
- data/spec/grape/validations/types_spec.rb +0 -111
- data/spec/grape/validations/validators/all_or_none_spec.rb +0 -162
- data/spec/grape/validations/validators/allow_blank_spec.rb +0 -575
- data/spec/grape/validations/validators/at_least_one_of_spec.rb +0 -205
- data/spec/grape/validations/validators/coerce_spec.rb +0 -1261
- data/spec/grape/validations/validators/default_spec.rb +0 -463
- data/spec/grape/validations/validators/exactly_one_of_spec.rb +0 -233
- data/spec/grape/validations/validators/except_values_spec.rb +0 -192
- data/spec/grape/validations/validators/mutual_exclusion_spec.rb +0 -214
- data/spec/grape/validations/validators/presence_spec.rb +0 -315
- data/spec/grape/validations/validators/regexp_spec.rb +0 -161
- data/spec/grape/validations/validators/same_as_spec.rb +0 -57
- data/spec/grape/validations/validators/values_spec.rb +0 -696
- data/spec/grape/validations/validators/zh-CN.yml +0 -10
- data/spec/grape/validations_spec.rb +0 -2029
- data/spec/integration/eager_load/eager_load_spec.rb +0 -15
- data/spec/integration/multi_json/json_spec.rb +0 -7
- data/spec/integration/multi_xml/xml_spec.rb +0 -7
- data/spec/shared/versioning_examples.rb +0 -215
- data/spec/spec_helper.rb +0 -52
- data/spec/support/basic_auth_encode_helpers.rb +0 -11
- data/spec/support/chunks.rb +0 -14
- data/spec/support/content_type_helpers.rb +0 -15
- data/spec/support/endpoint_faker.rb +0 -25
- data/spec/support/file_streamer.rb +0 -13
- data/spec/support/integer_helpers.rb +0 -13
- data/spec/support/versioned_helpers.rb +0 -55
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
4
|
-
require 'grape'
|
5
|
-
|
6
|
-
describe Grape do
|
7
|
-
it 'eager_load!' do
|
8
|
-
require 'grape/eager_load'
|
9
|
-
expect { described_class.eager_load! }.not_to raise_error
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'compile!' do
|
13
|
-
expect { Class.new(Grape::API).compile! }.not_to raise_error
|
14
|
-
end
|
15
|
-
end
|
@@ -1,215 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
shared_examples_for 'versioning' do
|
4
|
-
it 'sets the API version' do
|
5
|
-
subject.format :txt
|
6
|
-
subject.version 'v1', macro_options
|
7
|
-
subject.get :hello do
|
8
|
-
"Version: #{request.env['api.version']}"
|
9
|
-
end
|
10
|
-
versioned_get '/hello', 'v1', **macro_options
|
11
|
-
expect(last_response.body).to eql 'Version: v1'
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'adds the prefix before the API version' do
|
15
|
-
subject.format :txt
|
16
|
-
subject.prefix 'api'
|
17
|
-
subject.version 'v1', macro_options
|
18
|
-
subject.get :hello do
|
19
|
-
"Version: #{request.env['api.version']}"
|
20
|
-
end
|
21
|
-
versioned_get '/hello', 'v1', **macro_options.merge(prefix: 'api')
|
22
|
-
expect(last_response.body).to eql 'Version: v1'
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'is able to specify version as a nesting' do
|
26
|
-
subject.version 'v2', macro_options
|
27
|
-
subject.get '/awesome' do
|
28
|
-
'Radical'
|
29
|
-
end
|
30
|
-
|
31
|
-
subject.version 'v1', macro_options do
|
32
|
-
get '/legacy' do
|
33
|
-
'Totally'
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
versioned_get '/awesome', 'v1', **macro_options
|
38
|
-
expect(last_response.status).to be 404
|
39
|
-
|
40
|
-
versioned_get '/awesome', 'v2', **macro_options
|
41
|
-
expect(last_response.status).to be 200
|
42
|
-
versioned_get '/legacy', 'v1', **macro_options
|
43
|
-
expect(last_response.status).to be 200
|
44
|
-
versioned_get '/legacy', 'v2', **macro_options
|
45
|
-
expect(last_response.status).to be 404
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'is able to specify multiple versions' do
|
49
|
-
subject.version 'v1', 'v2', macro_options
|
50
|
-
subject.get 'awesome' do
|
51
|
-
'I exist'
|
52
|
-
end
|
53
|
-
|
54
|
-
versioned_get '/awesome', 'v1', **macro_options
|
55
|
-
expect(last_response.status).to be 200
|
56
|
-
versioned_get '/awesome', 'v2', **macro_options
|
57
|
-
expect(last_response.status).to be 200
|
58
|
-
versioned_get '/awesome', 'v3', **macro_options
|
59
|
-
expect(last_response.status).to be 404
|
60
|
-
end
|
61
|
-
|
62
|
-
context 'with different versions for the same endpoint' do
|
63
|
-
context 'without a prefix' do
|
64
|
-
it 'allows the same endpoint to be implemented' do
|
65
|
-
subject.format :txt
|
66
|
-
subject.version 'v2', macro_options
|
67
|
-
subject.get 'version' do
|
68
|
-
request.env['api.version']
|
69
|
-
end
|
70
|
-
|
71
|
-
subject.version 'v1', macro_options do
|
72
|
-
get 'version' do
|
73
|
-
"version #{request.env['api.version']}"
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
versioned_get '/version', 'v2', **macro_options
|
78
|
-
expect(last_response.status).to eq(200)
|
79
|
-
expect(last_response.body).to eq('v2')
|
80
|
-
versioned_get '/version', 'v1', **macro_options
|
81
|
-
expect(last_response.status).to eq(200)
|
82
|
-
expect(last_response.body).to eq('version v1')
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
context 'with a prefix' do
|
87
|
-
it 'allows the same endpoint to be implemented' do
|
88
|
-
subject.format :txt
|
89
|
-
subject.prefix 'api'
|
90
|
-
subject.version 'v2', macro_options
|
91
|
-
subject.get 'version' do
|
92
|
-
request.env['api.version']
|
93
|
-
end
|
94
|
-
|
95
|
-
subject.version 'v1', macro_options do
|
96
|
-
get 'version' do
|
97
|
-
"version #{request.env['api.version']}"
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
versioned_get '/version', 'v1', **macro_options.merge(prefix: subject.prefix)
|
102
|
-
expect(last_response.status).to eq(200)
|
103
|
-
expect(last_response.body).to eq('version v1')
|
104
|
-
|
105
|
-
versioned_get '/version', 'v2', **macro_options.merge(prefix: subject.prefix)
|
106
|
-
expect(last_response.status).to eq(200)
|
107
|
-
expect(last_response.body).to eq('v2')
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
context 'with before block defined within a version block' do
|
113
|
-
it 'calls before block that is defined within the version block' do
|
114
|
-
subject.format :txt
|
115
|
-
subject.prefix 'api'
|
116
|
-
subject.version 'v2', macro_options do
|
117
|
-
before do
|
118
|
-
@output ||= 'v2-'
|
119
|
-
end
|
120
|
-
|
121
|
-
get 'version' do
|
122
|
-
@output += 'version'
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
subject.version 'v1', macro_options do
|
127
|
-
before do
|
128
|
-
@output ||= 'v1-'
|
129
|
-
end
|
130
|
-
|
131
|
-
get 'version' do
|
132
|
-
@output += 'version'
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
versioned_get '/version', 'v1', **macro_options.merge(prefix: subject.prefix)
|
137
|
-
expect(last_response.status).to eq(200)
|
138
|
-
expect(last_response.body).to eq('v1-version')
|
139
|
-
|
140
|
-
versioned_get '/version', 'v2', **macro_options.merge(prefix: subject.prefix)
|
141
|
-
expect(last_response.status).to eq(200)
|
142
|
-
expect(last_response.body).to eq('v2-version')
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
it 'does not overwrite version parameter with API version' do
|
147
|
-
subject.format :txt
|
148
|
-
subject.version 'v1', macro_options
|
149
|
-
subject.params { requires :version }
|
150
|
-
subject.get :api_version_with_version_param do
|
151
|
-
params[:version]
|
152
|
-
end
|
153
|
-
versioned_get '/api_version_with_version_param?version=1', 'v1', **macro_options
|
154
|
-
expect(last_response.body).to eql '1'
|
155
|
-
end
|
156
|
-
|
157
|
-
context 'with catch-all' do
|
158
|
-
let(:options) { macro_options }
|
159
|
-
let(:v1) do
|
160
|
-
klass = Class.new(Grape::API)
|
161
|
-
klass.version 'v1', options
|
162
|
-
klass.get 'version' do
|
163
|
-
'v1'
|
164
|
-
end
|
165
|
-
klass
|
166
|
-
end
|
167
|
-
let(:v2) do
|
168
|
-
klass = Class.new(Grape::API)
|
169
|
-
klass.version 'v2', options
|
170
|
-
klass.get 'version' do
|
171
|
-
'v2'
|
172
|
-
end
|
173
|
-
klass
|
174
|
-
end
|
175
|
-
|
176
|
-
before do
|
177
|
-
subject.format :txt
|
178
|
-
|
179
|
-
subject.mount v1
|
180
|
-
subject.mount v2
|
181
|
-
|
182
|
-
subject.route :any, '*path' do
|
183
|
-
params[:path]
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
context 'v1' do
|
188
|
-
it 'finds endpoint' do
|
189
|
-
versioned_get '/version', 'v1', **macro_options
|
190
|
-
expect(last_response.status).to eq(200)
|
191
|
-
expect(last_response.body).to eq('v1')
|
192
|
-
end
|
193
|
-
|
194
|
-
it 'finds catch all' do
|
195
|
-
versioned_get '/whatever', 'v1', **macro_options
|
196
|
-
expect(last_response.status).to eq(200)
|
197
|
-
expect(last_response.body).to end_with 'whatever'
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
context 'v2' do
|
202
|
-
it 'finds endpoint' do
|
203
|
-
versioned_get '/version', 'v2', **macro_options
|
204
|
-
expect(last_response.status).to eq(200)
|
205
|
-
expect(last_response.body).to eq('v2')
|
206
|
-
end
|
207
|
-
|
208
|
-
it 'finds catch all' do
|
209
|
-
versioned_get '/whatever', 'v2', **macro_options
|
210
|
-
expect(last_response.status).to eq(200)
|
211
|
-
expect(last_response.body).to end_with 'whatever'
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
215
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
4
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
5
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'support'))
|
6
|
-
|
7
|
-
require 'grape'
|
8
|
-
require 'test_prof/recipes/rspec/let_it_be'
|
9
|
-
|
10
|
-
class NullAdapter
|
11
|
-
def begin_transaction; end
|
12
|
-
|
13
|
-
def rollback_transaction; end
|
14
|
-
end
|
15
|
-
|
16
|
-
TestProf::BeforeAll.adapter = NullAdapter.new
|
17
|
-
|
18
|
-
require 'rubygems'
|
19
|
-
require 'bundler'
|
20
|
-
Bundler.require :default, :test
|
21
|
-
|
22
|
-
Dir["#{File.dirname(__FILE__)}/support/*.rb"].sort.each do |file|
|
23
|
-
require file
|
24
|
-
end
|
25
|
-
|
26
|
-
# The default value for this setting is true in a standard Rails app,
|
27
|
-
# so it should be set to true here as well to reflect that.
|
28
|
-
I18n.enforce_available_locales = true
|
29
|
-
|
30
|
-
RSpec.configure do |config|
|
31
|
-
config.include Rack::Test::Methods
|
32
|
-
config.include Spec::Support::Helpers
|
33
|
-
config.raise_errors_for_deprecations!
|
34
|
-
config.filter_run_when_matching :focus
|
35
|
-
config.warnings = true
|
36
|
-
|
37
|
-
config.before(:all) { Grape::Util::InheritableSetting.reset_global! }
|
38
|
-
config.before { Grape::Util::InheritableSetting.reset_global! }
|
39
|
-
|
40
|
-
# Enable flags like --only-failures and --next-failure
|
41
|
-
config.example_status_persistence_file_path = '.rspec_status'
|
42
|
-
end
|
43
|
-
|
44
|
-
require 'simplecov'
|
45
|
-
require 'simplecov-lcov'
|
46
|
-
SimpleCov::Formatter::LcovFormatter.config do |c|
|
47
|
-
c.report_with_single_file = true
|
48
|
-
c.single_report_path = 'coverage/lcov.info'
|
49
|
-
end
|
50
|
-
|
51
|
-
SimpleCov.formatter = SimpleCov::Formatter::LcovFormatter
|
52
|
-
SimpleCov.start
|
data/spec/support/chunks.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Spec
|
4
|
-
module Support
|
5
|
-
module Helpers
|
6
|
-
%w[put patch post delete].each do |method|
|
7
|
-
define_method :"#{method}_with_json" do |uri, params = {}, env = {}, &block|
|
8
|
-
params = params.to_json
|
9
|
-
env['CONTENT_TYPE'] ||= 'application/json'
|
10
|
-
send(method, uri, params, env, &block)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Spec
|
4
|
-
module Support
|
5
|
-
class EndpointFaker
|
6
|
-
class FakerAPI < Grape::API
|
7
|
-
get '/' do
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def initialize(app, endpoint = FakerAPI.endpoints.first)
|
12
|
-
@app = app
|
13
|
-
@endpoint = endpoint
|
14
|
-
end
|
15
|
-
|
16
|
-
def call(env)
|
17
|
-
@endpoint.instance_exec do
|
18
|
-
@request = Grape::Request.new(env.dup)
|
19
|
-
end
|
20
|
-
|
21
|
-
@app.call(env.merge('api.endpoint' => @endpoint))
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Versioning
|
4
|
-
module Spec
|
5
|
-
module Support
|
6
|
-
module Helpers
|
7
|
-
# Returns the path with options[:version] prefixed if options[:using] is :path.
|
8
|
-
# Returns normal path otherwise.
|
9
|
-
def versioned_path(**options)
|
10
|
-
case options[:using]
|
11
|
-
when :path
|
12
|
-
File.join('/', options[:prefix] || '', options[:version], options[:path])
|
13
|
-
when :param
|
14
|
-
File.join('/', options[:prefix] || '', options[:path])
|
15
|
-
when :header
|
16
|
-
File.join('/', options[:prefix] || '', options[:path])
|
17
|
-
when :accept_version_header
|
18
|
-
File.join('/', options[:prefix] || '', options[:path])
|
19
|
-
else
|
20
|
-
raise ArgumentError.new("unknown versioning strategy: #{options[:using]}")
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def versioned_headers(**options)
|
25
|
-
case options[:using]
|
26
|
-
when :path
|
27
|
-
{} # no-op
|
28
|
-
when :param
|
29
|
-
{} # no-op
|
30
|
-
when :header
|
31
|
-
{
|
32
|
-
'HTTP_ACCEPT' => [
|
33
|
-
"application/vnd.#{options[:vendor]}-#{options[:version]}",
|
34
|
-
options[:format]
|
35
|
-
].compact.join('+')
|
36
|
-
}
|
37
|
-
when :accept_version_header
|
38
|
-
{
|
39
|
-
'HTTP_ACCEPT_VERSION' => options[:version].to_s
|
40
|
-
}
|
41
|
-
else
|
42
|
-
raise ArgumentError.new("unknown versioning strategy: #{options[:using]}")
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def versioned_get(path, version_name, **version_options)
|
47
|
-
path = versioned_path(**version_options.merge(version: version_name, path: path))
|
48
|
-
headers = versioned_headers(**version_options.merge(version: version_name))
|
49
|
-
params = {}
|
50
|
-
params = { version_options[:parameter] => version_name } if version_options[:using] == :param
|
51
|
-
get path, params, headers
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|