Skip to content

Commit aaa014a

Browse files
authored
Merge pull request #113 from mattpolzin/include14-support
add support for 14 includes
2 parents 399ec4c + f1945d2 commit aaa014a

File tree

6 files changed

+184
-3
lines changed

6 files changed

+184
-3
lines changed

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.6.0")),
20+
.package(url: "https://github.com/mattpolzin/Poly.git", .upToNextMajor(from: "2.7.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
@@ -222,6 +222,14 @@ extension Includes where I: _Poly13 {
222222
}
223223
}
224224

225+
// MARK: - 14 includes
226+
public typealias Include14 = Poly14
227+
extension Includes where I: _Poly14 {
228+
public subscript(_ lookup: I.N.Type) -> [I.N] {
229+
return values.compactMap(\.n)
230+
}
231+
}
232+
225233
// MARK: - DecodingError
226234
public struct IncludesDecodingError: Swift.Error, Equatable {
227235
public let error: Swift.Error

Sources/JSONAPI/Resource/Poly+PrimaryResource.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,38 @@ J: CodablePolyWrapped,
226226
K: CodablePolyWrapped,
227227
L: CodablePolyWrapped,
228228
M: CodablePolyWrapped {}
229+
230+
// MARK: - 14 types
231+
extension Poly14: EncodablePrimaryResource, OptionalEncodablePrimaryResource
232+
where
233+
A: EncodablePolyWrapped,
234+
B: EncodablePolyWrapped,
235+
C: EncodablePolyWrapped,
236+
D: EncodablePolyWrapped,
237+
E: EncodablePolyWrapped,
238+
F: EncodablePolyWrapped,
239+
G: EncodablePolyWrapped,
240+
H: EncodablePolyWrapped,
241+
I: EncodablePolyWrapped,
242+
J: EncodablePolyWrapped,
243+
K: EncodablePolyWrapped,
244+
L: EncodablePolyWrapped,
245+
M: EncodablePolyWrapped,
246+
N: EncodablePolyWrapped {}
247+
248+
extension Poly14: CodablePrimaryResource, OptionalCodablePrimaryResource
249+
where
250+
A: CodablePolyWrapped,
251+
B: CodablePolyWrapped,
252+
C: CodablePolyWrapped,
253+
D: CodablePolyWrapped,
254+
E: CodablePolyWrapped,
255+
F: CodablePolyWrapped,
256+
G: CodablePolyWrapped,
257+
H: CodablePolyWrapped,
258+
I: CodablePolyWrapped,
259+
J: CodablePolyWrapped,
260+
K: CodablePolyWrapped,
261+
L: CodablePolyWrapped,
262+
M: CodablePolyWrapped,
263+
N: CodablePolyWrapped {}

Tests/JSONAPITests/Includes/IncludeTests.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,31 @@ class IncludedTests: XCTestCase {
266266
test_DecodeEncodeEquality(type: Includes<Include13<TestEntity, TestEntity2, TestEntity3, TestEntity4, TestEntity5, TestEntity6, TestEntity7, TestEntity8, TestEntity9, TestEntity10, TestEntity11, TestEntity12, TestEntity13>>.self,
267267
data: thirteen_different_type_includes)
268268
}
269+
270+
func test_FourteenDifferentIncludes() {
271+
let includes = decoded(type: Includes<Include14<TestEntity, TestEntity2, TestEntity3, TestEntity4, TestEntity5, TestEntity6, TestEntity7, TestEntity8, TestEntity9, TestEntity10, TestEntity11, TestEntity12, TestEntity13, TestEntity14>>.self,
272+
data: fourteen_different_type_includes)
273+
274+
XCTAssertEqual(includes[TestEntity.self].count, 1)
275+
XCTAssertEqual(includes[TestEntity2.self].count, 1)
276+
XCTAssertEqual(includes[TestEntity3.self].count, 1)
277+
XCTAssertEqual(includes[TestEntity4.self].count, 1)
278+
XCTAssertEqual(includes[TestEntity5.self].count, 1)
279+
XCTAssertEqual(includes[TestEntity6.self].count, 1)
280+
XCTAssertEqual(includes[TestEntity7.self].count, 1)
281+
XCTAssertEqual(includes[TestEntity8.self].count, 1)
282+
XCTAssertEqual(includes[TestEntity9.self].count, 1)
283+
XCTAssertEqual(includes[TestEntity10.self].count, 1)
284+
XCTAssertEqual(includes[TestEntity11.self].count, 1)
285+
XCTAssertEqual(includes[TestEntity12.self].count, 1)
286+
XCTAssertEqual(includes[TestEntity13.self].count, 1)
287+
XCTAssertEqual(includes[TestEntity14.self].count, 1)
288+
}
289+
290+
func test_FourteenDifferentIncludes_encode() {
291+
test_DecodeEncodeEquality(type: Includes<Include14<TestEntity, TestEntity2, TestEntity3, TestEntity4, TestEntity5, TestEntity6, TestEntity7, TestEntity8, TestEntity9, TestEntity10, TestEntity11, TestEntity12, TestEntity13, TestEntity14>>.self,
292+
data: fourteen_different_type_includes)
293+
}
269294
}
270295

271296
// MARK: - Appending
@@ -605,4 +630,15 @@ extension IncludedTests {
605630
}
606631

607632
typealias TestEntity13 = BasicEntity<TestEntityType13>
633+
634+
enum TestEntityType14: ResourceObjectDescription {
635+
636+
typealias Attributes = NoAttributes
637+
638+
public static var jsonType: String { return "test_entity14" }
639+
640+
typealias Relationships = NoRelationships
641+
}
642+
643+
typealias TestEntity14 = BasicEntity<TestEntityType14>
608644
}

Tests/JSONAPITests/Includes/stubs/IncludeStubs.swift

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,108 @@ let thirteen_different_type_includes = """
877877
]
878878
""".data(using: .utf8)!
879879

880+
let fourteen_different_type_includes = """
881+
[
882+
{
883+
"type": "test_entity1",
884+
"id": "2DF03B69-4B0A-467F-B52E-B0C9E44FCECF",
885+
"attributes": {
886+
"foo": "Hello",
887+
"bar": 123
888+
}
889+
},
890+
{
891+
"type": "test_entity2",
892+
"id": "90F03B69-4DF1-467F-B52E-B0C9E44FC333",
893+
"attributes": {
894+
"foo": "World",
895+
"bar": 456
896+
},
897+
"relationships": {
898+
"entity1": {
899+
"data": {
900+
"type": "test_entity1",
901+
"id": "2DF03B69-4B0A-467F-B52E-B0C9E44FCECF"
902+
}
903+
}
904+
}
905+
},
906+
{
907+
"type": "test_entity3",
908+
"id": "11223B69-4DF1-467F-B52E-B0C9E44FC443",
909+
"relationships": {
910+
"entity1": {
911+
"data": {
912+
"type": "test_entity1",
913+
"id": "2DF03B69-4B0A-467F-B52E-B0C9E44FCECF"
914+
}
915+
},
916+
"entity2": {
917+
"data": [
918+
{
919+
"type": "test_entity2",
920+
"id": "90F03B69-4DF1-467F-B52E-B0C9E44FC333"
921+
}
922+
]
923+
}
924+
}
925+
},
926+
{
927+
"type": "test_entity6",
928+
"id": "11113B69-4DF1-467F-B52E-B0C9E44FC444",
929+
"relationships": {
930+
"entity4": {
931+
"data": {
932+
"type": "test_entity4",
933+
"id": "364B3B69-4DF1-467F-B52E-B0C9E44F666E"
934+
}
935+
}
936+
}
937+
},
938+
{
939+
"type": "test_entity5",
940+
"id": "A24B3B69-4DF1-467F-B52E-B0C9E44F436A"
941+
},
942+
{
943+
"type": "test_entity4",
944+
"id": "364B3B69-4DF1-467F-B52E-B0C9E44F666E"
945+
},
946+
{
947+
"type": "test_entity7",
948+
"id": "364B3B69-4DF1-222F-B52E-B0C9E44F666E"
949+
},
950+
{
951+
"type": "test_entity8",
952+
"id": "364B3B69-4DF1-222F-B52E-B0C9E44F266F"
953+
},
954+
{
955+
"type": "test_entity9",
956+
"id": "364B3B69-4DF1-218F-B52E-B0C9E44F2661"
957+
},
958+
{
959+
"type": "test_entity10",
960+
"id": "264B3B69-4DF1-212F-B52E-B0C9E44F2660"
961+
},
962+
{
963+
"type": "test_entity11",
964+
"id": "264B3B69-4DF3-212F-B32E-A0C9E44F26C0B"
965+
},
966+
{
967+
"type": "test_entity12",
968+
"id": "264B3B69-4DF3-212F-B32E-A0C9E44F26C00"
969+
},
970+
{
971+
"type": "test_entity13",
972+
"id": "264B3B69-4DF3-212F-B32E-A0C9E44F26C01"
973+
},
974+
{
975+
"type": "test_entity14",
976+
"id": "264B3B69-4DF3-312F-B32E-A0C9E44F26C01"
977+
}
978+
]
979+
""".data(using: .utf8)!
980+
981+
880982
let three_includes_one_missing_attributes = """
881983
[
882984
{

0 commit comments

Comments
 (0)