diff --git a/JSONAPI.playground/Pages/Full Client & Server Example.xcplaygroundpage/Contents.swift b/JSONAPI.playground/Pages/Full Client & Server Example.xcplaygroundpage/Contents.swift index 863d298..2e54355 100644 --- a/JSONAPI.playground/Pages/Full Client & Server Example.xcplaygroundpage/Contents.swift +++ b/JSONAPI.playground/Pages/Full Client & Server Example.xcplaygroundpage/Contents.swift @@ -19,13 +19,13 @@ extension String: CreatableRawIdType { // We create a typealias given that we do not expect JSON:API Resource // Objects for this particular API to have Metadata or Links associated // with them. We also expect them to have String Identifiers. -typealias JSONEntity = JSONAPI.Entity +typealias JSONEntity = JSONAPI.ResourceObject // Similarly, we create a typealias for unidentified entities. JSON:API // only allows unidentified entities (i.e. no "id" field) for client // requests that create new entities. In these situations, the server // is expected to assign the new entity a unique ID. -typealias UnidentifiedJSONEntity = JSONAPI.Entity +typealias UnidentifiedJSONEntity = JSONAPI.ResourceObject // We create typealiases given that we do not expect JSON:API Relationships // for this particular API to have Metadata or Links associated @@ -95,7 +95,7 @@ func articleDocument(includeAuthor: Bool) -> Either +typealias Author = JSONAPI.ResourceObject /// Description of an Article entity. enum ArticleDescription: ResourceObjectDescription { @@ -96,7 +96,7 @@ enum ArticleDescription: ResourceObjectDescription { } } -typealias Article = JSONAPI.Entity +typealias Article = JSONAPI.ResourceObject /// Metadata associated with the API Description struct APIDescriptionMetadata: JSONAPI.Meta { @@ -196,7 +196,7 @@ let documentLinks = SingleArticleDocumentLinks(otherArticlesByPrimaryAuthor: .in meta: .init(expiry: tomorrow))) let singleArticleDocument = SingleArticleDocument(apiDescription: apiDescription, - body: .init(entity: article), + body: .init(resourceObject: article), includes: .init(values: [.init(author1), .init(author2), .init(author3)]), meta: documentMetadata, links: documentLinks) diff --git a/JSONAPI.playground/Pages/Usage.xcplaygroundpage/Contents.swift b/JSONAPI.playground/Pages/Usage.xcplaygroundpage/Contents.swift index cdd90fe..22bb3c0 100644 --- a/JSONAPI.playground/Pages/Usage.xcplaygroundpage/Contents.swift +++ b/JSONAPI.playground/Pages/Usage.xcplaygroundpage/Contents.swift @@ -11,7 +11,7 @@ Please enjoy these examples, but allow me the forced casting and the lack of err // MARK: - Create a request or response body with one Dog in it let dogFromCode = try! Dog(name: "Buddy", owner: nil) -let singleDogDocument = SingleDogDocument(apiDescription: .none, body: .init(entity: dogFromCode), includes: .none, meta: .none, links: .none) +let singleDogDocument = SingleDogDocument(apiDescription: .none, body: .init(resourceObject: dogFromCode), includes: .none, meta: .none, links: .none) let singleDogData = try! JSONEncoder().encode(singleDogDocument) @@ -33,7 +33,7 @@ let houses = [House(attributes: .none, relationships: .none, meta: .none, links: let people = try! [Person(id: personIds[0], name: ["Gary", "Doe"], favoriteColor: "Orange-Red", friends: [], dogs: [dogs[0], dogs[1]], home: houses[0]), Person(id: personIds[1], name: ["Elise", "Joy"], favoriteColor: "Red", friends: [], dogs: [dogs[2]], home: houses[1])] let includes = dogs.map { BatchPeopleDocument.Include($0) } + houses.map { BatchPeopleDocument.Include($0) } -let batchPeopleDocument = BatchPeopleDocument(apiDescription: .none, body: .init(entities: people), includes: .init(values: includes), meta: .none, links: .none) +let batchPeopleDocument = BatchPeopleDocument(apiDescription: .none, body: .init(resourceObjects: people), includes: .init(values: includes), meta: .none, links: .none) let batchPeopleData = try! JSONEncoder().encode(batchPeopleDocument) // MARK: - Parse a request or response body with multiple people in it and dogs and houses included diff --git a/JSONAPI.playground/Sources/Entities.swift b/JSONAPI.playground/Sources/Entities.swift index c165d3d..a62c993 100644 --- a/JSONAPI.playground/Sources/Entities.swift +++ b/JSONAPI.playground/Sources/Entities.swift @@ -24,7 +24,7 @@ extension String: CreatableRawIdType { } // MARK: - typealiases for convenience -public typealias ExampleEntity = Entity +public typealias ExampleEntity = ResourceObject public typealias ToOne = ToOneRelationship public typealias ToMany = ToManyRelationship @@ -62,9 +62,9 @@ public enum PersonDescription: ResourceObjectDescription { public typealias Person = ExampleEntity -public extension Entity where Description == PersonDescription, MetaType == NoMetadata, LinksType == NoLinks, EntityRawIdType == String { +public extension ResourceObject where Description == PersonDescription, MetaType == NoMetadata, LinksType == NoLinks, EntityRawIdType == String { init(id: Person.Id? = nil,name: [String], favoriteColor: String, friends: [Person], dogs: [Dog], home: House) throws { - self = Person(id: id ?? Person.Id(), attributes: .init(name: .init(value: name), favoriteColor: .init(value: favoriteColor)), relationships: .init(friends: .init(entities: friends), dogs: .init(entities: dogs), home: .init(entity: home)), meta: .none, links: .none) + self = Person(id: id ?? Person.Id(), attributes: .init(name: .init(value: name), favoriteColor: .init(value: favoriteColor)), relationships: .init(friends: .init(resourceObjects: friends), dogs: .init(resourceObjects: dogs), home: .init(resourceObject: home)), meta: .none, links: .none) } } @@ -119,9 +119,9 @@ public enum AlternativeDogDescription: ResourceObjectDescription { public typealias AlternativeDog = ExampleEntity -public extension Entity where Description == DogDescription, MetaType == NoMetadata, LinksType == NoLinks, EntityRawIdType == String { +public extension ResourceObject where Description == DogDescription, MetaType == NoMetadata, LinksType == NoLinks, EntityRawIdType == String { init(name: String, owner: Person?) throws { - self = Dog(attributes: .init(name: .init(value: name)), relationships: DogDescription.Relationships(owner: .init(entity: owner)), meta: .none, links: .none) + self = Dog(attributes: .init(name: .init(value: name)), relationships: DogDescription.Relationships(owner: .init(resourceObject: owner)), meta: .none, links: .none) } init(name: String, owner: Person.Id) throws { diff --git a/Sources/JSONAPI/Document/ResourceBody.swift b/Sources/JSONAPI/Document/ResourceBody.swift index 62c5224..eed341e 100644 --- a/Sources/JSONAPI/Document/ResourceBody.swift +++ b/Sources/JSONAPI/Document/ResourceBody.swift @@ -30,20 +30,20 @@ public func +(_ left: R, right: R) -> R { public struct SingleResourceBody: ResourceBody { public let value: Entity - public init(entity: Entity) { - self.value = entity + public init(resourceObject: Entity) { + self.value = resourceObject } } public struct ManyResourceBody: AppendableResourceBody { public let values: [Entity] - public init(entities: [Entity]) { - values = entities + public init(resourceObjects: [Entity]) { + values = resourceObjects } public func appending(_ other: ManyResourceBody) -> ManyResourceBody { - return ManyResourceBody(entities: values + other.values) + return ManyResourceBody(resourceObjects: values + other.values) } } diff --git a/Sources/JSONAPI/Resource/Id.swift b/Sources/JSONAPI/Resource/Id.swift index fc611fe..7265a18 100644 --- a/Sources/JSONAPI/Resource/Id.swift +++ b/Sources/JSONAPI/Resource/Id.swift @@ -69,7 +69,7 @@ public protocol CreatableIdType: IdType { init() } -/// An Entity ID. These IDs can be encoded to or decoded from +/// An ResourceObject ID. These IDs can be encoded to or decoded from /// JSON API IDs. public struct Id: Equatable, OptionalId { diff --git a/Sources/JSONAPI/Resource/Relationship.swift b/Sources/JSONAPI/Resource/Relationship.swift index 2af4d04..f6a4bdc 100644 --- a/Sources/JSONAPI/Resource/Relationship.swift +++ b/Sources/JSONAPI/Resource/Relationship.swift @@ -13,7 +13,7 @@ public protocol RelationshipType { var meta: MetaType { get } } -/// An Entity relationship that can be encoded to or decoded from +/// An ResourceObject relationship that can be encoded to or decoded from /// a JSON API "Resource Linkage." /// See https://jsonapi.org/format/#document-resource-object-linkage /// A convenient typealias might make your code much more legible: `One` @@ -38,30 +38,30 @@ extension ToOneRelationship where MetaType == NoMetadata, LinksType == NoLinks { } extension ToOneRelationship { - public init(entity: E, meta: MetaType, links: LinksType) where E.Id == Identifiable.Identifier { - self.init(id: entity.id, meta: meta, links: links) + public init(resourceObject: T, meta: MetaType, links: LinksType) where T.Id == Identifiable.Identifier { + self.init(id: resourceObject.id, meta: meta, links: links) } } extension ToOneRelationship where MetaType == NoMetadata, LinksType == NoLinks { - public init(entity: E) where E.Id == Identifiable.Identifier { - self.init(id: entity.id, meta: .none, links: .none) + public init(resourceObject: T) where T.Id == Identifiable.Identifier { + self.init(id: resourceObject.id, meta: .none, links: .none) } } extension ToOneRelationship where Identifiable: OptionalRelatable { - public init(entity: E?, meta: MetaType, links: LinksType) where E.Id == Identifiable.Wrapped.Identifier { - self.init(id: entity?.id, meta: meta, links: links) + public init(resourceObject: T?, meta: MetaType, links: LinksType) where T.Id == Identifiable.Wrapped.Identifier { + self.init(id: resourceObject?.id, meta: meta, links: links) } } extension ToOneRelationship where Identifiable: OptionalRelatable, MetaType == NoMetadata, LinksType == NoLinks { - public init(entity: E?) where E.Id == Identifiable.Wrapped.Identifier { - self.init(id: entity?.id, meta: .none, links: .none) + public init(resourceObject: T?) where T.Id == Identifiable.Wrapped.Identifier { + self.init(id: resourceObject?.id, meta: .none, links: .none) } } -/// An Entity relationship that can be encoded to or decoded from +/// An ResourceObject relationship that can be encoded to or decoded from /// a JSON API "Resource Linkage." /// See https://jsonapi.org/format/#document-resource-object-linkage /// A convenient typealias might make your code much more legible: `Many` @@ -84,8 +84,8 @@ public struct ToManyRelationship(entities: [E], meta: MetaType, links: LinksType) where E.Id == Relatable.Identifier { - self.init(ids: entities.map { $0.id }, meta: meta, links: links) + public init(resourceObjects: [T], meta: MetaType, links: LinksType) where T.Id == Relatable.Identifier { + self.init(ids: resourceObjects.map { $0.id }, meta: meta, links: links) } private init(meta: MetaType, links: LinksType) { @@ -111,8 +111,8 @@ extension ToManyRelationship where MetaType == NoMetadata, LinksType == NoLinks return .none(withMeta: .none, links: .none) } - public init(entities: [E]) where E.Id == Relatable.Identifier { - self.init(entities: entities, meta: .none, links: .none) + public init(resourceObjects: [T]) where T.Id == Relatable.Identifier { + self.init(resourceObjects: resourceObjects, meta: .none, links: .none) } } diff --git a/Sources/JSONAPI/Resource/ResourceObject.swift b/Sources/JSONAPI/Resource/ResourceObject.swift index 89cdc52..cdbdd7e 100644 --- a/Sources/JSONAPI/Resource/ResourceObject.swift +++ b/Sources/JSONAPI/Resource/ResourceObject.swift @@ -1,16 +1,16 @@ // -// Entity.swift +// ResourceObject.swift // JSONAPI // // Created by Mathew Polzin on 7/24/18. // -/// A JSON API structure within an Entity that contains +/// A JSON API structure within an ResourceObject that contains /// named properties of types `ToOneRelationship` and /// `ToManyRelationship`. public protocol Relationships: Codable & Equatable {} -/// A JSON API structure within an Entity that contains +/// A JSON API structure within an ResourceObject that contains /// properties of any types that are JSON encodable. public protocol Attributes: Codable & Equatable {} @@ -50,7 +50,7 @@ public protocol ResourceObjectProxyDescription: JSONTyped { /// An `ResourceObjectDescription` describes a JSON API /// Resource Object. The Resource Object /// itself is encoded and decoded as an -/// `Entity`, which gets specialized on an +/// `ResourceObject`, which gets specialized on an /// `ResourceObjectDescription`. public protocol ResourceObjectDescription: ResourceObjectProxyDescription where Attributes: JSONAPI.Attributes, Relationships: JSONAPI.Relationships {} @@ -84,35 +84,35 @@ extension ResourceObjectProxy { public static var jsonType: String { return Description.jsonType } } -/// ResourceObjectType is the protocol that Entity conforms to. This -/// protocol lets other types accept any Entity as a generic +/// ResourceObjectType is the protocol that ResourceObject conforms to. This +/// protocol lets other types accept any ResourceObject as a generic /// specialization. public protocol ResourceObjectType: ResourceObjectProxy, PrimaryResource where Description: ResourceObjectDescription { associatedtype Meta: JSONAPI.Meta associatedtype Links: JSONAPI.Links } -public protocol IdentifiableEntityType: ResourceObjectType, Relatable where EntityRawIdType: JSONAPI.RawIdType {} +public protocol IdentifiableResourceObjectType: ResourceObjectType, Relatable where EntityRawIdType: JSONAPI.RawIdType {} -/// An `Entity` is a single model type that can be +/// An `ResourceObject` is a single model type that can be /// encoded to or decoded from a JSON API /// "Resource Object." /// See https://jsonapi.org/format/#document-resource-objects -public struct Entity: ResourceObjectType { +public struct ResourceObject: ResourceObjectType { public typealias Meta = MetaType public typealias Links = LinksType - /// The `Entity`'s Id. This can be of type `Unidentified` if + /// The `ResourceObject`'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`. - public let id: Entity.Id + public let id: ResourceObject.Id - /// The JSON API compliant attributes of this `Entity`. + /// The JSON API compliant attributes of this `ResourceObject`. public let attributes: Description.Attributes - /// The JSON API compliant relationships of this `Entity`. + /// The JSON API compliant relationships of this `ResourceObject`. public let relationships: Description.Relationships /// Any additional metadata packaged with the entity. @@ -121,7 +121,7 @@ public struct Entity(id: \(String(describing: id)), attributes: \(String(describing: attributes)), relationships: \(String(describing: relationships)))" + return "ResourceObject<\(ResourceObject.jsonType)>(id: \(String(describing: id)), attributes: \(String(describing: attributes)), relationships: \(String(describing: relationships)))" } } // MARK: Convenience initializers -extension Entity where EntityRawIdType: CreatableRawIdType { +extension ResourceObject where EntityRawIdType: CreatableRawIdType { public init(attributes: Description.Attributes, relationships: Description.Relationships, meta: MetaType, links: LinksType) { - self.id = Entity.Id() + self.id = ResourceObject.Id() self.attributes = attributes self.relationships = relationships self.meta = meta @@ -151,7 +151,7 @@ extension Entity where EntityRawIdType: CreatableRawIdType { } } -extension Entity where EntityRawIdType == Unidentified { +extension ResourceObject where EntityRawIdType == Unidentified { public init(attributes: Description.Attributes, relationships: Description.Relationships, meta: MetaType, links: LinksType) { self.id = .unidentified self.attributes = attributes @@ -162,229 +162,229 @@ extension Entity where EntityRawIdType == Unidentified { } /* -extension Entity where Description.Attributes == NoAttributes { - public init(id: Entity.Id, relationships: Description.Relationships, meta: MetaType, links: LinksType) { +extension ResourceObject where Description.Attributes == NoAttributes { + public init(id: ResourceObject.Id, relationships: Description.Relationships, meta: MetaType, links: LinksType) { self.init(id: id, attributes: NoAttributes(), relationships: relationships, meta: meta, links: links) } } -extension Entity where Description.Attributes == NoAttributes, MetaType == NoMetadata { - public init(id: Entity.Id, relationships: Description.Relationships, links: LinksType) { +extension ResourceObject where Description.Attributes == NoAttributes, MetaType == NoMetadata { + public init(id: ResourceObject.Id, relationships: Description.Relationships, links: LinksType) { self.init(id: id, relationships: relationships, meta: .none, links: links) } } -extension Entity where Description.Attributes == NoAttributes, LinksType == NoLinks { - public init(id: Entity.Id, relationships: Description.Relationships, meta: MetaType) { +extension ResourceObject where Description.Attributes == NoAttributes, LinksType == NoLinks { + public init(id: ResourceObject.Id, relationships: Description.Relationships, meta: MetaType) { self.init(id: id, relationships: relationships, meta: meta, links: .none) } } -extension Entity where Description.Attributes == NoAttributes, MetaType == NoMetadata, LinksType == NoLinks { - public init(id: Entity.Id, relationships: Description.Relationships) { +extension ResourceObject where Description.Attributes == NoAttributes, MetaType == NoMetadata, LinksType == NoLinks { + public init(id: ResourceObject.Id, relationships: Description.Relationships) { self.init(id: id, relationships: relationships, links: .none) } } -extension Entity where Description.Attributes == NoAttributes, EntityRawIdType: CreatableRawIdType { +extension ResourceObject where Description.Attributes == NoAttributes, EntityRawIdType: CreatableRawIdType { public init(relationships: Description.Relationships, meta: MetaType, links: LinksType) { self.init(attributes: NoAttributes(), relationships: relationships, meta: meta, links: links) } } -extension Entity where Description.Attributes == NoAttributes, MetaType == NoMetadata, EntityRawIdType: CreatableRawIdType { +extension ResourceObject where Description.Attributes == NoAttributes, MetaType == NoMetadata, EntityRawIdType: CreatableRawIdType { public init(relationships: Description.Relationships, links: LinksType) { self.init(attributes: NoAttributes(), relationships: relationships, meta: .none, links: links) } } -extension Entity where Description.Attributes == NoAttributes, LinksType == NoLinks, EntityRawIdType: CreatableRawIdType { +extension ResourceObject where Description.Attributes == NoAttributes, LinksType == NoLinks, EntityRawIdType: CreatableRawIdType { public init(relationships: Description.Relationships, meta: MetaType) { self.init(attributes: NoAttributes(), relationships: relationships, meta: meta, links: .none) } } -extension Entity where Description.Attributes == NoAttributes, MetaType == NoMetadata, LinksType == NoLinks, EntityRawIdType: CreatableRawIdType { +extension ResourceObject where Description.Attributes == NoAttributes, MetaType == NoMetadata, LinksType == NoLinks, EntityRawIdType: CreatableRawIdType { public init(relationships: Description.Relationships) { self.init(attributes: NoAttributes(), relationships: relationships, meta: .none, links: .none) } } -extension Entity where Description.Attributes == NoAttributes, EntityRawIdType == Unidentified { +extension ResourceObject where Description.Attributes == NoAttributes, EntityRawIdType == Unidentified { public init(relationships: Description.Relationships, meta: MetaType, links: LinksType) { self.init(attributes: NoAttributes(), relationships: relationships, meta: meta, links: links) } } -extension Entity where Description.Relationships == NoRelationships { - public init(id: Entity.Id, attributes: Description.Attributes, meta: MetaType, links: LinksType) { +extension ResourceObject where Description.Relationships == NoRelationships { + public init(id: ResourceObject.Id, attributes: Description.Attributes, meta: MetaType, links: LinksType) { self.init(id: id, attributes: attributes, relationships: NoRelationships(), meta: meta, links: links) } } -extension Entity where Description.Relationships == NoRelationships, MetaType == NoMetadata { - public init(id: Entity.Id, attributes: Description.Attributes, links: LinksType) { +extension ResourceObject where Description.Relationships == NoRelationships, MetaType == NoMetadata { + public init(id: ResourceObject.Id, attributes: Description.Attributes, links: LinksType) { self.init(id: id, attributes: attributes, meta: .none, links: links) } } -extension Entity where Description.Relationships == NoRelationships, LinksType == NoLinks { - public init(id: Entity.Id, attributes: Description.Attributes, meta: MetaType) { +extension ResourceObject where Description.Relationships == NoRelationships, LinksType == NoLinks { + public init(id: ResourceObject.Id, attributes: Description.Attributes, meta: MetaType) { self.init(id: id, attributes: attributes, meta: meta, links: .none) } } -extension Entity where Description.Relationships == NoRelationships, MetaType == NoMetadata, LinksType == NoLinks { - public init(id: Entity.Id, attributes: Description.Attributes) { +extension ResourceObject where Description.Relationships == NoRelationships, MetaType == NoMetadata, LinksType == NoLinks { + public init(id: ResourceObject.Id, attributes: Description.Attributes) { self.init(id: id, attributes: attributes, meta: .none, links: .none) } } -extension Entity where Description.Relationships == NoRelationships, EntityRawIdType: CreatableRawIdType { +extension ResourceObject where Description.Relationships == NoRelationships, EntityRawIdType: CreatableRawIdType { public init(attributes: Description.Attributes, meta: MetaType, links: LinksType) { self.init(attributes: attributes, relationships: NoRelationships(), meta: meta, links: links) } } -extension Entity where Description.Relationships == NoRelationships, MetaType == NoMetadata, EntityRawIdType: CreatableRawIdType { +extension ResourceObject where Description.Relationships == NoRelationships, MetaType == NoMetadata, EntityRawIdType: CreatableRawIdType { public init(attributes: Description.Attributes, links: LinksType) { self.init(attributes: attributes, relationships: NoRelationships(), meta: .none, links: links) } } -extension Entity where Description.Relationships == NoRelationships, LinksType == NoLinks, EntityRawIdType: CreatableRawIdType { +extension ResourceObject where Description.Relationships == NoRelationships, LinksType == NoLinks, EntityRawIdType: CreatableRawIdType { public init(attributes: Description.Attributes, meta: MetaType) { self.init(attributes: attributes, relationships: NoRelationships(), meta: meta, links: .none) } } -extension Entity where Description.Relationships == NoRelationships, MetaType == NoMetadata, LinksType == NoLinks, EntityRawIdType: CreatableRawIdType { +extension ResourceObject where Description.Relationships == NoRelationships, MetaType == NoMetadata, LinksType == NoLinks, EntityRawIdType: CreatableRawIdType { public init(attributes: Description.Attributes) { self.init(attributes: attributes, relationships: NoRelationships(), meta: .none, links: .none) } } -extension Entity where Description.Relationships == NoRelationships, EntityRawIdType == Unidentified { +extension ResourceObject where Description.Relationships == NoRelationships, EntityRawIdType == Unidentified { public init(attributes: Description.Attributes, meta: MetaType, links: LinksType) { self.init(attributes: attributes, relationships: NoRelationships(), meta: meta, links: links) } } -extension Entity where Description.Relationships == NoRelationships, MetaType == NoMetadata, EntityRawIdType == Unidentified { +extension ResourceObject where Description.Relationships == NoRelationships, MetaType == NoMetadata, EntityRawIdType == Unidentified { public init(attributes: Description.Attributes, links: LinksType) { self.init(attributes: attributes, relationships: NoRelationships(), meta: .none, links: links) } } -extension Entity where Description.Relationships == NoRelationships, LinksType == NoLinks, EntityRawIdType == Unidentified { +extension ResourceObject where Description.Relationships == NoRelationships, LinksType == NoLinks, EntityRawIdType == Unidentified { public init(attributes: Description.Attributes, meta: MetaType) { self.init(attributes: attributes, relationships: NoRelationships(), meta: meta, links: .none) } } -extension Entity where Description.Relationships == NoRelationships, MetaType == NoMetadata, LinksType == NoLinks, EntityRawIdType == Unidentified { +extension ResourceObject where Description.Relationships == NoRelationships, MetaType == NoMetadata, LinksType == NoLinks, EntityRawIdType == Unidentified { public init(attributes: Description.Attributes) { self.init(attributes: attributes, relationships: NoRelationships(), meta: .none, links: .none) } } -extension Entity where Description.Attributes == NoAttributes, Description.Relationships == NoRelationships { - public init(id: Entity.Id, meta: MetaType, links: LinksType) { +extension ResourceObject where Description.Attributes == NoAttributes, Description.Relationships == NoRelationships { + public init(id: ResourceObject.Id, meta: MetaType, links: LinksType) { self.init(id: id, attributes: NoAttributes(), relationships: NoRelationships(), meta: meta, links: links) } } -extension Entity where Description.Attributes == NoAttributes, Description.Relationships == NoRelationships, MetaType == NoMetadata { - public init(id: Entity.Id, links: LinksType) { +extension ResourceObject where Description.Attributes == NoAttributes, Description.Relationships == NoRelationships, MetaType == NoMetadata { + public init(id: ResourceObject.Id, links: LinksType) { self.init(id: id, attributes: NoAttributes(), relationships: NoRelationships(), meta: .none, links: links) } } -extension Entity where Description.Attributes == NoAttributes, Description.Relationships == NoRelationships, LinksType == NoLinks { - public init(id: Entity.Id, meta: MetaType) { +extension ResourceObject where Description.Attributes == NoAttributes, Description.Relationships == NoRelationships, LinksType == NoLinks { + public init(id: ResourceObject.Id, meta: MetaType) { self.init(id: id, attributes: NoAttributes(), relationships: NoRelationships(), meta: meta, links: .none) } } -extension Entity where Description.Attributes == NoAttributes, Description.Relationships == NoRelationships, MetaType == NoMetadata, LinksType == NoLinks { - public init(id: Entity.Id) { +extension ResourceObject where Description.Attributes == NoAttributes, Description.Relationships == NoRelationships, MetaType == NoMetadata, LinksType == NoLinks { + public init(id: ResourceObject.Id) { self.init(id: id, attributes: NoAttributes(), relationships: NoRelationships(), meta: .none, links: .none) } } -extension Entity where Description.Attributes == NoAttributes, Description.Relationships == NoRelationships, EntityRawIdType: CreatableRawIdType { +extension ResourceObject where Description.Attributes == NoAttributes, Description.Relationships == NoRelationships, EntityRawIdType: CreatableRawIdType { public init(meta: MetaType, links: LinksType) { self.init(attributes: NoAttributes(), relationships: NoRelationships(), meta: meta, links: links) } } -extension Entity where Description.Attributes == NoAttributes, Description.Relationships == NoRelationships, MetaType == NoMetadata, EntityRawIdType: CreatableRawIdType { +extension ResourceObject where Description.Attributes == NoAttributes, Description.Relationships == NoRelationships, MetaType == NoMetadata, EntityRawIdType: CreatableRawIdType { public init(links: LinksType) { self.init(attributes: NoAttributes(), relationships: NoRelationships(), meta: .none, links: links) } } -extension Entity where Description.Attributes == NoAttributes, Description.Relationships == NoRelationships, LinksType == NoLinks, EntityRawIdType: CreatableRawIdType { +extension ResourceObject where Description.Attributes == NoAttributes, Description.Relationships == NoRelationships, LinksType == NoLinks, EntityRawIdType: CreatableRawIdType { public init(meta: MetaType) { self.init(attributes: NoAttributes(), relationships: NoRelationships(), meta: meta, links: .none) } } -extension Entity where Description.Attributes == NoAttributes, Description.Relationships == NoRelationships, MetaType == NoMetadata, LinksType == NoLinks, EntityRawIdType: CreatableRawIdType { +extension ResourceObject where Description.Attributes == NoAttributes, Description.Relationships == NoRelationships, MetaType == NoMetadata, LinksType == NoLinks, EntityRawIdType: CreatableRawIdType { public init() { self.init(attributes: NoAttributes(), relationships: NoRelationships(), meta: .none, links: .none) } } -extension Entity where MetaType == NoMetadata { - public init(id: Entity.Id, attributes: Description.Attributes, relationships: Description.Relationships, links: LinksType) { +extension ResourceObject where MetaType == NoMetadata { + public init(id: ResourceObject.Id, attributes: Description.Attributes, relationships: Description.Relationships, links: LinksType) { self.init(id: id, attributes: attributes, relationships: relationships, meta: .none, links: links) } } -extension Entity where MetaType == NoMetadata, EntityRawIdType: CreatableRawIdType { +extension ResourceObject where MetaType == NoMetadata, EntityRawIdType: CreatableRawIdType { public init(attributes: Description.Attributes, relationships: Description.Relationships, links: LinksType) { self.init(attributes: attributes, relationships: relationships, meta: .none, links: links) } } -extension Entity where MetaType == NoMetadata, EntityRawIdType == Unidentified { +extension ResourceObject where MetaType == NoMetadata, EntityRawIdType == Unidentified { public init(attributes: Description.Attributes, relationships: Description.Relationships, links: LinksType) { self.init(attributes: attributes, relationships: relationships, meta: .none, links: links) } } -extension Entity where LinksType == NoLinks { - public init(id: Entity.Id, attributes: Description.Attributes, relationships: Description.Relationships, meta: MetaType) { +extension ResourceObject where LinksType == NoLinks { + public init(id: ResourceObject.Id, attributes: Description.Attributes, relationships: Description.Relationships, meta: MetaType) { self.init(id: id, attributes: attributes, relationships: relationships, meta: meta, links: .none) } } -extension Entity where LinksType == NoLinks, EntityRawIdType: CreatableRawIdType { +extension ResourceObject where LinksType == NoLinks, EntityRawIdType: CreatableRawIdType { public init(attributes: Description.Attributes, relationships: Description.Relationships, meta: MetaType) { self.init(attributes: attributes, relationships: relationships, meta: meta, links: .none) } } -extension Entity where LinksType == NoLinks, EntityRawIdType == Unidentified { +extension ResourceObject where LinksType == NoLinks, EntityRawIdType == Unidentified { public init(attributes: Description.Attributes, relationships: Description.Relationships, meta: MetaType) { self.init(attributes: attributes, relationships: relationships, meta: meta, links: .none) } } -extension Entity where MetaType == NoMetadata, LinksType == NoLinks { - public init(id: Entity.Id, attributes: Description.Attributes, relationships: Description.Relationships) { +extension ResourceObject where MetaType == NoMetadata, LinksType == NoLinks { + public init(id: ResourceObject.Id, attributes: Description.Attributes, relationships: Description.Relationships) { self.init(id: id, attributes: attributes, relationships: relationships, meta: .none, links: .none) } } -extension Entity where MetaType == NoMetadata, LinksType == NoLinks, EntityRawIdType: CreatableRawIdType { +extension ResourceObject where MetaType == NoMetadata, LinksType == NoLinks, EntityRawIdType: CreatableRawIdType { public init(attributes: Description.Attributes, relationships: Description.Relationships) { self.init(attributes: attributes, relationships: relationships, meta: .none, links: .none) } } -extension Entity where MetaType == NoMetadata, LinksType == NoLinks, EntityRawIdType == Unidentified { +extension ResourceObject where MetaType == NoMetadata, LinksType == NoLinks, EntityRawIdType == Unidentified { public init(attributes: Description.Attributes, relationships: Description.Relationships) { self.init(attributes: attributes, relationships: relationships, meta: .none, links: .none) } @@ -392,69 +392,69 @@ extension Entity where MetaType == NoMetadata, LinksType == NoLinks, EntityRawId */ // MARK: Pointer for Relationships use. -public extension Entity where EntityRawIdType: JSONAPI.RawIdType { +public extension ResourceObject where EntityRawIdType: JSONAPI.RawIdType { - /// An Entity.Pointer is a `ToOneRelationship` with no metadata or links. - /// This is just a convenient way to reference an Entity so that + /// An ResourceObject.Pointer is a `ToOneRelationship` with no metadata or links. + /// This is just a convenient way to reference an ResourceObject so that /// other Entities' Relationships can be built up from it. - typealias Pointer = ToOneRelationship + typealias Pointer = ToOneRelationship - /// Entity.Pointers is a `ToManyRelationship` with no metadata or links. + /// ResourceObject.Pointers is a `ToManyRelationship` with no metadata or links. /// This is just a convenient way to reference a bunch of Entities so /// that other Entities' Relationships can be built up from them. - typealias Pointers = ToManyRelationship + typealias Pointers = ToManyRelationship - /// Get a pointer to this entity that can be used as a - /// relationship to another entity. + /// Get a pointer to this resource object that can be used as a + /// relationship to another resource object. var pointer: Pointer { - return Pointer(entity: self) + return Pointer(resourceObject: self) } - func pointer(withMeta meta: MType, links: LType) -> ToOneRelationship { - return ToOneRelationship(entity: self, meta: meta, links: links) + func pointer(withMeta meta: MType, links: LType) -> ToOneRelationship { + return ToOneRelationship(resourceObject: self, meta: meta, links: links) } } // MARK: Identifying Unidentified Entities -public extension Entity where EntityRawIdType == Unidentified { - /// Create a new Entity from this one with a newly created +public extension ResourceObject where EntityRawIdType == Unidentified { + /// Create a new ResourceObject from this one with a newly created /// unique Id of the given type. - func identified(byType: RawIdType.Type) -> Entity { + func identified(byType: RawIdType.Type) -> ResourceObject { return .init(attributes: attributes, relationships: relationships, meta: meta, links: links) } - /// Create a new Entity from this one with the given Id. - func identified(by id: RawIdType) -> Entity { - return .init(id: Entity.Identifier(rawValue: id), attributes: attributes, relationships: relationships, meta: meta, links: links) + /// Create a new ResourceObject from this one with the given Id. + func identified(by id: RawIdType) -> ResourceObject { + return .init(id: ResourceObject.Identifier(rawValue: id), attributes: attributes, relationships: relationships, meta: meta, links: links) } } -public extension Entity where EntityRawIdType: CreatableRawIdType { - /// Create a copy of this Entity with a new unique Id. - func withNewIdentifier() -> Entity { - return Entity(attributes: attributes, relationships: relationships, meta: meta, links: links) +public extension ResourceObject where EntityRawIdType: CreatableRawIdType { + /// Create a copy of this ResourceObject with a new unique Id. + func withNewIdentifier() -> ResourceObject { + return ResourceObject(attributes: attributes, relationships: relationships, meta: meta, links: links) } } // MARK: Attribute Access public extension ResourceObjectProxy { /// Access the attribute at the given keypath. This just - /// allows you to write `entity[\.propertyName]` instead - /// of `entity.attributes.propertyName`. + /// allows you to write `resourceObject[\.propertyName]` instead + /// of `resourceObject.attributes.propertyName`. subscript(_ path: KeyPath) -> T.ValueType { return attributes[keyPath: path].value } /// Access the attribute at the given keypath. This just - /// allows you to write `entity[\.propertyName]` instead - /// of `entity.attributes.propertyName`. + /// allows you to write `resourceObject[\.propertyName]` instead + /// of `resourceObject.attributes.propertyName`. subscript(_ path: KeyPath) -> T.ValueType? { return attributes[keyPath: path]?.value } /// Access the attribute at the given keypath. This just - /// allows you to write `entity[\.propertyName]` instead - /// of `entity.attributes.propertyName`. + /// allows you to write `resourceObject[\.propertyName]` instead + /// of `resourceObject.attributes.propertyName`. subscript(_ path: KeyPath) -> U? where T.ValueType == U? { // Implementation Note: Handles Transform that returns optional // type. @@ -462,8 +462,8 @@ public extension ResourceObjectProxy { } /// Access the storage of the attribute at the given keypath. This just - /// allows you to write `entity[\.propertyName]` instead - /// of `entity.attributes.propertyName`. + /// allows you to write `resourceObject[direct: \.propertyName]` instead + /// of `resourceObject.attributes.propertyName`. /// Most of the subscripts dig into an `AttributeType`. This subscript /// returns the `AttributeType` (or another type, if you are accessing /// an attribute that is not stored in an `AttributeType`). @@ -486,15 +486,15 @@ public extension ResourceObjectProxy { // MARK: Relationship Access public extension ResourceObjectProxy { /// Access to an Id of a `ToOneRelationship`. - /// This allows you to write `entity ~> \.other` instead - /// of `entity.relationships.other.id`. + /// This allows you to write `resourceObject ~> \.other` instead + /// of `resourceObject.relationships.other.id`. static func ~>(entity: Self, path: KeyPath>) -> OtherEntity.Identifier { return entity.relationships[keyPath: path].id } /// Access to an Id of an optional `ToOneRelationship`. - /// This allows you to write `entity ~> \.other` instead - /// of `entity.relationships.other?.id`. + /// This allows you to write `resourceObject ~> \.other` instead + /// of `resourceObject.relationships.other?.id`. static func ~>(entity: Self, path: KeyPath?>) -> OtherEntity.Identifier { // Implementation Note: This signature applies to `ToOneRelationship?` // whereas the one below applies to `ToOneRelationship?` @@ -502,8 +502,8 @@ public extension ResourceObjectProxy { } /// Access to an Id of an optional `ToOneRelationship`. - /// This allows you to write `entity ~> \.other` instead - /// of `entity.relationships.other?.id`. + /// This allows you to write `resourceObject ~> \.other` instead + /// of `resourceObject.relationships.other?.id`. static func ~>(entity: Self, path: KeyPath?>) -> OtherEntity.Identifier? { // Implementation Note: This signature applies to `ToOneRelationship?` // whereas the one above applies to `ToOneRelationship?` @@ -511,15 +511,15 @@ public extension ResourceObjectProxy { } /// Access to all Ids of a `ToManyRelationship`. - /// This allows you to write `entity ~> \.others` instead - /// of `entity.relationships.others.ids`. + /// This allows you to write `resourceObject ~> \.others` instead + /// of `resourceObject.relationships.others.ids`. static func ~>(entity: Self, path: KeyPath>) -> [OtherEntity.Identifier] { return entity.relationships[keyPath: path].ids } /// Access to all Ids of an optional `ToManyRelationship`. - /// This allows you to write `entity ~> \.others` instead - /// of `entity.relationships.others?.ids`. + /// This allows you to write `resourceObject ~> \.others` instead + /// of `resourceObject.relationships.others?.ids`. static func ~>(entity: Self, path: KeyPath?>) -> [OtherEntity.Identifier]? { return entity.relationships[keyPath: path]?.ids } @@ -528,15 +528,15 @@ public extension ResourceObjectProxy { // MARK: Meta-Relationship Access public extension ResourceObjectProxy { /// Access to an Id of a `ToOneRelationship`. - /// This allows you to write `entity ~> \.other` instead - /// of `entity.relationships.other.id`. + /// This allows you to write `resourceObject ~> \.other` instead + /// of `resourceObject.relationships.other.id`. static func ~>(entity: Self, path: KeyPath Identifier>) -> Identifier { return entity.relationships[keyPath: path](entity) } /// Access to all Ids of a `ToManyRelationship`. - /// This allows you to write `entity ~> \.others` instead - /// of `entity.relationships.others.ids`. + /// This allows you to write `resourceObject ~> \.others` instead + /// of `resourceObject.relationships.others.ids`. static func ~>(entity: Self, path: KeyPath [Identifier]>) -> [Identifier] { return entity.relationships[keyPath: path](entity) } @@ -554,11 +554,11 @@ private enum ResourceObjectCodingKeys: String, CodingKey { case links = "links" } -public extension Entity { +public extension ResourceObject { func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: ResourceObjectCodingKeys.self) - try container.encode(Entity.jsonType, forKey: .type) + try container.encode(ResourceObject.jsonType, forKey: .type) if EntityRawIdType.self != Unidentified.self { try container.encode(id, forKey: .id) @@ -587,12 +587,12 @@ public extension Entity { let type = try container.decode(String.self, forKey: .type) - guard Entity.jsonType == type else { + guard ResourceObject.jsonType == type else { throw JSONAPIEncodingError.typeMismatch(expected: Description.jsonType, found: type) } let maybeUnidentified = Unidentified() as? EntityRawIdType - id = try maybeUnidentified.map { Entity.Id(rawValue: $0) } ?? container.decode(Entity.Id.self, forKey: .id) + id = try maybeUnidentified.map { ResourceObject.Id(rawValue: $0) } ?? container.decode(ResourceObject.Id.self, forKey: .id) attributes = try (NoAttributes() as? Description.Attributes) ?? container.decode(Description.Attributes.self, forKey: .attributes) diff --git a/Sources/JSONAPITesting/EntityCheck.swift b/Sources/JSONAPITesting/EntityCheck.swift index abac22b..361daa8 100644 --- a/Sources/JSONAPITesting/EntityCheck.swift +++ b/Sources/JSONAPITesting/EntityCheck.swift @@ -54,8 +54,8 @@ private protocol _AttributeType {} extension TransformedAttribute: _AttributeType {} extension Attribute: _AttributeType {} -public extension Entity { - static func check(_ entity: Entity) throws { +public extension ResourceObject { + static func check(_ entity: ResourceObject) throws { var problems = [EntityCheckError]() let attributesMirror = Mirror(reflecting: entity.attributes) diff --git a/Tests/JSONAPITestingTests/Test Helpers/EntityTestTypes.swift b/Tests/JSONAPITestingTests/Test Helpers/EntityTestTypes.swift index fe059c0..af99a71 100644 --- a/Tests/JSONAPITestingTests/Test Helpers/EntityTestTypes.swift +++ b/Tests/JSONAPITestingTests/Test Helpers/EntityTestTypes.swift @@ -7,8 +7,8 @@ import JSONAPI -public typealias Entity = JSONAPI.Entity +public typealias Entity = JSONAPI.ResourceObject public typealias BasicEntity = Entity -public typealias NewEntity = JSONAPI.Entity +public typealias NewEntity = JSONAPI.ResourceObject diff --git a/Tests/JSONAPITests/Document/DocumentTests.swift b/Tests/JSONAPITests/Document/DocumentTests.swift index 83d6fff..2aa8229 100644 --- a/Tests/JSONAPITests/Document/DocumentTests.swift +++ b/Tests/JSONAPITests/Document/DocumentTests.swift @@ -1049,11 +1049,11 @@ extension DocumentTests { let entity1 = Article(attributes: .none, relationships: .init(author: "2"), meta: .none, links: .none) let entity2 = Article(attributes: .none, relationships: .init(author: "3"), meta: .none, links: .none) - let bodyData1 = Document, NoMetadata, NoLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.Body.Data(primary: .init(entities: [entity1]), + let bodyData1 = Document, NoMetadata, NoLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.Body.Data(primary: .init(resourceObjects: [entity1]), includes: .none, meta: .none, links: .none) - let bodyData2 = Document, NoMetadata, NoLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.Body.Data(primary: .init(entities: [entity2]), + let bodyData2 = Document, NoMetadata, NoLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.Body.Data(primary: .init(resourceObjects: [entity2]), includes: .none, meta: .none, links: .none) @@ -1068,11 +1068,11 @@ extension DocumentTests { let article2 = Article(attributes: .none, relationships: .init(author: "3"), meta: .none, links: .none) let author2 = Author(id: "3", attributes: .none, relationships: .none, meta: .none, links: .none) - let bodyData1 = Document, TestPageMetadata, NoLinks, Include1, NoAPIDescription, UnknownJSONAPIError>.Body.Data(primary: .init(entities: [article1]), + let bodyData1 = Document, TestPageMetadata, NoLinks, Include1, NoAPIDescription, UnknownJSONAPIError>.Body.Data(primary: .init(resourceObjects: [article1]), includes: .init(values: [.init(author1)]), meta: .init(total: 50, limit: 5, offset: 5), links: .none) - let bodyData2 = Document, TestPageMetadata, NoLinks, Include1, NoAPIDescription, UnknownJSONAPIError>.Body.Data(primary: .init(entities: [article2]), + let bodyData2 = Document, TestPageMetadata, NoLinks, Include1, NoAPIDescription, UnknownJSONAPIError>.Body.Data(primary: .init(resourceObjects: [article2]), includes: .init(values: [.init(author2)]), meta: .init(total: 60, limit: 5, offset: 5), links: .none) diff --git a/Tests/JSONAPITests/Entity/EntityTests.swift b/Tests/JSONAPITests/Entity/EntityTests.swift index 467fba7..18e313e 100644 --- a/Tests/JSONAPITests/Entity/EntityTests.swift +++ b/Tests/JSONAPITests/Entity/EntityTests.swift @@ -27,7 +27,7 @@ class EntityTests: XCTestCase { func test_optional_relationship_operator_access() { let entity1 = TestEntity1(attributes: .none, relationships: .none, meta: .none, links: .none) - let entity = TestEntity9(attributes: .none, relationships: .init(one: entity1.pointer, nullableOne: .init(entity: entity1, meta: .none, links: .none), optionalOne: .init(entity: entity1, meta: .none, links: .none), optionalNullableOne: nil, optionalMany: .init(entities: [entity1, entity1], meta: .none, links: .none)), meta: .none, links: .none) + let entity = TestEntity9(attributes: .none, relationships: .init(one: entity1.pointer, nullableOne: .init(resourceObject: entity1, meta: .none, links: .none), optionalOne: .init(resourceObject: entity1, meta: .none, links: .none), optionalNullableOne: nil, optionalMany: .init(resourceObjects: [entity1, entity1], meta: .none, links: .none)), meta: .none, links: .none) XCTAssertEqual(entity ~> \.optionalOne, entity1.id) } @@ -43,7 +43,7 @@ class EntityTests: XCTestCase { func test_optionalToMany_relationship_opeartor_access() { let entity1 = TestEntity1(attributes: .none, relationships: .none, meta: .none, links: .none) - let entity = TestEntity9(attributes: .none, relationships: .init(one: entity1.pointer, nullableOne: .init(entity: entity1, meta: .none, links: .none), optionalOne: nil, optionalNullableOne: nil, optionalMany: .init(entities: [entity1, entity1], meta: .none, links: .none)), meta: .none, links: .none) + let entity = TestEntity9(attributes: .none, relationships: .init(one: entity1.pointer, nullableOne: .init(resourceObject: entity1, meta: .none, links: .none), optionalOne: nil, optionalNullableOne: nil, optionalMany: .init(resourceObjects: [entity1, entity1], meta: .none, links: .none)), meta: .none, links: .none) XCTAssertEqual(entity ~> \.optionalMany, [entity1.id, entity1.id]) } @@ -73,9 +73,9 @@ class EntityTests: XCTestCase { func test_initialization() { let entity1 = TestEntity1(id: .init(rawValue: "wow"), attributes: .none, relationships: .none, meta: .none, links: .none) - let entity2 = TestEntity2(id: .init(rawValue: "cool"), attributes: .none, relationships: .init(other: .init(entity: entity1)), meta: .none, links: .none) - let _ = TestEntity2(id: .init(rawValue: "cool"), attributes: .none, relationships: .init(other: .init(entity: entity1)), meta: .none, links: .none) - let _ = TestEntity2(id: .init(rawValue: "cool"), attributes: .none, relationships: .init(other: .init(entity: entity1)), meta: .none, links: .none) + let entity2 = TestEntity2(id: .init(rawValue: "cool"), attributes: .none, relationships: .init(other: .init(resourceObject: entity1)), meta: .none, links: .none) + let _ = TestEntity2(id: .init(rawValue: "cool"), attributes: .none, relationships: .init(other: .init(resourceObject: entity1)), meta: .none, links: .none) + let _ = TestEntity2(id: .init(rawValue: "cool"), attributes: .none, relationships: .init(other: .init(resourceObject: entity1)), meta: .none, links: .none) let _ = TestEntity3(id: .init(rawValue: "3"), attributes: .none, relationships: .init(others: .init(ids: [.init(rawValue: "10"), .init(rawValue: "20"), entity1.id])), meta: .none, links: .none) let _ = TestEntity3(id: .init(rawValue: "3"), attributes: .none, relationships: .init(others: .none), meta: .none, links: .none) let _ = TestEntity4(id: .init(rawValue: "4"), attributes: .init(word: .init(value: "hello"), number: .init(value: 10), array: .init(value: [10.2, 10.3])), relationships: .init(other: entity2.pointer), meta: .none, links: .none) @@ -84,12 +84,12 @@ class EntityTests: XCTestCase { let _ = TestEntity7(id: .init(rawValue: "7"), attributes: .init(here: .init(value: "hello"), maybeHereMaybeNull: .init(value: "world")), relationships: .none, meta: .none, links: .none) XCTAssertNoThrow(try TestEntity8(id: .init(rawValue: "8"), attributes: .init(string: .init(value: "hello"), int: .init(value: 10), stringFromInt: .init(rawValue: 20), plus: .init(rawValue: 30), doubleFromInt: .init(rawValue: 32), omitted: nil, nullToString: .init(rawValue: nil)), relationships: .none, meta: .none, links: .none)) let _ = TestEntity9(id: .init(rawValue: "9"), attributes: .none, relationships: .init(one: entity1.pointer, nullableOne: nil, optionalOne: nil, optionalNullableOne: nil, optionalMany: nil), meta: .none, links: .none) - let _ = TestEntity9(id: .init(rawValue: "9"), attributes: .none, relationships: .init(one: entity1.pointer, nullableOne: .init(entity: nil), optionalOne: nil, optionalNullableOne: nil, optionalMany: nil), meta: .none, links: .none) + let _ = TestEntity9(id: .init(rawValue: "9"), attributes: .none, relationships: .init(one: entity1.pointer, nullableOne: .init(resourceObject: nil), optionalOne: nil, optionalNullableOne: nil, optionalMany: nil), meta: .none, links: .none) let _ = TestEntity9(id: .init(rawValue: "9"), attributes: .none, relationships: .init(one: entity1.pointer, nullableOne: .init(id: nil), optionalOne: nil, optionalNullableOne: nil, optionalMany: nil), meta: .none, links: .none) - let _ = TestEntity9(id: .init(rawValue: "9"), attributes: .none, relationships: .init(one: entity1.pointer, nullableOne: .init(entity: entity1, meta: .none, links: .none), optionalOne: nil, optionalNullableOne: nil, optionalMany: nil), meta: .none, links: .none) + let _ = TestEntity9(id: .init(rawValue: "9"), attributes: .none, relationships: .init(one: entity1.pointer, nullableOne: .init(resourceObject: entity1, meta: .none, links: .none), optionalOne: nil, optionalNullableOne: nil, optionalMany: nil), meta: .none, links: .none) let _ = TestEntity9(id: .init(rawValue: "9"), attributes: .none, relationships: .init(one: entity1.pointer, nullableOne: nil, optionalOne: entity1.pointer, optionalNullableOne: nil, optionalMany: nil), meta: .none, links: .none) - let _ = TestEntity9(id: .init(rawValue: "9"), attributes: .none, relationships: .init(one: entity1.pointer, nullableOne: nil, optionalOne: nil, optionalNullableOne: .init(entity: entity1, meta: .none, links: .none), optionalMany: nil), meta: .none, links: .none) - let _ = TestEntity9(id: .init(rawValue: "9"), attributes: .none, relationships: .init(one: entity1.pointer, nullableOne: nil, optionalOne: nil, optionalNullableOne: .init(entity: entity1, meta: .none, links: .none), optionalMany: .init(entities: [], meta: .none, links: .none)), meta: .none, links: .none) + let _ = TestEntity9(id: .init(rawValue: "9"), attributes: .none, relationships: .init(one: entity1.pointer, nullableOne: nil, optionalOne: nil, optionalNullableOne: .init(resourceObject: entity1, meta: .none, links: .none), optionalMany: nil), meta: .none, links: .none) + let _ = TestEntity9(id: .init(rawValue: "9"), attributes: .none, relationships: .init(one: entity1.pointer, nullableOne: nil, optionalOne: nil, optionalNullableOne: .init(resourceObject: entity1, meta: .none, links: .none), optionalMany: .init(resourceObjects: [], meta: .none, links: .none)), meta: .none, links: .none) let e10id1 = TestEntity10.Identifier(rawValue: "hello") let e10id2 = TestEntity10.Id(rawValue: "world") let e10id3: TestEntity10.Id = "!" diff --git a/Tests/JSONAPITests/NonJSONAPIRelatable/NonJSONAPIRelatableTests.swift b/Tests/JSONAPITests/NonJSONAPIRelatable/NonJSONAPIRelatableTests.swift index 6a78d40..7546a29 100644 --- a/Tests/JSONAPITests/NonJSONAPIRelatable/NonJSONAPIRelatableTests.swift +++ b/Tests/JSONAPITests/NonJSONAPIRelatable/NonJSONAPIRelatableTests.swift @@ -63,7 +63,7 @@ extension NonJSONAPIRelatableTests { } } - typealias TestEntity = JSONAPI.Entity + typealias TestEntity = JSONAPI.ResourceObject enum TestEntity2Description: ResourceObjectDescription { static var jsonType: String { return "test" } @@ -78,7 +78,7 @@ extension NonJSONAPIRelatableTests { } } - typealias TestEntity2 = JSONAPI.Entity + typealias TestEntity2 = JSONAPI.ResourceObject struct NonJSONAPIEntity: Relatable, JSONTyped { static var jsonType: String { return "other" } diff --git a/Tests/JSONAPITests/Relationships/RelationshipTests.swift b/Tests/JSONAPITests/Relationships/RelationshipTests.swift index 0a17f12..08c1983 100644 --- a/Tests/JSONAPITests/Relationships/RelationshipTests.swift +++ b/Tests/JSONAPITests/Relationships/RelationshipTests.swift @@ -15,7 +15,7 @@ class RelationshipTests: XCTestCase { let entity2 = TestEntity1(attributes: .none, relationships: .none, meta: .none, links: .none) let entity3 = TestEntity1(attributes: .none, relationships: .none, meta: .none, links: .none) let entity4 = TestEntity1(attributes: .none, relationships: .none, meta: .none, links: .none) - let relationship = ToManyRelationship(entities: [entity1, entity2, entity3, entity4]) + let relationship = ToManyRelationship(resourceObjects: [entity1, entity2, entity3, entity4]) XCTAssertEqual(relationship.ids.count, 4) XCTAssertEqual(relationship.ids, [entity1, entity2, entity3, entity4].map { $0.id }) @@ -143,7 +143,7 @@ extension RelationshipTests { // MARK: Nullable extension RelationshipTests { func test_ToOneNullableIsNullIfNil() { - let relationship = ToOneNullable(entity: nil) + let relationship = ToOneNullable(resourceObject: nil) let relationshipData = try! JSONEncoder().encode(relationship) let relationshipString = String(data: relationshipData, encoding: .utf8)! @@ -152,8 +152,8 @@ extension RelationshipTests { func test_ToOneNullableIsEqualToNonNullableIfNotNil() { let entity = TestEntity1(attributes: .none, relationships: .none, meta: .none, links: .none) - let relationship1 = ToOneNonNullable(entity: entity) - let relationship2 = ToOneNullable(entity: entity) + let relationship1 = ToOneNonNullable(resourceObject: entity) + let relationship2 = ToOneNullable(resourceObject: entity) XCTAssertEqual(encoded(value: relationship1), encoded(value: relationship2)) } diff --git a/Tests/JSONAPITests/ResourceBody/ResourceBodyTests.swift b/Tests/JSONAPITests/ResourceBody/ResourceBodyTests.swift index ed73e60..a20db8c 100644 --- a/Tests/JSONAPITests/ResourceBody/ResourceBodyTests.swift +++ b/Tests/JSONAPITests/ResourceBody/ResourceBodyTests.swift @@ -15,8 +15,8 @@ class ResourceBodyTests: XCTestCase { Article(attributes: .init(title: "hello"), relationships: .none, meta: .none, links: .none), Article(attributes: .init(title: "world"), relationships: .none, meta: .none, links: .none) ] - let _ = SingleResourceBody(entity: articles[0]) - let _ = ManyResourceBody(entities: articles) + let _ = SingleResourceBody(resourceObject: articles[0]) + let _ = ManyResourceBody(resourceObjects: articles) let _: NoResourceBody = .none } @@ -77,7 +77,7 @@ class ResourceBodyTests: XCTestCase { } func test_manyResourceBodyMerge() { - let body1 = ManyResourceBody(entities: [ + let body1 = ManyResourceBody(resourceObjects: [ Article(attributes: .init(title: "hello"), relationships: .none, meta: .none, @@ -88,7 +88,7 @@ class ResourceBodyTests: XCTestCase { links: .none) ]) - let body2 = ManyResourceBody(entities: [ + let body2 = ManyResourceBody(resourceObjects: [ Article(attributes: .init(title: "once more"), relationships: .none, meta: .none, diff --git a/Tests/JSONAPITests/Test Helpers/EntityTestTypes.swift b/Tests/JSONAPITests/Test Helpers/EntityTestTypes.swift index fe059c0..af99a71 100644 --- a/Tests/JSONAPITests/Test Helpers/EntityTestTypes.swift +++ b/Tests/JSONAPITests/Test Helpers/EntityTestTypes.swift @@ -7,8 +7,8 @@ import JSONAPI -public typealias Entity = JSONAPI.Entity +public typealias Entity = JSONAPI.ResourceObject public typealias BasicEntity = Entity -public typealias NewEntity = JSONAPI.Entity +public typealias NewEntity = JSONAPI.ResourceObject