Skip to content

Commit ab19a13

Browse files
authored
Merge pull request #1004 from appwrite/fix-apple-generic-serialization
Fix nested object serialization with generics
2 parents 42d8d99 + 6e6db63 commit ab19a13

File tree

5 files changed

+24
-32
lines changed

5 files changed

+24
-32
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ docker run --rm -v $(pwd):$(pwd):rw -w $(pwd) -v /var/run/docker.sock:/var/run/d
262262
* **description** -> Description of Appwrite SDK
263263
* **namespace** -> SDK Namespace
264264
* **version** -> SDK Version
265-
* **endpoint** -> Default Endpoint (example: "https://appwrite.io/v1")
266-
* **host** -> Default Host (example: "appwrite.io")
265+
* **endpoint** -> Default Endpoint (example: "https://cloud.appwrite.io/v1")
266+
* **host** -> Default Host (example: "cloud.appwrite.io")
267267
* **basePath** -> Default Path to API (example: "/v1")
268268
* **licenseName** -> Name of license for SDK
269269
* **licenseURL** -> URL to SDK license

templates/apple/Sources/Client.swift.twig

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -429,23 +429,23 @@ open class Client {
429429
if param is String
430430
|| param is Int
431431
|| param is Float
432+
|| param is Double
432433
|| param is Bool
433434
|| param is [String]
434435
|| param is [Int]
435436
|| param is [Float]
437+
|| param is [Double]
436438
|| param is [Bool]
437439
|| param is [String: Any]
438440
|| param is [Int: Any]
439441
|| param is [Float: Any]
442+
|| param is [Double: Any]
440443
|| param is [Bool: Any] {
441444
encodedParams[key] = param
442-
} else {
443-
let value = try! (param as! Encodable).toJson()
444-
445-
let range = value.index(value.startIndex, offsetBy: 1)..<value.index(value.endIndex, offsetBy: -1)
446-
let substring = value[range]
447-
448-
encodedParams[key] = substring
445+
} else if let encodable = param as? Encodable {
446+
encodedParams[key] = try encodable.toJson()
447+
} else if let param = param {
448+
encodedParams[key] = String(describing: param)
449449
}
450450
}
451451

templates/swift/Sources/Client.swift.twig

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -465,23 +465,23 @@ open class Client {
465465
if param is String
466466
|| param is Int
467467
|| param is Float
468+
|| param is Double
468469
|| param is Bool
469470
|| param is [String]
470471
|| param is [Int]
471472
|| param is [Float]
473+
|| param is [Double]
472474
|| param is [Bool]
473475
|| param is [String: Any]
474476
|| param is [Int: Any]
475477
|| param is [Float: Any]
478+
|| param is [Double: Any]
476479
|| param is [Bool: Any] {
477480
encodedParams[key] = param
478-
} else {
479-
let value = try! (param as! Encodable).toJson()
480-
481-
let range = value.index(value.startIndex, offsetBy: 1)..<value.index(value.endIndex, offsetBy: -1)
482-
let substring = value[range]
483-
484-
encodedParams[key] = substring
481+
} else if let encodable = param as? Encodable {
482+
encodedParams[key] = try encodable.toJson()
483+
} else if let param = param {
484+
encodedParams[key] = String(describing: param)
485485
}
486486
}
487487

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import Foundation
22

3-
public enum {{ enum.name | caseUcfirst | overrideIdentifier }}: String, Codable {
3+
public enum {{ enum.name | caseUcfirst | overrideIdentifier }}: String, CustomStringConvertible {
44
{%~ for value in enum.enum %}
55
{%~ set key = enum.keys is empty ? value : enum.keys[loop.index0] %}
66
case {{ key | caseEnumKey | escapeSwiftKeyword }} = "{{ value }}"
77
{%~ endfor %}
88

9-
public func encode(to encoder: Encoder) throws {
10-
var container = encoder.singleValueContainer()
11-
try container.encode(rawValue)
9+
public var description: String {
10+
return rawValue
1211
}
1312
}

tests/Base.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,11 @@ public function setUp(): void
139139

140140
$this->expectedOutput[] = $headers;
141141

142-
// Figure out if mock-server is running
143-
$isMockAPIRunning = \strlen(\exec('docker ps | grep mock-server')) > 0;
144-
145-
if (!$isMockAPIRunning) {
146-
echo "Starting Mock API Server";
147-
148-
\exec('
149-
cd ./mock-server && \
150-
docker compose build && \
151-
docker compose up -d --force-recreate
152-
');
153-
}
142+
\exec('
143+
cd ./mock-server && \
144+
docker compose build && \
145+
docker compose up -d --force-recreate
146+
');
154147
}
155148

156149
public function tearDown(): void

0 commit comments

Comments
 (0)