praxis 2.0.pre.17 → 2.0.pre.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +54 -0
- data/.simplecov +3 -1
- data/.travis.yml +2 -1
- data/CHANGELOG.md +19 -0
- data/CONTRIBUTING.md +2 -79
- data/Gemfile +5 -1
- data/Guardfile +6 -4
- data/LICENSE +0 -2
- data/MAINTAINERS.md +1 -0
- data/README.md +15 -22
- data/Rakefile +4 -2
- data/bin/praxis +55 -58
- data/lib/praxis/action_definition/headers_dsl_compiler.rb +5 -6
- data/lib/praxis/action_definition.rb +65 -95
- data/lib/praxis/api_definition.rb +21 -29
- data/lib/praxis/api_general_info.rb +55 -66
- data/lib/praxis/application.rb +15 -32
- data/lib/praxis/blueprint.rb +80 -73
- data/lib/praxis/bootloader.rb +24 -33
- data/lib/praxis/bootloader_stages/environment.rb +5 -10
- data/lib/praxis/bootloader_stages/file_loader.rb +3 -6
- data/lib/praxis/bootloader_stages/plugin_config_load.rb +4 -6
- data/lib/praxis/bootloader_stages/plugin_config_prepare.rb +2 -2
- data/lib/praxis/bootloader_stages/plugin_loader.rb +3 -7
- data/lib/praxis/bootloader_stages/plugin_setup.rb +3 -3
- data/lib/praxis/bootloader_stages/routing.rb +5 -8
- data/lib/praxis/bootloader_stages/subgroup_loader.rb +2 -10
- data/lib/praxis/bootloader_stages/warn_unloaded_files.rb +15 -19
- data/lib/praxis/callbacks.rb +12 -11
- data/lib/praxis/collection.rb +11 -14
- data/lib/praxis/config.rb +17 -28
- data/lib/praxis/config_hash.rb +2 -1
- data/lib/praxis/controller.rb +7 -6
- data/lib/praxis/dispatcher.rb +34 -42
- data/lib/praxis/docs/open_api/info_object.rb +11 -8
- data/lib/praxis/docs/open_api/media_type_object.rb +18 -17
- data/lib/praxis/docs/open_api/operation_object.rb +7 -4
- data/lib/praxis/docs/open_api/parameter_object.rb +17 -14
- data/lib/praxis/docs/open_api/paths_object.rb +11 -9
- data/lib/praxis/docs/open_api/request_body_object.rb +14 -13
- data/lib/praxis/docs/open_api/response_object.rb +24 -18
- data/lib/praxis/docs/open_api/responses_object.rb +3 -1
- data/lib/praxis/docs/open_api/schema_object.rb +61 -29
- data/lib/praxis/docs/open_api/server_object.rb +5 -2
- data/lib/praxis/docs/open_api/tag_object.rb +9 -6
- data/lib/praxis/docs/open_api_generator.rb +114 -150
- data/lib/praxis/endpoint_definition.rb +60 -77
- data/lib/praxis/error_handler.rb +2 -2
- data/lib/praxis/exception.rb +2 -0
- data/lib/praxis/exceptions/config.rb +3 -1
- data/lib/praxis/exceptions/config_load.rb +2 -0
- data/lib/praxis/exceptions/config_validation.rb +3 -1
- data/lib/praxis/exceptions/invalid_configuration.rb +3 -1
- data/lib/praxis/exceptions/invalid_response.rb +3 -1
- data/lib/praxis/exceptions/invalid_trait.rb +3 -1
- data/lib/praxis/exceptions/stage_not_found.rb +3 -1
- data/lib/praxis/exceptions/validation.rb +4 -3
- data/lib/praxis/extensions/attribute_filtering/active_record_filter_query_builder.rb +163 -149
- data/lib/praxis/extensions/attribute_filtering/active_record_patches/5x.rb +18 -13
- data/lib/praxis/extensions/attribute_filtering/active_record_patches/6_0.rb +13 -9
- data/lib/praxis/extensions/attribute_filtering/active_record_patches/6_1_plus.rb +14 -11
- data/lib/praxis/extensions/attribute_filtering/active_record_patches.rb +12 -9
- data/lib/praxis/extensions/attribute_filtering/filter_tree_node.rb +8 -5
- data/lib/praxis/extensions/attribute_filtering/filtering_params.rb +89 -65
- data/lib/praxis/extensions/attribute_filtering/filters_parser.rb +68 -62
- data/lib/praxis/extensions/attribute_filtering.rb +3 -1
- data/lib/praxis/extensions/field_expansion.rb +6 -4
- data/lib/praxis/extensions/field_selection/active_record_query_selector.rb +10 -8
- data/lib/praxis/extensions/field_selection/field_selector.rb +91 -92
- data/lib/praxis/extensions/field_selection/sequel_query_selector.rb +12 -12
- data/lib/praxis/extensions/field_selection.rb +3 -1
- data/lib/praxis/extensions/pagination/active_record_pagination_handler.rb +6 -4
- data/lib/praxis/extensions/pagination/header_generator.rb +16 -11
- data/lib/praxis/extensions/pagination/ordering_params.rb +29 -28
- data/lib/praxis/extensions/pagination/pagination_handler.rb +44 -42
- data/lib/praxis/extensions/pagination/pagination_params.rb +29 -48
- data/lib/praxis/extensions/pagination/sequel_pagination_handler.rb +8 -7
- data/lib/praxis/extensions/pagination.rb +10 -15
- data/lib/praxis/extensions/rails_compat/request_methods.rb +3 -4
- data/lib/praxis/extensions/rails_compat.rb +2 -0
- data/lib/praxis/extensions/rendering.rb +12 -12
- data/lib/praxis/field_expander.rb +8 -9
- data/lib/praxis/file_group.rb +8 -12
- data/lib/praxis/finalizable.rb +1 -0
- data/lib/praxis/handlers/json.rb +5 -2
- data/lib/praxis/handlers/plain.rb +2 -1
- data/lib/praxis/handlers/www_form.rb +6 -3
- data/lib/praxis/handlers/{xml-sample.rb → xml_sample.rb} +26 -22
- data/lib/praxis/mapper/active_model_compat.rb +13 -10
- data/lib/praxis/mapper/resource.rb +196 -181
- data/lib/praxis/mapper/selector_generator.rb +106 -112
- data/lib/praxis/mapper/sequel_compat.rb +70 -67
- data/lib/praxis/media_type.rb +2 -2
- data/lib/praxis/media_type_identifier.rb +26 -22
- data/lib/praxis/middleware_app.rb +18 -15
- data/lib/praxis/multipart/parser.rb +46 -51
- data/lib/praxis/multipart/part.rb +78 -110
- data/lib/praxis/notifications.rb +2 -4
- data/lib/praxis/plugin.rb +11 -18
- data/lib/praxis/plugin_concern.rb +12 -15
- data/lib/praxis/plugins/mapper_plugin.rb +15 -13
- data/lib/praxis/plugins/pagination_plugin.rb +8 -6
- data/lib/praxis/plugins/rails_plugin.rb +33 -28
- data/lib/praxis/renderer.rb +11 -15
- data/lib/praxis/request.rb +48 -44
- data/lib/praxis/request_stages/action.rb +4 -6
- data/lib/praxis/request_stages/load_request.rb +2 -4
- data/lib/praxis/request_stages/request_stage.rb +19 -23
- data/lib/praxis/request_stages/response.rb +4 -6
- data/lib/praxis/request_stages/validate.rb +3 -5
- data/lib/praxis/request_stages/validate_params_and_headers.rb +15 -22
- data/lib/praxis/request_stages/validate_payload.rb +25 -28
- data/lib/praxis/request_superclassing.rb +3 -3
- data/lib/praxis/resource_definition.rb +1 -0
- data/lib/praxis/response.rb +24 -26
- data/lib/praxis/response_definition.rb +77 -122
- data/lib/praxis/response_template.rb +11 -15
- data/lib/praxis/responses/http.rb +23 -44
- data/lib/praxis/responses/internal_server_error.rb +18 -21
- data/lib/praxis/responses/multipart_ok.rb +4 -9
- data/lib/praxis/responses/validation_error.rb +8 -15
- data/lib/praxis/route.rb +8 -10
- data/lib/praxis/router/rack.rb +13 -7
- data/lib/praxis/router/simple.rb +10 -5
- data/lib/praxis/router.rb +27 -34
- data/lib/praxis/routing_config.rb +52 -29
- data/lib/praxis/simple_media_type.rb +5 -8
- data/lib/praxis/stage.rb +17 -25
- data/lib/praxis/tasks/api_docs.rb +17 -16
- data/lib/praxis/tasks/console.rb +3 -1
- data/lib/praxis/tasks/environment.rb +2 -0
- data/lib/praxis/tasks/routes.rb +26 -24
- data/lib/praxis/tasks.rb +3 -1
- data/lib/praxis/trait.rb +37 -46
- data/lib/praxis/types/fuzzy_hash.rb +13 -14
- data/lib/praxis/types/media_type_common.rb +11 -10
- data/lib/praxis/types/multipart_array/part_definition.rb +14 -17
- data/lib/praxis/types/multipart_array.rb +100 -115
- data/lib/praxis/validation_handler.rb +5 -3
- data/lib/praxis/version.rb +3 -1
- data/lib/praxis.rb +4 -5
- data/praxis.gemspec +22 -21
- data/spec/functional_spec.rb +44 -56
- data/spec/praxis/action_definition_spec.rb +39 -48
- data/spec/praxis/api_definition_spec.rb +45 -47
- data/spec/praxis/api_general_info_spec.rb +28 -29
- data/spec/praxis/application_spec.rb +18 -14
- data/spec/praxis/blueprint_spec.rb +33 -34
- data/spec/praxis/bootloader_spec.rb +32 -30
- data/spec/praxis/callbacks_spec.rb +37 -37
- data/spec/praxis/collection_spec.rb +18 -25
- data/spec/praxis/config_hash_spec.rb +5 -4
- data/spec/praxis/config_spec.rb +27 -26
- data/spec/praxis/controller_spec.rb +8 -9
- data/spec/praxis/endpoint_definition_spec.rb +25 -32
- data/spec/praxis/extensions/attribute_filtering/active_record_filter_query_builder_spec.rb +171 -114
- data/spec/praxis/extensions/attribute_filtering/filter_tree_node_spec.rb +22 -21
- data/spec/praxis/extensions/attribute_filtering/filtering_params_spec.rb +112 -60
- data/spec/praxis/extensions/attribute_filtering/filters_parser_spec.rb +37 -38
- data/spec/praxis/extensions/field_expansion_spec.rb +8 -10
- data/spec/praxis/extensions/field_selection/active_record_query_selector_spec.rb +14 -13
- data/spec/praxis/extensions/field_selection/field_selector_spec.rb +9 -16
- data/spec/praxis/extensions/field_selection/sequel_query_selector_spec.rb +50 -49
- data/spec/praxis/extensions/pagination/active_record_pagination_handler_spec.rb +32 -31
- data/spec/praxis/extensions/rendering_spec.rb +9 -9
- data/spec/praxis/extensions/support/spec_resources_active_model.rb +32 -49
- data/spec/praxis/extensions/support/spec_resources_sequel.rb +48 -48
- data/spec/praxis/field_expander_spec.rb +6 -5
- data/spec/praxis/file_group_spec.rb +3 -1
- data/spec/praxis/handlers/json_spec.rb +6 -5
- data/spec/praxis/mapper/resource_spec.rb +39 -29
- data/spec/praxis/mapper/selector_generator_spec.rb +80 -46
- data/spec/praxis/media_type_identifier_spec.rb +13 -10
- data/spec/praxis/media_type_spec.rb +12 -12
- data/spec/praxis/middleware_app_spec.rb +23 -22
- data/spec/praxis/multipart/parser_spec.rb +7 -9
- data/spec/praxis/notifications_spec.rb +4 -4
- data/spec/praxis/plugin_concern_spec.rb +5 -6
- data/spec/praxis/renderer_spec.rb +10 -9
- data/spec/praxis/request_spec.rb +38 -41
- data/spec/praxis/request_stages/action_spec.rb +14 -15
- data/spec/praxis/request_stages/request_stage_spec.rb +30 -41
- data/spec/praxis/request_stages/validate_spec.rb +3 -1
- data/spec/praxis/response_definition_spec.rb +79 -92
- data/spec/praxis/response_spec.rb +35 -40
- data/spec/praxis/responses/internal_server_error_spec.rb +6 -9
- data/spec/praxis/responses/validation_error_spec.rb +17 -18
- data/spec/praxis/route_spec.rb +4 -7
- data/spec/praxis/router_spec.rb +69 -79
- data/spec/praxis/routing_config_spec.rb +15 -14
- data/spec/praxis/stage_spec.rb +56 -53
- data/spec/praxis/trait_spec.rb +17 -17
- data/spec/praxis/types/fuzzy_hash_spec.rb +11 -9
- data/spec/praxis/types/multipart_array/part_definition_spec.rb +3 -2
- data/spec/praxis/types/multipart_array_spec.rb +33 -48
- data/spec/spec_app/app/concerns/authenticated.rb +5 -5
- data/spec/spec_app/app/concerns/basic_api.rb +3 -1
- data/spec/spec_app/app/concerns/log_wrapper.rb +5 -3
- data/spec/spec_app/app/controllers/base_class.rb +6 -5
- data/spec/spec_app/app/controllers/instances.rb +31 -34
- data/spec/spec_app/app/controllers/volumes.rb +6 -6
- data/spec/spec_app/app/responses/multipart.rb +1 -2
- data/spec/spec_app/app/responses/other_response.rb +2 -2
- data/spec/spec_app/config/environment.rb +19 -6
- data/spec/spec_app/config.ru +4 -3
- data/spec/spec_app/design/api.rb +13 -15
- data/spec/spec_app/design/media_types/instance.rb +6 -6
- data/spec/spec_app/design/media_types/volume.rb +2 -1
- data/spec/spec_app/design/media_types/volume_snapshot.rb +2 -1
- data/spec/spec_app/design/resources/instances.rb +11 -17
- data/spec/spec_app/design/resources/volume_snapshots.rb +4 -5
- data/spec/spec_app/design/resources/volumes.rb +4 -5
- data/spec/spec_helper.rb +11 -13
- data/spec/support/be_deep_equal_matcher.rb +5 -0
- data/spec/support/spec_authorization_plugin.rb +7 -12
- data/spec/support/spec_blueprints.rb +5 -4
- data/spec/support/spec_complex_authentication_plugin.rb +17 -34
- data/spec/support/spec_endpoint_definitions.rb +2 -3
- data/spec/support/spec_media_types.rb +28 -35
- data/spec/support/spec_resources.rb +22 -16
- data/spec/support/spec_simple_authentication_plugin.rb +5 -9
- data/tasks/loader.thor +4 -2
- data/tasks/thor/app.rb +7 -5
- data/tasks/thor/example.rb +23 -22
- data/tasks/thor/model.rb +7 -7
- data/tasks/thor/scaffold.rb +23 -23
- data/tasks/thor/templates/generator/example_app/app/v1/resources/user.rb +0 -8
- data/tasks/thor/templates/generator/scaffold/implementation/resources/item.rb +1 -2
- metadata +72 -84
- data/MAINTAINERS +0 -2
- data/TODO.md +0 -25
- data/spec/praxis/api_resource_spec.rb +0 -0
- data/spec/praxis/dispatcher_spec.rb +0 -0
- data/spec/spec_app/app/responses/bulk_response.rb +0 -0
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Praxis::EndpointDefinition do
|
@@ -22,17 +24,15 @@ describe Praxis::EndpointDefinition do
|
|
22
24
|
its([:actions]) { should have(2).items }
|
23
25
|
its([:metadata]) { should be_kind_of(Hash) }
|
24
26
|
its([:traits]) { should eq [:test] }
|
25
|
-
it { should_not have_key(:parent)}
|
27
|
+
it { should_not have_key(:parent) }
|
26
28
|
|
27
29
|
context 'for a resource with a parent' do
|
28
|
-
let(:endpoint_definition) { ApiResources::VolumeSnapshots}
|
30
|
+
let(:endpoint_definition) { ApiResources::VolumeSnapshots }
|
29
31
|
|
30
32
|
its([:parent]) { should eq ApiResources::Volumes.id }
|
31
33
|
end
|
32
|
-
|
33
34
|
end
|
34
35
|
|
35
|
-
|
36
36
|
context '.routing_prefix' do
|
37
37
|
subject(:endpoint_definition) { ApiResources::VolumeSnapshots }
|
38
38
|
it do
|
@@ -42,33 +42,33 @@ describe Praxis::EndpointDefinition do
|
|
42
42
|
|
43
43
|
context '.parent_prefix' do
|
44
44
|
subject(:endpoint_definition) { ApiResources::VolumeSnapshots }
|
45
|
-
let(:base_path){ Praxis::ApiDefinition.instance.info.base_path }
|
46
|
-
its(:parent_prefix){ should eq('/clouds/:cloud_id/volumes/:volume_id') }
|
45
|
+
let(:base_path) { Praxis::ApiDefinition.instance.info.base_path }
|
46
|
+
its(:parent_prefix) { should eq('/clouds/:cloud_id/volumes/:volume_id') }
|
47
47
|
it do
|
48
48
|
expect(endpoint_definition.parent_prefix).to_not match(/^#{base_path}/)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
|
53
52
|
context '.action' do
|
54
53
|
it 'requires a block' do
|
55
|
-
expect
|
56
|
-
|
54
|
+
expect do
|
55
|
+
endpoint_definition.action(:something)
|
56
|
+
end.to raise_error(ArgumentError)
|
57
57
|
end
|
58
58
|
it 'creates an ActionDefinition for actions' do
|
59
59
|
index = endpoint_definition.actions[:index]
|
60
60
|
expect(index).to be_kind_of(Praxis::ActionDefinition)
|
61
|
-
expect(index.description).to eq(
|
61
|
+
expect(index.description).to eq('index description')
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'complains if action names are not symbols' do
|
65
65
|
expect do
|
66
66
|
Class.new do
|
67
67
|
include Praxis::EndpointDefinition
|
68
|
-
action
|
68
|
+
action 'foo' do
|
69
69
|
end
|
70
70
|
end
|
71
|
-
end.to raise_error(ArgumentError
|
71
|
+
end.to raise_error(ArgumentError, /Action names must be defined using symbols/)
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -98,14 +98,12 @@ describe Praxis::EndpointDefinition do
|
|
98
98
|
get ''
|
99
99
|
end
|
100
100
|
end
|
101
|
-
|
102
101
|
end
|
103
102
|
end
|
104
103
|
|
105
104
|
let(:non_singleton_api) do
|
106
|
-
api_def=Praxis::ApiDefinition.__send__(:new)
|
105
|
+
api_def = Praxis::ApiDefinition.__send__(:new)
|
107
106
|
api_def.instance_eval do |api|
|
108
|
-
|
109
107
|
api.info do
|
110
108
|
base_path '/api/:base_param'
|
111
109
|
base_params do
|
@@ -141,7 +139,7 @@ describe Praxis::EndpointDefinition do
|
|
141
139
|
end
|
142
140
|
|
143
141
|
context 'includes base_params from the APIDefinition' do
|
144
|
-
let(:show_action_params){ endpoint_definition.actions[:show].params }
|
142
|
+
let(:show_action_params) { endpoint_definition.actions[:show].params }
|
145
143
|
|
146
144
|
it 'including globally defined' do
|
147
145
|
expect(show_action_params.attributes).to have_key(:base_param)
|
@@ -154,15 +152,14 @@ describe Praxis::EndpointDefinition do
|
|
154
152
|
expect(show_action_params.attributes).to have_key(:app_name)
|
155
153
|
expect(show_action_params.attributes).to_not have_key(:v2_param)
|
156
154
|
end
|
157
|
-
|
158
155
|
end
|
159
156
|
end
|
160
157
|
|
161
158
|
context 'setting other values' do
|
162
|
-
subject(:endpoint_definition) { Class.new {include Praxis::EndpointDefinition } }
|
159
|
+
subject(:endpoint_definition) { Class.new { include Praxis::EndpointDefinition } }
|
163
160
|
|
164
|
-
let(:some_proc) {
|
165
|
-
let(:some_hash) {
|
161
|
+
let(:some_proc) { proc {} }
|
162
|
+
let(:some_hash) { {} }
|
166
163
|
|
167
164
|
it 'accepts a string as media_type' do
|
168
165
|
endpoint_definition.media_type('Something')
|
@@ -170,13 +167,11 @@ describe Praxis::EndpointDefinition do
|
|
170
167
|
expect(endpoint_definition.media_type.identifier).to eq('Something')
|
171
168
|
end
|
172
169
|
|
173
|
-
its(:version_options){ should be_kind_of(Hash) }
|
174
|
-
|
170
|
+
its(:version_options) { should be_kind_of(Hash) }
|
175
171
|
end
|
176
172
|
|
177
|
-
|
178
173
|
context '.trait' do
|
179
|
-
subject(:endpoint_definition) { Class.new {include Praxis::EndpointDefinition } }
|
174
|
+
subject(:endpoint_definition) { Class.new { include Praxis::EndpointDefinition } }
|
180
175
|
it 'raises an error for missing traits' do
|
181
176
|
expect { endpoint_definition.trait(:stuff) }.to raise_error(Praxis::Exceptions::InvalidTrait)
|
182
177
|
end
|
@@ -201,7 +196,6 @@ describe Praxis::EndpointDefinition do
|
|
201
196
|
it 'is exposed in the describe' do
|
202
197
|
expect(endpoint_definition.describe[:metadata][:doc_visibility]).to be(:none)
|
203
198
|
end
|
204
|
-
|
205
199
|
end
|
206
200
|
|
207
201
|
context '#canonical_path' do
|
@@ -210,9 +204,9 @@ describe Praxis::EndpointDefinition do
|
|
210
204
|
expect(subject.canonical_path).to eq(subject.actions[:show])
|
211
205
|
end
|
212
206
|
it 'cannot be done if already been defined' do
|
213
|
-
expect
|
207
|
+
expect do
|
214
208
|
endpoint_definition.canonical_path :reset
|
215
|
-
|
209
|
+
end.to raise_error(/'canonical_path' can only be defined once./)
|
216
210
|
end
|
217
211
|
end
|
218
212
|
context 'if none specified' do
|
@@ -235,20 +229,20 @@ describe Praxis::EndpointDefinition do
|
|
235
229
|
end
|
236
230
|
end
|
237
231
|
it 'raises an error' do
|
238
|
-
expect
|
232
|
+
expect do
|
239
233
|
subject.canonical_path
|
240
|
-
|
234
|
+
end.to raise_error(/Action 'non_existent' does not exist/)
|
241
235
|
end
|
242
236
|
end
|
243
237
|
end
|
244
238
|
|
245
239
|
context '#to_href' do
|
246
240
|
it 'accesses the path expansion functions of the primary route' do
|
247
|
-
expect(subject.to_href(
|
241
|
+
expect(subject.to_href(id: 1)).to eq('/people/1')
|
248
242
|
end
|
249
243
|
end
|
250
244
|
context '#parse_href' do
|
251
|
-
let(:parsed){ endpoint_definition.parse_href(
|
245
|
+
let(:parsed) { endpoint_definition.parse_href('/people/1') }
|
252
246
|
it 'accesses the path expansion functions of the primary route' do
|
253
247
|
expect(parsed).to have_key(:id)
|
254
248
|
end
|
@@ -256,5 +250,4 @@ describe Praxis::EndpointDefinition do
|
|
256
250
|
expect(parsed[:id]).to be_kind_of(Integer)
|
257
251
|
end
|
258
252
|
end
|
259
|
-
|
260
253
|
end
|