From 3b0e7a02d7d4b855b034bfc439e6f949e108e486 Mon Sep 17 00:00:00 2001 From: Doan Thieu Date: Wed, 28 Jun 2023 08:22:25 +0700 Subject: [PATCH] [Chore] Decode Resource without `id` --- Sources/JSONAPIMapper/Models/Resource.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/JSONAPIMapper/Models/Resource.swift b/Sources/JSONAPIMapper/Models/Resource.swift index b19b249..cf4f0ba 100644 --- a/Sources/JSONAPIMapper/Models/Resource.swift +++ b/Sources/JSONAPIMapper/Models/Resource.swift @@ -22,7 +22,7 @@ public struct Resource: JSONAPICodable { public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: .id) + id = (try? container.decode(String.self, forKey: .id)) ?? "" type = try container.decode(String.self, forKey: .type) attributes = try container.decodeIfPresent(JSON.self, forKey: .attributes) relationships = try container.decodeIfPresent([String: Relationship].self, forKey: .relationships)