praxis 2.0.pre.3 → 2.0.pre.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rspec +0 -1
- data/.ruby-version +1 -0
- data/CHANGELOG.md +26 -0
- data/Gemfile +1 -1
- data/Guardfile +2 -1
- data/Rakefile +1 -7
- data/TODO.md +28 -0
- data/lib/api_browser/package-lock.json +7110 -0
- data/lib/praxis.rb +7 -4
- data/lib/praxis/action_definition.rb +9 -16
- data/lib/praxis/api_general_info.rb +21 -0
- data/lib/praxis/application.rb +1 -2
- data/lib/praxis/bootloader_stages/routing.rb +2 -4
- data/lib/praxis/docs/generator.rb +11 -6
- data/lib/praxis/docs/open_api_generator.rb +255 -0
- data/lib/praxis/docs/openapi/info_object.rb +31 -0
- data/lib/praxis/docs/openapi/media_type_object.rb +59 -0
- data/lib/praxis/docs/openapi/operation_object.rb +40 -0
- data/lib/praxis/docs/openapi/parameter_object.rb +69 -0
- data/lib/praxis/docs/openapi/paths_object.rb +55 -0
- data/lib/praxis/docs/openapi/request_body_object.rb +51 -0
- data/lib/praxis/docs/openapi/response_object.rb +63 -0
- data/lib/praxis/docs/openapi/responses_object.rb +44 -0
- data/lib/praxis/docs/openapi/schema_object.rb +87 -0
- data/lib/praxis/docs/openapi/server_object.rb +24 -0
- data/lib/praxis/docs/openapi/tag_object.rb +21 -0
- data/lib/praxis/extensions/attribute_filtering.rb +2 -0
- data/lib/praxis/extensions/attribute_filtering/active_record_filter_query_builder.rb +148 -157
- data/lib/praxis/extensions/attribute_filtering/active_record_patches.rb +15 -0
- data/lib/praxis/extensions/attribute_filtering/active_record_patches/5x.rb +90 -0
- data/lib/praxis/extensions/attribute_filtering/active_record_patches/6_0.rb +68 -0
- data/lib/praxis/extensions/attribute_filtering/active_record_patches/6_1_plus.rb +58 -0
- data/lib/praxis/extensions/attribute_filtering/filter_tree_node.rb +35 -0
- data/lib/praxis/extensions/attribute_filtering/filtering_params.rb +13 -12
- data/lib/praxis/extensions/attribute_filtering/sequel_filter_query_builder.rb +3 -2
- data/lib/praxis/extensions/field_selection/active_record_query_selector.rb +7 -9
- data/lib/praxis/extensions/field_selection/field_selector.rb +4 -0
- data/lib/praxis/extensions/field_selection/sequel_query_selector.rb +6 -9
- data/lib/praxis/extensions/pagination.rb +130 -0
- data/lib/praxis/extensions/pagination/active_record_pagination_handler.rb +42 -0
- data/lib/praxis/extensions/pagination/header_generator.rb +70 -0
- data/lib/praxis/extensions/pagination/ordering_params.rb +238 -0
- data/lib/praxis/extensions/pagination/pagination_handler.rb +68 -0
- data/lib/praxis/extensions/pagination/pagination_params.rb +378 -0
- data/lib/praxis/extensions/pagination/sequel_pagination_handler.rb +45 -0
- data/lib/praxis/handlers/json.rb +2 -0
- data/lib/praxis/handlers/www_form.rb +5 -0
- data/lib/praxis/handlers/{xml.rb → xml-sample.rb} +6 -0
- data/lib/praxis/links.rb +4 -0
- data/lib/praxis/mapper/active_model_compat.rb +23 -5
- data/lib/praxis/mapper/resource.rb +16 -9
- data/lib/praxis/mapper/selector_generator.rb +11 -10
- data/lib/praxis/mapper/sequel_compat.rb +1 -0
- data/lib/praxis/media_type.rb +1 -56
- data/lib/praxis/multipart/part.rb +5 -2
- data/lib/praxis/plugins/mapper_plugin.rb +1 -1
- data/lib/praxis/plugins/pagination_plugin.rb +71 -0
- data/lib/praxis/resource_definition.rb +4 -12
- data/lib/praxis/response_definition.rb +1 -1
- data/lib/praxis/route.rb +2 -4
- data/lib/praxis/routing_config.rb +4 -8
- data/lib/praxis/tasks/api_docs.rb +23 -0
- data/lib/praxis/tasks/routes.rb +10 -15
- data/lib/praxis/types/media_type_common.rb +10 -0
- data/lib/praxis/types/multipart_array.rb +62 -0
- data/lib/praxis/validation_handler.rb +1 -2
- data/lib/praxis/version.rb +1 -1
- data/praxis.gemspec +4 -5
- data/spec/functional_spec.rb +9 -6
- data/spec/praxis/action_definition_spec.rb +4 -16
- data/spec/praxis/api_general_info_spec.rb +6 -6
- data/spec/praxis/extensions/attribute_filtering/active_record_filter_query_builder_spec.rb +304 -0
- data/spec/praxis/extensions/attribute_filtering/filter_tree_node_spec.rb +39 -0
- data/spec/praxis/extensions/attribute_filtering/filtering_params_spec.rb +34 -0
- data/spec/praxis/extensions/field_expansion_spec.rb +6 -24
- data/spec/praxis/extensions/field_selection/active_record_query_selector_spec.rb +15 -11
- data/spec/praxis/extensions/field_selection/sequel_query_selector_spec.rb +4 -3
- data/spec/praxis/extensions/pagination/active_record_pagination_handler_spec.rb +130 -0
- data/spec/praxis/extensions/{field_selection/support → support}/spec_resources_active_model.rb +45 -2
- data/spec/praxis/extensions/{field_selection/support → support}/spec_resources_sequel.rb +0 -0
- data/spec/praxis/mapper/selector_generator_spec.rb +32 -0
- data/spec/praxis/media_type_spec.rb +5 -129
- data/spec/praxis/request_spec.rb +3 -22
- data/spec/praxis/resource_definition_spec.rb +1 -1
- data/spec/praxis/response_definition_spec.rb +8 -9
- data/spec/praxis/route_spec.rb +2 -9
- data/spec/praxis/routing_config_spec.rb +4 -13
- data/spec/praxis/types/multipart_array_spec.rb +4 -21
- data/spec/spec_app/config/environment.rb +0 -2
- data/spec/spec_app/design/api.rb +7 -1
- data/spec/spec_app/design/media_types/instance.rb +0 -8
- data/spec/spec_app/design/media_types/volume.rb +0 -12
- data/spec/spec_app/design/resources/instances.rb +1 -2
- data/spec/spec_helper.rb +6 -0
- data/spec/support/spec_media_types.rb +0 -73
- metadata +51 -49
- data/spec/praxis/handlers/xml_spec.rb +0 -177
- data/spec/praxis/links_spec.rb +0 -68
data/spec/praxis/request_spec.rb
CHANGED
@@ -2,8 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Praxis::Request do
|
4
4
|
let(:path) { '/instances/1?junk=foo&api_version=1.0' }
|
5
|
-
let(:rack_input) { StringIO.new('something
|
6
|
-
let(:env_content_type){ 'application/
|
5
|
+
let(:rack_input) { StringIO.new('{"something": "given"}') }
|
6
|
+
let(:env_content_type){ 'application/json' }
|
7
7
|
let(:env) do
|
8
8
|
env = Rack::MockRequest.env_for(path)
|
9
9
|
env['rack.input'] = rack_input
|
@@ -192,7 +192,7 @@ describe Praxis::Request do
|
|
192
192
|
end
|
193
193
|
|
194
194
|
context '#validate_payload' do
|
195
|
-
before { request.load_payload('') }
|
195
|
+
before { request.load_payload('{}') }
|
196
196
|
it 'should validate payload' do
|
197
197
|
expect(request.payload).to receive(:validate).and_return([])
|
198
198
|
request.validate_payload(context[:payload])
|
@@ -208,22 +208,11 @@ describe Praxis::Request do
|
|
208
208
|
let(:load_context){ context[:payload] }
|
209
209
|
let(:parsed_result){ double("parsed") }
|
210
210
|
|
211
|
-
before do
|
212
|
-
Praxis::Application.instance.handler 'xml', Praxis::Handlers::XML
|
213
|
-
end
|
214
|
-
|
215
211
|
after do
|
216
212
|
expect(request.action.payload).to receive(:load).with(parsed_result, load_context, content_type: request.content_type.to_s )
|
217
213
|
request.load_payload( load_context )
|
218
214
|
end
|
219
215
|
|
220
|
-
context 'that is url-encoded' do
|
221
|
-
let(:env_content_type){ 'application/x-www-form-urlencoded' }
|
222
|
-
let(:parsed_result) { {"something" => "given"} }
|
223
|
-
|
224
|
-
it 'decodes it the www-form handler' do end
|
225
|
-
end
|
226
|
-
|
227
216
|
context 'that is json encoded' do
|
228
217
|
let(:rack_input) { StringIO.new('{"one":1,"sub_hash":{"first":"hello"}}') }
|
229
218
|
let(:env_content_type){ 'application/json' }
|
@@ -231,14 +220,6 @@ describe Praxis::Request do
|
|
231
220
|
|
232
221
|
it 'decodes using the JSON handler' do end
|
233
222
|
end
|
234
|
-
context 'that is xml encoded' do
|
235
|
-
let(:rack_input) { StringIO.new('<hash><one type="integer">1</one><sub_hash><first>hello</first></sub_hash></hash>') }
|
236
|
-
let(:env_content_type) { 'application/xml' }
|
237
|
-
let(:parsed_result) { Praxis::Handlers::XML.new.parse(request.raw_payload) }
|
238
|
-
|
239
|
-
it 'decodes using the XML handler' do end
|
240
|
-
end
|
241
|
-
|
242
223
|
end
|
243
224
|
end
|
244
225
|
end
|
@@ -137,7 +137,7 @@ describe Praxis::ResourceDefinition do
|
|
137
137
|
it 'are applied to actions' do
|
138
138
|
action = resource_definition.actions[:show]
|
139
139
|
expect(action.params.attributes).to have_key(:id)
|
140
|
-
expect(action.
|
140
|
+
expect(action.route.path.to_s).to eq '/api/:base_param/people/:id'
|
141
141
|
end
|
142
142
|
|
143
143
|
context 'includes base_params from the APIDefinition' do
|
@@ -514,22 +514,18 @@ describe Praxis::ResponseDefinition do
|
|
514
514
|
|
515
515
|
context 'for a definition with a media type' do
|
516
516
|
let(:media_type) { Instance }
|
517
|
-
subject(:payload) { output[:payload] }
|
517
|
+
subject(:payload) { output[:payload][:type] }
|
518
518
|
|
519
519
|
before do
|
520
520
|
response.media_type Instance
|
521
521
|
end
|
522
|
-
|
523
522
|
its([:name]) { should eq 'Instance' }
|
524
523
|
context 'examples' do
|
525
524
|
subject(:examples) { payload[:examples] }
|
526
525
|
its(['json', :content_type]) { should eq('application/vnd.acme.instance+json') }
|
527
|
-
its(['xml', :content_type]) { should eq('application/vnd.acme.instance+xml') }
|
528
526
|
|
529
527
|
it 'properly encodes the example bodies' do
|
530
|
-
|
531
|
-
xml = Praxis::Application.instance.handlers['xml'].parse(examples['xml'][:body])
|
532
|
-
expect(json).to eq xml
|
528
|
+
expect(JSON.parse(examples['json'][:body])).to be_kind_of(Hash)
|
533
529
|
end
|
534
530
|
|
535
531
|
end
|
@@ -542,7 +538,6 @@ describe Praxis::ResponseDefinition do
|
|
542
538
|
|
543
539
|
it 'still renders examples but as pure handler types for contents' do
|
544
540
|
expect(subject['json'][:content_type]).to eq('application/json')
|
545
|
-
expect(subject['xml'][:content_type]).to eq('application/xml')
|
546
541
|
end
|
547
542
|
end
|
548
543
|
|
@@ -571,7 +566,9 @@ describe Praxis::ResponseDefinition do
|
|
571
566
|
end
|
572
567
|
|
573
568
|
it{ should be_kind_of(::Hash) }
|
574
|
-
|
569
|
+
it 'has the right type info' do
|
570
|
+
expect(subject[:payload][:type]).to match(id: 'Praxis-SimpleMediaType', name: 'Praxis::SimpleMediaType', family: 'string', identifier: 'foobar')
|
571
|
+
end
|
575
572
|
its([:status]){ should == 200 }
|
576
573
|
end
|
577
574
|
context 'using a full response definition block' do
|
@@ -587,7 +584,9 @@ describe Praxis::ResponseDefinition do
|
|
587
584
|
end
|
588
585
|
|
589
586
|
it{ should be_kind_of(::Hash) }
|
590
|
-
|
587
|
+
it 'has the right type info' do
|
588
|
+
expect(subject[:payload][:type]).to match(id: 'Praxis-SimpleMediaType', name: 'Praxis::SimpleMediaType', family: 'string', identifier: 'custom_media')
|
589
|
+
end
|
591
590
|
its([:status]) { should == 234 }
|
592
591
|
end
|
593
592
|
end
|
data/spec/praxis/route_spec.rb
CHANGED
@@ -5,21 +5,19 @@ describe Praxis::Route do
|
|
5
5
|
let(:verb) { 'GET' }
|
6
6
|
let(:path) { '/base/stuff' }
|
7
7
|
let(:prefixed_path) { '/stuff' }
|
8
|
-
let(:name) { nil }
|
9
8
|
let(:version) { '1.0' }
|
10
9
|
let(:options) { {} }
|
11
10
|
|
12
|
-
subject(:route) { Praxis::Route.new(verb, path, version,
|
11
|
+
subject(:route) { Praxis::Route.new(verb, path, version, prefixed_path: prefixed_path, **options) }
|
13
12
|
|
14
13
|
its(:verb) { should be(verb) }
|
15
14
|
its(:path) { should be(path) }
|
16
|
-
its(:name) { should be(name) }
|
17
15
|
its(:version) { should be(version) }
|
18
16
|
its(:prefixed_path) { should eq(prefixed_path) }
|
19
17
|
its(:options) { should eq(options) }
|
20
18
|
|
21
19
|
it 'defaults version to "n/a"' do
|
22
|
-
route = Praxis::Route.new(verb, path,
|
20
|
+
route = Praxis::Route.new(verb, path, **options)
|
23
21
|
expect(route.version).to eq('n/a')
|
24
22
|
end
|
25
23
|
|
@@ -27,11 +25,6 @@ describe Praxis::Route do
|
|
27
25
|
subject(:description) { route.describe }
|
28
26
|
it { should eq({verb:verb, path:path , version:version}) }
|
29
27
|
|
30
|
-
context 'with a named route' do
|
31
|
-
let(:name) { :stuff }
|
32
|
-
its([:name]) { should eq(name) }
|
33
|
-
end
|
34
|
-
|
35
28
|
context 'with options' do
|
36
29
|
let(:options) { {option: 'value'} }
|
37
30
|
its([:options]) { should eq(options) }
|
@@ -43,26 +43,17 @@ describe Praxis::RoutingConfig do
|
|
43
43
|
let(:options) { {} }
|
44
44
|
let(:base_path){ '/api' }
|
45
45
|
let(:route) { routing_config.add_route 'GET', path, **options}
|
46
|
-
|
46
|
+
|
47
47
|
it 'returns a corresponding Praxis::Route' do
|
48
48
|
expect(route).to be_kind_of(Praxis::Route)
|
49
49
|
end
|
50
50
|
|
51
|
-
it '
|
52
|
-
expect(
|
51
|
+
it 'sets the Route to its route' do
|
52
|
+
expect(route).to eq(routing_config.route)
|
53
53
|
end
|
54
54
|
|
55
55
|
context 'passing options' do
|
56
|
-
let(:options){ {
|
57
|
-
|
58
|
-
it 'uses :name to name the route' do
|
59
|
-
expect(route.name).to eq('alternative')
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'does NOT pass the name option down to mustermann' do
|
63
|
-
expect(Mustermann).to receive(:new).with(base_path + path, hash_excluding({name: 'alternative'}))
|
64
|
-
expect(route.name).to eq('alternative')
|
65
|
-
end
|
56
|
+
let(:options){ { except: '/special' } }
|
66
57
|
|
67
58
|
it 'passes them through the underlying mustermann object (telling it to ignore unknown ones)' do
|
68
59
|
expect(Mustermann).to receive(:new).with(base_path + path, hash_including(ignore_unknown_options: true, except: '/special'))
|
@@ -41,14 +41,6 @@ describe Praxis::Types::MultipartArray do
|
|
41
41
|
entity = MIME::Application.new('file2')
|
42
42
|
form_data.add entity,'files', 'file2'
|
43
43
|
|
44
|
-
entity = MIME::Application.new('
|
45
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
46
|
-
<hash>
|
47
|
-
<first_name>James</first_name>
|
48
|
-
</hash>
|
49
|
-
', 'xml')
|
50
|
-
form_data.add entity,'stuff1'
|
51
|
-
|
52
44
|
entity = MIME::Application.new('{"first_name": "Frank"}', 'json')
|
53
45
|
form_data.add entity,'stuff2'
|
54
46
|
|
@@ -81,9 +73,6 @@ describe Praxis::Types::MultipartArray do
|
|
81
73
|
files = payload.part('files')
|
82
74
|
expect(files).to have(2).items
|
83
75
|
|
84
|
-
stuff1 = payload.part('stuff1')
|
85
|
-
expect(stuff1.payload['first_name']).to eq 'James'
|
86
|
-
|
87
76
|
stuff2 = payload.part('stuff2')
|
88
77
|
expect(stuff2.payload['first_name']).to eq 'Frank'
|
89
78
|
|
@@ -274,7 +263,7 @@ describe Praxis::Types::MultipartArray do
|
|
274
263
|
|
275
264
|
let(:example) { type.example }
|
276
265
|
|
277
|
-
let(:default_format) { '
|
266
|
+
let(:default_format) { 'json' }
|
278
267
|
|
279
268
|
let(:output) { example.dump(default_format: default_format) }
|
280
269
|
|
@@ -282,29 +271,23 @@ describe Praxis::Types::MultipartArray do
|
|
282
271
|
|
283
272
|
it 'dumps the parts with the proper handler' do
|
284
273
|
json_handler = Praxis::Application.instance.handlers['json']
|
285
|
-
xml_handler = Praxis::Application.instance.handlers['xml']
|
286
274
|
|
287
275
|
# title is simple string, so should keep text/plain
|
288
276
|
title = parts.find { |part| part.name == 'title' }
|
289
277
|
expect(title.content_type.to_s).to eq 'text/plain'
|
290
278
|
expect(title.payload).to eq example.part('title').payload
|
291
279
|
|
292
|
-
# things are structs with no content-type header defined
|
293
|
-
thing = parts.find { |part| part.name == 'thing' }
|
294
|
-
expect(thing.content_type.to_s).to eq 'application/xml'
|
295
|
-
expect(thing.payload).to eq xml_handler.generate(example.part('thing').payload.dump)
|
296
|
-
|
297
280
|
# stuff has hardcoded 'application/json' content-type, and should remain such
|
298
281
|
stuff = parts.find { |part| part.name == 'stuff' }
|
299
282
|
expect(stuff.content_type.to_s).to eq 'application/json'
|
300
283
|
expect(stuff.payload).to eq json_handler.generate(example.part('stuff').payload.dump)
|
301
284
|
|
302
285
|
# instances just specify 'application/vnd.acme.instance', and should
|
303
|
-
# have
|
286
|
+
# have json suffix appended
|
304
287
|
instances = parts.select { |part| part.name == 'instances' }
|
305
288
|
instances.each_with_index do |instance, i|
|
306
|
-
expect(instance.content_type.to_s).to eq 'application/vnd.acme.instance+
|
307
|
-
expect(instance.payload).to eq
|
289
|
+
expect(instance.content_type.to_s).to eq 'application/vnd.acme.instance+json'
|
290
|
+
expect(instance.payload).to eq json_handler.generate(example.part('instances')[i].payload.dump)
|
308
291
|
end
|
309
292
|
end
|
310
293
|
|
@@ -14,8 +14,6 @@ end
|
|
14
14
|
|
15
15
|
Praxis::Application.configure do |application|
|
16
16
|
|
17
|
-
application.handler 'xml', Praxis::Handlers::XML
|
18
|
-
|
19
17
|
application.middleware SetHeader, 'Spec-Middleware', 'used'
|
20
18
|
|
21
19
|
application.bootloader.use SimpleAuthenticationPlugin, config_file: 'config/authentication.yml'
|
data/spec/spec_app/design/api.rb
CHANGED
@@ -24,9 +24,15 @@ Praxis::ApiDefinition.define do
|
|
24
24
|
description "This example API should really be replaced by a set of more full-fledged example apps in the future"
|
25
25
|
|
26
26
|
base_path "/api"
|
27
|
-
produces 'json'
|
27
|
+
produces 'json'
|
28
28
|
#version_with :path
|
29
29
|
#base_path "/v:api_version"
|
30
|
+
|
31
|
+
# Custom attributes (for OpenApi, for example)
|
32
|
+
termsOfService "http://example.com/tos"
|
33
|
+
contact name: 'Joe', email: 'joe@email.com'
|
34
|
+
license name: "Apache 2.0",
|
35
|
+
url: "https://www.apache.org/licenses/LICENSE-2.0.html"
|
30
36
|
end
|
31
37
|
|
32
38
|
info '1.0' do # Applies to 1.0 version (and inherits everything else form the global one)
|
@@ -14,16 +14,11 @@ class Instance < Praxis::MediaType
|
|
14
14
|
|
15
15
|
attribute :volumes, Volume::Collection
|
16
16
|
|
17
|
-
links do
|
18
|
-
link :root_volume
|
19
|
-
link :other_volume, Volume, using: :data_volume
|
20
|
-
end
|
21
17
|
end
|
22
18
|
|
23
19
|
view :default do
|
24
20
|
attribute :id
|
25
21
|
attribute :root_volume
|
26
|
-
attribute :links
|
27
22
|
end
|
28
23
|
|
29
24
|
view :link do
|
@@ -40,9 +35,6 @@ class Instance < Praxis::MediaType
|
|
40
35
|
attribute :id
|
41
36
|
attribute :name
|
42
37
|
attribute :root_volume
|
43
|
-
attribute :links do
|
44
|
-
attribute :root_volume
|
45
|
-
end
|
46
38
|
end
|
47
39
|
|
48
40
|
|
@@ -9,12 +9,6 @@ class Volume < Praxis::MediaType
|
|
9
9
|
|
10
10
|
attribute :snapshots, Praxis::Collection.of(VolumeSnapshot)
|
11
11
|
attribute :snapshots_summary, VolumeSnapshot::CollectionSummary
|
12
|
-
|
13
|
-
links do
|
14
|
-
link :source
|
15
|
-
link :snapshots, VolumeSnapshot::CollectionSummary, using: :snapshots_summary
|
16
|
-
end
|
17
|
-
|
18
12
|
end
|
19
13
|
|
20
14
|
view :default do
|
@@ -22,12 +16,6 @@ class Volume < Praxis::MediaType
|
|
22
16
|
attribute :name
|
23
17
|
attribute :source
|
24
18
|
attribute :snapshots
|
25
|
-
|
26
|
-
attribute :links
|
27
|
-
end
|
28
|
-
|
29
|
-
view :link do
|
30
|
-
attribute :id
|
31
19
|
end
|
32
20
|
|
33
21
|
class Collection < Praxis::Collection
|
@@ -44,7 +44,6 @@ module ApiResources
|
|
44
44
|
action :show do
|
45
45
|
routing do
|
46
46
|
get '/:id'
|
47
|
-
get '/something/:id', name: :alternate
|
48
47
|
end
|
49
48
|
|
50
49
|
response :ok, media_type: 'application/json'
|
@@ -144,7 +143,7 @@ module ApiResources
|
|
144
143
|
attribute :id
|
145
144
|
end
|
146
145
|
|
147
|
-
payload do
|
146
|
+
payload required: false do
|
148
147
|
attribute :when, DateTime
|
149
148
|
end
|
150
149
|
|
data/spec/spec_helper.rb
CHANGED
@@ -7,6 +7,12 @@ $:.unshift File.expand_path('support',__dir__)
|
|
7
7
|
|
8
8
|
require 'bundler'
|
9
9
|
Bundler.setup :default, :test
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.filter_run focus: true
|
13
|
+
config.run_all_when_everything_filtered = true
|
14
|
+
end
|
15
|
+
|
10
16
|
require 'simplecov'
|
11
17
|
SimpleCov.start 'praxis'
|
12
18
|
|
@@ -6,22 +6,13 @@ class Person < Praxis::MediaType
|
|
6
6
|
attribute :id, Integer
|
7
7
|
attribute :name, String, example: /[:name:]/
|
8
8
|
attribute :href, String, example: proc { |person| "/people/#{person.id}" }
|
9
|
-
attribute :links, Attributor::Collection.of(String),
|
10
|
-
description: 'Here to ensure an explicit links attribute works'
|
11
|
-
|
12
9
|
end
|
13
10
|
|
14
11
|
view :default do
|
15
12
|
attribute :id
|
16
13
|
attribute :name
|
17
|
-
attribute :links
|
18
14
|
end
|
19
15
|
|
20
|
-
view :link do
|
21
|
-
attribute :id
|
22
|
-
attribute :name
|
23
|
-
attribute :href
|
24
|
-
end
|
25
16
|
|
26
17
|
class CollectionSummary < Praxis::MediaType
|
27
18
|
attributes do
|
@@ -29,11 +20,6 @@ class Person < Praxis::MediaType
|
|
29
20
|
attribute :size, Integer
|
30
21
|
end
|
31
22
|
|
32
|
-
view :link do
|
33
|
-
attribute :href
|
34
|
-
attribute :size
|
35
|
-
end
|
36
|
-
|
37
23
|
view :default do
|
38
24
|
attribute :href
|
39
25
|
end
|
@@ -59,14 +45,6 @@ class Address < Praxis::MediaType
|
|
59
45
|
attribute :residents_summary, Person::CollectionSummary
|
60
46
|
|
61
47
|
attribute :fields, Praxis::Types::FieldSelector.for(Person)
|
62
|
-
|
63
|
-
links do
|
64
|
-
link :owner
|
65
|
-
link :super, Person, using: :manager
|
66
|
-
link :caretaker, using: :custodian
|
67
|
-
link :residents, using: :residents_summary
|
68
|
-
end
|
69
|
-
|
70
48
|
end
|
71
49
|
|
72
50
|
view :default do
|
@@ -74,15 +52,7 @@ class Address < Praxis::MediaType
|
|
74
52
|
attribute :name
|
75
53
|
attribute :owner
|
76
54
|
attribute :fields
|
77
|
-
|
78
|
-
attribute :links
|
79
|
-
end
|
80
|
-
|
81
|
-
view :link do
|
82
|
-
attribute :id
|
83
|
-
attribute :name
|
84
55
|
end
|
85
|
-
|
86
56
|
end
|
87
57
|
|
88
58
|
|
@@ -123,10 +93,6 @@ class Blog < Praxis::MediaType
|
|
123
93
|
example: proc { |blog,ctx| Post::CollectionSummary.example(ctx, href: "#{blog.href}/posts") },
|
124
94
|
description: "Summary of information from related Post resources"
|
125
95
|
|
126
|
-
links do
|
127
|
-
link :posts, using: :posts_summary
|
128
|
-
link :owner
|
129
|
-
end
|
130
96
|
end
|
131
97
|
|
132
98
|
view :default do
|
@@ -138,7 +104,6 @@ class Blog < Praxis::MediaType
|
|
138
104
|
attribute :timestamps
|
139
105
|
|
140
106
|
attribute :owner
|
141
|
-
attribute :links
|
142
107
|
end
|
143
108
|
|
144
109
|
view :overview do
|
@@ -146,11 +111,6 @@ class Blog < Praxis::MediaType
|
|
146
111
|
attribute :name
|
147
112
|
attribute :description
|
148
113
|
end
|
149
|
-
|
150
|
-
view :link do
|
151
|
-
attribute :href
|
152
|
-
end
|
153
|
-
|
154
114
|
end
|
155
115
|
|
156
116
|
|
@@ -185,11 +145,6 @@ class Post < Praxis::MediaType
|
|
185
145
|
attribute :created_at, DateTime
|
186
146
|
attribute :updated_at, DateTime
|
187
147
|
end
|
188
|
-
|
189
|
-
links do
|
190
|
-
link :author
|
191
|
-
link :blog
|
192
|
-
end
|
193
148
|
end
|
194
149
|
|
195
150
|
view :default do
|
@@ -202,23 +157,13 @@ class Post < Praxis::MediaType
|
|
202
157
|
attribute :author
|
203
158
|
|
204
159
|
attribute :timestamps
|
205
|
-
attribute :links
|
206
|
-
end
|
207
|
-
|
208
|
-
view :link do
|
209
|
-
attribute :href
|
210
160
|
end
|
211
161
|
|
212
|
-
|
213
162
|
class CollectionSummary < Praxis::MediaType
|
214
163
|
attributes do
|
215
164
|
attribute :href, String
|
216
165
|
attribute :count, Integer
|
217
166
|
end
|
218
|
-
|
219
|
-
view :link do
|
220
|
-
attribute :href
|
221
|
-
end
|
222
167
|
end
|
223
168
|
end
|
224
169
|
|
@@ -251,12 +196,6 @@ class User < Praxis::MediaType
|
|
251
196
|
|
252
197
|
attribute :posts_summary, Post::CollectionSummary,
|
253
198
|
example: proc { |user,ctx| Post::CollectionSummary.example(ctx, href: "#{user.href}/posts") }
|
254
|
-
|
255
|
-
links do
|
256
|
-
link :posts, using: :posts_summary
|
257
|
-
link :primary_blog
|
258
|
-
end
|
259
|
-
|
260
199
|
end
|
261
200
|
|
262
201
|
view :default do
|
@@ -265,8 +204,6 @@ class User < Praxis::MediaType
|
|
265
204
|
|
266
205
|
attribute :first
|
267
206
|
attribute :last
|
268
|
-
|
269
|
-
attribute :links
|
270
207
|
end
|
271
208
|
|
272
209
|
view :extended do
|
@@ -276,20 +213,10 @@ class User < Praxis::MediaType
|
|
276
213
|
attribute :first
|
277
214
|
attribute :last
|
278
215
|
attribute :primary_blog, view: :overview
|
279
|
-
|
280
|
-
attribute :links
|
281
216
|
end
|
282
217
|
|
283
218
|
view :with_post_links do
|
284
219
|
attribute :id
|
285
220
|
attribute :posts, view: :link
|
286
221
|
end
|
287
|
-
|
288
|
-
view :link do
|
289
|
-
attribute :href
|
290
|
-
end
|
291
|
-
|
292
|
-
view :summary do
|
293
|
-
attribute :links
|
294
|
-
end
|
295
222
|
end
|