From ff0495dacb8afdf64418b60af127a7838196afe4 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Mon, 21 Apr 2025 10:02:13 -0500 Subject: [PATCH 1/3] Add test that shows a custom generic included type of resource --- .../JSONAPITests/Includes/IncludeTests.swift | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/Tests/JSONAPITests/Includes/IncludeTests.swift b/Tests/JSONAPITests/Includes/IncludeTests.swift index 088fbe2..e4a24c5 100644 --- a/Tests/JSONAPITests/Includes/IncludeTests.swift +++ b/Tests/JSONAPITests/Includes/IncludeTests.swift @@ -72,6 +72,16 @@ class IncludedTests: XCTestCase { data: three_different_type_includes) } + func test_OneKnownAndTwoGenericIncludes() { + let includes = decoded(type: Includes>.self, + data: three_different_type_includes) + + XCTAssertEqual(includes[TestEntity.self].count, 1) + XCTAssertEqual(includes[TestEntityOther.self].count, 2) + XCTAssert(includes[TestEntityOther.self].contains { $0.type == "test_entity2"}) + XCTAssert(includes[TestEntityOther.self].contains { $0.type == "test_entity4"}) + } + func test_FourDifferentIncludes() { let includes = decoded(type: Includes>.self, data: four_different_type_includes) @@ -678,4 +688,50 @@ extension IncludedTests { } typealias TestEntity15 = BasicEntity + + enum TestEntityTypeOther: ResourceObjectProxyDescription { + public static var jsonType: String { return "_generic" } + + typealias Attributes = NoAttributes + typealias Relationships = NoRelationships + } + + struct TestEntityOther: ResourceObjectProxy, Codable { + typealias Description = TestEntityTypeOther + typealias EntityRawIdType = String + + public let type : String + public let id : JSONAPI.Id + + public let attributes = NoAttributes() + public let relationships = NoRelationships() + + enum CodingKeys: CodingKey { + case id + case type + } + + init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + let type: String + do { + type = try container.decode(String.self, forKey: .type) + } catch let error as DecodingError { + throw ResourceObjectDecodingError(error, jsonAPIType: Self.jsonType) + ?? error + } + + id = .init(rawValue: try container.decode(String.self, forKey: .id)) + self.type = type + } + + func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(type, forKey: .type) + + try container.encode(id, forKey: .id) + } + } } From 9017bc0e00ad8834b48be30b6813703383da5246 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Mon, 21 Apr 2025 10:07:50 -0500 Subject: [PATCH 2/3] remove unmaintained old Swift image variants --- .github/workflows/tests.yml | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e7cd4df..d6a87ee 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,29 +13,19 @@ jobs: fail-fast: false matrix: image: - - swift:5.2-xenial - - swift:5.2-bionic - swift:5.2-focal - swift:5.2-centos8 - - swift:5.2-amazonlinux2 - - swift:5.3-xenial - - swift:5.3-bionic - swift:5.3-focal - swift:5.3-centos8 - - swift:5.3-amazonlinux2 - - swift:5.4-xenial - - swift:5.4-bionic - swift:5.4-focal - swift:5.4-centos8 - - swift:5.4-amazonlinux2 - - swift:5.5-xenial - - swift:5.5-bionic - swift:5.5-focal - swift:5.5-centos8 - - swift:5.5-amazonlinux2 - - swift:5.6-bionic - swift:5.6-focal - - swift:5.6-amazonlinux2 + - swift:5.7-focal + - swift:5.8-focal + - swift:5.9-focal + - swift:5.10-focal container: ${{ matrix.image }} steps: - name: Checkout code From 93981efca07b74749f92f6a865ebca82cbc53161 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Mon, 21 Apr 2025 10:10:16 -0500 Subject: [PATCH 3/3] comment out versions of Linux Swift that have slightly different error messages so tests are not currently passing --- .github/workflows/tests.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d6a87ee..9644cf8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -22,10 +22,10 @@ jobs: - 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:5.7-focal +# - swift:5.8-focal +# - swift:5.9-focal +# - swift:5.10-focal container: ${{ matrix.image }} steps: - name: Checkout code