mirror of
https://github.com/encounter/JSONAPI.git
synced 2026-03-30 11:18:38 -07:00
Add metadata and links to resource objects (i.e. Entity). untested.
This commit is contained in:
@@ -80,7 +80,7 @@ public protocol IdentifiableEntityType: EntityType, Relatable where EntityRawIdT
|
||||
/// encoded to or decoded from a JSON API
|
||||
/// "Resource Object."
|
||||
/// See https://jsonapi.org/format/#document-resource-objects
|
||||
public struct Entity<Description: JSONAPI.EntityDescription, EntityRawIdType: JSONAPI.MaybeRawId>: EntityType {
|
||||
public struct Entity<Description: JSONAPI.EntityDescription, MetaType: JSONAPI.Meta, LinksType: JSONAPI.Links, EntityRawIdType: JSONAPI.MaybeRawId>: EntityType {
|
||||
/// 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,
|
||||
@@ -92,11 +92,19 @@ public struct Entity<Description: JSONAPI.EntityDescription, EntityRawIdType: JS
|
||||
|
||||
/// The JSON API compliant relationships of this `Entity`.
|
||||
public let relationships: Description.Relationships
|
||||
|
||||
/// Any additional metadata packaged with the entity.
|
||||
public let meta: MetaType
|
||||
|
||||
/// Links related to the entity.
|
||||
public let links: LinksType
|
||||
|
||||
public init(id: Entity.Id, attributes: Description.Attributes, relationships: Description.Relationships) {
|
||||
public init(id: Entity.Id, attributes: Description.Attributes, relationships: Description.Relationships, meta: MetaType, links: LinksType) {
|
||||
self.id = id
|
||||
self.attributes = attributes
|
||||
self.relationships = relationships
|
||||
self.meta = meta
|
||||
self.links = links
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,60 +121,214 @@ extension Entity: CustomStringConvertible {
|
||||
|
||||
// MARK: Convenience initializers
|
||||
extension Entity where EntityRawIdType: CreatableRawIdType {
|
||||
public init(attributes: Description.Attributes, relationships: Description.Relationships) {
|
||||
public init(attributes: Description.Attributes, relationships: Description.Relationships, meta: MetaType, links: LinksType) {
|
||||
self.id = Entity.Id()
|
||||
self.attributes = attributes
|
||||
self.relationships = relationships
|
||||
self.meta = meta
|
||||
self.links = links
|
||||
}
|
||||
}
|
||||
|
||||
extension Entity where EntityRawIdType == Unidentified {
|
||||
public init(attributes: Description.Attributes, relationships: Description.Relationships) {
|
||||
public init(attributes: Description.Attributes, relationships: Description.Relationships, meta: MetaType, links: LinksType) {
|
||||
self.id = .unidentified
|
||||
self.attributes = attributes
|
||||
self.relationships = relationships
|
||||
self.meta = meta
|
||||
self.links = links
|
||||
}
|
||||
}
|
||||
|
||||
extension Entity where Description.Attributes == NoAttributes {
|
||||
public init(id: Entity.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) {
|
||||
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) {
|
||||
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) {
|
||||
self.init(id: id, attributes: NoAttributes(), relationships: relationships)
|
||||
self.init(id: id, relationships: relationships, links: .none)
|
||||
}
|
||||
}
|
||||
|
||||
extension Entity 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 {
|
||||
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 {
|
||||
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 {
|
||||
public init(relationships: Description.Relationships) {
|
||||
self.init(attributes: NoAttributes(), relationships: relationships)
|
||||
self.init(attributes: NoAttributes(), relationships: relationships, meta: .none, links: .none)
|
||||
}
|
||||
}
|
||||
|
||||
extension Entity 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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
self.init(id: id, attributes: attributes, relationships: NoRelationships())
|
||||
self.init(id: id, attributes: attributes, meta: .none, links: .none)
|
||||
}
|
||||
}
|
||||
|
||||
extension Entity 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 {
|
||||
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 {
|
||||
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 {
|
||||
public init(attributes: Description.Attributes) {
|
||||
self.init(attributes: attributes, relationships: NoRelationships())
|
||||
self.init(attributes: attributes, relationships: NoRelationships(), meta: .none, links: .none)
|
||||
}
|
||||
}
|
||||
|
||||
extension Entity 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 {
|
||||
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 {
|
||||
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 {
|
||||
public init(attributes: Description.Attributes) {
|
||||
self.init(attributes: attributes, relationships: NoRelationships())
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
self.init(id: id, attributes: NoAttributes(), relationships: NoRelationships())
|
||||
self.init(id: id, attributes: NoAttributes(), relationships: NoRelationships(), meta: .none, links: .none)
|
||||
}
|
||||
}
|
||||
|
||||
extension Entity 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 {
|
||||
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 {
|
||||
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 {
|
||||
public init() {
|
||||
self.init(attributes: NoAttributes(), relationships: NoRelationships())
|
||||
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) {
|
||||
self.init(id: id, 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) {
|
||||
self.init(id: id, 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) {
|
||||
self.init(id: id, attributes: attributes, relationships: relationships, meta: .none, links: .none)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,6 +390,8 @@ private enum ResourceObjectCodingKeys: String, CodingKey {
|
||||
case id = "id"
|
||||
case attributes = "attributes"
|
||||
case relationships = "relationships"
|
||||
case meta = "meta"
|
||||
case links = "links"
|
||||
}
|
||||
|
||||
public extension Entity {
|
||||
@@ -247,6 +411,14 @@ public extension Entity {
|
||||
if Description.Relationships.self != NoRelationships.self {
|
||||
try container.encode(relationships, forKey: .relationships)
|
||||
}
|
||||
|
||||
if MetaType.self != NoMetadata.self {
|
||||
try container.encode(meta, forKey: .meta)
|
||||
}
|
||||
|
||||
if LinksType.self != NoLinks.self {
|
||||
try container.encode(links, forKey: .links)
|
||||
}
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
@@ -265,5 +437,9 @@ public extension Entity {
|
||||
attributes = try (NoAttributes() as? Description.Attributes) ?? container.decode(Description.Attributes.self, forKey: .attributes)
|
||||
|
||||
relationships = try (NoRelationships() as? Description.Relationships) ?? container.decode(Description.Relationships.self, forKey: .relationships)
|
||||
|
||||
meta = try (NoMetadata() as? MetaType) ?? container.decode(MetaType.self, forKey: .meta)
|
||||
|
||||
links = try (NoLinks() as? LinksType) ?? container.decode(LinksType.self, forKey: .links)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ extension Attribute_FunctorTests {
|
||||
public typealias Relationships = NoRelationships
|
||||
}
|
||||
|
||||
typealias TestType = Entity<TestTypeDescription>
|
||||
typealias TestType = BasicEntity<TestTypeDescription>
|
||||
|
||||
enum DoubleToString: Transformer {
|
||||
public static func transform(_ from: Double) -> String {
|
||||
|
||||
@@ -57,5 +57,5 @@ extension ComputedPropertiesTests {
|
||||
}
|
||||
}
|
||||
|
||||
public typealias TestType = Entity<TestTypeDescription>
|
||||
public typealias TestType = BasicEntity<TestTypeDescription>
|
||||
}
|
||||
|
||||
@@ -970,7 +970,7 @@ extension DocumentTests {
|
||||
typealias Relationships = NoRelationships
|
||||
}
|
||||
|
||||
typealias Author = Entity<AuthorType>
|
||||
typealias Author = BasicEntity<AuthorType>
|
||||
|
||||
enum ArticleType: EntityDescription {
|
||||
static var type: String { return "articles" }
|
||||
@@ -982,7 +982,7 @@ extension DocumentTests {
|
||||
}
|
||||
}
|
||||
|
||||
typealias Article = Entity<ArticleType>
|
||||
typealias Article = BasicEntity<ArticleType>
|
||||
|
||||
struct TestPageMetadata: JSONAPI.Meta {
|
||||
let total: Int
|
||||
|
||||
@@ -13,14 +13,14 @@ class EntityTests: XCTestCase {
|
||||
|
||||
func test_relationship_access() {
|
||||
let entity1 = TestEntity1()
|
||||
let entity2 = TestEntity2(other: entity1.pointer)
|
||||
let entity2 = TestEntity2(relationships: .init(other: entity1.pointer))
|
||||
|
||||
XCTAssertEqual(entity2.relationships.other, entity1.pointer)
|
||||
}
|
||||
|
||||
func test_relationship_operator_access() {
|
||||
let entity1 = TestEntity1()
|
||||
let entity2 = TestEntity2(other: entity1.pointer)
|
||||
let entity2 = TestEntity2(relationships: .init(other: entity1.pointer))
|
||||
|
||||
XCTAssertEqual(entity2 ~> \.other, entity1.id)
|
||||
}
|
||||
@@ -29,14 +29,14 @@ class EntityTests: XCTestCase {
|
||||
let entity1 = TestEntity1()
|
||||
let entity2 = TestEntity1()
|
||||
let entity4 = TestEntity1()
|
||||
let entity3 = TestEntity3(others: .init(relationships: [entity1.pointer, entity2.pointer, entity4.pointer]))
|
||||
let entity3 = TestEntity3(relationships: .init(others: .init(relationships: [entity1.pointer, entity2.pointer, entity4.pointer])))
|
||||
|
||||
XCTAssertEqual(entity3 ~> \.others, [entity1.id, entity2.id, entity4.id])
|
||||
}
|
||||
|
||||
func test_relationshipIds() {
|
||||
let entity1 = TestEntity1()
|
||||
let entity2 = TestEntity2(other: entity1.pointer)
|
||||
let entity2 = TestEntity2(relationships: .init(other: entity1.pointer))
|
||||
|
||||
XCTAssertEqual(entity2.relationships.other.id, entity1.id)
|
||||
}
|
||||
@@ -346,7 +346,7 @@ extension EntityTests {
|
||||
typealias Relationships = NoRelationships
|
||||
}
|
||||
|
||||
typealias TestEntity1 = Entity<TestEntityType1>
|
||||
typealias TestEntity1 = BasicEntity<TestEntityType1>
|
||||
|
||||
enum TestEntityType2: EntityDescription {
|
||||
static var type: String { return "second_test_entities"}
|
||||
@@ -358,7 +358,7 @@ extension EntityTests {
|
||||
}
|
||||
}
|
||||
|
||||
typealias TestEntity2 = Entity<TestEntityType2>
|
||||
typealias TestEntity2 = BasicEntity<TestEntityType2>
|
||||
|
||||
enum TestEntityType3: EntityDescription {
|
||||
static var type: String { return "third_test_entities"}
|
||||
@@ -370,7 +370,7 @@ extension EntityTests {
|
||||
}
|
||||
}
|
||||
|
||||
typealias TestEntity3 = Entity<TestEntityType3>
|
||||
typealias TestEntity3 = BasicEntity<TestEntityType3>
|
||||
|
||||
enum TestEntityType4: EntityDescription {
|
||||
static var type: String { return "fourth_test_entities"}
|
||||
@@ -386,7 +386,7 @@ extension EntityTests {
|
||||
}
|
||||
}
|
||||
|
||||
typealias TestEntity4 = Entity<TestEntityType4>
|
||||
typealias TestEntity4 = BasicEntity<TestEntityType4>
|
||||
|
||||
enum TestEntityType5: EntityDescription {
|
||||
static var type: String { return "fifth_test_entities"}
|
||||
@@ -398,7 +398,7 @@ extension EntityTests {
|
||||
}
|
||||
}
|
||||
|
||||
typealias TestEntity5 = Entity<TestEntityType5>
|
||||
typealias TestEntity5 = BasicEntity<TestEntityType5>
|
||||
|
||||
enum TestEntityType6: EntityDescription {
|
||||
static var type: String { return "sixth_test_entities" }
|
||||
@@ -412,7 +412,7 @@ extension EntityTests {
|
||||
}
|
||||
}
|
||||
|
||||
typealias TestEntity6 = Entity<TestEntityType6>
|
||||
typealias TestEntity6 = BasicEntity<TestEntityType6>
|
||||
|
||||
enum TestEntityType7: EntityDescription {
|
||||
static var type: String { return "seventh_test_entities" }
|
||||
@@ -425,7 +425,7 @@ extension EntityTests {
|
||||
}
|
||||
}
|
||||
|
||||
typealias TestEntity7 = Entity<TestEntityType7>
|
||||
typealias TestEntity7 = BasicEntity<TestEntityType7>
|
||||
|
||||
enum TestEntityType8: EntityDescription {
|
||||
static var type: String { return "eighth_test_entities" }
|
||||
@@ -443,7 +443,7 @@ extension EntityTests {
|
||||
}
|
||||
}
|
||||
|
||||
typealias TestEntity8 = Entity<TestEntityType8>
|
||||
typealias TestEntity8 = BasicEntity<TestEntityType8>
|
||||
|
||||
enum TestEntityType9: EntityDescription {
|
||||
public static var type: String { return "ninth_test_entities" }
|
||||
@@ -465,7 +465,7 @@ extension EntityTests {
|
||||
}
|
||||
}
|
||||
|
||||
typealias TestEntity9 = Entity<TestEntityType9>
|
||||
typealias TestEntity9 = BasicEntity<TestEntityType9>
|
||||
|
||||
enum TestEntityType10: EntityDescription {
|
||||
public static var type: String { return "tenth_test_entities" }
|
||||
@@ -478,7 +478,7 @@ extension EntityTests {
|
||||
}
|
||||
}
|
||||
|
||||
typealias TestEntity10 = Entity<TestEntityType10>
|
||||
typealias TestEntity10 = BasicEntity<TestEntityType10>
|
||||
|
||||
enum TestEntityType11: EntityDescription {
|
||||
public static var type: String { return "eleventh_test_entities" }
|
||||
@@ -490,7 +490,7 @@ extension EntityTests {
|
||||
typealias Relationships = NoRelationships
|
||||
}
|
||||
|
||||
typealias TestEntity11 = Entity<TestEntityType11>
|
||||
typealias TestEntity11 = BasicEntity<TestEntityType11>
|
||||
|
||||
enum UnidentifiedTestEntityType: EntityDescription {
|
||||
public static var type: String { return "unidentified_test_entities" }
|
||||
@@ -502,7 +502,7 @@ extension EntityTests {
|
||||
typealias Relationships = NoRelationships
|
||||
}
|
||||
|
||||
typealias UnidentifiedTestEntity = NewEntity<UnidentifiedTestEntityType>
|
||||
typealias UnidentifiedTestEntity = NewEntity<UnidentifiedTestEntityType, NoMetadata, NoLinks>
|
||||
|
||||
enum IntToString: Transformer {
|
||||
public static func transform(_ from: Int) -> String {
|
||||
@@ -541,15 +541,3 @@ extension EntityTests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Entity where Description == EntityTests.TestEntityType2, EntityRawIdType: CreatableRawIdType {
|
||||
init(other: ToOneRelationship<EntityTests.TestEntity1>) {
|
||||
self.init(relationships: .init(other: other))
|
||||
}
|
||||
}
|
||||
|
||||
extension Entity where Description == EntityTests.TestEntityType3, EntityRawIdType: CreatableRawIdType {
|
||||
init(others: ToManyRelationship<EntityTests.TestEntity1>) {
|
||||
self.init(relationships: .init(others: others))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ extension IncludedTests {
|
||||
}
|
||||
}
|
||||
|
||||
typealias TestEntity = Entity<TestEntityType>
|
||||
typealias TestEntity = BasicEntity<TestEntityType>
|
||||
|
||||
enum TestEntityType2: EntityDescription {
|
||||
|
||||
@@ -153,7 +153,7 @@ extension IncludedTests {
|
||||
}
|
||||
}
|
||||
|
||||
typealias TestEntity2 = Entity<TestEntityType2>
|
||||
typealias TestEntity2 = BasicEntity<TestEntityType2>
|
||||
|
||||
enum TestEntityType3: EntityDescription {
|
||||
|
||||
@@ -167,7 +167,7 @@ extension IncludedTests {
|
||||
}
|
||||
}
|
||||
|
||||
typealias TestEntity3 = Entity<TestEntityType3>
|
||||
typealias TestEntity3 = BasicEntity<TestEntityType3>
|
||||
|
||||
enum TestEntityType4: EntityDescription {
|
||||
|
||||
@@ -178,7 +178,7 @@ extension IncludedTests {
|
||||
public static var type: String { return "test_entity4" }
|
||||
}
|
||||
|
||||
typealias TestEntity4 = Entity<TestEntityType4>
|
||||
typealias TestEntity4 = BasicEntity<TestEntityType4>
|
||||
|
||||
enum TestEntityType5: EntityDescription {
|
||||
|
||||
@@ -189,7 +189,7 @@ extension IncludedTests {
|
||||
public static var type: String { return "test_entity5" }
|
||||
}
|
||||
|
||||
typealias TestEntity5 = Entity<TestEntityType5>
|
||||
typealias TestEntity5 = BasicEntity<TestEntityType5>
|
||||
|
||||
enum TestEntityType6: EntityDescription {
|
||||
|
||||
@@ -202,5 +202,5 @@ extension IncludedTests {
|
||||
}
|
||||
}
|
||||
|
||||
typealias TestEntity6 = Entity<TestEntityType6>
|
||||
typealias TestEntity6 = BasicEntity<TestEntityType6>
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ extension EntityCheckTests {
|
||||
public typealias Relationships = NoRelationships
|
||||
}
|
||||
|
||||
public typealias OkEntity = Entity<OkDescription>
|
||||
public typealias OkEntity = BasicEntity<OkDescription>
|
||||
|
||||
enum OtherOkDescription: EntityDescription {
|
||||
public static var type: String { return "hmm" }
|
||||
@@ -56,7 +56,7 @@ extension EntityCheckTests {
|
||||
public typealias Relationships = NoRelationships
|
||||
}
|
||||
|
||||
public typealias OtherOkEntity = Entity<OtherOkDescription>
|
||||
public typealias OtherOkEntity = BasicEntity<OtherOkDescription>
|
||||
|
||||
enum EnumAttributesDescription: EntityDescription {
|
||||
public static var type: String { return "hello" }
|
||||
@@ -75,7 +75,7 @@ extension EntityCheckTests {
|
||||
public typealias Relationships = NoRelationships
|
||||
}
|
||||
|
||||
public typealias EnumAttributesEntity = Entity<EnumAttributesDescription>
|
||||
public typealias EnumAttributesEntity = BasicEntity<EnumAttributesDescription>
|
||||
|
||||
enum EnumRelationshipsDescription: EntityDescription {
|
||||
public static var type: String { return "hello" }
|
||||
@@ -94,7 +94,7 @@ extension EntityCheckTests {
|
||||
}
|
||||
}
|
||||
|
||||
public typealias EnumRelationshipsEntity = Entity<EnumRelationshipsDescription>
|
||||
public typealias EnumRelationshipsEntity = BasicEntity<EnumRelationshipsDescription>
|
||||
|
||||
enum BadAttributeDescription: EntityDescription {
|
||||
public static var type: String { return "hello" }
|
||||
@@ -107,7 +107,7 @@ extension EntityCheckTests {
|
||||
public typealias Relationships = NoRelationships
|
||||
}
|
||||
|
||||
public typealias BadAttributeEntity = Entity<BadAttributeDescription>
|
||||
public typealias BadAttributeEntity = BasicEntity<BadAttributeDescription>
|
||||
|
||||
enum BadRelationshipDescription: EntityDescription {
|
||||
public static var type: String { return "hello" }
|
||||
@@ -120,7 +120,7 @@ extension EntityCheckTests {
|
||||
}
|
||||
}
|
||||
|
||||
public typealias BadRelationshipEntity = Entity<BadRelationshipDescription>
|
||||
public typealias BadRelationshipEntity = BasicEntity<BadRelationshipDescription>
|
||||
|
||||
enum OptionalArrayAttributeDescription: EntityDescription {
|
||||
public static var type: String { return "hello" }
|
||||
@@ -133,5 +133,5 @@ extension EntityCheckTests {
|
||||
public typealias Relationships = NoRelationships
|
||||
}
|
||||
|
||||
public typealias OptionalArrayAttributeEntity = Entity<OptionalArrayAttributeDescription>
|
||||
public typealias OptionalArrayAttributeEntity = BasicEntity<OptionalArrayAttributeDescription>
|
||||
}
|
||||
|
||||
@@ -31,5 +31,5 @@ extension Id_LiteralTests {
|
||||
public typealias Relationships = NoRelationships
|
||||
}
|
||||
|
||||
typealias TestEntity = Entity<TestDescription>
|
||||
typealias TestEntity = BasicEntity<TestDescription>
|
||||
}
|
||||
|
||||
@@ -34,5 +34,5 @@ extension Relationship_LiteralTests {
|
||||
public typealias Relationships = NoRelationships
|
||||
}
|
||||
|
||||
typealias TestEntity = Entity<TestDescription>
|
||||
typealias TestEntity = BasicEntity<TestDescription>
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ class LinksTests: XCTestCase {
|
||||
let links = decoded(type: LinksTests.Links.self, data: link_without_meta)
|
||||
|
||||
XCTAssertEqual(links.link.url, "https://website.com/path/file")
|
||||
XCTAssertEqual(links.optionalLink?.url, "https://theweb.com/not")
|
||||
XCTAssertEqual(links.link.meta, NoMetadata())
|
||||
}
|
||||
|
||||
@@ -20,6 +21,18 @@ class LinksTests: XCTestCase {
|
||||
test_DecodeEncodeEquality(type: LinksTests.Links.self, data: link_without_meta)
|
||||
}
|
||||
|
||||
func test_linkWithNoMetaWithoutOptionalLink() {
|
||||
let links = decoded(type: LinksTests.Links.self, data: link_without_meta_without_optional_link)
|
||||
|
||||
XCTAssertEqual(links.link.url, "https://website.com/path/file")
|
||||
XCTAssertNil(links.optionalLink)
|
||||
XCTAssertEqual(links.link.meta, NoMetadata())
|
||||
}
|
||||
|
||||
func test_linkWithNoMetaWithoutOptionalLink_encode() {
|
||||
test_DecodeEncodeEquality(type: LinksTests.Links.self, data: link_without_meta_without_optional_link)
|
||||
}
|
||||
|
||||
func test_linkWithNullMetadata() {
|
||||
let link = decoded(type: Link<LinksTests.URL, Metadata?>.self, data: link_with_null_meta)
|
||||
|
||||
@@ -60,6 +73,7 @@ extension LinksTests {
|
||||
|
||||
struct Links: JSONAPI.Links {
|
||||
let link: Link<LinksTests.URL, NoMetadata>
|
||||
let optionalLink: Link<LinksTests.URL, NoMetadata>?
|
||||
}
|
||||
|
||||
struct Metadata: JSONAPI.Meta {
|
||||
|
||||
@@ -6,6 +6,13 @@
|
||||
//
|
||||
|
||||
let link_without_meta = """
|
||||
{
|
||||
"link": "https://website.com/path/file",
|
||||
"optionalLink": "https://theweb.com/not"
|
||||
}
|
||||
""".data(using: .utf8)!
|
||||
|
||||
let link_without_meta_without_optional_link = """
|
||||
{
|
||||
"link": "https://website.com/path/file"
|
||||
}
|
||||
|
||||
@@ -83,8 +83,8 @@ public extension PolyProxyTests {
|
||||
public typealias Relationships = NoRelationships
|
||||
}
|
||||
|
||||
public typealias UserA = Entity<UserDescription1>
|
||||
public typealias UserB = Entity<UserDescription2>
|
||||
public typealias UserA = BasicEntity<UserDescription1>
|
||||
public typealias UserB = BasicEntity<UserDescription2>
|
||||
|
||||
public typealias User = Poly2<UserA, UserB>
|
||||
}
|
||||
|
||||
@@ -275,7 +275,7 @@ extension PolyTests {
|
||||
}
|
||||
}
|
||||
|
||||
typealias TestEntity = Entity<TestEntityType>
|
||||
typealias TestEntity = BasicEntity<TestEntityType>
|
||||
|
||||
enum TestEntityType2: EntityDescription {
|
||||
|
||||
@@ -291,7 +291,7 @@ extension PolyTests {
|
||||
}
|
||||
}
|
||||
|
||||
typealias TestEntity2 = Entity<TestEntityType2>
|
||||
typealias TestEntity2 = BasicEntity<TestEntityType2>
|
||||
|
||||
enum TestEntityType3: EntityDescription {
|
||||
|
||||
@@ -305,7 +305,7 @@ extension PolyTests {
|
||||
}
|
||||
}
|
||||
|
||||
typealias TestEntity3 = Entity<TestEntityType3>
|
||||
typealias TestEntity3 = BasicEntity<TestEntityType3>
|
||||
|
||||
enum TestEntityType4: EntityDescription {
|
||||
|
||||
@@ -316,7 +316,7 @@ extension PolyTests {
|
||||
public static var type: String { return "test_entity4" }
|
||||
}
|
||||
|
||||
typealias TestEntity4 = Entity<TestEntityType4>
|
||||
typealias TestEntity4 = BasicEntity<TestEntityType4>
|
||||
|
||||
enum TestEntityType5: EntityDescription {
|
||||
|
||||
@@ -327,7 +327,7 @@ extension PolyTests {
|
||||
public static var type: String { return "test_entity5" }
|
||||
}
|
||||
|
||||
typealias TestEntity5 = Entity<TestEntityType5>
|
||||
typealias TestEntity5 = BasicEntity<TestEntityType5>
|
||||
|
||||
enum TestEntityType6: EntityDescription {
|
||||
|
||||
@@ -340,5 +340,5 @@ extension PolyTests {
|
||||
}
|
||||
}
|
||||
|
||||
typealias TestEntity6 = Entity<TestEntityType6>
|
||||
typealias TestEntity6 = BasicEntity<TestEntityType6>
|
||||
}
|
||||
|
||||
@@ -81,5 +81,5 @@ extension RelationshipTests {
|
||||
public static var type: String { return "test_entity1" }
|
||||
}
|
||||
|
||||
typealias TestEntity1 = Entity<TestEntityType1>
|
||||
typealias TestEntity1 = BasicEntity<TestEntityType1>
|
||||
}
|
||||
|
||||
@@ -61,5 +61,5 @@ class ResourceBodyTests: XCTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
typealias Article = Entity<ArticleType>
|
||||
typealias Article = BasicEntity<ArticleType>
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
import JSONAPI
|
||||
|
||||
public typealias Entity<Description: JSONAPI.EntityDescription> = JSONAPI.Entity<Description, String>
|
||||
public typealias Entity<Description: JSONAPI.EntityDescription, Meta: JSONAPI.Meta, Links: JSONAPI.Links> = JSONAPI.Entity<Description, Meta, Links, String>
|
||||
|
||||
public typealias NewEntity<Description: JSONAPI.EntityDescription> = JSONAPI.Entity<Description, Unidentified>
|
||||
public typealias BasicEntity<Description: JSONAPI.EntityDescription> = Entity<Description, NoMetadata, NoLinks>
|
||||
|
||||
public typealias NewEntity<Description: JSONAPI.EntityDescription, Meta: JSONAPI.Meta, Links: JSONAPI.Links> = JSONAPI.Entity<Description, Meta, Links, Unidentified>
|
||||
|
||||
Reference in New Issue
Block a user