jsonapi-serializers 0.6.5 → 0.7.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/.travis.yml +6 -0
- data/README.md +11 -0
- data/lib/jsonapi-serializers/serializer.rb +2 -0
- data/lib/jsonapi-serializers/version.rb +1 -1
- data/spec/serializer_spec.rb +19 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41b4f33131c66343d6703be670fe9a9e58f32c91
|
4
|
+
data.tar.gz: 5660da86b24a037e99e5cb21b7d60f484a8e6884
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc1f3bd07a774a7e2703a00f700280b3013ada8eda1977b12fd9525c8f5fee9f162a831d0c0d6c91bd0c01db383e52904bd8916179d523aa9a5fd5e9f16173a8
|
7
|
+
data.tar.gz: 940b4a24eedd64d9f5e568592972bd3c2f6c4e3e04ddefeedbaefd977f02016e707f5fb672629720def6db6b82cb2ea3e64fac95178188a65e0cc492a30697c6
|
data/.travis.yml
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
language: ruby
|
2
|
+
sudo: false
|
3
|
+
cache: bundler
|
2
4
|
rvm:
|
3
5
|
- 1.9.3
|
4
6
|
- 2.1.1
|
5
7
|
- 2.2.2
|
6
8
|
- ruby-head
|
9
|
+
before_install:
|
10
|
+
# TODO: remove this when this issue is fixed: https://github.com/travis-ci/travis-ci/issues/5798
|
11
|
+
- gem uninstall bundler -v 1.6.9
|
12
|
+
- gem install bundler
|
7
13
|
script: bundle exec rspec
|
data/README.md
CHANGED
@@ -19,6 +19,7 @@ This library is up-to-date with the finalized v1 JSON API spec.
|
|
19
19
|
* [More customizations](#more-customizations)
|
20
20
|
* [Base URL](#base-url)
|
21
21
|
* [Root metadata](#root-metadata)
|
22
|
+
* [Root errors](#root-errors)
|
22
23
|
* [Explicit serializer discovery](#explicit-serializer-discovery)
|
23
24
|
* [Relationships](#relationships)
|
24
25
|
* [Compound documents and includes](#compound-documents-and-includes)
|
@@ -315,6 +316,15 @@ You can pass a `meta` argument to specify top-level metadata:
|
|
315
316
|
JSONAPI::Serializer.serialize(post, meta: {copyright: 'Copyright 2015 Example Corp.'})
|
316
317
|
```
|
317
318
|
|
319
|
+
### Root errors
|
320
|
+
|
321
|
+
You can pass an `errors` argument to specify top-level errors:
|
322
|
+
|
323
|
+
```ruby
|
324
|
+
errors = [{ "title": "Invalid Attribute", "detail": "First name must contain at least three characters." }]
|
325
|
+
JSONAPI::Serializer.serialize(post, errors: errors)
|
326
|
+
```
|
327
|
+
|
318
328
|
### Explicit serializer discovery
|
319
329
|
|
320
330
|
By default, jsonapi-serializers assumes that the serializer class for `Namespace::User` is `Namespace::UserSerializer`. You can override this behavior on a per-object basis by implementing the `jsonapi_serializer_class_name` method.
|
@@ -652,6 +662,7 @@ end
|
|
652
662
|
|
653
663
|
## Release notes
|
654
664
|
|
665
|
+
* v0.7.0: Support for root error objects.
|
655
666
|
* v0.6.5: Exclude attributes when empty.
|
656
667
|
* v0.6.4: Fix regression of including links when empty.
|
657
668
|
* v0.6.3: Fix support for underscore-formatted attribute names.
|
@@ -234,6 +234,7 @@ module JSONAPI
|
|
234
234
|
options[:skip_collection_check] = options.delete('skip_collection_check') || options[:skip_collection_check] || false
|
235
235
|
options[:base_url] = options.delete('base_url') || options[:base_url]
|
236
236
|
options[:meta] = options.delete('meta') || options[:meta]
|
237
|
+
options[:errors] = options.delete('errors') || options[:errors]
|
237
238
|
|
238
239
|
# Normalize includes.
|
239
240
|
includes = options[:include]
|
@@ -284,6 +285,7 @@ module JSONAPI
|
|
284
285
|
'data' => primary_data,
|
285
286
|
}
|
286
287
|
result['meta'] = options[:meta] if options[:meta]
|
288
|
+
result['errors'] = options[:errors] if options[:errors]
|
287
289
|
|
288
290
|
# If 'include' relationships are given, recursively find and include each object.
|
289
291
|
if includes
|
data/spec/serializer_spec.rb
CHANGED
@@ -381,6 +381,25 @@ 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
|
385
|
+
post = create(:post)
|
386
|
+
errors = [
|
387
|
+
{
|
388
|
+
"source" => { "pointer" => "/data/attributes/first-name" },
|
389
|
+
"title" => "Invalid Attribute",
|
390
|
+
"detail" => "First name must contain at least three characters."
|
391
|
+
},
|
392
|
+
{
|
393
|
+
"source" => { "pointer" => "/data/attributes/first-name" },
|
394
|
+
"title" => "Invalid Attribute",
|
395
|
+
"detail" => "First name must contain an emoji."
|
396
|
+
}
|
397
|
+
]
|
398
|
+
expect(JSONAPI::Serializer.serialize(post, errors: errors)).to eq({
|
399
|
+
'errors' => errors,
|
400
|
+
'data' => serialize_primary(post, {serializer: MyApp::PostSerializer}),
|
401
|
+
})
|
402
|
+
end
|
384
403
|
it 'can serialize a single object with an `each` method by passing skip_collection_check: true' do
|
385
404
|
post = create(:post)
|
386
405
|
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.7.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-03-
|
11
|
+
date: 2016-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
version: '0'
|
124
124
|
requirements: []
|
125
125
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.
|
126
|
+
rubygems_version: 2.2.2
|
127
127
|
signing_key:
|
128
128
|
specification_version: 4
|
129
129
|
summary: Pure Ruby readonly serializers for the JSON:API spec.
|
@@ -132,4 +132,3 @@ test_files:
|
|
132
132
|
- spec/spec_helper.rb
|
133
133
|
- spec/support/factory.rb
|
134
134
|
- spec/support/serializers.rb
|
135
|
-
has_rdoc:
|