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.
This commit is contained in:
Luke S
2019-12-02 18:42:03 -05:00
committed by GitHub
parent f41521e33b
commit 99d9d96dbb
+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,