typed_params 1.2.1 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/typed_params/formatters/jsonapi.rb +15 -11
- data/lib/typed_params/schema.rb +2 -0
- data/lib/typed_params/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f94106e5442d1a47d16c72246e4dd91a981a6bc574b2c341983c70d2407a252f
|
4
|
+
data.tar.gz: 28935e7de711ac1d8ef7b53ad46bc673b06a3537667d845adc9561b927f95a02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87fcccc2315b7216cd2e4d2e24c413fbf3e482bd4f49df486afed6335312dc19226bd72cf90665e23134b26ed8bab34bae9f4f3eb93720dc405790db3f3290dd
|
7
|
+
data.tar.gz: 3dd050bb4b2d4a8a01a434b8c44599b14e23bd9a0aec353d80cad127925f378177d63f3e5f58d736a33d40120ed3828217bfcd355f704e91d77e9ade49693b2c
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.2.3
|
4
|
+
|
5
|
+
- Remove `alias` from child lookup criteria in JSONAPI serializer.
|
6
|
+
|
7
|
+
## 1.2.2
|
8
|
+
|
9
|
+
- Fix issue where `as:` keyword was not handled in JSONAPI relationship formatter.
|
10
|
+
|
3
11
|
## 1.2.1
|
4
12
|
|
5
13
|
- Update JSONAPI formatter to simplify logic for polymorphic relationships.
|
@@ -58,9 +58,10 @@ module TypedParams
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def self.format_hash_data(data, schema:)
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
relationships = data[:relationships]
|
62
|
+
attributes = data[:attributes]
|
63
|
+
|
64
|
+
res = data.except(
|
64
65
|
:attributes,
|
65
66
|
:links,
|
66
67
|
:meta,
|
@@ -69,18 +70,21 @@ module TypedParams
|
|
69
70
|
)
|
70
71
|
|
71
72
|
# Move attributes over to top-level params
|
72
|
-
|
73
|
-
res[key] =
|
73
|
+
attributes&.each do |key, attribute|
|
74
|
+
res[key] = attribute
|
74
75
|
end
|
75
76
|
|
76
77
|
# Move relationships over. This will use x_id and x_ids when the
|
77
78
|
# relationship data only contains :type and :id, otherwise it
|
78
79
|
# will use the x_attributes key.
|
79
|
-
|
80
|
-
child = schema.children.fetch(:relationships)
|
81
|
-
|
82
|
-
|
83
|
-
|
80
|
+
relationships&.each do |key, relationship|
|
81
|
+
child = schema.children.fetch(:relationships).then do |rels|
|
82
|
+
rels.children.fetch(key) {
|
83
|
+
rels.children.values.find { _1.as == key }
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
case relationship
|
84
88
|
# FIXME(ezekg) We need https://bugs.ruby-lang.org/issues/18961 to
|
85
89
|
# clean this up (i.e. remove the if guard).
|
86
90
|
in data: [{ type:, id:, **nil }, *] => linkage if linkage.all? { _1 in type:, id:, **nil }
|
@@ -96,7 +100,7 @@ module TypedParams
|
|
96
100
|
else
|
97
101
|
# NOTE(ezekg) Embedded relationships are non-standard as per the
|
98
102
|
# JSONAPI spec, but I don't really care. :)
|
99
|
-
res[:"#{key}_attributes"] = call(
|
103
|
+
res[:"#{key}_attributes"] = call(relationship, schema: child)
|
100
104
|
end
|
101
105
|
end
|
102
106
|
|
data/lib/typed_params/schema.rb
CHANGED
@@ -10,6 +10,7 @@ module TypedParams
|
|
10
10
|
:source,
|
11
11
|
:type,
|
12
12
|
:key,
|
13
|
+
:as,
|
13
14
|
:alias,
|
14
15
|
:if,
|
15
16
|
:unless
|
@@ -80,6 +81,7 @@ module TypedParams
|
|
80
81
|
@strict = strict
|
81
82
|
@parent = parent
|
82
83
|
@key = key
|
84
|
+
@as = as
|
83
85
|
@alias = binding.local_variable_get(:alias)
|
84
86
|
@optional = optional
|
85
87
|
@coerce = coerce && @type.coercable?
|
data/lib/typed_params/version.rb
CHANGED