Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,12 @@ jobs:
fail-fast: false
matrix:
image:
- swift:5.2-focal
- swift:5.2-centos8
- swift:5.3-focal
- swift:5.3-centos8
- swift:5.4-focal
- swift:5.4-centos8
- swift:5.5-focal
- swift:5.5-centos8
- swift:5.6-focal
# - swift:5.7-focal
# - swift:5.8-focal
# - swift:5.9-focal
# - swift:5.10-focal
- swift:6.0
- swift:6.1
container: ${{ matrix.image }}
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v5
- name: Run tests
run: swift test --enable-test-discovery
osx:
Expand All @@ -39,6 +28,6 @@ jobs:
uses: maxim-lobanov/setup-xcode@v1
with: { 'xcode-version': 'latest' }
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v5
- name: Run tests
run: swift test --enable-test-discovery
141 changes: 0 additions & 141 deletions JSONAPI.podspec

This file was deleted.

25 changes: 12 additions & 13 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// swift-tools-version:5.2
// swift-tools-version:6.0

import PackageDescription

let package = Package(
name: "JSONAPI",
platforms: [
.macOS(.v10_10),
.iOS(.v10)
.macOS(.v10_15),
.iOS(.v13)
],
products: [
.library(
Expand All @@ -17,7 +17,7 @@ let package = Package(
targets: ["JSONAPITesting"])
],
dependencies: [
.package(url: "https://github.com/mattpolzin/Poly.git", .upToNextMajor(from: "2.8.0")),
.package(url: "https://github.com/mattpolzin/Poly.git", .upToNextMajor(from: "3.0.0")),
],
targets: [
.target(
Expand All @@ -33,5 +33,5 @@ let package = Package(
name: "JSONAPITestingTests",
dependencies: ["JSONAPI", "JSONAPITesting"])
],
swiftLanguageVersions: [.v5]
swiftLanguageModes: [.v5, .v6]
)
28 changes: 4 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# JSONAPI
[![MIT license](http://img.shields.io/badge/license-MIT-lightgrey.svg)](http://opensource.org/licenses/MIT) [![Swift 5.2+](http://img.shields.io/badge/Swift-5.2+-blue.svg)](https://swift.org) [![Tests](https://github.com/mattpolzin/JSONAPI/actions/workflows/tests.yml/badge.svg)](https://github.com/mattpolzin/JSONAPI/actions/workflows/tests.yml)
[![MIT license](http://img.shields.io/badge/license-MIT-lightgrey.svg)](http://opensource.org/licenses/MIT) [![Swift 6.0+](http://img.shields.io/badge/Swift-6.0+-blue.svg)](https://swift.org) [![Tests](https://github.com/mattpolzin/JSONAPI/actions/workflows/tests.yml/badge.svg)](https://github.com/mattpolzin/JSONAPI/actions/workflows/tests.yml)

A Swift package for encoding to- and decoding from **JSON API** compliant requests and responses.

Expand Down Expand Up @@ -58,35 +58,15 @@ If you find something wrong with this library and it isn't already mentioned und

## Dev Environment
### Prerequisites
1. Swift 5.2+
2. Swift Package Manager, Xcode 11+, or Cocoapods
1. Swift 6.0+
2. Swift Package Manager

### Swift Package Manager
Just include the following in your package's dependencies and add `JSONAPI` to the dependencies for any of your targets.
```swift
.package(url: "https://github.com/mattpolzin/JSONAPI.git", from: "5.1.0")
.package(url: "https://github.com/mattpolzin/JSONAPI.git", from: "6.0.0")
```

### Xcode project
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`.

### CocoaPods
To use this framework in your project via Cocoapods, add the following dependencies to your Podfile.
```ruby
pod 'Poly', :git => 'https://github.com/mattpolzin/Poly.git'
pod 'MP-JSONAPI', :git => 'https://github.com/mattpolzin/JSONAPI.git'
```

### Carthage
This library does not support the Carthage package manager. This is intentional to avoid an additional dependency on Xcode and the Xcode's project files as their format changes throughout versions (in addition to the complexity of maintaining different shared schemes for each supported operating system).

The difference between supporting and not supporting Carthage is the difference between maintaining an Xcode project with at least one shared build scheme; I encourage those that need Carthage support to fork this repository and add support to their fork by committing an Xcode project (you can generate one as described in the [Xcode project](#xcode-project) section above). Once an Xcode project is generated, you need to mark at least one scheme as [shared](https://github.com/Carthage/Carthage#share-your-xcode-schemes).

### Running the Playground
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.

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.

## Deeper Dive
- [Project Status](./documentation/project-status.md)
- [Server & Client Example](./documentation/examples/client-server-example.md)
Expand Down
4 changes: 4 additions & 0 deletions Sources/JSONAPI/Document/APIDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public struct APIDescription<Meta: JSONAPI.Meta>: APIDescriptionType {
}
}

extension APIDescription: Sendable where Meta: Sendable {}

/// Can be used as `APIDescriptionType` for Documents that do not
/// have any API Description (a.k.a. "JSON:API Object").
public struct NoAPIDescription: APIDescriptionType, CustomStringConvertible {
Expand All @@ -33,6 +35,8 @@ public struct NoAPIDescription: APIDescriptionType, CustomStringConvertible {
public var description: String { return "No JSON:API Object" }
}

extension NoAPIDescription: Sendable {}

extension APIDescription {
private enum CodingKeys: String, CodingKey {
case version
Expand Down
15 changes: 15 additions & 0 deletions Sources/JSONAPI/Document/Document.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ public struct Document<PrimaryResourceBody: JSONAPI.EncodableResourceBody, MetaT
}
}

extension Document: Sendable where
APIDescription: Sendable,
Body: Sendable {}

extension Document {
public enum Body: DocumentBody, Equatable {
case errors([Error], meta: MetaType?, links: LinksType?)
Expand Down Expand Up @@ -260,6 +264,17 @@ extension Document {
}
}

extension Document.Body: Sendable where
MetaType: Sendable,
LinksType: Sendable,
Data: Sendable {}

extension Document.Body.Data: Sendable where
PrimaryResourceBody: Sendable,
IncludeType: Sendable,
MetaType: Sendable,
LinksType: Sendable {}

extension Document.Body.Data where PrimaryResourceBody: ResourceBodyAppendable {
public func merging<OtherDescription, OtherError>(_ other: Document<PrimaryResourceBody, MetaType, LinksType, IncludeType, OtherDescription, OtherError>.Body.Data,
combiningMetaWith metaMerge: (MetaType, MetaType) -> MetaType,
Expand Down
2 changes: 2 additions & 0 deletions Sources/JSONAPI/Document/Includes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public struct Includes<I: Include>: Encodable, Equatable {
}
}

extension Includes: Sendable where I: Sendable {}

extension Includes: Decodable where I: Decodable {
public init(from decoder: Decoder) throws {
var container = try decoder.unkeyedContainer()
Expand Down
6 changes: 6 additions & 0 deletions Sources/JSONAPI/Document/ResourceBody.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public struct SingleResourceBody<PrimaryResource: JSONAPI.OptionalEncodablePrima
}
}

extension SingleResourceBody: Sendable where PrimaryResource: Sendable {}

public protocol ManyResourceBodyProtocol: EncodableResourceBody {
var values: [PrimaryResource] { get }

Expand All @@ -84,6 +86,8 @@ public struct ManyResourceBody<PrimaryResource: JSONAPI.EncodablePrimaryResource
}
}

extension ManyResourceBody: Sendable where PrimaryResource: Sendable {}

/// Use NoResourceBody to indicate you expect a JSON API document to not
/// contain a "data" top-level key.
public struct NoResourceBody: CodableResourceBody {
Expand All @@ -92,6 +96,8 @@ public struct NoResourceBody: CodableResourceBody {
public static var none: NoResourceBody { return NoResourceBody() }
}

extension NoResourceBody: Sendable {}

// MARK: Codable
extension SingleResourceBody {
public func encode(to encoder: Encoder) throws {
Expand Down
6 changes: 4 additions & 2 deletions Sources/JSONAPI/Error/BasicJSONAPIError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public struct BasicJSONAPIErrorPayload<IdType: Codable & Equatable>: Codable, Eq
self.source = source
}

public struct Source: Codable, Equatable {
public struct Source: Codable, Equatable, Sendable {
/// a JSON Pointer [RFC6901] to the associated entity in the request document [e.g. "/data" for a primary data object, or "/data/attributes/title" for a specific attribute].
public let pointer: String?
/// which URI query parameter caused the error
Expand Down Expand Up @@ -70,6 +70,8 @@ public struct BasicJSONAPIErrorPayload<IdType: Codable & Equatable>: Codable, Eq
}
}

extension BasicJSONAPIErrorPayload: Sendable where IdType: Sendable {}

/// `BasicJSONAPIError` optionally decodes many possible fields
/// specified by the JSON:API 1.0 Spec. It gives no type-guarantees of what
/// will be non-nil, but could provide good diagnostic information when
Expand Down Expand Up @@ -100,4 +102,4 @@ public struct BasicJSONAPIErrorPayload<IdType: Codable & Equatable>: Codable, Eq
/// with non-nil values in a flattened way. There will be no `source` key
/// but there will be `pointer` and `parameter` keys (if those values
/// are non-nil).
public typealias BasicJSONAPIError<IdType: Codable & Equatable> = GenericJSONAPIError<BasicJSONAPIErrorPayload<IdType>>
public typealias BasicJSONAPIError<IdType: Codable & Equatable & Sendable> = GenericJSONAPIError<BasicJSONAPIErrorPayload<IdType>>
2 changes: 1 addition & 1 deletion Sources/JSONAPI/Error/GenericJSONAPIError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/// `GenericJSONAPIError` can be used to specify whatever error
/// payload you expect to need to parse in responses and handle any
/// other payload structure as `.unknownError`.
public enum GenericJSONAPIError<ErrorPayload: Codable & Equatable>: JSONAPIError, CustomStringConvertible {
public enum GenericJSONAPIError<ErrorPayload: Codable & Equatable & Sendable>: JSONAPIError, CustomStringConvertible {
case unknownError
case error(ErrorPayload)

Expand Down
Loading