You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+11-1Lines changed: 11 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -100,7 +100,7 @@ To create an Xcode project for JSONAPI, run
100
100
-[x] Roll my own `Result` or find an alternative that doesn't use `Foundation`.
101
101
-[ ] Create more descriptive errors that are easier to use for troubleshooting.
102
102
-[x] Make it easier to construct `Attributes` and `Relationships` values in test cases (literal expressibility).
103
-
-[] Make `TransformedAttribute` a Monad (or at least a Functor).
103
+
-[x] Make `TransformedAttribute` a Functor.
104
104
105
105
## Usage
106
106
@@ -257,6 +257,16 @@ Note that the first generic parameter of `TransformAttribute` is the type you ex
257
257
258
258
You can also creator `Validator`s and `ValidatedAttribute`s. A `Validator` is just a `Transformer` that by convention does not perform a transformation. It simply `throws` if an attribute value is invalid.
259
259
260
+
#### Computed `Attribute`
261
+
262
+
You can add computed properties to your `EntityDescription.Attributes` struct if you would like to expose attributes that are not explicitly represented by the JSON. These computed properties should still have the type `Attribute` because that way you can take advantage of the quick access provided by `Entity`'s subscript operator. Here's an example of how you might take the `Person[\.name]` attribute from the example above and create a `fullName` computed property.
263
+
264
+
```
265
+
public var fullName: Attribute<String> {
266
+
return name.map { $0.joined(separator: " ") }
267
+
}
268
+
```
269
+
260
270
### `JSONAPIDocument`
261
271
262
272
The entirety of a JSON API request or response is encoded or decoded from- or to a `JSONAPIDocument`. As an example, a JSON API response containing one `Person` and no included entities could be decoded as follows:
0 commit comments