Skip to content

Commit 3fac784

Browse files
committed
Add return type generic filter
1 parent fe30201 commit 3fac784

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/SDK/Language/Kotlin.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,12 +444,39 @@ public function getFiles()
444444
public function getFilters(): array
445445
{
446446
return [
447+
new TwigFilter('returnType', function (array $method, array $spec, string $namespace, string $generic = 'T') {
448+
return $this->getReturnType($method, $spec, $namespace, $generic);
449+
}),
447450
new TwigFilter('hasGenericType', function (string $model, array $spec) {
448451
return $this->hasGenericType($model, $spec);
449452
}),
450453
];
451454
}
452455

456+
protected function getReturnType(array $method, array $spec, string $namespace, string $generic = 'T'): string
457+
{
458+
if ($method['type'] === 'webAuth') {
459+
return 'Bool';
460+
}
461+
if ($method['type'] === 'location') {
462+
return 'ByteArray';
463+
}
464+
465+
if (!\array_key_exists('responseModel', $method)
466+
|| empty($method['responseModel'])
467+
|| $method['responseModel'] === 'any') {
468+
return 'Any';
469+
}
470+
471+
$ret = $this->toUpperCase($method['responseModel']);
472+
473+
if ($this->hasGenericType($method['responseModel'], $spec)) {
474+
$ret .= '<' . $generic . '>';
475+
}
476+
477+
return $namespace . '.models.' . $ret;
478+
}
479+
453480
protected function hasGenericType(?string $model, array $spec): string
454481
{
455482
if (empty($model)) {

0 commit comments

Comments
 (0)