Skip to content

Commit

Permalink
fix swift generics
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Oct 9, 2024
1 parent c5b3c17 commit 7ba8909
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
14 changes: 12 additions & 2 deletions src/Generator/Swift.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,20 @@ protected function newNormalizer(): NormalizerInterface

protected function writeStruct(Code\Name $name, array $properties, ?string $extends, ?array $generics, ?array $templates, StructDefinitionType $origin): string
{
$code = 'class ' . $name->getClass() . ': ';
$code = 'class ' . $name->getClass();

if (!empty($generics)) {
$code.= $this->generator->getGenericDefinition($generics);
}

$code.= ': ';

if (!empty($extends)) {
$code.= $extends . ' ';
$code.= $extends;
if (!empty($templates)) {
$code.= $this->generator->getGenericDefinition($templates);
}
$code.= ' ';
} else {
$code.= 'Codable ';
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Generator/resource/swift/swift_oop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Student: Human {
}
}

class Map: Codable {
class Map<P, T>: Codable {
var totalResults: Int
var parent: P
var entries: Array<T>
Expand All @@ -28,13 +28,13 @@ class Map: Codable {
}
}

class StudentMap: Map {
class StudentMap: Map<Human, Student> {

enum CodingKeys: String, CodingKey {
}
}

class HumanMap: Map {
class HumanMap: Map<Human, Human> {

enum CodingKeys: String, CodingKey {
}
Expand Down

0 comments on commit 7ba8909

Please sign in to comment.