Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 6 additions & 6 deletions src/Generator/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() . '>';
Expand Down Expand Up @@ -155,21 +155,21 @@ 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)';
$setDefaylt = false;
}

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)';
Expand Down
9 changes: 5 additions & 4 deletions src/SchemaRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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
Expand Down