Skip to content

Commit 575199e

Browse files
committed
Add Include12 and Include13 types.
1 parent a72ed5c commit 575199e

9 files changed

Lines changed: 348 additions & 5 deletions

File tree

.github/workflows/tests.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ jobs:
2828
- swift:5.4-focal
2929
- swift:5.4-centos8
3030
- swift:5.4-amazonlinux2
31+
- swift:5.5-xenial
32+
- swift:5.5-bionic
33+
- swift:5.5-focal
34+
- swift:5.5-centos8
35+
- swift:5.5-amazonlinux2
3136
container: ${{ matrix.image }}
3237
steps:
3338
- name: Checkout code

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let package = Package(
1717
targets: ["JSONAPITesting"])
1818
],
1919
dependencies: [
20-
.package(url: "https://github.com/mattpolzin/Poly.git", .upToNextMajor(from: "2.4.0")),
20+
.package(url: "https://github.com/mattpolzin/Poly.git", .upToNextMajor(from: "2.6.0")),
2121
],
2222
targets: [
2323
.target(

Sources/JSONAPI/Document/CompoundResource.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ extension Sequence where Element: CompoundResourceProtocol {
7171
}
7272
}
7373

74-
extension EncodableJSONAPIDocument where PrimaryResourceBody: EncodableResourceBody, PrimaryResourceBody.PrimaryResource: ResourceObjectType {
74+
extension EncodableJSONAPIDocument where PrimaryResourceBody.PrimaryResource: ResourceObjectType {
7575
public typealias CompoundResource = JSONAPI.CompoundResource<PrimaryResourceBody.PrimaryResource, IncludeType>
7676
}
7777

Sources/JSONAPI/Document/Includes.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,22 @@ extension Includes where I: _Poly11 {
206206
}
207207
}
208208

209+
// MARK: - 12 includes
210+
public typealias Include12 = Poly12
211+
extension Includes where I: _Poly12 {
212+
public subscript(_ lookup: I.L.Type) -> [I.L] {
213+
return values.compactMap(\.l)
214+
}
215+
}
216+
217+
// MARK: - 13 includes
218+
public typealias Include13 = Poly13
219+
extension Includes where I: _Poly13 {
220+
public subscript(_ lookup: I.M.Type) -> [I.M] {
221+
return values.compactMap(\.m)
222+
}
223+
}
224+
209225
// MARK: - DecodingError
210226
public struct IncludesDecodingError: Swift.Error, Equatable {
211227
public let error: Swift.Error

Sources/JSONAPI/Resource/Poly+PrimaryResource.swift

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,67 @@ extension Poly11: CodablePrimaryResource, OptionalCodablePrimaryResource
162162
I: CodablePolyWrapped,
163163
J: CodablePolyWrapped,
164164
K: CodablePolyWrapped {}
165+
166+
// MARK: - 12 types
167+
extension Poly12: EncodablePrimaryResource, OptionalEncodablePrimaryResource
168+
where
169+
A: EncodablePolyWrapped,
170+
B: EncodablePolyWrapped,
171+
C: EncodablePolyWrapped,
172+
D: EncodablePolyWrapped,
173+
E: EncodablePolyWrapped,
174+
F: EncodablePolyWrapped,
175+
G: EncodablePolyWrapped,
176+
H: EncodablePolyWrapped,
177+
I: EncodablePolyWrapped,
178+
J: EncodablePolyWrapped,
179+
K: EncodablePolyWrapped,
180+
L: EncodablePolyWrapped {}
181+
182+
extension Poly12: CodablePrimaryResource, OptionalCodablePrimaryResource
183+
where
184+
A: CodablePolyWrapped,
185+
B: CodablePolyWrapped,
186+
C: CodablePolyWrapped,
187+
D: CodablePolyWrapped,
188+
E: CodablePolyWrapped,
189+
F: CodablePolyWrapped,
190+
G: CodablePolyWrapped,
191+
H: CodablePolyWrapped,
192+
I: CodablePolyWrapped,
193+
J: CodablePolyWrapped,
194+
K: CodablePolyWrapped,
195+
L: CodablePolyWrapped {}
196+
197+
// MARK: - 13 types
198+
extension Poly13: EncodablePrimaryResource, OptionalEncodablePrimaryResource
199+
where
200+
A: EncodablePolyWrapped,
201+
B: EncodablePolyWrapped,
202+
C: EncodablePolyWrapped,
203+
D: EncodablePolyWrapped,
204+
E: EncodablePolyWrapped,
205+
F: EncodablePolyWrapped,
206+
G: EncodablePolyWrapped,
207+
H: EncodablePolyWrapped,
208+
I: EncodablePolyWrapped,
209+
J: EncodablePolyWrapped,
210+
K: EncodablePolyWrapped,
211+
L: EncodablePolyWrapped,
212+
M: EncodablePolyWrapped {}
213+
214+
extension Poly13: CodablePrimaryResource, OptionalCodablePrimaryResource
215+
where
216+
A: CodablePolyWrapped,
217+
B: CodablePolyWrapped,
218+
C: CodablePolyWrapped,
219+
D: CodablePolyWrapped,
220+
E: CodablePolyWrapped,
221+
F: CodablePolyWrapped,
222+
G: CodablePolyWrapped,
223+
H: CodablePolyWrapped,
224+
I: CodablePolyWrapped,
225+
J: CodablePolyWrapped,
226+
K: CodablePolyWrapped,
227+
L: CodablePolyWrapped,
228+
M: CodablePolyWrapped {}

Sources/JSONAPITesting/Comparisons/DocumentDataCompare.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public struct ManyResourceObjectComparison: Equatable, PropertyComparison {
8686
}
8787
}
8888

89-
extension TestableResourceBody where TestablePrimaryResourceType: ResourceObjectType {
89+
extension TestableResourceBody {
9090
public func compare(to other: Self) -> PrimaryResourceBodyComparison {
9191
guard let one = testableResourceObject,
9292
let two = other.testableResourceObject else {

Tests/JSONAPITests/Includes/IncludeTests.swift

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,53 @@ class IncludedTests: XCTestCase {
219219
test_DecodeEncodeEquality(type: Includes<Include11<TestEntity, TestEntity2, TestEntity3, TestEntity4, TestEntity5, TestEntity6, TestEntity7, TestEntity8, TestEntity9, TestEntity10, TestEntity11>>.self,
220220
data: eleven_different_type_includes)
221221
}
222+
223+
func test_TwelveDifferentIncludes() {
224+
let includes = decoded(type: Includes<Include12<TestEntity, TestEntity2, TestEntity3, TestEntity4, TestEntity5, TestEntity6, TestEntity7, TestEntity8, TestEntity9, TestEntity10, TestEntity11, TestEntity12>>.self,
225+
data: twelve_different_type_includes)
226+
227+
XCTAssertEqual(includes[TestEntity.self].count, 1)
228+
XCTAssertEqual(includes[TestEntity2.self].count, 1)
229+
XCTAssertEqual(includes[TestEntity3.self].count, 1)
230+
XCTAssertEqual(includes[TestEntity4.self].count, 1)
231+
XCTAssertEqual(includes[TestEntity5.self].count, 1)
232+
XCTAssertEqual(includes[TestEntity6.self].count, 1)
233+
XCTAssertEqual(includes[TestEntity7.self].count, 1)
234+
XCTAssertEqual(includes[TestEntity8.self].count, 1)
235+
XCTAssertEqual(includes[TestEntity9.self].count, 1)
236+
XCTAssertEqual(includes[TestEntity10.self].count, 1)
237+
XCTAssertEqual(includes[TestEntity11.self].count, 1)
238+
XCTAssertEqual(includes[TestEntity12.self].count, 1)
239+
}
240+
241+
func test_TwelveDifferentIncludes_encode() {
242+
test_DecodeEncodeEquality(type: Includes<Include12<TestEntity, TestEntity2, TestEntity3, TestEntity4, TestEntity5, TestEntity6, TestEntity7, TestEntity8, TestEntity9, TestEntity10, TestEntity11, TestEntity12>>.self,
243+
data: twelve_different_type_includes)
244+
}
245+
246+
func test_ThirteenDifferentIncludes() {
247+
let includes = decoded(type: Includes<Include13<TestEntity, TestEntity2, TestEntity3, TestEntity4, TestEntity5, TestEntity6, TestEntity7, TestEntity8, TestEntity9, TestEntity10, TestEntity11, TestEntity12, TestEntity13>>.self,
248+
data: thirteen_different_type_includes)
249+
250+
XCTAssertEqual(includes[TestEntity.self].count, 1)
251+
XCTAssertEqual(includes[TestEntity2.self].count, 1)
252+
XCTAssertEqual(includes[TestEntity3.self].count, 1)
253+
XCTAssertEqual(includes[TestEntity4.self].count, 1)
254+
XCTAssertEqual(includes[TestEntity5.self].count, 1)
255+
XCTAssertEqual(includes[TestEntity6.self].count, 1)
256+
XCTAssertEqual(includes[TestEntity7.self].count, 1)
257+
XCTAssertEqual(includes[TestEntity8.self].count, 1)
258+
XCTAssertEqual(includes[TestEntity9.self].count, 1)
259+
XCTAssertEqual(includes[TestEntity10.self].count, 1)
260+
XCTAssertEqual(includes[TestEntity11.self].count, 1)
261+
XCTAssertEqual(includes[TestEntity12.self].count, 1)
262+
XCTAssertEqual(includes[TestEntity13.self].count, 1)
263+
}
264+
265+
func test_ThirteenDifferentIncludes_encode() {
266+
test_DecodeEncodeEquality(type: Includes<Include13<TestEntity, TestEntity2, TestEntity3, TestEntity4, TestEntity5, TestEntity6, TestEntity7, TestEntity8, TestEntity9, TestEntity10, TestEntity11, TestEntity12, TestEntity13>>.self,
267+
data: thirteen_different_type_includes)
268+
}
222269
}
223270

224271
// MARK: - Appending
@@ -536,4 +583,26 @@ extension IncludedTests {
536583
}
537584

538585
typealias TestEntity11 = BasicEntity<TestEntityType11>
586+
587+
enum TestEntityType12: ResourceObjectDescription {
588+
589+
typealias Attributes = NoAttributes
590+
591+
public static var jsonType: String { return "test_entity12" }
592+
593+
typealias Relationships = NoRelationships
594+
}
595+
596+
typealias TestEntity12 = BasicEntity<TestEntityType12>
597+
598+
enum TestEntityType13: ResourceObjectDescription {
599+
600+
typealias Attributes = NoAttributes
601+
602+
public static var jsonType: String { return "test_entity13" }
603+
604+
typealias Relationships = NoRelationships
605+
}
606+
607+
typealias TestEntity13 = BasicEntity<TestEntityType13>
539608
}

0 commit comments

Comments
 (0)