Skip to content

Commit 7be29ab

Browse files
authored
Merge pull request #4 from nimblehq/feature/empty-dictionary
Remove throwing error when there no dictionary for an identifier
2 parents d40a5a0 + 82f682e commit 7be29ab

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Once you have your Swift package set up, adding Alamofire as a dependency is as
1212

1313
```swift
1414
dependencies: [
15-
.package(url: "https://github.com/nimblehq/JSONMapper.git", .upToNextMajor(from: "1.0.1"))
15+
.package(url: "https://github.com/nimblehq/JSONMapper.git", .upToNextMajor(from: "1.0.2"))
1616
]
1717
```
1818

Sources/JSONMapper/JSONAPIDecoder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ extension JSONAPIDecoder {
129129
private func getResource(from includedDictionary: ResourceDictionary,
130130
for identifier: ResourceIdentifier) throws -> Resource {
131131
guard let resource = includedDictionary[identifier] else {
132-
throw Errors.JSONAPIDecodingError.resourceNotFound(identifier: identifier)
132+
return Resource(id: identifier.id, type: identifier.type)
133133
}
134134
return resource
135135
}

Sources/JSONMapper/Models/Resource.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,13 @@ public struct Resource: JSONAPICodable {
2929
links = try container.decodeIfPresent(Links.self, forKey: .links)
3030
meta = try container.decodeIfPresent(JSON.self, forKey: .meta)
3131
}
32+
33+
init(id: String, type: String) {
34+
self.id = id
35+
self.type = type
36+
self.attributes = nil
37+
self.relationships = nil
38+
self.links = nil
39+
self.meta = nil
40+
}
3241
}

0 commit comments

Comments
 (0)