Compare commits

...

1 Commits

17 changed files with 68 additions and 68 deletions
+6 -6
View File
@@ -37,7 +37,7 @@ extension NoAttributes: CustomStringConvertible {
/// Something that is JSONTyped provides a String representation
/// of its type.
public protocol JSONTyped {
static var type: String { get }
static var jsonType: String { get }
}
/// An `EntityProxyDescription` is an `EntityDescription`
@@ -81,7 +81,7 @@ public protocol EntityProxy: Equatable, JSONTyped {
extension EntityProxy {
/// The JSON API compliant "type" of this `Entity`.
public static var type: String { return Description.type }
public static var jsonType: String { return Description.jsonType }
}
/// EntityType is the protocol that Entity conforms to. This
@@ -136,7 +136,7 @@ extension Entity: Identifiable, IdentifiableEntityType, Relatable where EntityRa
extension Entity: CustomStringConvertible {
public var description: String {
return "Entity<\(Entity.type)>(id: \(String(describing: id)), attributes: \(String(describing: attributes)), relationships: \(String(describing: relationships)))"
return "Entity<\(Entity.jsonType)>(id: \(String(describing: id)), attributes: \(String(describing: attributes)), relationships: \(String(describing: relationships)))"
}
}
@@ -529,7 +529,7 @@ public extension Entity {
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: ResourceObjectCodingKeys.self)
try container.encode(Entity.type, forKey: .type)
try container.encode(Entity.jsonType, forKey: .type)
if EntityRawIdType.self != Unidentified.self {
try container.encode(id, forKey: .id)
@@ -558,8 +558,8 @@ public extension Entity {
let type = try container.decode(String.self, forKey: .type)
guard Entity.type == type else {
throw JSONAPIEncodingError.typeMismatch(expected: Description.type, found: type)
guard Entity.jsonType == type else {
throw JSONAPIEncodingError.typeMismatch(expected: Description.jsonType, found: type)
}
let maybeUnidentified = Unidentified() as? EntityRawIdType
+7 -7
View File
@@ -134,7 +134,7 @@ public protocol OptionalRelatable: Identifiable where Identifier == Wrapped.Iden
extension Optional: Identifiable, OptionalRelatable, JSONTyped where Wrapped: JSONAPI.Relatable {
public typealias Identifier = Wrapped.Identifier?
public static var type: String { return Wrapped.type }
public static var jsonType: String { return Wrapped.jsonType }
}
// MARK: Codable
@@ -180,8 +180,8 @@ extension ToOneRelationship: Codable where Identifiable.Identifier: OptionalId {
let type = try identifier.decode(String.self, forKey: .entityType)
guard type == Identifiable.type else {
throw JSONAPIEncodingError.typeMismatch(expected: Identifiable.type, found: type)
guard type == Identifiable.jsonType else {
throw JSONAPIEncodingError.typeMismatch(expected: Identifiable.jsonType, found: type)
}
id = Identifiable.Identifier(rawValue: try identifier.decode(Identifiable.Identifier.RawType.self, forKey: .id))
@@ -214,7 +214,7 @@ extension ToOneRelationship: Codable where Identifiable.Identifier: OptionalId {
var identifier = container.nestedContainer(keyedBy: ResourceIdentifierCodingKeys.self, forKey: .data)
try identifier.encode(id.rawValue, forKey: .id)
try identifier.encode(Identifiable.type, forKey: .entityType)
try identifier.encode(Identifiable.jsonType, forKey: .entityType)
}
}
@@ -242,8 +242,8 @@ extension ToManyRelationship: Codable {
let type = try identifier.decode(String.self, forKey: .entityType)
guard type == Relatable.type else {
throw JSONAPIEncodingError.typeMismatch(expected: Relatable.type, found: type)
guard type == Relatable.jsonType else {
throw JSONAPIEncodingError.typeMismatch(expected: Relatable.jsonType, found: type)
}
newIds.append(Relatable.Identifier(rawValue: try identifier.decode(Relatable.Identifier.RawType.self, forKey: .id)))
@@ -268,7 +268,7 @@ extension ToManyRelationship: Codable {
var identifier = identifiers.nestedContainer(keyedBy: ResourceIdentifierCodingKeys.self)
try identifier.encode(id.rawValue, forKey: .id)
try identifier.encode(Relatable.type, forKey: .entityType)
try identifier.encode(Relatable.jsonType, forKey: .entityType)
}
}
}
@@ -38,7 +38,7 @@ class Attribute_FunctorTests: XCTestCase {
// MARK: Test types
extension Attribute_FunctorTests {
enum TestTypeDescription: EntityDescription {
public static var type: String { return "test" }
public static var jsonType: String { return "test" }
public struct Attributes: JSONAPI.Attributes {
let name: Attribute<String>
@@ -46,7 +46,7 @@ class ComputedPropertiesTests: XCTestCase {
// MARK: Test types
extension ComputedPropertiesTests {
public enum TestTypeDescription: EntityDescription {
public static var type: String { return "test" }
public static var jsonType: String { return "test" }
public struct Attributes: JSONAPI.Attributes {
public let name: Attribute<String>
@@ -40,7 +40,7 @@ class CustomAttributesTests: XCTestCase {
// MARK: - Test Types
extension CustomAttributesTests {
enum CustomAttributeEntityDescription: EntityDescription {
public static var type: String { return "test1" }
public static var jsonType: String { return "test1" }
public struct Attributes: JSONAPI.Attributes {
let firstName: Attribute<String>
@@ -58,7 +58,7 @@ extension CustomAttributesTests {
typealias CustomAttributeEntity = BasicEntity<CustomAttributeEntityDescription>
enum CustomKeysEntityDescription: EntityDescription {
public static var type: String { return "test1" }
public static var jsonType: String { return "test1" }
public struct Attributes: JSONAPI.Attributes {
public let firstNameSilly: Attribute<String>
@@ -1094,7 +1094,7 @@ extension DocumentTests {
// MARK: - Test Types
extension DocumentTests {
enum AuthorType: EntityDescription {
static var type: String { return "authors" }
static var jsonType: String { return "authors" }
typealias Attributes = NoAttributes
typealias Relationships = NoRelationships
@@ -1103,7 +1103,7 @@ extension DocumentTests {
typealias Author = BasicEntity<AuthorType>
enum ArticleType: EntityDescription {
static var type: String { return "articles" }
static var jsonType: String { return "articles" }
typealias Attributes = NoAttributes
+12 -12
View File
@@ -613,7 +613,7 @@ extension EntityTests {
extension EntityTests {
enum TestEntityType1: EntityDescription {
static var type: String { return "test_entities"}
static var jsonType: String { return "test_entities"}
typealias Attributes = NoAttributes
typealias Relationships = NoRelationships
@@ -622,7 +622,7 @@ extension EntityTests {
typealias TestEntity1 = BasicEntity<TestEntityType1>
enum TestEntityType2: EntityDescription {
static var type: String { return "second_test_entities"}
static var jsonType: String { return "second_test_entities"}
typealias Attributes = NoAttributes
@@ -634,7 +634,7 @@ extension EntityTests {
typealias TestEntity2 = BasicEntity<TestEntityType2>
enum TestEntityType3: EntityDescription {
static var type: String { return "third_test_entities"}
static var jsonType: String { return "third_test_entities"}
typealias Attributes = NoAttributes
@@ -646,7 +646,7 @@ extension EntityTests {
typealias TestEntity3 = BasicEntity<TestEntityType3>
enum TestEntityType4: EntityDescription {
static var type: String { return "fourth_test_entities"}
static var jsonType: String { return "fourth_test_entities"}
struct Relationships: JSONAPI.Relationships {
let other: ToOneRelationship<TestEntity2, NoMetadata, NoLinks>
@@ -668,7 +668,7 @@ extension EntityTests {
typealias TestEntity4WithMetaAndLinks = Entity<TestEntityType4, TestEntityMeta, TestEntityLinks>
enum TestEntityType5: EntityDescription {
static var type: String { return "fifth_test_entities"}
static var jsonType: String { return "fifth_test_entities"}
typealias Relationships = NoRelationships
@@ -680,7 +680,7 @@ extension EntityTests {
typealias TestEntity5 = BasicEntity<TestEntityType5>
enum TestEntityType6: EntityDescription {
static var type: String { return "sixth_test_entities" }
static var jsonType: String { return "sixth_test_entities" }
typealias Relationships = NoRelationships
@@ -694,7 +694,7 @@ extension EntityTests {
typealias TestEntity6 = BasicEntity<TestEntityType6>
enum TestEntityType7: EntityDescription {
static var type: String { return "seventh_test_entities" }
static var jsonType: String { return "seventh_test_entities" }
typealias Relationships = NoRelationships
@@ -707,7 +707,7 @@ extension EntityTests {
typealias TestEntity7 = BasicEntity<TestEntityType7>
enum TestEntityType8: EntityDescription {
static var type: String { return "eighth_test_entities" }
static var jsonType: String { return "eighth_test_entities" }
typealias Relationships = NoRelationships
@@ -725,7 +725,7 @@ extension EntityTests {
typealias TestEntity8 = BasicEntity<TestEntityType8>
enum TestEntityType9: EntityDescription {
public static var type: String { return "ninth_test_entities" }
public static var jsonType: String { return "ninth_test_entities" }
typealias Attributes = NoAttributes
@@ -748,7 +748,7 @@ extension EntityTests {
typealias TestEntity9 = BasicEntity<TestEntityType9>
enum TestEntityType10: EntityDescription {
public static var type: String { return "tenth_test_entities" }
public static var jsonType: String { return "tenth_test_entities" }
typealias Attributes = NoAttributes
@@ -761,7 +761,7 @@ extension EntityTests {
typealias TestEntity10 = BasicEntity<TestEntityType10>
enum TestEntityType11: EntityDescription {
public static var type: String { return "eleventh_test_entities" }
public static var jsonType: String { return "eleventh_test_entities" }
public struct Attributes: JSONAPI.Attributes {
let number: ValidatedAttribute<Int, IntOver10>
@@ -773,7 +773,7 @@ extension EntityTests {
typealias TestEntity11 = BasicEntity<TestEntityType11>
enum UnidentifiedTestEntityType: EntityDescription {
public static var type: String { return "unidentified_test_entities" }
public static var jsonType: String { return "unidentified_test_entities" }
struct Attributes: JSONAPI.Attributes {
let me: Attribute<String>?
@@ -198,7 +198,7 @@ extension IncludedTests {
typealias Relationships = NoRelationships
public static var type: String { return "test_entity1" }
public static var jsonType: String { return "test_entity1" }
public struct Attributes: JSONAPI.Attributes {
let foo: Attribute<String>
@@ -210,7 +210,7 @@ extension IncludedTests {
enum TestEntityType2: EntityDescription {
public static var type: String { return "test_entity2" }
public static var jsonType: String { return "test_entity2" }
public struct Relationships: JSONAPI.Relationships {
let entity1: ToOneRelationship<TestEntity, NoMetadata, NoLinks>
@@ -228,7 +228,7 @@ extension IncludedTests {
typealias Attributes = NoAttributes
public static var type: String { return "test_entity3" }
public static var jsonType: String { return "test_entity3" }
public struct Relationships: JSONAPI.Relationships {
let entity1: ToOneRelationship<TestEntity, NoMetadata, NoLinks>
@@ -244,7 +244,7 @@ extension IncludedTests {
typealias Relationships = NoRelationships
public static var type: String { return "test_entity4" }
public static var jsonType: String { return "test_entity4" }
}
typealias TestEntity4 = BasicEntity<TestEntityType4>
@@ -255,7 +255,7 @@ extension IncludedTests {
typealias Relationships = NoRelationships
public static var type: String { return "test_entity5" }
public static var jsonType: String { return "test_entity5" }
}
typealias TestEntity5 = BasicEntity<TestEntityType5>
@@ -264,7 +264,7 @@ extension IncludedTests {
typealias Attributes = NoAttributes
public static var type: String { return "test_entity6" }
public static var jsonType: String { return "test_entity6" }
struct Relationships: JSONAPI.Relationships {
let entity4: ToOneRelationship<TestEntity4, NoMetadata, NoLinks>
@@ -277,7 +277,7 @@ extension IncludedTests {
typealias Attributes = NoAttributes
public static var type: String { return "test_entity7" }
public static var jsonType: String { return "test_entity7" }
typealias Relationships = NoRelationships
}
@@ -288,7 +288,7 @@ extension IncludedTests {
typealias Attributes = NoAttributes
public static var type: String { return "test_entity8" }
public static var jsonType: String { return "test_entity8" }
typealias Relationships = NoRelationships
}
@@ -299,7 +299,7 @@ extension IncludedTests {
typealias Attributes = NoAttributes
public static var type: String { return "test_entity9" }
public static var jsonType: String { return "test_entity9" }
typealias Relationships = NoRelationships
}
@@ -41,7 +41,7 @@ class EntityCheckTests: XCTestCase {
// MARK: - Test types
extension EntityCheckTests {
enum OkDescription: EntityDescription {
public static var type: String { return "hello" }
public static var jsonType: String { return "hello" }
public typealias Attributes = NoAttributes
public typealias Relationships = NoRelationships
@@ -50,7 +50,7 @@ extension EntityCheckTests {
public typealias OkEntity = BasicEntity<OkDescription>
enum OtherOkDescription: EntityDescription {
public static var type: String { return "hmm" }
public static var jsonType: String { return "hmm" }
public typealias Attributes = NoAttributes
public typealias Relationships = NoRelationships
@@ -59,7 +59,7 @@ extension EntityCheckTests {
public typealias OtherOkEntity = BasicEntity<OtherOkDescription>
enum EnumAttributesDescription: EntityDescription {
public static var type: String { return "hello" }
public static var jsonType: String { return "hello" }
public enum Attributes: JSONAPI.Attributes {
case hello
@@ -78,7 +78,7 @@ extension EntityCheckTests {
public typealias EnumAttributesEntity = BasicEntity<EnumAttributesDescription>
enum EnumRelationshipsDescription: EntityDescription {
public static var type: String { return "hello" }
public static var jsonType: String { return "hello" }
public typealias Attributes = NoAttributes
@@ -97,7 +97,7 @@ extension EntityCheckTests {
public typealias EnumRelationshipsEntity = BasicEntity<EnumRelationshipsDescription>
enum BadAttributeDescription: EntityDescription {
public static var type: String { return "hello" }
public static var jsonType: String { return "hello" }
public struct Attributes: JSONAPI.Attributes {
let x: Attribute<String>
@@ -110,7 +110,7 @@ extension EntityCheckTests {
public typealias BadAttributeEntity = BasicEntity<BadAttributeDescription>
enum BadRelationshipDescription: EntityDescription {
public static var type: String { return "hello" }
public static var jsonType: String { return "hello" }
public typealias Attributes = NoAttributes
@@ -123,7 +123,7 @@ extension EntityCheckTests {
public typealias BadRelationshipEntity = BasicEntity<BadRelationshipDescription>
enum OptionalArrayAttributeDescription: EntityDescription {
public static var type: String { return "hello" }
public static var jsonType: String { return "hello" }
public struct Attributes: JSONAPI.Attributes {
let x: Attribute<[String]>
@@ -25,7 +25,7 @@ class Id_LiteralTests: XCTestCase {
// MARK: - Test types
extension Id_LiteralTests {
enum TestDescription: EntityDescription {
public static var type: String { return "test" }
public static var jsonType: String { return "test" }
public typealias Attributes = NoAttributes
public typealias Relationships = NoRelationships
@@ -28,7 +28,7 @@ class Relationship_LiteralTests: XCTestCase {
// MARK: - Test types
extension Relationship_LiteralTests {
enum TestDescription: EntityDescription {
public static var type: String { return "test" }
public static var jsonType: String { return "test" }
public typealias Attributes = NoAttributes
public typealias Relationships = NoRelationships
@@ -53,7 +53,7 @@ class NonJSONAPIRelatableTests: XCTestCase {
// MARK: - Test Types
extension NonJSONAPIRelatableTests {
enum TestEntityDescription: EntityDescription {
static var type: String { return "test" }
static var jsonType: String { return "test" }
typealias Attributes = NoAttributes
@@ -66,7 +66,7 @@ extension NonJSONAPIRelatableTests {
typealias TestEntity = JSONAPI.Entity<TestEntityDescription, NoMetadata, NoLinks, String>
enum TestEntity2Description: EntityDescription {
static var type: String { return "test" }
static var jsonType: String { return "test" }
typealias Attributes = NoAttributes
@@ -81,7 +81,7 @@ extension NonJSONAPIRelatableTests {
typealias TestEntity2 = JSONAPI.Entity<TestEntity2Description, NoMetadata, NoLinks, String>
struct NonJSONAPIEntity: Relatable, JSONTyped {
static var type: String { return "other" }
static var jsonType: String { return "other" }
typealias Identifier = NonJSONAPIEntity.Id
+4 -4
View File
@@ -11,7 +11,7 @@ import JSONAPI
public class PolyProxyTests: XCTestCase {
func test_generalReasonableness() {
XCTAssertNotEqual(decoded(type: User.self, data: poly_user_stub_1), decoded(type: User.self, data: poly_user_stub_2))
XCTAssertEqual(User.type, "users")
XCTAssertEqual(User.jsonType, "users")
}
func test_UserADecode() {
@@ -65,7 +65,7 @@ public class PolyProxyTests: XCTestCase {
// MARK: - Test types
public extension PolyProxyTests {
public enum UserDescription1: EntityDescription {
public static var type: String { return "users" }
public static var jsonType: String { return "users" }
public struct Attributes: JSONAPI.Attributes {
let firstName: Attribute<String>
@@ -76,7 +76,7 @@ public extension PolyProxyTests {
}
public enum UserDescription2: EntityDescription {
public static var type: String { return "users" }
public static var jsonType: String { return "users" }
public struct Attributes: JSONAPI.Attributes {
let name: Attribute<[String]>
@@ -124,7 +124,7 @@ extension Poly2: EntityProxy, JSONTyped where A == PolyProxyTests.UserA, B == Po
}
public enum SharedUserDescription: EntityProxyDescription {
public static var type: String { return A.type }
public static var jsonType: String { return A.jsonType }
public struct Attributes: Equatable {
let name: Attribute<String>
+9 -9
View File
@@ -572,7 +572,7 @@ extension PolyTests {
typealias Relationships = NoRelationships
public static var type: String { return "test_entity1" }
public static var jsonType: String { return "test_entity1" }
public struct Attributes: JSONAPI.Attributes {
let foo: Attribute<String>
@@ -584,7 +584,7 @@ extension PolyTests {
enum TestEntityType2: EntityDescription {
public static var type: String { return "test_entity2" }
public static var jsonType: String { return "test_entity2" }
public struct Relationships: JSONAPI.Relationships {
let entity1: ToOneRelationship<TestEntity, NoMetadata, NoLinks>
@@ -602,7 +602,7 @@ extension PolyTests {
typealias Attributes = NoAttributes
public static var type: String { return "test_entity3" }
public static var jsonType: String { return "test_entity3" }
public struct Relationships: JSONAPI.Relationships {
let entity1: ToOneRelationship<TestEntity, NoMetadata, NoLinks>
@@ -618,7 +618,7 @@ extension PolyTests {
typealias Relationships = NoRelationships
public static var type: String { return "test_entity4" }
public static var jsonType: String { return "test_entity4" }
}
typealias TestEntity4 = BasicEntity<TestEntityType4>
@@ -629,7 +629,7 @@ extension PolyTests {
typealias Relationships = NoRelationships
public static var type: String { return "test_entity5" }
public static var jsonType: String { return "test_entity5" }
}
typealias TestEntity5 = BasicEntity<TestEntityType5>
@@ -638,7 +638,7 @@ extension PolyTests {
typealias Attributes = NoAttributes
public static var type: String { return "test_entity6" }
public static var jsonType: String { return "test_entity6" }
struct Relationships: JSONAPI.Relationships {
let entity4: ToOneRelationship<TestEntity4, NoMetadata, NoLinks>
@@ -651,7 +651,7 @@ extension PolyTests {
typealias Attributes = NoAttributes
public static var type: String { return "test_entity7" }
public static var jsonType: String { return "test_entity7" }
typealias Relationships = NoRelationships
}
@@ -662,7 +662,7 @@ extension PolyTests {
typealias Attributes = NoAttributes
public static var type: String { return "test_entity8" }
public static var jsonType: String { return "test_entity8" }
typealias Relationships = NoRelationships
}
@@ -673,7 +673,7 @@ extension PolyTests {
typealias Attributes = NoAttributes
public static var type: String { return "test_entity9" }
public static var jsonType: String { return "test_entity9" }
typealias Relationships = NoRelationships
}
@@ -177,7 +177,7 @@ extension RelationshipTests {
typealias Relationships = NoRelationships
public static var type: String { return "test_entity1" }
public static var jsonType: String { return "test_entity1" }
}
typealias TestEntity1 = BasicEntity<TestEntityType1>
@@ -102,7 +102,7 @@ class ResourceBodyTests: XCTestCase {
}
enum ArticleType: EntityDescription {
public static var type: String { return "articles" }
public static var jsonType: String { return "articles" }
typealias Relationships = NoRelationships
@@ -27,7 +27,7 @@ func testEncoded<E: EntityType>(entity: E) {
let jsonType = jsonDict?["type"] as? String
XCTAssertEqual(jsonType, E.type)
XCTAssertEqual(jsonType, E.jsonType)
let jsonAttributes = jsonDict?["attributes"] as? [String: Any]