diff --git a/Sources/JSONAPI/Document/Document.swift b/Sources/JSONAPI/Document/Document.swift index da0a37f..b10a97f 100644 --- a/Sources/JSONAPI/Document/Document.swift +++ b/Sources/JSONAPI/Document/Document.swift @@ -261,7 +261,7 @@ extension Document { } extension Document.Body.Data where PrimaryResourceBody: ResourceBodyAppendable { - public func merging(_ other: Document.Body.Data, + public func merging(_ other: Document.Body.Data, combiningMetaWith metaMerge: (MetaType, MetaType) -> MetaType, combiningLinksWith linksMerge: (LinksType, LinksType) -> LinksType) -> Document.Body.Data { return Document.Body.Data(primary: primary.appending(other.primary), @@ -272,10 +272,11 @@ extension Document.Body.Data where PrimaryResourceBody: ResourceBodyAppendable { } extension Document.Body.Data where PrimaryResourceBody: ResourceBodyAppendable, MetaType == NoMetadata, LinksType == NoLinks { - public func merging(_ other: Document.Body.Data) -> Document.Body.Data { - return merging(other, - combiningMetaWith: { _, _ in .none }, - combiningLinksWith: { _, _ in .none }) + public func merging(_ other: Document.Body.Data) -> Document.Body.Data { + return Document.Body.Data(primary: primary.appending(other.primary), + includes: includes.appending(other.includes), + meta: meta, + links: links) } } diff --git a/Tests/JSONAPITests/Document/DocumentTests.swift b/Tests/JSONAPITests/Document/DocumentTests.swift index d6058ec..6d3a60a 100644 --- a/Tests/JSONAPITests/Document/DocumentTests.swift +++ b/Tests/JSONAPITests/Document/DocumentTests.swift @@ -1528,6 +1528,23 @@ extension DocumentTests { XCTAssertEqual(combined.primary.values, bodyData1.primary.values + bodyData2.primary.values) } + public func test_MergeBodyDataMixedMetaAndLinks(){ + let entity1 = Article(attributes: .none, relationships: .init(author: "2"), meta: .none, links: .none) + let entity2 = Article(attributes: .none, relationships: .init(author: "3"), meta: .none, links: .none) + + let bodyData1 = Document, NoMetadata, NoLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.Body.Data(primary: .init(resourceObjects: [entity1]), + includes: .none, + meta: .none, + links: .none) + let bodyData2 = Document, TestPageMetadata, TestLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.Body.Data(primary: .init(resourceObjects: [entity2]), + includes: .none, + meta: .init(total: 5, limit: 2, offset: 2), + links: .init(link: .init(url: "one"), link2: .init(url: .init(), meta: .init(hello: "world")))) + let combined = bodyData1.merging(bodyData2) + + XCTAssertEqual(combined.primary.values, bodyData1.primary.values + bodyData2.primary.values) + } + public func test_MergeBodyDataWithMergeFunctions() { let article1 = Article(attributes: .none, relationships: .init(author: "2"), meta: .none, links: .none) let author1 = Author(id: "2", attributes: .none, relationships: .none, meta: .none, links: .none) @@ -1649,3 +1666,7 @@ extension DocumentTests { } } } + +enum SomeMeta: String, JSONAPI.Meta { + case some +}