jsonapi-serializers 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/lib/jsonapi-serializers/serializer.rb +8 -5
- data/lib/jsonapi-serializers/version.rb +1 -1
- data/spec/serializer_spec.rb +16 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea36d39568cd4df788499db7681358013569975f
|
4
|
+
data.tar.gz: 9487670f424a8d0191a157b6dc556a8964fc47c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de078d2a6e9eba0f0c3a18e90e2f2826997e7bbd7a9eb77ff24dd9eadc57d19011fe771db95a31c762efc80f178cefd1ba79e90dd088af762d9dc0553b58cde3
|
7
|
+
data.tar.gz: f0bbd2106ce7a6aec5e6d0d4b722d3e08e75266bb3688a8b92f615748c5586a048dae1f8ca9e2c36a4d412e0aaf5f5735d91d1eb1b9346e5619d4ab03cbcc384
|
data/README.md
CHANGED
@@ -318,11 +318,11 @@ JSONAPI::Serializer.serialize(post, meta: {copyright: 'Copyright 2015 Example Co
|
|
318
318
|
|
319
319
|
### Root errors
|
320
320
|
|
321
|
-
You can
|
321
|
+
You can use `serialize_errors` method in order to specify top-level errors:
|
322
322
|
|
323
323
|
```ruby
|
324
324
|
errors = [{ "title": "Invalid Attribute", "detail": "First name must contain at least three characters." }]
|
325
|
-
JSONAPI::Serializer.
|
325
|
+
JSONAPI::Serializer.serialize_errors(errors)
|
326
326
|
```
|
327
327
|
|
328
328
|
### Explicit serializer discovery
|
@@ -662,6 +662,8 @@ end
|
|
662
662
|
|
663
663
|
## Release notes
|
664
664
|
|
665
|
+
* v0.9.0: Add initial `serialize_errors` support.
|
666
|
+
* v0.8.0: Pass context through recursive relationships.
|
665
667
|
* v0.7.0: Support for root error objects.
|
666
668
|
* v0.6.5: Exclude attributes when empty.
|
667
669
|
* v0.6.4: Fix regression of including links when empty.
|
@@ -235,6 +235,8 @@ module JSONAPI
|
|
235
235
|
options[:skip_collection_check] = options.delete('skip_collection_check') || options[:skip_collection_check] || false
|
236
236
|
options[:base_url] = options.delete('base_url') || options[:base_url]
|
237
237
|
options[:meta] = options.delete('meta') || options[:meta]
|
238
|
+
|
239
|
+
# Deprecated: use serialize_errors method instead
|
238
240
|
options[:errors] = options.delete('errors') || options[:errors]
|
239
241
|
|
240
242
|
# Normalize includes.
|
@@ -314,6 +316,10 @@ module JSONAPI
|
|
314
316
|
result
|
315
317
|
end
|
316
318
|
|
319
|
+
def self.serialize_errors(errors)
|
320
|
+
{'errors' => errors}
|
321
|
+
end
|
322
|
+
|
317
323
|
def self.serialize_primary(object, options = {})
|
318
324
|
serializer_class = options[:serializer] || find_serializer_class(object)
|
319
325
|
|
@@ -400,11 +406,8 @@ module JSONAPI
|
|
400
406
|
# We're finding relationships for compound documents, so skip anything that doesn't exist.
|
401
407
|
next if object.nil?
|
402
408
|
|
403
|
-
#
|
404
|
-
#
|
405
|
-
# in the response. This can happen if the client already has the comments locally, and now
|
406
|
-
# wants to fetch the associated authors without fetching the comments again.
|
407
|
-
# http://jsonapi.org/format/#fetching-includes
|
409
|
+
# Full linkage: a request for comments.author MUST automatically include comments
|
410
|
+
# in the response.
|
408
411
|
objects = is_collection ? object : [object]
|
409
412
|
if child_inclusion_tree[:_include] == true
|
410
413
|
# Include the current level objects if the _include attribute exists.
|
data/spec/serializer_spec.rb
CHANGED
@@ -381,7 +381,7 @@ describe JSONAPI::Serializer do
|
|
381
381
|
'data' => serialize_primary(post, {serializer: MyApp::PostSerializer}),
|
382
382
|
})
|
383
383
|
end
|
384
|
-
it 'can include a top level errors node' do
|
384
|
+
it 'can include a top level errors node - deprecated' do
|
385
385
|
post = create(:post)
|
386
386
|
errors = [
|
387
387
|
{
|
@@ -400,6 +400,21 @@ describe JSONAPI::Serializer do
|
|
400
400
|
'data' => serialize_primary(post, {serializer: MyApp::PostSerializer}),
|
401
401
|
})
|
402
402
|
end
|
403
|
+
it 'can include a top level errors node' do
|
404
|
+
errors = [
|
405
|
+
{
|
406
|
+
"source" => { "pointer" => "/data/attributes/first-name" },
|
407
|
+
"title" => "Invalid Attribute",
|
408
|
+
"detail" => "First name must contain at least three characters."
|
409
|
+
},
|
410
|
+
{
|
411
|
+
"source" => { "pointer" => "/data/attributes/first-name" },
|
412
|
+
"title" => "Invalid Attribute",
|
413
|
+
"detail" => "First name must contain an emoji."
|
414
|
+
}
|
415
|
+
]
|
416
|
+
expect(JSONAPI::Serializer.serialize_errors(errors)).to eq({'errors' => errors})
|
417
|
+
end
|
403
418
|
it 'can serialize a single object with an `each` method by passing skip_collection_check: true' do
|
404
419
|
post = create(:post)
|
405
420
|
post.define_singleton_method(:each) do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi-serializers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Fotinakis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|