Skip to content

Commit a8bda31

Browse files
committed
Update unions to take in unknown types
1 parent 64192b4 commit a8bda31

25 files changed

+94
-94
lines changed

Sources/ATProtoKit/Models/Lexicons/app.bsky/Actor/AppBskyActorDefs.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ extension AppBskyLexicon.Actor {
785785
// Implement custom decoding
786786
public init(from decoder: Decoder) throws {
787787
let container = try decoder.container(keyedBy: CodingKeys.self)
788-
let type = try container.decode(String.self, forKey: .type)
788+
let type = try container.decodeIfPresent(String.self, forKey: .type)
789789

790790
switch type {
791791
case "app.bsky.actor.defs#adultContentPref":
@@ -820,7 +820,7 @@ extension AppBskyLexicon.Actor {
820820
let singleValueDecodingContainer = try decoder.singleValueContainer()
821821
let dictionary = try Self.decodeDictionary(from: singleValueDecodingContainer, decoder: decoder)
822822

823-
self = .unknown(type, dictionary)
823+
self = .unknown(type ?? "unknown", dictionary)
824824
}
825825
}
826826

@@ -1740,7 +1740,7 @@ extension AppBskyLexicon.Actor {
17401740

17411741
public init(from decoder: any Decoder) throws {
17421742
let container = try decoder.container(keyedBy: CodingKeys.self)
1743-
let type = try container.decode(String.self, forKey: .type)
1743+
let type = try container.decodeIfPresent(String.self, forKey: .type)
17441744

17451745
switch type {
17461746
case "app.bsky.feed.threadgate#mentionRule":
@@ -1755,7 +1755,7 @@ extension AppBskyLexicon.Actor {
17551755
let singleValueDecodingContainer = try decoder.singleValueContainer()
17561756
let dictionary = try Self.decodeDictionary(from: singleValueDecodingContainer, decoder: decoder)
17571757

1758-
self = .unknown(type, dictionary)
1758+
self = .unknown(type ?? "unknown", dictionary)
17591759
}
17601760
}
17611761

@@ -1792,7 +1792,7 @@ extension AppBskyLexicon.Actor {
17921792

17931793
public init(from decoder: any Decoder) throws {
17941794
let container = try decoder.container(keyedBy: CodingKeys.self)
1795-
let type = try container.decode(String.self, forKey: .type)
1795+
let type = try container.decodeIfPresent(String.self, forKey: .type)
17961796

17971797
switch type {
17981798
case "app.bsky.feed.postgate#disableRule":
@@ -1801,7 +1801,7 @@ extension AppBskyLexicon.Actor {
18011801
let singleValueDecodingContainer = try decoder.singleValueContainer()
18021802
let dictionary = try Self.decodeDictionary(from: singleValueDecodingContainer, decoder: decoder)
18031803

1804-
self = .unknown(type, dictionary)
1804+
self = .unknown(type ?? "unknown", dictionary)
18051805
}
18061806
}
18071807

@@ -1948,7 +1948,7 @@ extension AppBskyLexicon.Actor {
19481948

19491949
public init(from decoder: any Decoder) throws {
19501950
let container = try decoder.container(keyedBy: CodingKeys.self)
1951-
let type = try container.decode(String.self, forKey: .type)
1951+
let type = try container.decodeIfPresent(String.self, forKey: .type)
19521952

19531953
switch type {
19541954
case "app.bsky.embed.external#view":
@@ -1957,7 +1957,7 @@ extension AppBskyLexicon.Actor {
19571957
let singleValueDecodingContainer = try decoder.singleValueContainer()
19581958
let dictionary = try Self.decodeDictionary(from: singleValueDecodingContainer, decoder: decoder)
19591959

1960-
self = .unknown(type, dictionary)
1960+
self = .unknown(type ?? "unknown", dictionary)
19611961
}
19621962
}
19631963

Sources/ATProtoKit/Models/Lexicons/app.bsky/Embed/AppBskyEmbedRecord.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ extension AppBskyLexicon.Embed {
9090

9191
public init(from decoder: Decoder) throws {
9292
let container = try decoder.container(keyedBy: CodingKeys.self)
93-
let type = try container.decode(String.self, forKey: .type)
93+
let type = try container.decodeIfPresent(String.self, forKey: .type)
9494

9595
switch type {
9696
case "app.bsky.embed.record#viewRecord":
@@ -113,7 +113,7 @@ extension AppBskyLexicon.Embed {
113113
let singleValueDecodingContainer = try decoder.singleValueContainer()
114114
let dictionary = try Self.decodeDictionary(from: singleValueDecodingContainer, decoder: decoder)
115115

116-
self = .unknown(type, dictionary)
116+
self = .unknown(type ?? "unknown", dictionary)
117117
}
118118
}
119119

@@ -266,7 +266,7 @@ extension AppBskyLexicon.Embed {
266266

267267
public init(from decoder: Decoder) throws {
268268
let container = try decoder.container(keyedBy: CodingKeys.self)
269-
let type = try container.decode(String.self, forKey: .type)
269+
let type = try container.decodeIfPresent(String.self, forKey: .type)
270270

271271
switch type {
272272
case "app.bsky.embed.external#view":
@@ -283,7 +283,7 @@ extension AppBskyLexicon.Embed {
283283
let singleValueDecodingContainer = try decoder.singleValueContainer()
284284
let dictionary = try Self.decodeDictionary(from: singleValueDecodingContainer, decoder: decoder)
285285

286-
self = .unknown(type, dictionary)
286+
self = .unknown(type ?? "unknown", dictionary)
287287

288288
}
289289
}

Sources/ATProtoKit/Models/Lexicons/app.bsky/Embed/AppBskyEmbedRecordWithMedia.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ extension AppBskyLexicon.Embed {
5858

5959
public init(from decoder: Decoder) throws {
6060
let container = try decoder.container(keyedBy: CodingKeys.self)
61-
let type = try container.decode(String.self, forKey: .type)
61+
let type = try container.decodeIfPresent(String.self, forKey: .type)
6262

6363
switch type {
6464
case "app.bsky.embed.images":
@@ -71,7 +71,7 @@ extension AppBskyLexicon.Embed {
7171
let singleValueDecodingContainer = try decoder.singleValueContainer()
7272
let dictionary = try Self.decodeDictionary(from: singleValueDecodingContainer, decoder: decoder)
7373

74-
self = .unknown(type, dictionary)
74+
self = .unknown(type ?? "unknown", dictionary)
7575
}
7676
}
7777

Sources/ATProtoKit/Models/Lexicons/app.bsky/Feed/AppBskyFeedDefs.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ extension AppBskyLexicon.Feed {
140140

141141
public init(from decoder: Decoder) throws {
142142
let container = try decoder.container(keyedBy: CodingKeys.self)
143-
let type = try container.decode(String.self, forKey: .type)
143+
let type = try container.decodeIfPresent(String.self, forKey: .type)
144144

145145
switch type {
146146
case "app.bsky.embed.images#view":
@@ -157,7 +157,7 @@ extension AppBskyLexicon.Feed {
157157
let singleValueDecodingContainer = try decoder.singleValueContainer()
158158
let dictionary = try Self.decodeDictionary(from: singleValueDecodingContainer, decoder: decoder)
159159

160-
self = .unknown(type, dictionary)
160+
self = .unknown(type ?? "unknown", dictionary)
161161
}
162162
}
163163

@@ -305,7 +305,7 @@ extension AppBskyLexicon.Feed {
305305

306306
public init(from decoder: any Decoder) throws {
307307
let container = try decoder.container(keyedBy: CodingKeys.self)
308-
let type = try container.decode(String.self, forKey: .type)
308+
let type = try container.decodeIfPresent(String.self, forKey: .type)
309309

310310
switch type {
311311
case "app.bsky.feed.defs#reasonRepost":
@@ -316,7 +316,7 @@ extension AppBskyLexicon.Feed {
316316
let singleValueDecodingContainer = try decoder.singleValueContainer()
317317
let dictionary = try Self.decodeDictionary(from: singleValueDecodingContainer, decoder: decoder)
318318

319-
self = .unknown(type, dictionary)
319+
self = .unknown(type ?? "unknown", dictionary)
320320
}
321321
}
322322

Sources/ATProtoKit/Models/Lexicons/app.bsky/Feed/AppBskyFeedGenerator.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ extension AppBskyLexicon.Feed {
130130

131131
public init(from decoder: Decoder) throws {
132132
let container = try decoder.container(keyedBy: CodingKeys.self)
133-
let type = try container.decode(String.self, forKey: .type)
133+
let type = try container.decodeIfPresent(String.self, forKey: .type)
134134

135135
switch type {
136136
case "com.atproto.label.defs#selfLabels":
@@ -139,7 +139,7 @@ extension AppBskyLexicon.Feed {
139139
let singleValueDecodingContainer = try decoder.singleValueContainer()
140140
let dictionary = try Self.decodeDictionary(from: singleValueDecodingContainer, decoder: decoder)
141141

142-
self = .unknown(type, dictionary)
142+
self = .unknown(type ?? "unknown", dictionary)
143143
}
144144
}
145145

Sources/ATProtoKit/Models/Lexicons/app.bsky/Feed/AppBskyFeedGetPostThread.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ extension AppBskyLexicon.Feed {
4646

4747
public init(from decoder: Decoder) throws {
4848
let container = try decoder.container(keyedBy: CodingKeys.self)
49-
let type = try container.decode(String.self, forKey: .type)
49+
let type = try container.decodeIfPresent(String.self, forKey: .type)
5050

5151
switch type {
5252
case "app.bsky.feed.defs#threadViewPost":
@@ -59,7 +59,7 @@ extension AppBskyLexicon.Feed {
5959
let singleValueDecodingContainer = try decoder.singleValueContainer()
6060
let dictionary = try Self.decodeDictionary(from: singleValueDecodingContainer, decoder: decoder)
6161

62-
self = .unknown(type, dictionary)
62+
self = .unknown(type ?? "unknown", dictionary)
6363
}
6464
}
6565

Sources/ATProtoKit/Models/Lexicons/app.bsky/Feed/AppBskyFeedPost.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ extension AppBskyLexicon.Feed {
195195

196196
public init(from decoder: Decoder) throws {
197197
let container = try decoder.container(keyedBy: CodingKeys.self)
198-
let type = try container.decode(String.self, forKey: .type)
198+
let type = try container.decodeIfPresent(String.self, forKey: .type)
199199

200200
switch type {
201201
case "app.bsky.embed.images":
@@ -212,7 +212,7 @@ extension AppBskyLexicon.Feed {
212212
let singleValueDecodingContainer = try decoder.singleValueContainer()
213213
let dictionary = try Self.decodeDictionary(from: singleValueDecodingContainer, decoder: decoder)
214214

215-
self = .unknown(type, dictionary)
215+
self = .unknown(type ?? "unknown", dictionary)
216216
}
217217
}
218218

@@ -256,7 +256,7 @@ extension AppBskyLexicon.Feed {
256256

257257
public init(from decoder: Decoder) throws {
258258
let container = try decoder.container(keyedBy: CodingKeys.self)
259-
let type = try container.decode(String.self, forKey: .type)
259+
let type = try container.decodeIfPresent(String.self, forKey: .type)
260260

261261
switch type {
262262
case "com.atproto.label.defs#selfLabels":
@@ -265,7 +265,7 @@ extension AppBskyLexicon.Feed {
265265
let singleValueDecodingContainer = try decoder.singleValueContainer()
266266
let dictionary = try Self.decodeDictionary(from: singleValueDecodingContainer, decoder: decoder)
267267

268-
self = .unknown(type, dictionary)
268+
self = .unknown(type ?? "unknown", dictionary)
269269
}
270270
}
271271

Sources/ATProtoKit/Models/Lexicons/app.bsky/Feed/AppBskyFeedPostgate.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ extension AppBskyLexicon.Feed {
115115

116116
public init(from decoder: any Decoder) throws {
117117
let container = try decoder.container(keyedBy: CodingKeys.self)
118-
let type = try container.decode(String.self, forKey: .type)
118+
let type = try container.decodeIfPresent(String.self, forKey: .type)
119119

120120
switch type {
121121
case "app.bsky.feed.postgate#disableRule":
@@ -124,7 +124,7 @@ extension AppBskyLexicon.Feed {
124124
let singleValueDecodingContainer = try decoder.singleValueContainer()
125125
let dictionary = try Self.decodeDictionary(from: singleValueDecodingContainer, decoder: decoder)
126126

127-
self = .unknown(type, dictionary)
127+
self = .unknown(type ?? "unknown", dictionary)
128128
}
129129
}
130130

Sources/ATProtoKit/Models/Lexicons/app.bsky/Feed/AppBskyFeedThreadgate.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ extension AppBskyLexicon.Feed {
166166

167167
public init(from decoder: Decoder) throws {
168168
let container = try decoder.container(keyedBy: CodingKeys.self)
169-
let type = try container.decode(String.self, forKey: .type)
169+
let type = try container.decodeIfPresent(String.self, forKey: .type)
170170

171171
switch type {
172172
case "app.bsky.feed.threadgate#mentionRule":
@@ -181,7 +181,7 @@ extension AppBskyLexicon.Feed {
181181
let singleValueDecodingContainer = try decoder.singleValueContainer()
182182
let dictionary = try Self.decodeDictionary(from: singleValueDecodingContainer, decoder: decoder)
183183

184-
self = .unknown(type, dictionary)
184+
self = .unknown(type ?? "unknown", dictionary)
185185
}
186186
}
187187

Sources/ATProtoKit/Models/Lexicons/app.bsky/Graph/AppBskyGraphGetRelationships.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ extension AppBskyLexicon.Graph {
4848

4949
public init(from decoder: Decoder) throws {
5050
let container = try decoder.container(keyedBy: CodingKeys.self)
51-
let type = try container.decode(String.self, forKey: .type)
51+
let type = try container.decodeIfPresent(String.self, forKey: .type)
5252

5353
switch type {
5454
case "app.bsky.graph.defs#relationship":
@@ -59,7 +59,7 @@ extension AppBskyLexicon.Graph {
5959
let singleValueDecodingContainer = try decoder.singleValueContainer()
6060
let dictionary = try Self.decodeDictionary(from: singleValueDecodingContainer, decoder: decoder)
6161

62-
self = .unknown(type, dictionary)
62+
self = .unknown(type ?? "unknown", dictionary)
6363
}
6464
}
6565

0 commit comments

Comments
 (0)