Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nested object serialization with generics #1004

Merged
merged 6 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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