Skip to content

Commit 7e28cd2

Browse files
authored
Merge pull request #35 from mattpolzin/add-include-10
Add include10 Type
2 parents 5ed4507 + cf6fa39 commit 7e28cd2

9 files changed

Lines changed: 137 additions & 727 deletions

File tree

JSONAPI.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Pod::Spec.new do |spec|
1616
#
1717

1818
spec.name = "MP-JSONAPI"
19-
spec.version = "2.0.0"
19+
spec.version = "2.1.0"
2020
spec.summary = "Swift Codable JSON API framework."
2121

2222
# This description is used to generate tags and improve search results.
@@ -136,6 +136,6 @@ See the JSON API Spec here: https://jsonapi.org/format/
136136
# spec.requires_arc = true
137137

138138
# spec.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
139-
spec.dependency "Poly", "~> 2.0"
139+
spec.dependency "Poly", "~> 2.1"
140140

141141
end

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
@@ -18,7 +18,7 @@ let package = Package(
1818
targets: ["JSONAPITesting"])
1919
],
2020
dependencies: [
21-
.package(url: "https://github.com/mattpolzin/Poly.git", .upToNextMajor(from: "2.0.0")),
21+
.package(url: "https://github.com/mattpolzin/Poly.git", .upToNextMajor(from: "2.1.0")),
2222
],
2323
targets: [
2424
.target(

Sources/JSONAPI/Document/Includes.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,11 @@ extension Includes where I: _Poly9 {
161161
return values.compactMap { $0.i }
162162
}
163163
}
164+
165+
// MARK: - 10 includes
166+
public typealias Include10 = Poly10
167+
extension Includes where I: _Poly10 {
168+
public subscript(_ lookup: I.J.Type) -> [I.J] {
169+
return values.compactMap { $0.j }
170+
}
171+
}

Sources/JSONAPI/Resource/Poly+PrimaryResource.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,8 @@ extension Poly8: PrimaryResource, OptionalPrimaryResource where A: PolyWrapped,
7474
extension Poly9: EncodablePrimaryResource, OptionalEncodablePrimaryResource where A: EncodablePolyWrapped, B: EncodablePolyWrapped, C: EncodablePolyWrapped, D: EncodablePolyWrapped, E: EncodablePolyWrapped, F: EncodablePolyWrapped, G: EncodablePolyWrapped, H: EncodablePolyWrapped, I: EncodablePolyWrapped {}
7575

7676
extension Poly9: PrimaryResource, OptionalPrimaryResource where A: PolyWrapped, B: PolyWrapped, C: PolyWrapped, D: PolyWrapped, E: PolyWrapped, F: PolyWrapped, G: PolyWrapped, H: PolyWrapped, I: PolyWrapped {}
77+
78+
// MARK: - 10 types
79+
extension Poly10: EncodablePrimaryResource, OptionalEncodablePrimaryResource where A: EncodablePolyWrapped, B: EncodablePolyWrapped, C: EncodablePolyWrapped, D: EncodablePolyWrapped, E: EncodablePolyWrapped, F: EncodablePolyWrapped, G: EncodablePolyWrapped, H: EncodablePolyWrapped, I: EncodablePolyWrapped, J: EncodablePolyWrapped {}
80+
81+
extension Poly10: PrimaryResource, OptionalPrimaryResource where A: PolyWrapped, B: PolyWrapped, C: PolyWrapped, D: PolyWrapped, E: PolyWrapped, F: PolyWrapped, G: PolyWrapped, H: PolyWrapped, I: PolyWrapped, J: PolyWrapped {}

Tests/JSONAPITests/Includes/IncludeTests.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,27 @@ class IncludedTests: XCTestCase {
176176
test_DecodeEncodeEquality(type: Includes<Include9<TestEntity, TestEntity2, TestEntity3, TestEntity4, TestEntity5, TestEntity6, TestEntity7, TestEntity8, TestEntity9>>.self,
177177
data: nine_different_type_includes)
178178
}
179+
180+
func test_TenDifferentIncludes() {
181+
let includes = decoded(type: Includes<Include10<TestEntity, TestEntity2, TestEntity3, TestEntity4, TestEntity5, TestEntity6, TestEntity7, TestEntity8, TestEntity9, TestEntity10>>.self,
182+
data: ten_different_type_includes)
183+
184+
XCTAssertEqual(includes[TestEntity.self].count, 1)
185+
XCTAssertEqual(includes[TestEntity2.self].count, 1)
186+
XCTAssertEqual(includes[TestEntity3.self].count, 1)
187+
XCTAssertEqual(includes[TestEntity4.self].count, 1)
188+
XCTAssertEqual(includes[TestEntity5.self].count, 1)
189+
XCTAssertEqual(includes[TestEntity6.self].count, 1)
190+
XCTAssertEqual(includes[TestEntity7.self].count, 1)
191+
XCTAssertEqual(includes[TestEntity8.self].count, 1)
192+
XCTAssertEqual(includes[TestEntity9.self].count, 1)
193+
XCTAssertEqual(includes[TestEntity10.self].count, 1)
194+
}
195+
196+
func test_TenDifferentIncludes_encode() {
197+
test_DecodeEncodeEquality(type: Includes<Include10<TestEntity, TestEntity2, TestEntity3, TestEntity4, TestEntity5, TestEntity6, TestEntity7, TestEntity8, TestEntity9, TestEntity10>>.self,
198+
data: ten_different_type_includes)
199+
}
179200
}
180201

181202
// MARK: - Appending
@@ -471,4 +492,15 @@ extension IncludedTests {
471492
}
472493

473494
typealias TestEntity9 = BasicEntity<TestEntityType9>
495+
496+
enum TestEntityType10: ResourceObjectDescription {
497+
498+
typealias Attributes = NoAttributes
499+
500+
public static var jsonType: String { return "test_entity10" }
501+
502+
typealias Relationships = NoRelationships
503+
}
504+
505+
typealias TestEntity10 = BasicEntity<TestEntityType10>
474506
}

Tests/JSONAPITests/Includes/stubs/IncludeStubs.swift

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,3 +512,88 @@ let nine_different_type_includes = """
512512
}
513513
]
514514
""".data(using: .utf8)!
515+
516+
let ten_different_type_includes = """
517+
[
518+
{
519+
"type": "test_entity1",
520+
"id": "2DF03B69-4B0A-467F-B52E-B0C9E44FCECF",
521+
"attributes": {
522+
"foo": "Hello",
523+
"bar": 123
524+
}
525+
},
526+
{
527+
"type": "test_entity2",
528+
"id": "90F03B69-4DF1-467F-B52E-B0C9E44FC333",
529+
"attributes": {
530+
"foo": "World",
531+
"bar": 456
532+
},
533+
"relationships": {
534+
"entity1": {
535+
"data": {
536+
"type": "test_entity1",
537+
"id": "2DF03B69-4B0A-467F-B52E-B0C9E44FCECF"
538+
}
539+
}
540+
}
541+
},
542+
{
543+
"type": "test_entity3",
544+
"id": "11223B69-4DF1-467F-B52E-B0C9E44FC443",
545+
"relationships": {
546+
"entity1": {
547+
"data": {
548+
"type": "test_entity1",
549+
"id": "2DF03B69-4B0A-467F-B52E-B0C9E44FCECF"
550+
}
551+
},
552+
"entity2": {
553+
"data": [
554+
{
555+
"type": "test_entity2",
556+
"id": "90F03B69-4DF1-467F-B52E-B0C9E44FC333"
557+
}
558+
]
559+
}
560+
}
561+
},
562+
{
563+
"type": "test_entity6",
564+
"id": "11113B69-4DF1-467F-B52E-B0C9E44FC444",
565+
"relationships": {
566+
"entity4": {
567+
"data": {
568+
"type": "test_entity4",
569+
"id": "364B3B69-4DF1-467F-B52E-B0C9E44F666E"
570+
}
571+
}
572+
}
573+
},
574+
{
575+
"type": "test_entity5",
576+
"id": "A24B3B69-4DF1-467F-B52E-B0C9E44F436A"
577+
},
578+
{
579+
"type": "test_entity4",
580+
"id": "364B3B69-4DF1-467F-B52E-B0C9E44F666E"
581+
},
582+
{
583+
"type": "test_entity7",
584+
"id": "364B3B69-4DF1-222F-B52E-B0C9E44F666E"
585+
},
586+
{
587+
"type": "test_entity8",
588+
"id": "364B3B69-4DF1-222F-B52E-B0C9E44F266F"
589+
},
590+
{
591+
"type": "test_entity9",
592+
"id": "364B3B69-4DF1-218F-B52E-B0C9E44F2661"
593+
},
594+
{
595+
"type": "test_entity10",
596+
"id": "264B3B69-4DF1-212F-B52E-B0C9E44F2660"
597+
}
598+
]
599+
""".data(using: .utf8)!

0 commit comments

Comments
 (0)