You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -5,25 +5,24 @@ A Swift package for encoding to- and decoding from **JSON API** compliant reques
5
5
6
6
See the JSON API Spec here: https://jsonapi.org/format/
7
7
8
-
:warning: This library provides well-tested type safety when working with JSON:API 1.0. However, the Swift compiler can sometimes have difficulty tracking down small typos when initializing `ResourceObjects`. Correct code will always compile, but tracking down the source of programmer errors can be an annoyance. This is mostly a concern when creating resource objects in-code (i.e. declaratively) like you might for unit testing. Writing a client that uses this framework to ingest and decode JSON API Compliant API responses is much less painful.
9
-
10
8
## Quick Start
11
9
12
-
:warning: The following Google Colab examples have correct code, but from time to time the Google Colab Swift compiler may be buggy and produce incorrect or erroneous results. Just keep that in mind if you run the code as you read through the Colab examples.
10
+
:warning: The following Google Colab examples have correct code, but from time to time the Google Colab Swift compiler may be buggy and claim it cannot build the JSONAPI library.
This library works well when used by both the server responsible for serialization and the client responsible for deserialization. Check out the [example](#example) further down in this README.
25
+
This library works well when used by both the server responsible for serialization and the client responsible for deserialization. Check out the [example](./documentation/client-server-example.md).
27
26
28
27
## Table of Contents
29
28
- JSONAPI
@@ -34,8 +33,8 @@ This library works well when used by both the server responsible for serializati
34
33
- [Xcode project](#xcode-project)
35
34
- [CocoaPods](#cocoapods)
36
35
- [Running the Playground](#running-the-playground)
With Xcode 11+ you can also just open the folder containing your clone of this repository and begin working.
73
+
With Xcode 11+, you can open the folder containing this repository. There is no need for an Xcode project, but you can generate one with `swift package generate-xcodeproj`.
78
74
79
75
### CocoaPods
80
76
To use this framework in your project via Cocoapods, add the following dependencies to your Podfile.
@@ -86,232 +82,12 @@ pod 'MP-JSONAPI', :git => 'https://github.com/mattpolzin/JSONAPI.git'
86
82
### Running the Playground
87
83
To run the included Playground files, create an Xcode project using Swift Package Manager, then create an Xcode Workspace in the root of the repository and add both the generated Xcode project and the playground to the Workspace.
88
84
89
-
Note that Playground support for importing non-system Frameworks is still a bit touchy as of Swift 4.2. Sometimes building, cleaning and building, or commenting out and then uncommenting import statements (especially in the Entities.swift Playground Source file) can get things working for me when I am getting an error about `JSONAPI` not being found.
90
-
91
-
## Project Status
92
-
93
-
### JSON:API
94
-
#### Document
95
-
-[x]`data`
96
-
-[x]`included`
97
-
-[x]`errors`
98
-
-[x]`meta`
99
-
-[x]`jsonapi` (i.e. API Information)
100
-
-[x]`links`
101
-
102
-
#### Resource Object
103
-
-[x]`id`
104
-
-[x]`type`
105
-
-[x]`attributes`
106
-
-[x]`relationships`
107
-
-[x]`links`
108
-
-[x]`meta`
109
-
110
-
#### Relationship Object
111
-
-[x]`data`
112
-
-[x]`links`
113
-
-[x]`meta`
114
-
115
-
#### Links Object
116
-
-[x]`href`
117
-
-[x]`meta`
118
-
119
-
### Misc
120
-
-[x] Support transforms on `Attributes` values (e.g. to support different representations of `Date`)
121
-
-[x] Support validation on `Attributes`.
122
-
-[x] Support sparse fieldsets (encoding only). A client can likely just define a new model to represent a sparse population of another model in a very specific use case for decoding purposes. On the server side, sparse fieldsets of Resource Objects can be encoded without creating one model for every possible sparse fieldset.
123
-
124
-
### Testing
125
-
#### Resource Object Validator
126
-
-[x] Disallow optional array in `Attribute` (should be empty array, not `null`).
127
-
-[x] Only allow `TransformedAttribute` and its derivatives as stored properties within `Attributes` struct. Computed properties can still be any type because they do not get encoded or decoded.
128
-
-[x] Only allow `MetaRelationship`, `ToManyRelationship` and `ToOneRelationship` within `Relationships` struct.
129
-
130
-
### Potential Improvements
131
-
These ideas could be implemented in future versions.
132
-
133
-
-[ ] (Maybe) Use `KeyPath` to specify `Includes` thus creating type safety around the relationship between a primary resource type and the types of included resources.
134
-
-[ ] (Maybe) Replace `SingleResourceBody` and `ManyResourceBody` with support at the `Document` level to just interpret `PrimaryResource`, `PrimaryResource?`, or `[PrimaryResource]` as the same decoding/encoding strategies.
135
-
-[ ] 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`.
136
-
-[ ] 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).
137
-
138
-
## Example
139
-
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.
140
-
141
-
### Preamble (Setup shared by server and client)
142
-
```swift
143
-
// Make String a CreatableRawIdType.
144
-
var globalStringId: Int=0
145
-
extensionString: CreatableRawIdType {
146
-
publicstaticfuncunique() ->String {
147
-
globalStringId +=1
148
-
returnString(globalStringId)
149
-
}
150
-
}
151
-
152
-
// Create a typealias because we do not expect JSON:API Resource
153
-
// Objects for this particular API to have Metadata or Links associated
154
-
// with them. We also expect them to have String Ids.
let response =try!docode(articleResponseData: responseData)
306
-
307
-
// Next step would be to do something useful with the article and author but we will print them instead.
308
-
print("-----")
309
-
print(response.article)
310
-
print(response.author)
311
-
```
85
+
Note that Playground support for importing non-system Frameworks is still a bit touchy as of Swift 4.2. Sometimes building, cleaning and building, or commenting out and then uncommenting import statements (especially in the` Entities.swift` Playground Source file) can get things working for me when I am getting an error about `JSONAPI` not being found.
312
86
313
87
## Deeper Dive
314
-
See the [usage documentation](./documentation/usage.md).
The `JSONAPI` framework is packaged with a test library to help you test your `JSONAPI` integration. The test library is called `JSONAPITesting`. You can see `JSONAPITesting` in action in the Playground included with the `JSONAPI` repository.
0 commit comments