Skip to content

Commit

Permalink
Merge pull request #71 from mattpolzin/bugfix/expose-ID-publicly
Browse files Browse the repository at this point in the history
Bugfix/expose id publicly
  • Loading branch information
mattpolzin authored May 29, 2020
2 parents 8aa20f3 + 7dd0977 commit 0c48ddf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions Sources/JSONAPI/Resource/Resource Object/ResourceObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,14 @@ public protocol ResourceObjectProxy: Equatable, JSONTyped {
associatedtype Description: ResourceObjectProxyDescription
associatedtype EntityRawIdType: JSONAPI.MaybeRawId

typealias ID = JSONAPI.Id<EntityRawIdType, Self>

typealias Attributes = Description.Attributes
typealias Relationships = Description.Relationships

/// The `Entity`'s Id. This can be of type `Unidentified` if
/// 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<EntityRawIdType, Self> { get }

/// The JSON API compliant attributes of this `Entity`.
var attributes: Attributes { get }
Expand All @@ -91,6 +89,10 @@ public protocol ResourceObjectProxy: Equatable, JSONTyped {
var relationships: Relationships { get }
}

extension ResourceObjectProxy {
public typealias ID = JSONAPI.Id<EntityRawIdType, Self>
}

extension ResourceObjectProxy {
/// The JSON API compliant "type" of this `ResourceObject`.
public static var jsonType: String { return Description.jsonType }
Expand Down Expand Up @@ -121,7 +123,6 @@ public protocol IdentifiableResourceObjectType: ResourceObjectType, Relatable wh
/// See https://jsonapi.org/format/#document-resource-objects
public struct ResourceObject<Description: JSONAPI.ResourceObjectDescription, MetaType: JSONAPI.Meta, LinksType: JSONAPI.Links, EntityRawIdType: JSONAPI.MaybeRawId>: ResourceObjectType {

public typealias ID = JSONAPI.Id<EntityRawIdType, Self>
public typealias Meta = MetaType
public typealias Links = LinksType

Expand Down

0 comments on commit 0c48ddf

Please sign in to comment.