From 9374956b920325d2eae4ed0cbb68801f23eecfbf Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Fri, 29 May 2020 15:03:23 -0700 Subject: [PATCH 1/2] bug fix to playground example. --- .../Pages/PATCHing.xcplaygroundpage/Contents.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/JSONAPI.playground/Pages/PATCHing.xcplaygroundpage/Contents.swift b/JSONAPI.playground/Pages/PATCHing.xcplaygroundpage/Contents.swift index ded305e..f916054 100644 --- a/JSONAPI.playground/Pages/PATCHing.xcplaygroundpage/Contents.swift +++ b/JSONAPI.playground/Pages/PATCHing.xcplaygroundpage/Contents.swift @@ -108,7 +108,7 @@ print("Received dog with owner: \(dog3 ~> \.owner)") // give the dog an owner let changedDog3 = dog3.replacingRelationships { _ in - return .init(owner: .init(id: ID(rawValue: "1"))) + return .init(owner: .init(id: Id(rawValue: "1"))) } // create a document to be used as a request body for a PATCH request From 7dd09779a0222d2d57f274d11749d534538b205a Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Fri, 29 May 2020 15:40:05 -0700 Subject: [PATCH 2/2] Attempt to force compiler to acknowledge that ResourceObjectProxy and ResourceObject have the same ID type. --- .../Resource/Resource Object/ResourceObject.swift | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Sources/JSONAPI/Resource/Resource Object/ResourceObject.swift b/Sources/JSONAPI/Resource/Resource Object/ResourceObject.swift index b068ebd..88ae539 100644 --- a/Sources/JSONAPI/Resource/Resource Object/ResourceObject.swift +++ b/Sources/JSONAPI/Resource/Resource Object/ResourceObject.swift @@ -73,8 +73,6 @@ public protocol ResourceObjectProxy: Equatable, JSONTyped { associatedtype Description: ResourceObjectProxyDescription associatedtype EntityRawIdType: JSONAPI.MaybeRawId - typealias ID = JSONAPI.Id - typealias Attributes = Description.Attributes typealias Relationships = Description.Relationships @@ -82,7 +80,7 @@ public protocol ResourceObjectProxy: Equatable, JSONTyped { /// the entity is being created clientside and the /// server is being asked to create a unique Id. Otherwise, /// this should be of a type conforming to `IdType`. - var id: ID { get } + var id: JSONAPI.Id { get } /// The JSON API compliant attributes of this `Entity`. var attributes: Attributes { get } @@ -91,6 +89,10 @@ public protocol ResourceObjectProxy: Equatable, JSONTyped { var relationships: Relationships { get } } +extension ResourceObjectProxy { + public typealias ID = JSONAPI.Id +} + extension ResourceObjectProxy { /// The JSON API compliant "type" of this `ResourceObject`. public static var jsonType: String { return Description.jsonType } @@ -121,7 +123,6 @@ public protocol IdentifiableResourceObjectType: ResourceObjectType, Relatable wh /// See https://jsonapi.org/format/#document-resource-objects public struct ResourceObject: ResourceObjectType { - public typealias ID = JSONAPI.Id public typealias Meta = MetaType public typealias Links = LinksType