Skip to content

Commit 3409feb

Browse files
authored
Merge pull request #31 from php-api-clients/Improved_Handle_setting_the_default_value_better
Improved: Handle setting the default value better
2 parents 1ae8aed + 0c04abc commit 3409feb

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/Generator/Schema.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,26 @@ public static function generate(string $name, string $namespace, string $classNa
9191
$docBlock[] = '@\WyriHaximus\Hydrator\Attribute\HydrateArray(\\' . $namespace . '\\' . $className . '\\' . (new Convert($propertyName))->toPascal() . '::class)';
9292
}
9393
}
94+
95+
96+
if (is_string($property->type)) {
97+
$t = str_replace([
98+
'object',
99+
'integer',
100+
'any',
101+
'boolean',
102+
], [
103+
'array',
104+
'int',
105+
'',
106+
'bool',
107+
], $property->type);
108+
if ($t !== '') {
109+
$propertyStmt->setType($t);
110+
$method->setReturnType($t);
111+
}
112+
}
113+
94114
}
95115

96116
if (is_array($property->anyOf) && $property->anyOf[0] instanceof OpenAPiSchema && array_key_exists(spl_object_hash($property->anyOf[0]), $schemaClassNameMap)) {
@@ -123,11 +143,8 @@ public static function generate(string $name, string $namespace, string $classNa
123143
], $property->type);
124144
if ($t !== '') {
125145
if ($t === 'array' && $setDefaylt === true) {
126-
$propertyStmt->setType($t)->setDefault([]);
127-
} else {
128-
$propertyStmt->setType($t);
146+
$propertyStmt->setDefault([]);
129147
}
130-
$method->setReturnType($t);
131148
}
132149
}
133150

0 commit comments

Comments
 (0)