Skip to content

Commit 0fd4e73

Browse files
authored
Merge pull request #65 from mattpolzin/feature/add-initializers
Add some convenience initializers
2 parents bbd6db6 + 07eed9c commit 0fd4e73

2 files changed

Lines changed: 78 additions & 0 deletions

File tree

Sources/JSONAPI/Document/Document.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,3 +655,37 @@ extension Document.SuccessDocument where IncludeType: _Poly1 {
655655
}
656656
}
657657
}
658+
659+
extension Document where MetaType == NoMetadata, LinksType == NoLinks, IncludeType == NoIncludes, APIDescription == NoAPIDescription {
660+
public init(body: PrimaryResourceBody) {
661+
self.init(
662+
apiDescription: .none,
663+
body: body,
664+
includes: .none,
665+
meta: .none,
666+
links: .none
667+
)
668+
}
669+
670+
public init(errors: [Error]) {
671+
self.init(apiDescription: .none, errors: errors)
672+
}
673+
}
674+
675+
extension Document.SuccessDocument where Document.MetaType == NoMetadata, Document.LinksType == NoLinks, Document.IncludeType == NoIncludes, Document.APIDescription == NoAPIDescription {
676+
public init(body: PrimaryResourceBody) {
677+
self.init(
678+
apiDescription: .none,
679+
body: body,
680+
includes: .none,
681+
meta: .none,
682+
links: .none
683+
)
684+
}
685+
}
686+
687+
extension Document.ErrorDocument where Document.MetaType == NoMetadata, Document.LinksType == NoLinks, Document.IncludeType == NoIncludes, Document.APIDescription == NoAPIDescription {
688+
public init(errors: [Error]) {
689+
self.init(apiDescription: .none, errors: errors)
690+
}
691+
}

Tests/JSONAPITests/Document/DocumentTests.swift

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,28 @@ class DocumentTests: XCTestCase {
3939
links: .none
4040
))
4141

42+
test(JSONAPI.Document<
43+
NoResourceBody,
44+
NoMetadata,
45+
NoLinks,
46+
NoIncludes,
47+
NoAPIDescription,
48+
UnknownJSONAPIError
49+
>(
50+
body: .none
51+
))
52+
53+
test(JSONAPI.Document<
54+
NoResourceBody,
55+
NoMetadata,
56+
NoLinks,
57+
NoIncludes,
58+
NoAPIDescription,
59+
UnknownJSONAPIError
60+
>(
61+
errors: []
62+
))
63+
4264
// Document.SuccessDocument
4365
test(JSONAPI.Document<
4466
NoResourceBody,
@@ -55,6 +77,17 @@ class DocumentTests: XCTestCase {
5577
links: .none
5678
))
5779

80+
test(JSONAPI.Document<
81+
NoResourceBody,
82+
NoMetadata,
83+
NoLinks,
84+
NoIncludes,
85+
NoAPIDescription,
86+
UnknownJSONAPIError
87+
>.SuccessDocument(
88+
body: .none
89+
))
90+
5891
// Document.ErrorDocument
5992
test(JSONAPI.Document<
6093
NoResourceBody,
@@ -67,6 +100,17 @@ class DocumentTests: XCTestCase {
67100
apiDescription: .none,
68101
errors: []
69102
))
103+
104+
test(JSONAPI.Document<
105+
NoResourceBody,
106+
NoMetadata,
107+
NoLinks,
108+
NoIncludes,
109+
NoAPIDescription,
110+
UnknownJSONAPIError
111+
>.ErrorDocument(
112+
errors: []
113+
))
70114
}
71115

72116
func test_singleDocumentNull() {

0 commit comments

Comments
 (0)