Skip to content

Commit 3856a88

Browse files
authored
Merge pull request #114 from mattpolzin/include15-support
support for Include15 type
2 parents aaa014a + 9b919b6 commit 3856a88

6 files changed

Lines changed: 190 additions & 3 deletions

File tree

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.7.0")),
20+
.package(url: "https://github.com/mattpolzin/Poly.git", .upToNextMajor(from: "2.8.0")),
2121
],
2222
targets: [
2323
.target(

Sources/JSONAPI/Document/Includes.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,14 @@ extension Includes where I: _Poly14 {
230230
}
231231
}
232232

233+
// MARK: - 15 includes
234+
public typealias Include15 = Poly15
235+
extension Includes where I: _Poly15 {
236+
public subscript(_ lookup: I.O.Type) -> [I.O] {
237+
return values.compactMap(\.o)
238+
}
239+
}
240+
233241
// MARK: - DecodingError
234242
public struct IncludesDecodingError: Swift.Error, Equatable {
235243
public let error: Swift.Error

Sources/JSONAPI/Resource/Poly+PrimaryResource.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,40 @@ K: CodablePolyWrapped,
261261
L: CodablePolyWrapped,
262262
M: CodablePolyWrapped,
263263
N: CodablePolyWrapped {}
264+
265+
// MARK: - 15 types
266+
extension Poly15: EncodablePrimaryResource, OptionalEncodablePrimaryResource
267+
where
268+
A: EncodablePolyWrapped,
269+
B: EncodablePolyWrapped,
270+
C: EncodablePolyWrapped,
271+
D: EncodablePolyWrapped,
272+
E: EncodablePolyWrapped,
273+
F: EncodablePolyWrapped,
274+
G: EncodablePolyWrapped,
275+
H: EncodablePolyWrapped,
276+
I: EncodablePolyWrapped,
277+
J: EncodablePolyWrapped,
278+
K: EncodablePolyWrapped,
279+
L: EncodablePolyWrapped,
280+
M: EncodablePolyWrapped,
281+
N: EncodablePolyWrapped,
282+
O: EncodablePolyWrapped {}
283+
284+
extension Poly15: CodablePrimaryResource, OptionalCodablePrimaryResource
285+
where
286+
A: CodablePolyWrapped,
287+
B: CodablePolyWrapped,
288+
C: CodablePolyWrapped,
289+
D: CodablePolyWrapped,
290+
E: CodablePolyWrapped,
291+
F: CodablePolyWrapped,
292+
G: CodablePolyWrapped,
293+
H: CodablePolyWrapped,
294+
I: CodablePolyWrapped,
295+
J: CodablePolyWrapped,
296+
K: CodablePolyWrapped,
297+
L: CodablePolyWrapped,
298+
M: CodablePolyWrapped,
299+
N: CodablePolyWrapped,
300+
O: CodablePolyWrapped {}

Tests/JSONAPITests/Includes/IncludeTests.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,32 @@ class IncludedTests: XCTestCase {
291291
test_DecodeEncodeEquality(type: Includes<Include14<TestEntity, TestEntity2, TestEntity3, TestEntity4, TestEntity5, TestEntity6, TestEntity7, TestEntity8, TestEntity9, TestEntity10, TestEntity11, TestEntity12, TestEntity13, TestEntity14>>.self,
292292
data: fourteen_different_type_includes)
293293
}
294+
295+
func test_FifteenDifferentIncludes() {
296+
let includes = decoded(type: Includes<Include15<TestEntity, TestEntity2, TestEntity3, TestEntity4, TestEntity5, TestEntity6, TestEntity7, TestEntity8, TestEntity9, TestEntity10, TestEntity11, TestEntity12, TestEntity13, TestEntity14, TestEntity15>>.self,
297+
data: fifteen_different_type_includes)
298+
299+
XCTAssertEqual(includes[TestEntity.self].count, 1)
300+
XCTAssertEqual(includes[TestEntity2.self].count, 1)
301+
XCTAssertEqual(includes[TestEntity3.self].count, 1)
302+
XCTAssertEqual(includes[TestEntity4.self].count, 1)
303+
XCTAssertEqual(includes[TestEntity5.self].count, 1)
304+
XCTAssertEqual(includes[TestEntity6.self].count, 1)
305+
XCTAssertEqual(includes[TestEntity7.self].count, 1)
306+
XCTAssertEqual(includes[TestEntity8.self].count, 1)
307+
XCTAssertEqual(includes[TestEntity9.self].count, 1)
308+
XCTAssertEqual(includes[TestEntity10.self].count, 1)
309+
XCTAssertEqual(includes[TestEntity11.self].count, 1)
310+
XCTAssertEqual(includes[TestEntity12.self].count, 1)
311+
XCTAssertEqual(includes[TestEntity13.self].count, 1)
312+
XCTAssertEqual(includes[TestEntity14.self].count, 1)
313+
XCTAssertEqual(includes[TestEntity15.self].count, 1)
314+
}
315+
316+
func test_FifteenDifferentIncludes_encode() {
317+
test_DecodeEncodeEquality(type: Includes<Include15<TestEntity, TestEntity2, TestEntity3, TestEntity4, TestEntity5, TestEntity6, TestEntity7, TestEntity8, TestEntity9, TestEntity10, TestEntity11, TestEntity12, TestEntity13, TestEntity14, TestEntity15>>.self,
318+
data: fifteen_different_type_includes)
319+
}
294320
}
295321

296322
// MARK: - Appending
@@ -641,4 +667,15 @@ extension IncludedTests {
641667
}
642668

643669
typealias TestEntity14 = BasicEntity<TestEntityType14>
670+
671+
enum TestEntityType15: ResourceObjectDescription {
672+
673+
typealias Attributes = NoAttributes
674+
675+
public static var jsonType: String { return "test_entity15" }
676+
677+
typealias Relationships = NoRelationships
678+
}
679+
680+
typealias TestEntity15 = BasicEntity<TestEntityType15>
644681
}

Tests/JSONAPITests/Includes/stubs/IncludeStubs.swift

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,111 @@ let fourteen_different_type_includes = """
978978
]
979979
""".data(using: .utf8)!
980980

981+
let fifteen_different_type_includes = """
982+
[
983+
{
984+
"type": "test_entity1",
985+
"id": "2DF03B69-4B0A-467F-B52E-B0C9E44FCECF",
986+
"attributes": {
987+
"foo": "Hello",
988+
"bar": 123
989+
}
990+
},
991+
{
992+
"type": "test_entity2",
993+
"id": "90F03B69-4DF1-467F-B52E-B0C9E44FC333",
994+
"attributes": {
995+
"foo": "World",
996+
"bar": 456
997+
},
998+
"relationships": {
999+
"entity1": {
1000+
"data": {
1001+
"type": "test_entity1",
1002+
"id": "2DF03B69-4B0A-467F-B52E-B0C9E44FCECF"
1003+
}
1004+
}
1005+
}
1006+
},
1007+
{
1008+
"type": "test_entity3",
1009+
"id": "11223B69-4DF1-467F-B52E-B0C9E44FC443",
1010+
"relationships": {
1011+
"entity1": {
1012+
"data": {
1013+
"type": "test_entity1",
1014+
"id": "2DF03B69-4B0A-467F-B52E-B0C9E44FCECF"
1015+
}
1016+
},
1017+
"entity2": {
1018+
"data": [
1019+
{
1020+
"type": "test_entity2",
1021+
"id": "90F03B69-4DF1-467F-B52E-B0C9E44FC333"
1022+
}
1023+
]
1024+
}
1025+
}
1026+
},
1027+
{
1028+
"type": "test_entity6",
1029+
"id": "11113B69-4DF1-467F-B52E-B0C9E44FC444",
1030+
"relationships": {
1031+
"entity4": {
1032+
"data": {
1033+
"type": "test_entity4",
1034+
"id": "364B3B69-4DF1-467F-B52E-B0C9E44F666E"
1035+
}
1036+
}
1037+
}
1038+
},
1039+
{
1040+
"type": "test_entity5",
1041+
"id": "A24B3B69-4DF1-467F-B52E-B0C9E44F436A"
1042+
},
1043+
{
1044+
"type": "test_entity4",
1045+
"id": "364B3B69-4DF1-467F-B52E-B0C9E44F666E"
1046+
},
1047+
{
1048+
"type": "test_entity7",
1049+
"id": "364B3B69-4DF1-222F-B52E-B0C9E44F666E"
1050+
},
1051+
{
1052+
"type": "test_entity8",
1053+
"id": "364B3B69-4DF1-222F-B52E-B0C9E44F266F"
1054+
},
1055+
{
1056+
"type": "test_entity9",
1057+
"id": "364B3B69-4DF1-218F-B52E-B0C9E44F2661"
1058+
},
1059+
{
1060+
"type": "test_entity10",
1061+
"id": "264B3B69-4DF1-212F-B52E-B0C9E44F2660"
1062+
},
1063+
{
1064+
"type": "test_entity11",
1065+
"id": "264B3B69-4DF3-212F-B32E-A0C9E44F26C0B"
1066+
},
1067+
{
1068+
"type": "test_entity12",
1069+
"id": "264B3B69-4DF3-212F-B32E-A0C9E44F26C00"
1070+
},
1071+
{
1072+
"type": "test_entity13",
1073+
"id": "264B3B69-4DF3-212F-B32E-A0C9E44F26C01"
1074+
},
1075+
{
1076+
"type": "test_entity14",
1077+
"id": "264B3B69-4DF3-312F-B32E-A0C9E44F26C01"
1078+
},
1079+
{
1080+
"type": "test_entity15",
1081+
"id": "264B3B69-4DF3-312A-B32E-A0C9E44F26C01"
1082+
}
1083+
]
1084+
""".data(using: .utf8)!
1085+
9811086

9821087
let three_includes_one_missing_attributes = """
9831088
[

0 commit comments

Comments
 (0)