Skip to content

Commit

Permalink
Breaking - Rename static var type: String to static var jsonType:Stri…
Browse files Browse the repository at this point in the history
…ng to avoid unnecessary conflict with Swift.type(of:)
  • Loading branch information
mattpolzin committed Jan 3, 2019
1 parent 8974104 commit 072b081
Show file tree
Hide file tree
Showing 17 changed files with 68 additions and 68 deletions.
12 changes: 6 additions & 6 deletions Sources/JSONAPI/Resource/Entity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)))"
}
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions Sources/JSONAPI/Resource/Relationship.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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)))
Expand All @@ -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)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/JSONAPITests/Attribute/Attribute+FunctorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand Down
4 changes: 2 additions & 2 deletions Tests/JSONAPITests/Document/DocumentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
24 changes: 12 additions & 12 deletions Tests/JSONAPITests/Entity/EntityTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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>
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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>
Expand All @@ -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>?
Expand Down
18 changes: 9 additions & 9 deletions Tests/JSONAPITests/Includes/IncludeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -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>
Expand All @@ -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>
Expand All @@ -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>
Expand All @@ -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>
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
Loading

0 comments on commit 072b081

Please sign in to comment.