Skip to content
Merged
Changes from all 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
36 changes: 21 additions & 15 deletions src/Generator/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public static function generate(string $name, string $namespace, string $classNa
)
)
);
$setDefaylt = true;
if (is_string($property->type)) {
if ($property->type === 'array' && $property->items instanceof OpenAPiSchema) {
if (array_key_exists(spl_object_hash($property->items), $schemaClassNameMap)) {
Expand All @@ -90,6 +91,25 @@ public static function generate(string $name, string $namespace, string $classNa
$docBlock[] = '@\WyriHaximus\Hydrator\Attribute\HydrateArray(\\' . $namespace . '\\' . $className . '\\' . (new Convert($propertyName))->toPascal() . '::class)';
}
}
}

if (is_array($property->anyOf) && $property->anyOf[0] instanceof OpenAPiSchema && array_key_exists(spl_object_hash($property->anyOf[0]), $schemaClassNameMap)) {
$fqcnn = '\\' . $rootNamespace . '\\' . $schemaClassNameMap[spl_object_hash($property->anyOf[0])];
$propertyStmt->setType( $fqcnn);
$method->setReturnType( $fqcnn);
$propertyDocBlock[] = '@\WyriHaximus\Hydrator\Attribute\Hydrate(' . $fqcnn . '::class)';
$setDefaylt = false;
}

if ($property->type === 'object' && $property instanceof OpenAPiSchema && array_key_exists(spl_object_hash($property), $schemaClassNameMap)) {
$fqcnn = '\\' . $rootNamespace . '\\' . $schemaClassNameMap[spl_object_hash($property)];
$propertyStmt->setType( $fqcnn);
$method->setReturnType( $fqcnn);
$propertyDocBlock[] = '@\WyriHaximus\Hydrator\Attribute\Hydrate(' . $fqcnn . '::class)';
$setDefaylt = false;
}

if (is_string($property->type)) {
$t = str_replace([
'object',
'integer',
Expand All @@ -102,7 +122,7 @@ public static function generate(string $name, string $namespace, string $classNa
'bool',
], $property->type);
if ($t !== '') {
if ($t === 'array') {
if ($t === 'array' && $setDefaylt === true) {
$propertyStmt->setType($t)->setDefault([]);
} else {
$propertyStmt->setType($t);
Expand All @@ -111,20 +131,6 @@ public static function generate(string $name, string $namespace, string $classNa
}
}

if (is_array($property->anyOf) && $property->anyOf[0] instanceof OpenAPiSchema && array_key_exists(spl_object_hash($property->anyOf[0]), $schemaClassNameMap)) {
$fqcnn = '\\' . $rootNamespace . '\\' . $schemaClassNameMap[spl_object_hash($property->anyOf[0])];
$propertyStmt->setType( $fqcnn);
$method->setReturnType( $fqcnn);
$propertyDocBlock[] = '@\WyriHaximus\Hydrator\Attribute\Hydrate(' . $fqcnn . '::class)';
}

if ($property->type === 'object' && $property instanceof OpenAPiSchema && array_key_exists(spl_object_hash($property), $schemaClassNameMap)) {
$fqcnn = '\\' . $rootNamespace . '\\' . $schemaClassNameMap[spl_object_hash($property)];
$propertyStmt->setType( $fqcnn);
$method->setReturnType( $fqcnn);
$propertyDocBlock[] = '@\WyriHaximus\Hydrator\Attribute\Hydrate(' . $fqcnn . '::class)';
}

if (count($propertyDocBlock) > 0) {
$propertyStmt->setDocComment('/**' . PHP_EOL . ' * ' . implode(PHP_EOL . ' * ', $propertyDocBlock) . PHP_EOL .' */');
}
Expand Down