diff --git a/src/Generator/Schema.php b/src/Generator/Schema.php index 99194eb..f8852de 100644 --- a/src/Generator/Schema.php +++ b/src/Generator/Schema.php @@ -118,9 +118,9 @@ private static function fillUpSchema(string $name, string $namespace, string $cl if ($property->type === 'array' && $property->items instanceof OpenAPiSchema) { // if (array_key_exists(spl_object_hash($property->items), $schemaClassNameMap)) { - $methodDocBlock[] = '@return array<\\' . $rootNamespace . '\\' . $schemaRegistry->get($property->items) . '>'; - $propertyDocBlock[] = '@var array<\\' . $rootNamespace . '\\' . $schemaRegistry->get($property->items) . '>'; - $propertyDocBlock[] = '@\WyriHaximus\Hydrator\Attribute\HydrateArray(\\' . $rootNamespace . '\\' . $schemaRegistry->get($property->items) . '::class)'; + $methodDocBlock[] = '@return array<\\' . $rootNamespace . '\\' . $schemaRegistry->get($property->items, $className . '\\' . (new Convert($propertyName))->toPascal()) . '>'; + $propertyDocBlock[] = '@var array<\\' . $rootNamespace . '\\' . $schemaRegistry->get($property->items, $className . '\\' . (new Convert($propertyName))->toPascal()) . '>'; + $propertyDocBlock[] = '@\WyriHaximus\Hydrator\Attribute\HydrateArray(\\' . $rootNamespace . '\\' . $schemaRegistry->get($property->items, $className . '\\' . (new Convert($propertyName))->toPascal()) . '::class)'; // } elseif ($property->items->type === 'object') { // yield from self::generate($name . '::' . $propertyName, $namespace . '\\' . $className, (new Convert($propertyName))->toPascal(), $property->items, $schemaClassNameMap, $rootNamespace); // $methodDocBlock[] = '@return array<\\' . $namespace . '\\' . $className . '\\' . (new Convert($propertyName))->toPascal() . '>'; @@ -155,13 +155,13 @@ private static function fillUpSchema(string $name, string $namespace, string $cl } if (is_array($property->anyOf) && $property->anyOf[0] instanceof OpenAPiSchema/* && array_key_exists(spl_object_hash($property->anyOf[0]), $schemaClassNameMap)*/) { - $fqcnn = '\\' . $rootNamespace . '\\' . $schemaRegistry->get($property->anyOf[0]); + $fqcnn = '\\' . $rootNamespace . '\\' . $schemaRegistry->get($property->anyOf[0], $className . '\\' . (new Convert($propertyName))->toPascal()); $propertyStmt->setType($nullable . $fqcnn); $method->setReturnType($nullable . $fqcnn); $propertyDocBlock[] = '@\WyriHaximus\Hydrator\Attribute\Hydrate(' . $fqcnn . '::class)'; $setDefaylt = false; } else if (is_array($property->allOf) && $property->allOf[0] instanceof OpenAPiSchema/* && array_key_exists(spl_object_hash($property->allOf[0]), $schemaClassNameMap)*/) { - $fqcnn = '\\' . $rootNamespace . '\\' . $schemaRegistry->get($property->allOf[0]); + $fqcnn = '\\' . $rootNamespace . '\\' . $schemaRegistry->get($property->allOf[0], $className . '\\' . (new Convert($propertyName))->toPascal()); $propertyStmt->setType($nullable . $fqcnn); $method->setReturnType($nullable . $fqcnn); $propertyDocBlock[] = '@\WyriHaximus\Hydrator\Attribute\Hydrate(' . $fqcnn . '::class)'; @@ -169,7 +169,7 @@ private static function fillUpSchema(string $name, string $namespace, string $cl } if ($property->type === 'object' && $property instanceof OpenAPiSchema/* && array_key_exists(spl_object_hash($property), $schemaClassNameMap)*/) { - $fqcnn = '\\' . $rootNamespace . '\\' . $schemaRegistry->get($property); + $fqcnn = '\\' . $rootNamespace . '\\' . $schemaRegistry->get($property, $className . '\\' . (new Convert($propertyName))->toPascal()); $propertyStmt->setType($nullable . $fqcnn); $method->setReturnType($nullable . $fqcnn); $propertyDocBlock[] = '@\WyriHaximus\Hydrator\Attribute\Hydrate(' . $fqcnn . '::class)'; diff --git a/src/SchemaRegistry.php b/src/SchemaRegistry.php index 90f6c7a..02976c8 100644 --- a/src/SchemaRegistry.php +++ b/src/SchemaRegistry.php @@ -26,7 +26,7 @@ public function addClassName(string $className, Schema $schema): void $this->json[json_encode($schema->getSerializableData())] = $className; } - public function get(\cebe\openapi\spec\Schema $schema): string + public function get(\cebe\openapi\spec\Schema $schema, string $fallbackName = ''): string { $hash = spl_object_hash($schema); if (array_key_exists($hash, $this->splHash)) { @@ -38,14 +38,15 @@ public function get(\cebe\openapi\spec\Schema $schema): string return $this->json[$json]; } - $name = 'c_' . md5($json); + $name = $fallbackName === '' ? 'c_' . md5($json) : $fallbackName; + $className = $fallbackName === '' ? Generator::className('Unknown\C_' . md5($json)) : $fallbackName; $this->unknownSchemas[$hash] = [ 'name' => $name, - 'className' => Generator::className('Unknown\C_' . md5($json)), + 'className' => $className, 'schema' => $schema, ]; - return $this->unknownSchemas[$hash]['className']; + return $className; } public function unknownSchemas(): iterable