json_apiable 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +7 -3
- data/lib/json_apiable/params_parser.rb +1 -12
- data/lib/json_apiable/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2730ce86ac44faba4e0e0259559e346efe33442f474f9ba715aa2601045a02ac
|
4
|
+
data.tar.gz: f98a96c78028431660ac200e568b857133d581618594277a25829135a1a40cb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9646248670873df706251afa484cfc14cff8ac9f8fd3e3eea7465659b52fac3a1f4ffa5b5312ed3d4c570e3178d05354bb1d7991eaf7dbac3e27861bd510ec9b
|
7
|
+
data.tar.gz: 872d84af6b05e4396be7aece31fc8fff11c34690dc2f17cb5908b0d2c08d9cf9a2f06bc811e9de0e2b9a78e7edb9d12dd5c2a96365c46d95d1cb84bb5f5f1800
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -150,10 +150,14 @@ JsonApiable.configure do |config|
|
|
150
150
|
end
|
151
151
|
```
|
152
152
|
|
153
|
+
### Gotchas
|
154
|
+
- To make sure requests with invalid attributes/relationships result in a well-structured json-api error, configure your Rails app to raise
|
155
|
+
exceptions on invalid parameters (JsonApiable will catch them and return an appropriate response). In `config/application.rb` set `config.action_controller.action_on_unpermitted_parameters = :raise`
|
156
|
+
|
153
157
|
### Limitations
|
154
|
-
- `has_one` associations are
|
155
|
-
|
156
|
-
|
158
|
+
- `has_one` associations are expected to be represented as complex-attributes on the API level. So if User `has_one` Address,
|
159
|
+
than on the API level, JsonApiable expects address to be specified as a hash inside User's `attributes` rather than a separate relationship.
|
160
|
+
This makes sense in most cases. If your API represantion differs, `@post.update_attributes!(jsonapi_assign_params)` assignment won't work correctly.
|
157
161
|
|
158
162
|
## Development
|
159
163
|
|
@@ -24,18 +24,7 @@ module JsonApiable
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def self.validate_data_params!(params, attributes, relationships)
|
27
|
-
|
28
|
-
unpermitted = params.dig(:data)&.keys.to_a - permitted&.keys.to_a
|
29
|
-
raise ArgumentError, "Unpermitted member: #{unpermitted.first}" if unpermitted.present?
|
30
|
-
|
31
|
-
|
32
|
-
unpermitted_arguments = params.dig(:data, :attributes)&.keys.to_a - permitted.dig(:attributes)&.keys.to_a
|
33
|
-
raise ArgumentError, "Unpermitted attribute: #{unpermitted_arguments.first}" if unpermitted_arguments.present?
|
34
|
-
|
35
|
-
unpermitted_relationships = params.dig(:data, :relationships)&.keys.to_a - permitted.dig(:relationships)&.keys.to_a
|
36
|
-
raise ArgumentError, "Unpermitted relationship: #{unpermitted_relationships.first}" if unpermitted_relationships.present?
|
37
|
-
|
38
|
-
permitted
|
27
|
+
DataParams.build(params, attributes, relationships)
|
39
28
|
end
|
40
29
|
|
41
30
|
def self.build_attributes_hash(attributes, excluded_attributes)
|
data/lib/json_apiable/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_apiable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Polischuk
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|