Compare commits

..

3 Commits

Author SHA1 Message Date
Luke S 99d9d96dbb Permit missing data key for optional relationships
This prevents a decoding error when `included[].relationships.*.data` is missing, using the same logic as if it was nil.
2019-12-02 18:42:03 -05:00
Mathew Polzin f41521e33b Update example indentation 2019-11-16 00:06:49 -08:00
Mathew Polzin 45ec7ba753 Update SwiftPM package manifest example for version 3 2019-11-16 00:03:46 -08:00
2 changed files with 9 additions and 7 deletions
+8 -6
View File
@@ -66,7 +66,7 @@ If you find something wrong with this library and it isn't already mentioned und
### Swift Package Manager
Just include the following in your package's dependencies and add `JSONAPI` to the dependencies for any of your targets.
```
.package(url: "https://github.com/mattpolzin/JSONAPI.git", .upToNextMajor(from: "2.2.0"))
.package(url: "https://github.com/mattpolzin/JSONAPI.git", .upToNextMajor(from: "3.0.0"))
```
### Xcode project
@@ -317,11 +317,13 @@ Literal expressibility for `Attribute`, `ToOneRelationship`, and `Id` are provid
For example, you could create a mock `Author` (from the above example) as follows
```swift
let author = Author(id: "1234", // You can just use a String directly as an Id
attributes: .init(name: "Janice Bluff"), // The name Attribute does not need to be initialized, you just use a String directly.
relationships: .none,
meta: .none,
links: .none)
let author = Author(
id: "1234", // You can just use a String directly as an Id
attributes: .init(name: "Janice Bluff"), // The name Attribute does not need to be initialized, you just use a String directly.
relationships: .none,
meta: .none,
links: .none
)
```
## Resource Object `check()`
+1 -1
View File
@@ -170,7 +170,7 @@ extension ToOneRelationship: Codable where Identifiable.Identifier: OptionalId {
// succeeds and then attempt to coerce nil to a Identifier
// type at which point we can store nil in `id`.
let anyNil: Any? = nil
if try container.decodeNil(forKey: .data) {
if try !container.contains(.data) || container.decodeNil(forKey: .data) {
guard let val = anyNil as? Identifiable.Identifier else {
throw DecodingError.valueNotFound(
Self.self,