more documentation updates

This commit is contained in:
Mathew Polzin
2018-11-25 20:06:27 -08:00
parent 9f2c7aa2e4
commit 1a2ba17f02
+7 -3
View File
@@ -233,20 +233,24 @@ enum ISODateTransformer: Transformer {
}
```
Then you define the attribute as a `TransformAttribute` instead of an `Attribute`:
Then you define the attribute as a `TransformedAttribute` instead of an `Attribute`:
```
let date: TransformAttribute<String, ISODateTransformer>
let date: TransformedAttribute<String, ISODateTransformer>
```
Note that the first generic parameter of `TransformAttribute` is the type you expect to decode from JSON, not the type you want to end up with after transformation.
#### `Validator`
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.
### `JSONAPIDocument`
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:
```
let decoder = JSONDecoder()
let responseStructure = JSONAPIDocument<SingleResourceBody<Person>, NoMetadata, NoIncludes, BasicJSONAPIError>.self
let responseStructure = JSONAPIDocument<SingleResourceBody<Person>, NoMetadata, NoLinks, NoIncludes, BasicJSONAPIError>.self
let document = try decoder.decode(responseStructure, from: data)
```