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
37 changes: 30 additions & 7 deletions src/Generator/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,39 @@ private static function fillUpSchema(string $name, string $namespace, string $cl
)
)
);
$propertyType = $property->type;
$setDefaylt = true;
$nullable = '';
if ($property->nullable) {
$nullable = '?';
$propertyStmt->setDefault(null);
}
if (is_string($property->type)) {

if (
is_array($propertyType) &&
count($propertyType) === 2 &&
(
in_array(null, $propertyType) ||
in_array("null", $propertyType)
)
) {
foreach ($propertyType as $pt) {
if ($pt !== null && $pt !== "null") {
$propertyType = $pt;
break;
}
}

$nullable = '?';
}

if (is_string($propertyType)) {
if (is_array($schema->required) && !in_array($propertyName, $schema->required, false)) {
$nullable = '?';
$propertyStmt->setDefault(null);
}

if ($property->type === 'array' && $property->items instanceof OpenAPiSchema) {
if ($propertyType === 'array' && $property->items instanceof OpenAPiSchema) {
// if (array_key_exists(spl_object_hash($property->items), $schemaClassNameMap)) {
$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()) . '>';
Expand All @@ -130,7 +150,7 @@ private static function fillUpSchema(string $name, string $namespace, string $cl
}


if (is_string($property->type)) {
if (is_string($propertyType)) {
$t = str_replace([
'object',
'integer',
Expand All @@ -145,7 +165,7 @@ private static function fillUpSchema(string $name, string $namespace, string $cl
'',
'',
'bool',
], $property->type);
], $propertyType);

if ($t !== '') {
$propertyStmt->setType(($t === 'array' ? '' : $nullable) . $t);
Expand All @@ -154,6 +174,8 @@ private static function fillUpSchema(string $name, string $namespace, string $cl
}
}

// 74908

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], $className . '\\' . (new Convert($propertyName))->toPascal());
$propertyStmt->setType($nullable . $fqcnn);
Expand All @@ -168,15 +190,16 @@ private static function fillUpSchema(string $name, string $namespace, string $cl
$setDefaylt = false;
}

if ($property->type === 'object' && $property instanceof OpenAPiSchema/* && array_key_exists(spl_object_hash($property), $schemaClassNameMap)*/) {
// if (($property->type === 'object' || (is_array($property->type) && count($property->type) === 2)) && $property instanceof OpenAPiSchema/* && array_key_exists(spl_object_hash($property), $schemaClassNameMap)*/) {
if ($propertyType === 'object') {
$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)';
$setDefaylt = false;
}

if (is_string($property->type)) {
if (is_string($propertyType)) {
$t = str_replace([
'object',
'integer',
Expand All @@ -187,7 +210,7 @@ private static function fillUpSchema(string $name, string $namespace, string $cl
'int',
'',
'bool',
], $property->type);
], $propertyType);
if ($t !== '') {
if ($t === 'array' && $setDefaylt === true) {
$propertyStmt->setDefault([]);
Expand Down