jsonapi_compliable 0.11.29 → 0.11.34
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.ruby-version +1 -1
- data/.travis.yml +2 -1
- data/jsonapi_compliable.gemspec +1 -1
- data/lib/jsonapi_compliable/base.rb +1 -1
- data/lib/jsonapi_compliable/deserializer.rb +11 -2
- data/lib/jsonapi_compliable/query.rb +4 -2
- data/lib/jsonapi_compliable/scope.rb +1 -1
- data/lib/jsonapi_compliable/util/validation_response.rb +8 -6
- data/lib/jsonapi_compliable/version.rb +1 -1
- metadata +10 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2b577a79ded38bd4613b559334071632b188d2b78f14cc0cb882b5375a37b5a4
|
4
|
+
data.tar.gz: 49f8349533f4dcd5be4344b4bf54997eaef316cd279611ca830e323ee421f9e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fb80bd50abadabaab56dabc4fb9f20bd2638e2da29cea7b51e5040a388d15f0ce02c2df0dbcd70d7d01b428d4de15fdfd7134a872f45da197e5a39f55776829
|
7
|
+
data.tar.gz: 00f3c45f9deb647c227d575d17589b6354025b415e7012c96722f3069eccebd2829cebcfd37987f4180e433826835039aaf3b1b82dabd5634bd760a20c7bafef
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.5.2
|
data/.travis.yml
CHANGED
data/jsonapi_compliable.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
|
23
23
|
spec.add_development_dependency "activerecord", ['>= 4.1', '< 6']
|
24
24
|
spec.add_development_dependency "kaminari", '~> 0.17'
|
25
|
-
spec.add_development_dependency "bundler", "~> 1.
|
25
|
+
spec.add_development_dependency "bundler", "~> 2.1.4"
|
26
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
27
27
|
spec.add_development_dependency "sqlite3"
|
28
28
|
spec.add_development_dependency "database_cleaner"
|
@@ -48,14 +48,23 @@ class JsonapiCompliable::Deserializer
|
|
48
48
|
# @param payload [Hash] The incoming payload with symbolized keys
|
49
49
|
# @param env [Hash] the Rack env (e.g. +request.env+).
|
50
50
|
def initialize(payload, env)
|
51
|
-
@payload = payload
|
51
|
+
@payload = payload || {}
|
52
52
|
@payload = @payload[:_jsonapi] if @payload.has_key?(:_jsonapi)
|
53
53
|
@env = env
|
54
|
+
validate_content_type
|
55
|
+
end
|
56
|
+
|
57
|
+
# checks Content-Type header and prints a warning if it doesn't seem correct
|
58
|
+
def validate_content_type
|
59
|
+
content_type = @env['CONTENT_TYPE'] || ""
|
60
|
+
if !(content_type.include?("application/json") || content_type.include?("application/vnd.api+json"))
|
61
|
+
print("WARNING - JSONAPI Compliable :: Content-Type header appears to be set to an invalid value: #{content_type}\n")
|
62
|
+
end
|
54
63
|
end
|
55
64
|
|
56
65
|
# @return [Hash] the raw :data value of the payload
|
57
66
|
def data
|
58
|
-
@payload[:data]
|
67
|
+
@payload[:data] || {}
|
59
68
|
end
|
60
69
|
|
61
70
|
# @return [String] the raw :id value of the payload
|
@@ -209,8 +209,10 @@ module JsonapiCompliable
|
|
209
209
|
key = key.to_sym
|
210
210
|
|
211
211
|
if association?(key)
|
212
|
-
|
213
|
-
|
212
|
+
symbolized_hash = value.to_h.each_with_object({}) do |(k, v), hash|
|
213
|
+
hash[k.to_sym] = v
|
214
|
+
end
|
215
|
+
hash[key][:filter].merge!(symbolized_hash)
|
214
216
|
else
|
215
217
|
hash[resource.type][:filter][key] = value
|
216
218
|
end
|
@@ -45,26 +45,28 @@ class JsonapiCompliable::Util::ValidationResponse
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def all_valid?(model, deserialized_params)
|
48
|
-
|
49
|
-
|
48
|
+
checks = []
|
49
|
+
checks << valid_object?(model)
|
50
50
|
deserialized_params.each_pair do |name, payload|
|
51
51
|
if payload.is_a?(Array)
|
52
52
|
related_objects = model.send(name)
|
53
|
-
related_objects.
|
53
|
+
related_objects.each_with_index do |r, index|
|
54
54
|
valid = valid_object?(r)
|
55
|
+
checks << valid
|
55
56
|
|
56
57
|
if valid
|
57
|
-
|
58
|
+
checks << all_valid?(r, payload[index][:relationships] || {})
|
58
59
|
end
|
59
60
|
end
|
60
61
|
else
|
61
62
|
related_object = model.send(name)
|
62
63
|
valid = valid_object?(related_object)
|
64
|
+
checks << valid
|
63
65
|
if valid
|
64
|
-
|
66
|
+
checks << all_valid?(related_object, payload[:relationships] || {})
|
65
67
|
end
|
66
68
|
end
|
67
69
|
end
|
68
|
-
|
70
|
+
checks.all? { |c| c == true }
|
69
71
|
end
|
70
72
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi_compliable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.34
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Richmond
|
8
8
|
- Venkata Pasupuleti
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-11-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jsonapi-serializable
|
@@ -65,14 +65,14 @@ dependencies:
|
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 2.1.4
|
69
69
|
type: :development
|
70
70
|
prerelease: false
|
71
71
|
version_requirements: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 2.1.4
|
76
76
|
- !ruby/object:Gem::Dependency
|
77
77
|
name: rake
|
78
78
|
requirement: !ruby/object:Gem::Requirement
|
@@ -115,7 +115,7 @@ dependencies:
|
|
115
115
|
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
|
-
description:
|
118
|
+
description:
|
119
119
|
email:
|
120
120
|
- richmolj@gmail.com
|
121
121
|
- spasupuleti4@bloomberg.net
|
@@ -253,11 +253,11 @@ files:
|
|
253
253
|
- lib/jsonapi_compliable/util/sideload.rb
|
254
254
|
- lib/jsonapi_compliable/util/validation_response.rb
|
255
255
|
- lib/jsonapi_compliable/version.rb
|
256
|
-
homepage:
|
256
|
+
homepage:
|
257
257
|
licenses:
|
258
258
|
- MIT
|
259
259
|
metadata: {}
|
260
|
-
post_install_message:
|
260
|
+
post_install_message:
|
261
261
|
rdoc_options: []
|
262
262
|
require_paths:
|
263
263
|
- lib
|
@@ -272,9 +272,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
272
272
|
- !ruby/object:Gem::Version
|
273
273
|
version: '0'
|
274
274
|
requirements: []
|
275
|
-
|
276
|
-
|
277
|
-
signing_key:
|
275
|
+
rubygems_version: 3.0.6
|
276
|
+
signing_key:
|
278
277
|
specification_version: 4
|
279
278
|
summary: Easily build jsonapi.org-compatible APIs
|
280
279
|
test_files: []
|