Skip to content

Commit 9610b7b

Browse files
committed
Detect single ref properties better
1 parent 192051b commit 9610b7b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/Generator/Schema.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,22 @@ public static function generate(string $name, string $namespace, string $classNa
9898
$propertyStmt->setType($t)->setDefault($dft);
9999
$method->setReturnType($t);
100100
}
101-
} else if (is_array($property->anyOf) && $property->anyOf[0] instanceof OpenAPiSchema && array_key_exists(spl_object_hash($property->anyOf[0]), $schemaClassNameMap)) {
101+
}
102+
103+
if (is_array($property->anyOf) && $property->anyOf[0] instanceof OpenAPiSchema && array_key_exists(spl_object_hash($property->anyOf[0]), $schemaClassNameMap)) {
102104
$fqcnn = '\\' . $namespace . '\\' . $schemaClassNameMap[spl_object_hash($property->anyOf[0])];
103105
$propertyStmt->setType('?' . $fqcnn)->setDefault(null);
104106
$method->setReturnType('?' . $fqcnn);
105107
$docBlock[] = '@\WyriHaximus\Hydrator\Attribute\Hydrate(' . $fqcnn . '::class)';
106108
}
107109

110+
if ($property->type === 'object' && $property instanceof OpenAPiSchema && array_key_exists(spl_object_hash($property), $schemaClassNameMap)) {
111+
$fqcnn = '\\' . $namespace . '\\' . $schemaClassNameMap[spl_object_hash($property)];
112+
$propertyStmt->setType('?' . $fqcnn)->setDefault(null);
113+
$method->setReturnType('?' . $fqcnn);
114+
$docBlock[] = '@\WyriHaximus\Hydrator\Attribute\Hydrate(' . $fqcnn . '::class)';
115+
}
116+
108117
if (count($docBlock) > 0) {
109118
$propertyStmt->setDocComment('/**' . PHP_EOL . ' * ' . implode(PHP_EOL . ' * ', $docBlock) . PHP_EOL .' */');
110119
}

0 commit comments

Comments
 (0)