mirror of
https://github.com/encounter/JSONAPI.git
synced 2026-07-10 12:18:40 -07:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f41521e33b | |||
| 45ec7ba753 | |||
| 6ab4237c97 | |||
| 75711648a4 | |||
| 2b4209ccb1 | |||
| ebd11df104 | |||
| 96da1b4e21 | |||
| c7696d83fa | |||
| 8ee04d8932 | |||
| 4a7a14b1b0 |
+1
-1
@@ -37,7 +37,7 @@ typealias ToManyRelationship<Entity: Relatable> = JSONAPI.ToManyRelationship<Ent
|
||||
// JSON:API Documents for this particular API to have Metadata, Links,
|
||||
// useful Errors, or an APIDescription (The *SPEC* calls this
|
||||
// "API Description" the "JSON:API Object").
|
||||
typealias Document<PrimaryResourceBody: JSONAPI.ResourceBody, IncludeType: JSONAPI.Include> = JSONAPI.Document<PrimaryResourceBody, NoMetadata, NoLinks, IncludeType, NoAPIDescription, BasicJSONAPIError<String>>
|
||||
typealias Document<PrimaryResourceBody: JSONAPI.CodableResourceBody, IncludeType: JSONAPI.Include> = JSONAPI.Document<PrimaryResourceBody, NoMetadata, NoLinks, IncludeType, NoAPIDescription, BasicJSONAPIError<String>>
|
||||
|
||||
// MARK: Entity Definitions
|
||||
|
||||
|
||||
@@ -64,11 +64,11 @@ if case let .data(bodyData) = peopleResponse.body {
|
||||
|
||||
// MARK: - Work in the abstract
|
||||
print("-----")
|
||||
func process<T: JSONAPIDocument>(document: T) {
|
||||
guard case let .data(body) = document.body else {
|
||||
func process<T: CodableJSONAPIDocument>(document: T) {
|
||||
guard let body = document.body.data else {
|
||||
return
|
||||
}
|
||||
let x: T.Body.Data = body
|
||||
let x: T.BodyData = body
|
||||
}
|
||||
process(document: peopleResponse)
|
||||
|
||||
|
||||
+2
-2
@@ -16,7 +16,7 @@ Pod::Spec.new do |spec|
|
||||
#
|
||||
|
||||
spec.name = "MP-JSONAPI"
|
||||
spec.version = "2.5.0"
|
||||
spec.version = "3.0.0"
|
||||
spec.summary = "Swift Codable JSON API framework."
|
||||
|
||||
# This description is used to generate tags and improve search results.
|
||||
@@ -136,6 +136,6 @@ See the JSON API Spec here: https://jsonapi.org/format/
|
||||
# spec.requires_arc = true
|
||||
|
||||
# spec.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
|
||||
spec.dependency "Poly", "~> 2.2"
|
||||
spec.dependency "Poly", "~> 2.3.1"
|
||||
|
||||
end
|
||||
|
||||
@@ -12,32 +12,71 @@ import JSONAPITesting
|
||||
final class ResourceObjectCompareTests: XCTestCase {
|
||||
func test_same() {
|
||||
XCTAssertTrue(test1.compare(to: test1).differences.isEmpty)
|
||||
XCTAssertTrue(test2.compare(to: test2).differences.isEmpty)
|
||||
XCTAssertTrue(test1_differentId.compare(to: test1_differentId).differences.isEmpty)
|
||||
XCTAssertTrue(test1_differentAttributes.compare(to: test1_differentAttributes).differences.isEmpty)
|
||||
}
|
||||
|
||||
func test_differentAttributes() {
|
||||
// TODO: write actual test
|
||||
print(test1.compare(to: test2).differences.map { "\($0): \($1)" }.joined(separator: ", "))
|
||||
XCTAssertEqual(test1.compare(to: test1_differentAttributes).differences, [
|
||||
"'favoriteColor' attribute": #"Optional("red") ≠nil"#,
|
||||
"'name' attribute": "James ≠Fred",
|
||||
"'age' attribute": "12 ≠10"
|
||||
])
|
||||
}
|
||||
|
||||
func test_differentRelationships() {
|
||||
// TODO: write test
|
||||
}
|
||||
|
||||
func test_differentTypes() {
|
||||
// TODO: write test
|
||||
XCTAssertEqual(test1.compare(to: test1_differentRelationships).differences, [
|
||||
"'parents' relationship": "4, 5 ≠3",
|
||||
"'bestFriend' relationship": "Optional(Id(3)) ≠nil"
|
||||
])
|
||||
}
|
||||
|
||||
func test_differentIds() {
|
||||
// TODO: write test
|
||||
XCTAssertEqual(test1.compare(to: test1_differentId).differences, [
|
||||
"id": "2 ≠3"
|
||||
])
|
||||
}
|
||||
|
||||
func test_differentMetadata() {
|
||||
// TODO: write test
|
||||
let test1 = TestType2(
|
||||
id: "2",
|
||||
attributes: .none,
|
||||
relationships: .none,
|
||||
meta: .init(total: 10),
|
||||
links: .init(link: .init(url: "http://google.com"))
|
||||
)
|
||||
let test1_differentMeta = TestType2(
|
||||
id: "2",
|
||||
attributes: .none,
|
||||
relationships: .none,
|
||||
meta: .init(total: 12),
|
||||
links: .init(link: .init(url: "http://google.com"))
|
||||
)
|
||||
|
||||
XCTAssertEqual(test1.compare(to: test1_differentMeta).differences, [
|
||||
"meta": "total: 10 ≠total: 12"
|
||||
])
|
||||
}
|
||||
|
||||
func test_differentLinks() {
|
||||
// TODO: write test
|
||||
let test1 = TestType2(
|
||||
id: "2",
|
||||
attributes: .none,
|
||||
relationships: .none,
|
||||
meta: .init(total: 10),
|
||||
links: .init(link: .init(url: "http://google.com"))
|
||||
)
|
||||
let test1_differentLinks = TestType2(
|
||||
id: "2",
|
||||
attributes: .none,
|
||||
relationships: .none,
|
||||
meta: .init(total: 10),
|
||||
links: .init(link: .init(url: "http://yahoo.com"))
|
||||
)
|
||||
|
||||
XCTAssertEqual(test1.compare(to: test1_differentLinks).differences, [
|
||||
"links": "link: http://google.com ≠link: http://yahoo.com"
|
||||
])
|
||||
}
|
||||
|
||||
fileprivate let test1 = TestType(
|
||||
@@ -54,15 +93,43 @@ final class ResourceObjectCompareTests: XCTestCase {
|
||||
links: .none
|
||||
)
|
||||
|
||||
fileprivate let test2 = TestType(
|
||||
fileprivate let test1_differentId = TestType(
|
||||
id: "3",
|
||||
attributes: .init(
|
||||
name: "James",
|
||||
age: 12,
|
||||
favoriteColor: "red"),
|
||||
relationships: .init(
|
||||
bestFriend: "3",
|
||||
parents: ["4", "5"]
|
||||
),
|
||||
meta: .none,
|
||||
links: .none
|
||||
)
|
||||
|
||||
fileprivate let test1_differentAttributes = TestType(
|
||||
id: "2",
|
||||
attributes: .init(
|
||||
name: "Fred",
|
||||
age: 10,
|
||||
favoriteColor: .init(value: nil)),
|
||||
relationships: .init(
|
||||
bestFriend: "3",
|
||||
parents: ["4", "5"]
|
||||
),
|
||||
meta: .none,
|
||||
links: .none
|
||||
)
|
||||
|
||||
fileprivate let test1_differentRelationships = TestType(
|
||||
id: "2",
|
||||
attributes: .init(
|
||||
name: "James",
|
||||
age: 12,
|
||||
favoriteColor: "red"),
|
||||
relationships: .init(
|
||||
bestFriend: nil,
|
||||
parents: ["1"]
|
||||
parents: ["3"]
|
||||
),
|
||||
meta: .none,
|
||||
links: .none
|
||||
@@ -85,3 +152,29 @@ private enum TestDescription: JSONAPI.ResourceObjectDescription {
|
||||
}
|
||||
|
||||
private typealias TestType = ResourceObject<TestDescription, NoMetadata, NoLinks, String>
|
||||
|
||||
private struct TestMetadata: JSONAPI.Meta, CustomStringConvertible {
|
||||
let total: Int
|
||||
|
||||
var description: String {
|
||||
"total: \(total)"
|
||||
}
|
||||
}
|
||||
|
||||
private struct TestLinks: JSONAPI.Links, CustomStringConvertible {
|
||||
let link: Link<String, NoMetadata>
|
||||
|
||||
var description: String {
|
||||
"link: \(link.url)"
|
||||
}
|
||||
}
|
||||
|
||||
private enum TestDescription2: JSONAPI.ResourceObjectDescription {
|
||||
static let jsonType: String = "test_type2"
|
||||
|
||||
typealias Attributes = NoAttributes
|
||||
|
||||
typealias Relationships = NoRelationships
|
||||
}
|
||||
|
||||
private typealias TestType2 = ResourceObject<TestDescription2, TestMetadata, TestLinks, String>
|
||||
|
||||
@@ -1,6 +1,18 @@
|
||||
#if !canImport(ObjectiveC)
|
||||
import XCTest
|
||||
|
||||
extension ArrayCompareTests {
|
||||
// DO NOT MODIFY: This is autogenerated, use:
|
||||
// `swift test --generate-linuxmain`
|
||||
// to regenerate.
|
||||
static let __allTests__ArrayCompareTests = [
|
||||
("test_differentLengths", test_differentLengths),
|
||||
("test_differentValues", test_differentValues),
|
||||
("test_reducePrebuilt", test_reducePrebuilt),
|
||||
("test_same", test_same),
|
||||
]
|
||||
}
|
||||
|
||||
extension Attribute_LiteralTests {
|
||||
// DO NOT MODIFY: This is autogenerated, use:
|
||||
// `swift test --generate-linuxmain`
|
||||
@@ -41,6 +53,7 @@ extension AttributesCompareTests {
|
||||
// to regenerate.
|
||||
static let __allTests__AttributesCompareTests = [
|
||||
("test_differentAttributes", test_differentAttributes),
|
||||
("test_nonAttributeTypes", test_nonAttributeTypes),
|
||||
("test_sameAttributes", test_sameAttributes),
|
||||
]
|
||||
}
|
||||
@@ -50,10 +63,14 @@ extension DocumentCompareTests {
|
||||
// `swift test --generate-linuxmain`
|
||||
// to regenerate.
|
||||
static let __allTests__DocumentCompareTests = [
|
||||
("test_differentAPIDescription", test_differentAPIDescription),
|
||||
("test_differentData", test_differentData),
|
||||
("test_differentErrors", test_differentErrors),
|
||||
("test_differentLinks", test_differentLinks),
|
||||
("test_differentMetadata", test_differentMetadata),
|
||||
("test_errorAndData", test_errorAndData),
|
||||
("test_same", test_same),
|
||||
("test_sameErrorsDifferentMetadata", test_sameErrorsDifferentMetadata),
|
||||
]
|
||||
}
|
||||
|
||||
@@ -103,18 +120,36 @@ extension Relationship_LiteralTests {
|
||||
]
|
||||
}
|
||||
|
||||
extension RelationshipsCompareTests {
|
||||
// DO NOT MODIFY: This is autogenerated, use:
|
||||
// `swift test --generate-linuxmain`
|
||||
// to regenerate.
|
||||
static let __allTests__RelationshipsCompareTests = [
|
||||
("test_differentIds", test_differentIds),
|
||||
("test_differentLinks", test_differentLinks),
|
||||
("test_differentMetadata", test_differentMetadata),
|
||||
("test_nonRelationshipTypes", test_nonRelationshipTypes),
|
||||
("test_same", test_same),
|
||||
]
|
||||
}
|
||||
|
||||
extension ResourceObjectCompareTests {
|
||||
// DO NOT MODIFY: This is autogenerated, use:
|
||||
// `swift test --generate-linuxmain`
|
||||
// to regenerate.
|
||||
static let __allTests__ResourceObjectCompareTests = [
|
||||
("test_different", test_different),
|
||||
("test_differentAttributes", test_differentAttributes),
|
||||
("test_differentIds", test_differentIds),
|
||||
("test_differentLinks", test_differentLinks),
|
||||
("test_differentMetadata", test_differentMetadata),
|
||||
("test_differentRelationships", test_differentRelationships),
|
||||
("test_same", test_same),
|
||||
]
|
||||
}
|
||||
|
||||
public func __allTests() -> [XCTestCaseEntry] {
|
||||
return [
|
||||
testCase(ArrayCompareTests.__allTests__ArrayCompareTests),
|
||||
testCase(Attribute_LiteralTests.__allTests__Attribute_LiteralTests),
|
||||
testCase(AttributesCompareTests.__allTests__AttributesCompareTests),
|
||||
testCase(DocumentCompareTests.__allTests__DocumentCompareTests),
|
||||
@@ -122,6 +157,7 @@ public func __allTests() -> [XCTestCaseEntry] {
|
||||
testCase(Id_LiteralTests.__allTests__Id_LiteralTests),
|
||||
testCase(IncludesCompareTests.__allTests__IncludesCompareTests),
|
||||
testCase(Relationship_LiteralTests.__allTests__Relationship_LiteralTests),
|
||||
testCase(RelationshipsCompareTests.__allTests__RelationshipsCompareTests),
|
||||
testCase(ResourceObjectCompareTests.__allTests__ResourceObjectCompareTests),
|
||||
]
|
||||
}
|
||||
|
||||
@@ -22,10 +22,12 @@ extension AttributeTests {
|
||||
// to regenerate.
|
||||
static let __allTests__AttributeTests = [
|
||||
("test_AttributeConstructor", test_AttributeConstructor),
|
||||
("test_AttributeRawType", test_AttributeRawType),
|
||||
("test_EncodedPrimitives", test_EncodedPrimitives),
|
||||
("test_NullableIsEqualToNonNullableIfNotNil", test_NullableIsEqualToNonNullableIfNotNil),
|
||||
("test_NullableIsNullIfNil", test_NullableIsNullIfNil),
|
||||
("test_TransformedAttributeNoThrow", test_TransformedAttributeNoThrow),
|
||||
("test_TransformedAttributeRawType", test_TransformedAttributeRawType),
|
||||
("test_TransformedAttributeReversNoThrow", test_TransformedAttributeReversNoThrow),
|
||||
("test_TransformedAttributeThrows", test_TransformedAttributeThrows),
|
||||
]
|
||||
@@ -91,10 +93,13 @@ extension DocumentDecodingErrorTests {
|
||||
// to regenerate.
|
||||
static let __allTests__DocumentDecodingErrorTests = [
|
||||
("test_include_failure", test_include_failure),
|
||||
("test_include_failure2", test_include_failure2),
|
||||
("test_manyPrimaryResource_failure", test_manyPrimaryResource_failure),
|
||||
("test_manyPrimaryResource_missing", test_manyPrimaryResource_missing),
|
||||
("test_singlePrimaryResource_failure", test_singlePrimaryResource_failure),
|
||||
("test_singlePrimaryResource_missing", test_singlePrimaryResource_missing),
|
||||
("test_wantError_foundSuccess", test_wantError_foundSuccess),
|
||||
("test_wantSuccess_foundError", test_wantSuccess_foundError),
|
||||
]
|
||||
}
|
||||
|
||||
@@ -283,6 +288,15 @@ extension IncludedTests {
|
||||
]
|
||||
}
|
||||
|
||||
extension IncludesDecodingErrorTests {
|
||||
// DO NOT MODIFY: This is autogenerated, use:
|
||||
// `swift test --generate-linuxmain`
|
||||
// to regenerate.
|
||||
static let __allTests__IncludesDecodingErrorTests = [
|
||||
("test_unexpectedIncludeType", test_unexpectedIncludeType),
|
||||
]
|
||||
}
|
||||
|
||||
extension LinksTests {
|
||||
// DO NOT MODIFY: This is autogenerated, use:
|
||||
// `swift test --generate-linuxmain`
|
||||
@@ -318,6 +332,7 @@ extension PolyProxyTests {
|
||||
static let __allTests__PolyProxyTests = [
|
||||
("test_AsymmetricEncodeDecodeUserA", test_AsymmetricEncodeDecodeUserA),
|
||||
("test_AsymmetricEncodeDecodeUserB", test_AsymmetricEncodeDecodeUserB),
|
||||
("test_CannotEncodeOrDecodePoly0", test_CannotEncodeOrDecodePoly0),
|
||||
("test_generalReasonableness", test_generalReasonableness),
|
||||
("test_UserAAndBEncodeEquality", test_UserAAndBEncodeEquality),
|
||||
("test_UserADecode", test_UserADecode),
|
||||
@@ -391,8 +406,13 @@ extension ResourceObjectDecodingErrorTests {
|
||||
("test_oneTypeVsAnother_relationship", test_oneTypeVsAnother_relationship),
|
||||
("test_required_attribute", test_required_attribute),
|
||||
("test_required_relationship", test_required_relationship),
|
||||
("test_transformed_attribute", test_transformed_attribute),
|
||||
("test_transformed_attribute2", test_transformed_attribute2),
|
||||
("test_twoOneVsToMany_relationship", test_twoOneVsToMany_relationship),
|
||||
("test_wrongType", test_wrongType),
|
||||
("test_type_missing", test_type_missing),
|
||||
("test_type_null", test_type_null),
|
||||
("test_wrongDecodedType", test_wrongDecodedType),
|
||||
("test_wrongJSONAPIType", test_wrongJSONAPIType),
|
||||
]
|
||||
}
|
||||
|
||||
@@ -538,6 +558,16 @@ extension SparseFieldsetTests {
|
||||
]
|
||||
}
|
||||
|
||||
extension SuccessAndErrorDocumentTests {
|
||||
// DO NOT MODIFY: This is autogenerated, use:
|
||||
// `swift test --generate-linuxmain`
|
||||
// to regenerate.
|
||||
static let __allTests__SuccessAndErrorDocumentTests = [
|
||||
("test_errorAccessors", test_errorAccessors),
|
||||
("test_successAccessors", test_successAccessors),
|
||||
]
|
||||
}
|
||||
|
||||
extension TransformerTests {
|
||||
// DO NOT MODIFY: This is autogenerated, use:
|
||||
// `swift test --generate-linuxmain`
|
||||
@@ -561,6 +591,7 @@ public func __allTests() -> [XCTestCaseEntry] {
|
||||
testCase(EmptyObjectDecoderTests.__allTests__EmptyObjectDecoderTests),
|
||||
testCase(GenericJSONAPIErrorTests.__allTests__GenericJSONAPIErrorTests),
|
||||
testCase(IncludedTests.__allTests__IncludedTests),
|
||||
testCase(IncludesDecodingErrorTests.__allTests__IncludesDecodingErrorTests),
|
||||
testCase(LinksTests.__allTests__LinksTests),
|
||||
testCase(NonJSONAPIRelatableTests.__allTests__NonJSONAPIRelatableTests),
|
||||
testCase(PolyProxyTests.__allTests__PolyProxyTests),
|
||||
@@ -571,6 +602,7 @@ public func __allTests() -> [XCTestCaseEntry] {
|
||||
testCase(ResourceObjectTests.__allTests__ResourceObjectTests),
|
||||
testCase(SparseFieldEncoderTests.__allTests__SparseFieldEncoderTests),
|
||||
testCase(SparseFieldsetTests.__allTests__SparseFieldsetTests),
|
||||
testCase(SuccessAndErrorDocumentTests.__allTests__SuccessAndErrorDocumentTests),
|
||||
testCase(TransformerTests.__allTests__TransformerTests),
|
||||
]
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user