Skip to content

Commit 661dfc3

Browse files
authored
Merge pull request #103 from mattpolzin/add-include12-include13
Add Include12 and Include13 types.
2 parents a72ed5c + aec39fc commit 661dfc3

File tree

15 files changed

+481
-49
lines changed

15 files changed

+481
-49
lines changed

.github/workflows/tests.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ 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
36+
- swift:5.6-bionic
37+
- swift:5.6-focal
38+
- swift:5.6-amazonlinux2
3139
container: ${{ matrix.image }}
3240
steps:
3341
- name: Checkout code

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 = "5.0.2"
19+
spec.version = "5.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.4"
139+
spec.dependency "Poly", "~> 2.6"
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
@@ -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(

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ If you find something wrong with this library and it isn't already mentioned und
6666
### Swift Package Manager
6767
Just include the following in your package's dependencies and add `JSONAPI` to the dependencies for any of your targets.
6868
```swift
69-
.package(url: "https://github.com/mattpolzin/JSONAPI.git", from: "5.0.2")
69+
.package(url: "https://github.com/mattpolzin/JSONAPI.git", from: "5.1.0")
7070
```
7171

7272
### Xcode project

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/DocumentDecodingError.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ public enum DocumentDecodingError: Swift.Error, Equatable {
3333
self = .primaryResourceMissing
3434
case .valueNotFound(let type, let context) where Location(context) == .data && type == UnkeyedDecodingContainer.self:
3535
self = .primaryResourcesMissing
36+
case .typeMismatch(let type, let context) where Location(context) == .data && type is _ArrayType.Type && context.debugDescription.hasSuffix("but found null instead."):
37+
self = .primaryResourcesMissing
38+
case .typeMismatch(_, let context) where Location(context) == .data && context.debugDescription.hasSuffix("but found null instead."):
39+
self = .primaryResourceMissing
3640
default:
3741
return nil
3842
}
@@ -71,3 +75,6 @@ extension DocumentDecodingError: CustomStringConvertible {
7175
}
7276
}
7377
}
78+
79+
private protocol _ArrayType {}
80+
extension Array: _ArrayType {}

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/JSONAPI/Resource/Resource Object/ResourceObjectDecodingError.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,16 @@ public struct ResourceObjectDecodingError: Swift.Error, Equatable {
117117
location = .type
118118
}
119119

120+
let subjectPath: [CodingKey]
121+
if location == .relationships && path.last?.stringValue == "data" {
122+
subjectPath = path.dropLast()
123+
} else {
124+
subjectPath = path
125+
}
126+
120127
return (
121128
location,
122-
name: path.last?.stringValue ?? "unnamed"
129+
name: subjectPath.last?.stringValue ?? "unnamed"
123130
)
124131
}
125132
}
@@ -130,15 +137,15 @@ extension ResourceObjectDecodingError: CustomStringConvertible {
130137
case .keyNotFound where subjectName == ResourceObjectDecodingError.entireObject:
131138
return "\(location) object is required and missing."
132139
case .keyNotFound where location == .type:
133-
return "'type' (a.k.a. JSON:API type name) is required and missing."
140+
return "'type' (a.k.a. the JSON:API type name) is required and missing."
134141
case .keyNotFound where location == .relationshipType:
135142
return "'\(subjectName)' relationship does not have a 'type'."
136143
case .keyNotFound where location == .relationshipId:
137144
return "'\(subjectName)' relationship does not have an 'id'."
138145
case .keyNotFound:
139146
return "'\(subjectName)' \(location.singular) is required and missing."
140147
case .valueNotFound where location == .type:
141-
return "'\(location.singular)' (a.k.a. JSON:API type name) is not nullable but null was found."
148+
return "'\(location.singular)' (a.k.a. the JSON:API type name) is not nullable but null was found."
142149
case .valueNotFound:
143150
return "'\(subjectName)' \(location.singular) is not nullable but null was found."
144151
case .typeMismatch(expectedTypeName: let expected) where location == .type:

0 commit comments

Comments
 (0)