From bd8ee83dcb775a8f005b4d514afc7745df1f7bd3 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 21 Oct 2024 16:58:05 +1300 Subject: [PATCH 1/4] Fix nested object serialization with generics --- templates/apple/Sources/Client.swift.twig | 7 +------ templates/swift/Sources/Client.swift.twig | 7 +------ 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/templates/apple/Sources/Client.swift.twig b/templates/apple/Sources/Client.swift.twig index 2a93f526c..b5e65d229 100644 --- a/templates/apple/Sources/Client.swift.twig +++ b/templates/apple/Sources/Client.swift.twig @@ -440,12 +440,7 @@ open class Client { || param is [Bool: Any] { encodedParams[key] = param } else { - let value = try! (param as! Encodable).toJson() - - let range = value.index(value.startIndex, offsetBy: 1).. Date: Thu, 24 Oct 2024 01:02:30 +1300 Subject: [PATCH 2/4] Fix enum serialization --- templates/apple/Sources/Client.swift.twig | 7 ++++++- templates/swift/Sources/Client.swift.twig | 7 ++++++- templates/swift/Sources/Enums/Enum.swift.twig | 6 +++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/templates/apple/Sources/Client.swift.twig b/templates/apple/Sources/Client.swift.twig index b5e65d229..1f11f898d 100644 --- a/templates/apple/Sources/Client.swift.twig +++ b/templates/apple/Sources/Client.swift.twig @@ -429,18 +429,23 @@ open class Client { if param is String || param is Int || param is Float + || param is Double || param is Bool || param is [String] || param is [Int] || param is [Float] + || param is [Double] || param is [Bool] || param is [String: Any] || param is [Int: Any] || param is [Float: Any] + || param is [Double: Any] || param is [Bool: Any] { encodedParams[key] = param + } else if let encodable = param as? Encodable { + encodedParams[key] = try encodable.toJson() } else { - encodedParams[key] = try (param as! Encodable).toJson() + encodedParams[key] = String(describing: param) } } diff --git a/templates/swift/Sources/Client.swift.twig b/templates/swift/Sources/Client.swift.twig index bb87a2f68..c91d8314e 100644 --- a/templates/swift/Sources/Client.swift.twig +++ b/templates/swift/Sources/Client.swift.twig @@ -465,18 +465,23 @@ open class Client { if param is String || param is Int || param is Float + || param is Double || param is Bool || param is [String] || param is [Int] || param is [Float] + || param is [Double] || param is [Bool] || param is [String: Any] || param is [Int: Any] || param is [Float: Any] + || param is [Double: Any] || param is [Bool: Any] { encodedParams[key] = param + } else if let encodable = param as? Encodable { + encodedParams[key] = try encodable.toJson() } else { - encodedParams[key] = try (param as! Encodable).toJson() + encodedParams[key] = String(describing: param) } } diff --git a/templates/swift/Sources/Enums/Enum.swift.twig b/templates/swift/Sources/Enums/Enum.swift.twig index a54c148e1..2f19e23c1 100644 --- a/templates/swift/Sources/Enums/Enum.swift.twig +++ b/templates/swift/Sources/Enums/Enum.swift.twig @@ -1,11 +1,15 @@ import Foundation -public enum {{ enum.name | caseUcfirst | overrideIdentifier }}: String, Codable { +public enum {{ enum.name | caseUcfirst | overrideIdentifier }}: String, CustomStringConvertible, Codable { {%~ for value in enum.enum %} {%~ set key = enum.keys is empty ? value : enum.keys[loop.index0] %} case {{ key | caseEnumKey | escapeSwiftKeyword }} = "{{ value }}" {%~ endfor %} + public var description: String { + return rawValue + } + public func encode(to encoder: Encoder) throws { var container = encoder.singleValueContainer() try container.encode(rawValue) From 86ebddc6b8adff948d8e0aa3fef74eaca02931ba Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 24 Oct 2024 02:11:54 +1300 Subject: [PATCH 3/4] Fix optional wrapping --- templates/apple/Sources/Client.swift.twig | 2 +- templates/swift/Sources/Client.swift.twig | 2 +- templates/swift/Sources/Enums/Enum.swift.twig | 7 +------ tests/Base.php | 17 +++++------------ 4 files changed, 8 insertions(+), 20 deletions(-) diff --git a/templates/apple/Sources/Client.swift.twig b/templates/apple/Sources/Client.swift.twig index 1f11f898d..baa7adbcb 100644 --- a/templates/apple/Sources/Client.swift.twig +++ b/templates/apple/Sources/Client.swift.twig @@ -444,7 +444,7 @@ open class Client { encodedParams[key] = param } else if let encodable = param as? Encodable { encodedParams[key] = try encodable.toJson() - } else { + } else if let param = param { encodedParams[key] = String(describing: param) } } diff --git a/templates/swift/Sources/Client.swift.twig b/templates/swift/Sources/Client.swift.twig index c91d8314e..6cd23d78b 100644 --- a/templates/swift/Sources/Client.swift.twig +++ b/templates/swift/Sources/Client.swift.twig @@ -480,7 +480,7 @@ open class Client { encodedParams[key] = param } else if let encodable = param as? Encodable { encodedParams[key] = try encodable.toJson() - } else { + } else if let param = param { encodedParams[key] = String(describing: param) } } diff --git a/templates/swift/Sources/Enums/Enum.swift.twig b/templates/swift/Sources/Enums/Enum.swift.twig index 2f19e23c1..861905af8 100644 --- a/templates/swift/Sources/Enums/Enum.swift.twig +++ b/templates/swift/Sources/Enums/Enum.swift.twig @@ -1,6 +1,6 @@ import Foundation -public enum {{ enum.name | caseUcfirst | overrideIdentifier }}: String, CustomStringConvertible, Codable { +public enum {{ enum.name | caseUcfirst | overrideIdentifier }}: String, CustomStringConvertible { {%~ for value in enum.enum %} {%~ set key = enum.keys is empty ? value : enum.keys[loop.index0] %} case {{ key | caseEnumKey | escapeSwiftKeyword }} = "{{ value }}" @@ -9,9 +9,4 @@ public enum {{ enum.name | caseUcfirst | overrideIdentifier }}: String, CustomSt public var description: String { return rawValue } - - public func encode(to encoder: Encoder) throws { - var container = encoder.singleValueContainer() - try container.encode(rawValue) - } } diff --git a/tests/Base.php b/tests/Base.php index a731cd673..86422c7b2 100644 --- a/tests/Base.php +++ b/tests/Base.php @@ -139,18 +139,11 @@ public function setUp(): void $this->expectedOutput[] = $headers; - // Figure out if mock-server is running - $isMockAPIRunning = \strlen(\exec('docker ps | grep mock-server')) > 0; - - if (!$isMockAPIRunning) { - echo "Starting Mock API Server"; - - \exec(' - cd ./mock-server && \ - docker compose build && \ - docker compose up -d --force-recreate - '); - } + \exec(' + cd ./mock-server && \ + docker compose build && \ + docker compose up -d --force-recreate + '); } public function tearDown(): void From 6e6db63bc153067e4b50a37f980075e1ed4b23d0 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 6 Nov 2024 16:11:16 +1300 Subject: [PATCH 4/4] Fix revert --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 838ac8d5a..6991001f3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -262,8 +262,8 @@ docker run --rm -v $(pwd):$(pwd):rw -w $(pwd) -v /var/run/docker.sock:/var/run/d * **description** -> Description of Appwrite SDK * **namespace** -> SDK Namespace * **version** -> SDK Version - * **endpoint** -> Default Endpoint (example: "https://appwrite.io/v1") - * **host** -> Default Host (example: "appwrite.io") + * **endpoint** -> Default Endpoint (example: "https://cloud.appwrite.io/v1") + * **host** -> Default Host (example: "cloud.appwrite.io") * **basePath** -> Default Path to API (example: "/v1") * **licenseName** -> Name of license for SDK * **licenseURL** -> URL to SDK license