66//
77
88public protocol JSONAPIDocument : Codable , Equatable {
9- associatedtype ResourceBody : JSONAPI . ResourceBody
9+ associatedtype PrimaryResourceBody : JSONAPI . ResourceBody
1010 associatedtype MetaType : JSONAPI . Meta
1111 associatedtype LinksType : JSONAPI . Links
1212 associatedtype IncludeType : JSONAPI . Include
1313 associatedtype Error : JSONAPIError
1414
15- var body : Document < ResourceBody , MetaType , LinksType , IncludeType , Error > . Body { get }
15+ typealias Body = Document < PrimaryResourceBody , MetaType , LinksType , IncludeType , Error > . Body
16+ typealias BodyData = Body . Data
17+
18+ var body : Body { get }
1619}
1720
1821/// A JSON API Document represents the entire body
@@ -22,7 +25,7 @@ public protocol JSONAPIDocument: Codable, Equatable {
2225/// API uses snake case, you will want to use
2326/// a conversion such as the one offerred by the
2427/// Foundation JSONEncoder/Decoder: `KeyDecodingStrategy`
25- public struct Document < ResourceBody : JSONAPI . ResourceBody , MetaType: JSONAPI . Meta , LinksType: JSONAPI . Links , IncludeType: JSONAPI . Include , Error: JSONAPIError > : JSONAPIDocument {
28+ public struct Document < PrimaryResourceBody : JSONAPI . ResourceBody , MetaType: JSONAPI . Meta , LinksType: JSONAPI . Links , IncludeType: JSONAPI . Include , Error: JSONAPIError > : JSONAPIDocument {
2629 public typealias Include = IncludeType
2730
2831 public let body : Body
@@ -33,7 +36,7 @@ public struct Document<ResourceBody: JSONAPI.ResourceBody, MetaType: JSONAPI.Met
3336 case data( Data )
3437
3538 public struct Data : Equatable {
36- public let primary : ResourceBody
39+ public let primary : PrimaryResourceBody
3740 public let includes : Includes < Include >
3841 public let meta : MetaType
3942 public let links : LinksType
@@ -49,7 +52,7 @@ public struct Document<ResourceBody: JSONAPI.ResourceBody, MetaType: JSONAPI.Met
4952 return errors
5053 }
5154
52- public var primaryData : ResourceBody ? {
55+ public var primaryData : PrimaryResourceBody ? {
5356 guard case let . data( data) = self else { return nil }
5457 return data. primary
5558 }
@@ -86,49 +89,49 @@ public struct Document<ResourceBody: JSONAPI.ResourceBody, MetaType: JSONAPI.Met
8689 body = . errors( errors, meta: meta, links: links)
8790 }
8891
89- public init ( body: ResourceBody , includes: Includes < Include > , meta: MetaType , links: LinksType ) {
92+ public init ( body: PrimaryResourceBody , includes: Includes < Include > , meta: MetaType , links: LinksType ) {
9093 self . body = . data( . init( primary: body, includes: includes, meta: meta, links: links) )
9194 }
9295}
9396
9497extension Document where IncludeType == NoIncludes {
95- public init ( body: ResourceBody , meta: MetaType , links: LinksType ) {
98+ public init ( body: PrimaryResourceBody , meta: MetaType , links: LinksType ) {
9699 self . body = . data( . init( primary: body, includes: . none, meta: meta, links: links) )
97100 }
98101}
99102
100103extension Document where MetaType == NoMetadata {
101- public init ( body: ResourceBody , includes: Includes < Include > , links: LinksType ) {
104+ public init ( body: PrimaryResourceBody , includes: Includes < Include > , links: LinksType ) {
102105 self . body = . data( . init( primary: body, includes: includes, meta: . none, links: links) )
103106 }
104107}
105108
106109extension Document where LinksType == NoLinks {
107- public init ( body: ResourceBody , includes: Includes < Include > , meta: MetaType ) {
110+ public init ( body: PrimaryResourceBody , includes: Includes < Include > , meta: MetaType ) {
108111 self . body = . data( . init( primary: body, includes: includes, meta: meta, links: . none) )
109112 }
110113}
111114
112115extension Document where IncludeType == NoIncludes , LinksType == NoLinks {
113- public init ( body: ResourceBody , meta: MetaType ) {
116+ public init ( body: PrimaryResourceBody , meta: MetaType ) {
114117 self . body = . data( . init( primary: body, includes: . none, meta: meta, links: . none) )
115118 }
116119}
117120
118121extension Document where IncludeType == NoIncludes , MetaType == NoMetadata {
119- public init ( body: ResourceBody , links: LinksType ) {
122+ public init ( body: PrimaryResourceBody , links: LinksType ) {
120123 self . body = . data( . init( primary: body, includes: . none, meta: . none, links: links) )
121124 }
122125}
123126
124127extension Document where MetaType == NoMetadata , LinksType == NoLinks {
125- public init ( body: ResourceBody , includes: Includes < Include > ) {
128+ public init ( body: PrimaryResourceBody , includes: Includes < Include > ) {
126129 self . body = . data( . init( primary: body, includes: includes, meta: . none, links: . none) )
127130 }
128131}
129132
130133extension Document where IncludeType == NoIncludes , MetaType == NoMetadata , LinksType == NoLinks {
131- public init ( body: ResourceBody ) {
134+ public init ( body: PrimaryResourceBody ) {
132135 self . body = . data( . init( primary: body, includes: . none, meta: . none, links: . none) )
133136 }
134137}
@@ -176,11 +179,11 @@ extension Document {
176179 return
177180 }
178181
179- let data : ResourceBody
180- if let noData = NoResourceBody ( ) as? ResourceBody {
182+ let data : PrimaryResourceBody
183+ if let noData = NoResourceBody ( ) as? PrimaryResourceBody {
181184 data = noData
182185 } else {
183- data = try container. decode ( ResourceBody . self, forKey: . data)
186+ data = try container. decode ( PrimaryResourceBody . self, forKey: . data)
184187 }
185188
186189 let maybeIncludes = try container. decodeIfPresent ( Includes< Include> . self , forKey: . included)
0 commit comments