Adding some documentation and making SparseFieldEncoder internal because it does not need to be public.

This commit is contained in:
Mathew Polzin
2019-08-14 09:22:06 -07:00
parent 8f9ec11f27
commit 86a9345fdd
6 changed files with 24 additions and 3 deletions
+4
View File
@@ -53,7 +53,9 @@ public struct Document<PrimaryResourceBody: JSONAPI.EncodableResourceBody, MetaT
case data(Data)
public struct Data: Equatable {
/// The document's Primary Resource object(s)
public let primary: PrimaryResourceBody
/// The document's included objects
public let includes: Includes<Include>
public let meta: MetaType
public let links: LinksType
@@ -66,6 +68,8 @@ public struct Document<PrimaryResourceBody: JSONAPI.EncodableResourceBody, MetaT
}
}
/// `true` if the document represents one or more errors. `false` if the
/// document represents JSON:API data and/or metadata.
public var isError: Bool {
guard case .errors = self else { return false }
return true
+10
View File
@@ -9,6 +9,16 @@ import Poly
public typealias Include = EncodableJSONPoly
/// A structure holding zero or more included Resource Objects.
/// The resources are accessed by their type using a subscript.
///
/// If you have
///
/// `let includes: Includes<Include2<Thing1, Thing2>> = ...`
///
/// then you can access all `Thing1` included resources with
///
/// `let includedThings = includes[Thing1.self]`
public struct Includes<I: Include>: Encodable, Equatable {
public static var none: Includes { return .init(values: []) }
@@ -48,6 +48,9 @@ public func +<R: Appendable>(_ left: R, right: R) -> R {
return left.appending(right)
}
/// A type allowing for a document body containing 1 primary resource.
/// If the `Entity` specialization is an `Optional` type, the body can contain
/// 0 or 1 primary resources.
public struct SingleResourceBody<Entity: JSONAPI.OptionalEncodablePrimaryResource>: EncodableResourceBody {
public let value: Entity
@@ -56,6 +59,7 @@ public struct SingleResourceBody<Entity: JSONAPI.OptionalEncodablePrimaryResourc
}
}
/// A type allowing for a document body containing 0 or more primary resources.
public struct ManyResourceBody<Entity: JSONAPI.EncodablePrimaryResource>: EncodableResourceBody, Appendable {
public let values: [Entity]
+3
View File
@@ -28,6 +28,9 @@ public protocol CreatableRawIdType: RawIdType {
extension String: RawIdType {}
/// A type that can be used as the `MaybeRawId` for a `ResourceObject` that does not
/// have an Id (most likely because it was created by a client and the server will be responsible
/// for assigning it an Id).
public struct Unidentified: MaybeRawId, CustomStringConvertible {
public init() {}
@@ -5,7 +5,7 @@
// Created by Mathew Polzin on 8/4/19.
//
public class SparseFieldEncoder<SparseKey: CodingKey & Equatable>: Encoder {
class SparseFieldEncoder<SparseKey: CodingKey & Equatable>: Encoder {
private let wrappedEncoder: Encoder
private let allowedKeys: [SparseKey]
@@ -37,7 +37,7 @@ public class SparseFieldEncoder<SparseKey: CodingKey & Equatable>: Encoder {
}
}
public struct SparseFieldKeyedEncodingContainer<Key, SparseKey>: KeyedEncodingContainerProtocol where SparseKey: CodingKey, SparseKey: Equatable, Key: CodingKey {
struct SparseFieldKeyedEncodingContainer<Key, SparseKey>: KeyedEncodingContainerProtocol where SparseKey: CodingKey, SparseKey: Equatable, Key: CodingKey {
private var wrappedContainer: KeyedEncodingContainer<Key>
private let allowedKeys: [SparseKey]
@@ -6,7 +6,7 @@
//
import XCTest
import JSONAPI
@testable import JSONAPI
import Foundation
class SparseFieldEncoderTests: XCTestCase {