grape_fast_jsonapi 0.2.3 → 0.2.4
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/CHANGELOG.md +6 -2
- data/Gemfile.lock +1 -1
- data/README.md +8 -4
- data/lib/grape_fast_jsonapi/parser.rb +2 -2
- data/lib/grape_fast_jsonapi/version.rb +1 -1
- data/spec/lib/grape_fast_jsonapi/parser_spec.rb +48 -1
- data/spec/lib/grape_fast_jsonapi/version_spec.rb +1 -1
- data/spec/support/serializers/another_blog_post_serializer.rb +9 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c949823976af65fb4896c7a49333309978436c22324d79f296d6fb02fc4734db
|
4
|
+
data.tar.gz: 6381b94d235e84227841b123ae7b70a9b819d244473bd62180c59738997eca5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
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,
|
73
|
+
GrapeSwagger.model_parsers.register(GrapeSwagger::FastJsonapi::Parser, BaseSerializer)
|
71
74
|
|
72
75
|
# Your grape API endpoint
|
73
|
-
desc 'Get current user'
|
74
|
-
success
|
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
|
@@ -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
|
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.
|
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-
|
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
|