Skip to content

Remove throwing error when there no dictionary for an identifier #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Once you have your Swift package set up, adding Alamofire as a dependency is as

```swift
dependencies: [
.package(url: "https://github.com/nimblehq/JSONMapper.git", .upToNextMajor(from: "1.0.1"))
.package(url: "https://github.com/nimblehq/JSONMapper.git", .upToNextMajor(from: "1.0.2"))
]
```

Expand Down
2 changes: 1 addition & 1 deletion Sources/JSONMapper/JSONAPIDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ extension JSONAPIDecoder {
private func getResource(from includedDictionary: ResourceDictionary,
for identifier: ResourceIdentifier) throws -> Resource {
guard let resource = includedDictionary[identifier] else {
throw Errors.JSONAPIDecodingError.resourceNotFound(identifier: identifier)
return Resource(id: identifier.id, type: identifier.type)
}
return resource
}
Expand Down
9 changes: 9 additions & 0 deletions Sources/JSONMapper/Models/Resource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,13 @@ public struct Resource: JSONAPICodable {
links = try container.decodeIfPresent(Links.self, forKey: .links)
meta = try container.decodeIfPresent(JSON.self, forKey: .meta)
}

init(id: String, type: String) {
self.id = id
self.type = type
self.attributes = nil
self.relationships = nil
self.links = nil
self.meta = nil
}
}