mirror of
https://github.com/encounter/JSONAPI.git
synced 2026-07-10 12:18:40 -07:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d68404db36 | |||
| 4f7db98a87 |
+2
-2
@@ -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>
|
||||
|
||||
+2
-2
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -3,7 +3,5 @@
|
||||
<pages>
|
||||
<page name='Test Library'/>
|
||||
<page name='Usage'/>
|
||||
<page name='Full Document Verbose Generation'/>
|
||||
<page name='Full Client & Server Example'/>
|
||||
</pages>
|
||||
</playground>
|
||||
@@ -143,7 +143,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 +157,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 +460,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 +470,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 +486,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>
|
||||
@@ -565,7 +565,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 +577,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>
|
||||
|
||||
Reference in New Issue
Block a user