Skip to content

Commit a72054f

Browse files
committed
chore: update apple and swift
1 parent 7d0705a commit a72054f

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

src/SDK/Language/Swift.php

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,14 +435,61 @@ public function getParamExample(array $param): string
435435
$output .= "\"{$example}\"";
436436
break;
437437
case self::TYPE_OBJECT:
438-
$output .= '[:]';
438+
$decoded = json_decode($example, true);
439+
if ($decoded && is_array($decoded)) {
440+
$output .= $this->jsonToSwiftDict($decoded);
441+
} else {
442+
$output .= '[:]';
443+
}
439444
break;
440445
}
441446
}
442447

443448
return $output;
444449
}
445450

451+
/**
452+
* Converts JSON Object To Swift Native Dictionary
453+
*
454+
* @param array $data
455+
* @param int $indent
456+
* @return string
457+
*/
458+
protected function jsonToSwiftDict(array $data, int $indent = 0): string
459+
{
460+
if (empty($data)) {
461+
return '[:]';
462+
}
463+
464+
$baseIndent = str_repeat(' ', $indent);
465+
$itemIndent = str_repeat(' ', $indent + 1);
466+
$output = "[\n";
467+
468+
$keys = array_keys($data);
469+
foreach ($keys as $index => $key) {
470+
$node = $data[$key];
471+
472+
if (is_array($node)) {
473+
$value = $this->jsonToSwiftDict($node, $indent + 1);
474+
} elseif (is_string($node)) {
475+
$value = '"' . $node . '"';
476+
} elseif (is_bool($node)) {
477+
$value = $node ? 'true' : 'false';
478+
} elseif (is_null($node)) {
479+
$value = 'nil';
480+
} else {
481+
$value = $node;
482+
}
483+
484+
$comma = ($index < count($keys) - 1) ? ',' : '';
485+
$output .= ' ' . $itemIndent . '"' . $key . '": ' . $value . $comma . "\n";
486+
}
487+
488+
$output .= ' ' . $baseIndent . ']';
489+
490+
return $output;
491+
}
492+
446493
public function getFilters(): array
447494
{
448495
return [

0 commit comments

Comments
 (0)