Skip to content

Commit

Permalink
Merge pull request #1004 from appwrite/fix-apple-generic-serialization
Browse files Browse the repository at this point in the history
Fix nested object serialization with generics
  • Loading branch information
abnegate authored Nov 6, 2024
2 parents 42d8d99 + 6e6db63 commit ab19a13
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 32 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions templates/apple/Sources/Client.swift.twig
Original file line number Diff line number Diff line change
Expand Up @@ -429,23 +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 {
let value = try! (param as! Encodable).toJson()

let range = value.index(value.startIndex, offsetBy: 1)..<value.index(value.endIndex, offsetBy: -1)
let substring = value[range]

encodedParams[key] = substring
} else if let encodable = param as? Encodable {
encodedParams[key] = try encodable.toJson()
} else if let param = param {
encodedParams[key] = String(describing: param)
}
}

Expand Down
14 changes: 7 additions & 7 deletions templates/swift/Sources/Client.swift.twig
Original file line number Diff line number Diff line change
Expand Up @@ -465,23 +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 {
let value = try! (param as! Encodable).toJson()

let range = value.index(value.startIndex, offsetBy: 1)..<value.index(value.endIndex, offsetBy: -1)
let substring = value[range]

encodedParams[key] = substring
} else if let encodable = param as? Encodable {
encodedParams[key] = try encodable.toJson()
} else if let param = param {
encodedParams[key] = String(describing: param)
}
}

Expand Down
7 changes: 3 additions & 4 deletions templates/swift/Sources/Enums/Enum.swift.twig
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import Foundation

public enum {{ enum.name | caseUcfirst | overrideIdentifier }}: String, 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 }}"
{%~ endfor %}

public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(rawValue)
public var description: String {
return rawValue
}
}
17 changes: 5 additions & 12 deletions tests/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ab19a13

Please sign in to comment.