File tree Expand file tree Collapse file tree 3 files changed +21
-0
lines changed
Tests/JSONAPITests/Relationships Expand file tree Collapse file tree 3 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -401,6 +401,11 @@ extension ToManyRelationship: Codable {
401401 links = try container. decode ( LinksType . self, forKey: . links)
402402 }
403403
404+ guard container. contains ( . data) else {
405+ idsWithMeta = [ ]
406+ return
407+ }
408+
404409 var identifiers : UnkeyedDecodingContainer
405410 do {
406411 identifiers = try container. nestedUnkeyedContainer ( forKey: . data)
Original file line number Diff line number Diff line change @@ -235,6 +235,14 @@ extension RelationshipTests {
235235 test_DecodeEncodeEquality ( type: ToManyWithMetaAndLinks . self,
236236 data: to_many_relationship_with_meta_and_links)
237237 }
238+
239+ func test_ToManyRelationshipWithMetaNoData( ) {
240+ let relationship = decoded ( type: ToManyWithMeta . self,
241+ data: to_many_relationship_with_meta_no_data)
242+
243+ XCTAssertEqual ( relationship. ids, [ ] )
244+ XCTAssertEqual ( relationship. meta. a, " hello " )
245+ }
238246}
239247
240248// MARK: Nullable
Original file line number Diff line number Diff line change @@ -241,3 +241,11 @@ let to_many_relationship_type_mismatch = """
241241 ]
242242}
243243""" . data ( using: . utf8) !
244+
245+ let to_many_relationship_with_meta_no_data = """
246+ {
247+ " meta " : {
248+ " a " : " hello "
249+ }
250+ }
251+ """ . data ( using: . utf8) !
You can’t perform that action at this time.
0 commit comments