Skip to content

Commit 3cc7ea2

Browse files
committed
fixing up documentation and code samples
1 parent 2d88ef3 commit 3cc7ea2

6 files changed

Lines changed: 26 additions & 14 deletions

File tree

JSONAPI.playground/Pages/Full Client & Server Example.xcplaygroundpage/Contents.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ typealias UnidentifiedJSONEntity<Description: ResourceObjectDescription> = JSONA
3030
// Create relationship typealiases because we do not expect
3131
// JSON:API Relationships for this particular API to have
3232
// Metadata or Links associated with them.
33-
typealias ToOneRelationship<Entity: JSONAPIIdentifiable> = JSONAPI.ToOneRelationship<Entity, NoMetadata, NoLinks>
34-
typealias ToManyRelationship<Entity: Relatable> = JSONAPI.ToManyRelationship<Entity, NoMetadata, NoLinks>
33+
typealias ToOneRelationship<Entity: JSONAPIIdentifiable> = JSONAPI.ToOneRelationship<Entity, NoIdMetadata, NoMetadata, NoLinks>
34+
typealias ToManyRelationship<Entity: Relatable> = JSONAPI.ToManyRelationship<Entity, NoIdMetadata, NoMetadata, NoLinks>
3535

3636
// Create a typealias for a Document because we do not expect
3737
// JSON:API Documents for this particular API to have Metadata, Links,

JSONAPI.playground/Pages/Full Document Verbose Generation.xcplaygroundpage/Contents.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ enum AuthorDescription: ResourceObjectDescription {
7272
}
7373

7474
struct Relationships: JSONAPI.Relationships {
75-
let articles: ToManyRelationship<Article, ToManyRelationshipMetadata, ToManyRelationshipLinks>
75+
let articles: ToManyRelationship<Article, NoIdMetadata, ToManyRelationshipMetadata, ToManyRelationshipLinks>
7676
}
7777
}
7878

@@ -88,11 +88,11 @@ enum ArticleDescription: ResourceObjectDescription {
8888

8989
struct Relationships: JSONAPI.Relationships {
9090
/// The primary attributed author of the article.
91-
let primaryAuthor: ToOneRelationship<Author, NoMetadata, NoLinks>
91+
let primaryAuthor: ToOneRelationship<Author, NoIdMetadata, NoMetadata, NoLinks>
9292
/// All authors excluding the primary author.
9393
/// It is customary to print the primary author's
9494
/// name first, followed by the other authors.
95-
let otherAuthors: ToManyRelationship<Author, ToManyRelationshipMetadata, ToManyRelationshipLinks>
95+
let otherAuthors: ToManyRelationship<Author, NoIdMetadata, ToManyRelationshipMetadata, ToManyRelationshipLinks>
9696
}
9797
}
9898

JSONAPI.playground/Sources/Entities.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ extension String: CreatableRawIdType {
2525

2626
// MARK: - typealiases for convenience
2727
public typealias ExampleEntity<Description: ResourceObjectDescription> = ResourceObject<Description, NoMetadata, NoLinks, String>
28-
public typealias ToOne<E: JSONAPIIdentifiable> = ToOneRelationship<E, NoMetadata, NoLinks>
29-
public typealias ToMany<E: Relatable> = ToManyRelationship<E, NoMetadata, NoLinks>
28+
public typealias ToOne<E: JSONAPIIdentifiable> = ToOneRelationship<E, NoIdMetadata, NoMetadata, NoLinks>
29+
public typealias ToMany<E: Relatable> = ToManyRelationship<E, NoIdMetadata, NoMetadata, NoLinks>
3030

3131
// MARK: - A few resource objects (entities)
3232
public enum PersonDescription: ResourceObjectDescription {

documentation/client-server-example.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ typealias UnidentifiedJSONEntity<Description: ResourceObjectDescription> = JSONA
2626
// Create relationship typealiases because we do not expect
2727
// JSON:API Relationships for this particular API to have
2828
// Metadata or Links associated with them.
29-
typealias ToOneRelationship<Entity: JSONAPIIdentifiable> = JSONAPI.ToOneRelationship<Entity, NoMetadata, NoLinks>
30-
typealias ToManyRelationship<Entity: Relatable> = JSONAPI.ToManyRelationship<Entity, NoMetadata, NoLinks>
29+
typealias ToOneRelationship<Entity: JSONAPIIdentifiable> = JSONAPI.ToOneRelationship<Entity, NoIdMetadata, NoMetadata, NoLinks>
30+
typealias ToManyRelationship<Entity: Relatable> = JSONAPI.ToManyRelationship<Entity, NoIdMetadata, NoMetadata, NoLinks>
3131

3232
// Create a typealias for a Document because we do not expect
3333
// JSON:API Documents for this particular API to have Metadata, Links,
@@ -183,4 +183,4 @@ let response = try! docode(articleResponseData: responseData)
183183
print("-----")
184184
print(response.article)
185185
print(response.author)
186-
```
186+
```

documentation/project-status.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
- [x] `links`
2323
- [x] `meta`
2424

25+
##### Resource Identifier Object
26+
- [x] `id`
27+
- [x] `type`
28+
- [x] `meta`
29+
2530
#### Links Object
2631
- [x] `href`
2732
- [x] `meta`
@@ -43,4 +48,4 @@ These ideas could be implemented in future versions.
4348
- [ ] (Maybe) Use `KeyPath` to specify `Includes` thus creating type safety around the relationship between a primary resource type and the types of included resources.
4449
- [ ] (Maybe) Replace `SingleResourceBody` and `ManyResourceBody` with support at the `Document` level to just interpret `PrimaryResource`, `PrimaryResource?`, or `[PrimaryResource]` as the same decoding/encoding strategies.
4550
- [ ] Support sideposting. JSONAPI spec might become opinionated in the future (https://github.com/json-api/json-api/pull/1197, https://github.com/json-api/json-api/issues/1215, https://github.com/json-api/json-api/issues/1216) but there is also an existing implementation to consider (https://jsonapi-suite.github.io/jsonapi_suite/ruby/writes/nested-writes). At this time, any sidepost implementation would be an awesome tertiary library to be used alongside the primary JSONAPI library. Maybe `JSONAPISideloading`.
46-
- [ ] Error or warning if an included resource object is not related to a primary resource object or another included resource object (Turned off or at least not throwing by default).
51+
- [ ] Error or warning if an included resource object is not related to a primary resource object or another included resource object (Turned off or at least not throwing by default).

documentation/usage.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ enum PersonDescription: ResourceObjectDescription {
5757
}
5858

5959
struct Relationships: JSONAPI.Relationships {
60-
let friends: ToManyRelationship<Person>
60+
let friends: ToManyRelationship<Person, NoIdMetadata, NoMetadata, NoLinks>
6161
}
6262
}
6363
```
@@ -153,9 +153,16 @@ In addition to identifying resource objects by ID and type, `Relationships` can
153153

154154
The `MetaRelationship` is special in that it represents a Relationship Object with no `data` (it must contain at least one of `meta` or `links`). The other two relationship types are Relationship Objects with either singular resource linkages (`ToOneRelationship`) or arrays of resource linkages (`ToManyRelationship`).
155155

156-
To describe a relationship that may be omitted (i.e. the key is not even present in the JSON object), you make the entire `MetaRelationship`, `ToOneRelationship` or `ToManyRelationship` optional. A `ToOneRelationship` can be marked as nullable (i.e. the value could be either `null` or a resource identifier) like this:
156+
To describe a relationship that may be omitted (i.e. the key is not even present in the JSON object), you make the entire `MetaRelationship`, `ToOneRelationship` or `ToManyRelationship` optional.
157157
```swift
158-
let nullableRelative: ToOneRelationship<Person?, NoMetadata, NoLinks>
158+
// note the question mark at the very end of the line.
159+
let optionalRelative: ToOneRelationship<Person, NoIdMetadata, NoMetadata, NoLinks>?
160+
```
161+
162+
A `ToOneRelationship` can be marked as nullable (i.e. the value could be either `null` or a resource identifier) like this:
163+
```swift
164+
// note the question mark just after `Person`.
165+
let nullableRelative: ToOneRelationship<Person?, NoIdMetadata, NoMetadata, NoLinks>
159166
```
160167

161168
A `ToManyRelationship` can naturally represent the absence of related values with an empty array, so `ToManyRelationship` do not support nullability.

0 commit comments

Comments
 (0)