grape_fast_jsonapi 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b2ef04c9a3d2b69160a93779d60466a90a93fed1bf1109e1e32c91e8632bad8
4
- data.tar.gz: 1ba50c7bdf05a933b7c736f2a4f36e55f5bc3d4742bb2d552260760eb63dffe2
3
+ metadata.gz: c949823976af65fb4896c7a49333309978436c22324d79f296d6fb02fc4734db
4
+ data.tar.gz: 6381b94d235e84227841b123ae7b70a9b819d244473bd62180c59738997eca5c
5
5
  SHA512:
6
- metadata.gz: d5175b87b19aca5fd04a5532d901ff03f41c06f1792de26f15b0c452f5e8a3357a0237a3ad6c835bb19da20cb3b09133e08b093e3680837307e3fa23d57b1317
7
- data.tar.gz: 148a701839831d1b6b384b93ceddcfe07799eef6b233ec7e8df449711e94a2b4cf673cc859ab8760a96f4d20d85b4ff3c16d487c63489fac589eac3e88485c8e
6
+ metadata.gz: 61dc166df0aa1a94506aaa609016a805810bbf8d3589c1457764324cd418d75cc4cad8891235d056e22a8ea2d751efcb528ad236a7c7b93c764d5b17a1594331
7
+ data.tar.gz: 9f812886c303cc04a96a6b3e4380da40805e7614a3cfd36324823c52831e47dc3a3aaa6423302d01cf2e6ea3b1543b2990eda387edad8eb79d26f4b0cd349fbc
data/CHANGELOG.md CHANGED
@@ -1,9 +1,13 @@
1
1
  ## Changelog
2
2
 
3
- ### v0.2.4 (Next)
3
+ ### v0.2.5 (Next)
4
4
 
5
5
  * Your contribution here.
6
6
 
7
+ ### v0.2.4 (December 16, 2019)
8
+
9
+ * [#15](https://github.com/EmCousin/grape_fast_jsonapi/pull/15) - Handle serializers which don't have any attributes - [@vesan](https://github.com/vesan)
10
+
7
11
  ### v0.2.3 (December 12, 2019)
8
12
 
9
13
  * Reverted v0.2.2 and bumped `loofah` using `dependabot`
@@ -19,7 +23,7 @@
19
23
  ### v0.2.0 (February 8, 2019)
20
24
 
21
25
  * [#5](https://github.com/EmCousin/grape_fast_jsonapi/pull/5): Provide custom Grape Swagger parser for fast_jsonapi object serializers, as well as unit test coverage - [@EmCousin](https://github.com/EmCousin)
22
- * [#6](https://github.com/EmCousin/grape_fast_jsonapi/pull/6) - Fix to make the parser compatible with latest version of fast_jsonapi (1.5 at date) - @rromanchuk](https://github.com/rromanchuk).
26
+ * [#6](https://github.com/EmCousin/grape_fast_jsonapi/pull/6) - Fix to make the parser compatible with latest version of fast_jsonapi (1.5 at date) - [@rromanchuk](https://github.com/rromanchuk).
23
27
 
24
28
  ### v0.1.0
25
29
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grape_fast_jsonapi (0.2.3)
4
+ grape_fast_jsonapi (0.2.4)
5
5
  fast_jsonapi (>= 1.5)
6
6
  grape
7
7
 
data/README.md CHANGED
@@ -56,8 +56,11 @@ When using Grape with Swagger via [grape-swagger](https://github.com/ruby-grape/
56
56
 
57
57
  ```ruby
58
58
  # FastJsonapi serializer example
59
+
60
+ # app/serializers/base_serializer.rb
61
+ class BaseSerializer; end
59
62
  # app/serializers/user_serializer.rb
60
- class UserSerializer
63
+ class UserSerializer < BaseSerializer
61
64
  include FastJsonapi::ObjectSerializer
62
65
 
63
66
  set_type :user
@@ -67,12 +70,13 @@ class UserSerializer
67
70
  end
68
71
 
69
72
  # config/initializers/grape_swagger.rb
70
- GrapeSwagger.model_parsers.register(GrapeSwagger::FastJsonapi::Parser, UserSerializer)
73
+ GrapeSwagger.model_parsers.register(GrapeSwagger::FastJsonapi::Parser, BaseSerializer)
71
74
 
72
75
  # Your grape API endpoint
73
- desc 'Get current user',
74
- success: { code: 200, model: UserSerializer, message: 'The current user' }
76
+ desc 'Get current user' do
77
+ success code: 200, model: UserSerializer, message: 'The current user'
75
78
  # [...]
79
+ end
76
80
  ```
77
81
 
78
82
  Note that you **need** the `grape-swagger` gem for this to work, otherwise it will throw an error.
@@ -83,7 +83,7 @@ module GrapeSwagger
83
83
 
84
84
  def map_model_attributes
85
85
  attributes = {}
86
- model.attributes_to_serialize.each do |attribute, _|
86
+ (model.attributes_to_serialize || []).each do |attribute, _|
87
87
  attributes[attribute] = :string
88
88
  end
89
89
  attributes
@@ -175,4 +175,4 @@ module GrapeSwagger
175
175
  end
176
176
  end
177
177
  end
178
- end
178
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Grape
4
4
  module FastJsonapi
5
- VERSION = '0.2.3'.freeze
5
+ VERSION = '0.2.4'.freeze
6
6
  end
7
7
  end
@@ -126,6 +126,53 @@ describe GrapeSwagger::FastJsonapi::Parser do
126
126
  })
127
127
  end
128
128
  end
129
+ context 'when the serializer doesn\'t have any attributes' do
130
+ let(:model) { AnotherBlogPostSerializer } # no attributes
131
+
132
+ it 'return a hash defining the schema with empty attributes' do
133
+ expect(subject).to eq({
134
+ data: {
135
+ type: :object,
136
+ properties: {
137
+ id: { type: :integer },
138
+ type: { type: :string },
139
+ attributes: {
140
+ type: :object,
141
+ properties: {}
142
+ },
143
+ relationships: {
144
+ type: :object,
145
+ properties: {
146
+ user: {
147
+ properties: {
148
+ data: {
149
+ properties: {
150
+ id: { type: :integer },
151
+ type: { type: :string }
152
+ },
153
+ type: :object,
154
+ }
155
+ },
156
+ type: :object,
157
+ }
158
+ }
159
+ }
160
+ },
161
+ example: {
162
+ id: 1,
163
+ type: :blog_post,
164
+ attributes: {
165
+ },
166
+ relationships: {
167
+ user: {
168
+ data: { id: 1, type: :user }
169
+ }
170
+ }
171
+ }
172
+ }
173
+ })
174
+ end
175
+ end
129
176
  end
130
177
  end
131
- end
178
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  describe Grape::FastJsonapi::VERSION do
4
- it { is_expected.to eq '0.2.3' }
4
+ it { is_expected.to eq '0.2.4' }
5
5
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AnotherBlogPostSerializer
4
+ include FastJsonapi::ObjectSerializer
5
+
6
+ set_type :blog_post
7
+
8
+ belongs_to :user
9
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape_fast_jsonapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emmanuel Cousin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-12 00:00:00.000000000 Z
11
+ date: 2019-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grape
@@ -94,6 +94,7 @@ files:
94
94
  - spec/spec_helper.rb
95
95
  - spec/support/models/blog_post.rb
96
96
  - spec/support/models/user.rb
97
+ - spec/support/serializers/another_blog_post_serializer.rb
97
98
  - spec/support/serializers/another_user_serializer.rb
98
99
  - spec/support/serializers/blog_post_serializer.rb
99
100
  - spec/support/serializers/user_serializer.rb
@@ -127,6 +128,7 @@ test_files:
127
128
  - spec/spec_helper.rb
128
129
  - spec/support/models/blog_post.rb
129
130
  - spec/support/models/user.rb
131
+ - spec/support/serializers/another_blog_post_serializer.rb
130
132
  - spec/support/serializers/another_user_serializer.rb
131
133
  - spec/support/serializers/blog_post_serializer.rb
132
134
  - spec/support/serializers/user_serializer.rb