Compare commits

..

4 Commits

23 changed files with 175 additions and 85 deletions
@@ -40,7 +40,7 @@ typealias Document<PrimaryResourceBody: JSONAPI.ResourceBody, IncludeType: JSONA
// MARK: Entity Definitions
enum AuthorDescription: EntityDescription {
public static var type: String { return "authors" }
public static var jsonType: String { return "authors" }
public struct Attributes: JSONAPI.Attributes {
public let name: Attribute<String>
@@ -52,7 +52,7 @@ enum AuthorDescription: EntityDescription {
typealias Author = JSONEntity<AuthorDescription>
enum ArticleDescription: EntityDescription {
public static var type: String { return "articles" }
public static var jsonType: String { return "articles" }
public struct Attributes: JSONAPI.Attributes {
public let title: Attribute<String>
@@ -65,7 +65,7 @@ struct ToManyRelationshipLinks: JSONAPI.Links {
/// Description of an Author entity.
enum AuthorDescription: EntityDescription {
static var type: String { return "authors" }
static var jsonType: String { return "authors" }
struct Attributes: JSONAPI.Attributes {
let name: Attribute<String>
@@ -80,7 +80,7 @@ typealias Author = JSONAPI.Entity<AuthorDescription, EntityMetadata, EntityLinks
/// Description of an Article entity.
enum ArticleDescription: EntityDescription {
static var type: String { return "articles" }
static var jsonType: String { return "articles" }
struct Attributes: JSONAPI.Attributes {
let title: Attribute<String>
+4 -4
View File
@@ -31,7 +31,7 @@ public typealias ToMany<E: Relatable> = ToManyRelationship<E, NoMetadata, NoLink
// MARK: - A few resource objects (entities)
public enum PersonDescription: EntityDescription {
public static var type: String { return "people" }
public static var jsonType: String { return "people" }
public struct Attributes: JSONAPI.Attributes {
public let name: Attribute<[String]>
@@ -70,7 +70,7 @@ public extension Entity where Description == PersonDescription, MetaType == NoMe
public enum DogDescription: EntityDescription {
public static var type: String { return "dogs" }
public static var jsonType: String { return "dogs" }
public struct Attributes: JSONAPI.Attributes {
public let name: Attribute<String>
@@ -93,7 +93,7 @@ public typealias Dog = ExampleEntity<DogDescription>
public enum AlternativeDogDescription: EntityDescription {
public static var type: String { return "dogs" }
public static var jsonType: String { return "dogs" }
public struct Attributes: JSONAPI.Attributes {
public let name: Attribute<String>
@@ -131,7 +131,7 @@ public extension Entity where Description == DogDescription, MetaType == NoMetad
public enum HouseDescription: EntityDescription {
public static var type: String { return "houses" }
public static var jsonType: String { return "houses" }
public typealias Attributes = NoAttributes
public typealias Relationships = NoRelationships
-2
View File
@@ -3,7 +3,5 @@
<pages>
<page name='Test Library'/>
<page name='Usage'/>
<page name='Full Document Verbose Generation'/>
<page name='Full Client &amp; Server Example'/>
</pages>
</playground>
+53 -7
View File
@@ -52,6 +52,7 @@ See the JSON API Spec here: https://jsonapi.org/format/
- [`JSONAPI.RawIdType`](#jsonapirawidtype)
- [Custom Attribute or Relationship Key Mapping](#custom-attribute-or-relationship-key-mapping)
- [Custom Attribute Encode/Decode](#custom-attribute-encodedecode)
- [Meta-attributes](#meta-attributes)
- [Example](#example)
- [Preamble (Setup shared by server and client)](#preamble-setup-shared-by-server-and-client)
- [Server Pseudo-example](#server-pseudo-example)
@@ -143,7 +144,7 @@ An `EntityDescription` is the `JSONAPI` framework's representation of what the *
```
enum PersonDescription: IdentifiedEntityDescription {
static var type: String { return "people" }
static var jsonType: String { return "people" }
struct Attributes: JSONAPI.Attributes {
let name: Attribute<[String]>
@@ -157,7 +158,7 @@ enum PersonDescription: IdentifiedEntityDescription {
```
The requirements of an `EntityDescription` are:
1. A static `var` "type" that matches the JSON type; The **SPEC** requires every *Resource Object* to have a "type".
1. A static `var` "jsonType" that matches the JSON type; The **SPEC** requires every *Resource Object* to have a "type".
2. A `struct` of `Attributes` **- OR -** `typealias Attributes = NoAttributes`
3. A `struct` of `Relationships` **- OR -** `typealias Relationships = NoRelationships`
@@ -460,7 +461,7 @@ extension String: CreatableRawIdType {
There is not anything special going on at the `JSONAPI.Attributes` and `JSONAPI.Relationships` levels, so you can easily provide custom key mappings by taking advantage of `Codable`'s `CodingKeys` pattern. Here are two models that will encode/decode equivalently but offer different naming in your codebase:
```
public enum EntityDescription1: JSONAPI.EntityDescription {
public static var type: String { return "entity" }
public static var jsonType: String { return "entity" }
public struct Attributes: JSONAPI.Attributes {
public let coolProperty: Attribute<String>
@@ -470,7 +471,7 @@ public enum EntityDescription1: JSONAPI.EntityDescription {
}
public enum EntityDescription2: JSONAPI.EntityDescription {
public static var type: String { return "entity" }
public static var jsonType: String { return "entity" }
public struct Attributes: JSONAPI.Attributes {
public let wholeOtherThing: Attribute<String>
@@ -486,7 +487,7 @@ public enum EntityDescription2: JSONAPI.EntityDescription {
You can safely provide your own encoding or decoding functions for your Attributes struct if you need to as long as you are careful that your encode operation correctly reverses your decode operation. Although this is generally not necessary, `AttributeType` provides a convenience method to make your decoding a bit less boilerplate ridden. This is what it looks like:
```
public enum EntityDescription1: JSONAPI.EntityDescription {
public static var type: String { return "entity" }
public static var jsonType: String { return "entity" }
public struct Attributes: JSONAPI.Attributes {
public let property1: Attribute<String>
@@ -526,6 +527,51 @@ extension EntityDescription1.Attributes {
}
```
### Meta-attributes
This advanced feature may not ever be useful, but if you find yourself in the situation of dealing with an API that does not 100% follow the **SPEC** then you might find meta-attributes are just the thing to make your entities more natural to work with.
Suppose, for example, you are presented with the unfortunate situation where a piece of information you need is only available as part of the `Id` of an entity. Perhaps a user's `Id` is formatted "{integer}-{createdAt}" where "createdAt" is the unix timestamp when the user account was created. The following `UserDescription` will expose what you need as an attribute. Realistically, this code is still terrible for its error handling. Using a `Result` type and/or invariants would clean things up substantially.
```
enum UserDescription: EntityDescription {
public static var jsonType: String { return "users" }
struct Attributes: JSONAPI.Attributes {
var createdAt: (User) -> Date {
return { user in
let components = user.id.rawValue.split(separator: "-")
guard components.count == 2 else {
assertionFailure()
return Date()
}
let timestamp = TimeInterval(components[1])
guard let date = timestamp.map(Date.init(timeIntervalSince1970:)) else {
assertionFailure()
return Date()
}
return date
}
}
}
typealias Relationships = NoRelationships
}
typealias User = JSONAPI.Entity<UserDescription, NoMetadata, NoLinks, String>
```
Given a value `user` of the above entity type, you can access the `createdAt` attribute just like you would any other:
```
let createdAt = user[\.createdAt]
```
This works because `createdAt` is defined in the form: `var {name}: ({Entity}) -> {Value}` where `{Entity}` is the `JSONAPI.Entity` described by the `EntityDescription` containing the meta-attribute.
## Example
The following serves as a sort of pseudo-example. It skips server/client implementation details not related to JSON:API but still gives a more complete picture of what an implementation using this framework might look like. You can play with this example code in the Playground provided with this repo.
@@ -565,7 +611,7 @@ typealias Document<PrimaryResourceBody: JSONAPI.ResourceBody, IncludeType: JSONA
// MARK: Entity Definitions
enum AuthorDescription: EntityDescription {
public static var type: String { return "authors" }
public static var jsonType: String { return "authors" }
public struct Attributes: JSONAPI.Attributes {
public let name: Attribute<String>
@@ -577,7 +623,7 @@ enum AuthorDescription: EntityDescription {
typealias Author = JSONEntity<AuthorDescription>
enum ArticleDescription: EntityDescription {
public static var type: String { return "articles" }
public static var jsonType: String { return "articles" }
public struct Attributes: JSONAPI.Attributes {
public let title: Attribute<String>
+15 -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)))"
}
}
@@ -471,6 +471,15 @@ public extension EntityProxy {
}
}
// MARK: Meta-Attribute Access
public extension EntityProxy {
/// Access an attribute requiring a transformation on the RawValue _and_
/// a secondary transformation on this entity (self).
subscript<T>(_ path: KeyPath<Description.Attributes, (Self) -> T>) -> T {
return attributes[keyPath: path](self)
}
}
// MARK: Relationship Access
public extension EntityProxy {
/// Access to an Id of a `ToOneRelationship`.
@@ -529,7 +538,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 +567,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
+48 -12
View File
@@ -609,11 +609,31 @@ extension EntityTests {
}
}
// MARK: With a Meta Attribute
extension EntityTests {
func test_MetaEntityAccessWorks() {
let entity1 = TestEntityWithMetaAttribute(id: "even",
attributes: .init(),
relationships: .none,
meta: .none,
links: .none)
let entity2 = TestEntityWithMetaAttribute(id: "odd",
attributes: .init(),
relationships: .none,
meta: .none,
links: .none)
XCTAssertEqual(entity1[\.metaAttribute], true)
XCTAssertEqual(entity2[\.metaAttribute], false)
}
}
// MARK: - Test Types
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 +642,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 +654,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 +666,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 +688,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 +700,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 +714,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 +727,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 +745,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 +768,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 +781,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 +793,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>?
@@ -790,6 +810,22 @@ extension EntityTests {
typealias UnidentifiedTestEntityWithMetaAndLinks = NewEntity<UnidentifiedTestEntityType, TestEntityMeta, TestEntityLinks>
enum TestEntityWithMetaAttributeDescription: EntityDescription {
public static var jsonType: String { return "meta_attribute_entity" }
struct Attributes: JSONAPI.Attributes {
var metaAttribute: (TestEntityWithMetaAttribute) -> Bool {
return { entity in
(entity.id.rawValue.count % 2) == 0
}
}
}
typealias Relationships = NoRelationships
}
typealias TestEntityWithMetaAttribute = BasicEntity<TestEntityWithMetaAttributeDescription>
enum IntToString: Transformer {
public static func transform(_ from: Int) -> String {
return String(from)
@@ -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>

Some files were not shown because too many files have changed in this diff Show More