diff --git a/src/Generator/Schema.php b/src/Generator/Schema.php index 5278b2b..d3418a6 100644 --- a/src/Generator/Schema.php +++ b/src/Generator/Schema.php @@ -169,7 +169,8 @@ private static function fillUpSchema(string $name, string $namespace, string $cl $propertyStmt->setType(($propertyType === 'array' ? '' : $nullable) . $propertyType); - $constructor->addParam((new Param($propertyName))->setType($propertyType))->addStmt( + $constructorParam = (new Param($propertyName))->setType($propertyType); + $constructor->addStmt( new Node\Expr\Assign( new Node\Expr\PropertyFetch( new Node\Expr\Variable('this'), @@ -184,10 +185,12 @@ 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], $className . '\\' . (new Convert($propertyName))->toPascal()); $propertyStmt->setType($nullable . $fqcnn); + $constructorParam->setType($nullable . $fqcnn); $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], $className . '\\' . (new Convert($propertyName))->toPascal()); $propertyStmt->setType($nullable . $fqcnn); + $constructorParam->setType($nullable . $fqcnn); $setDefaylt = false; } @@ -195,6 +198,7 @@ private static function fillUpSchema(string $name, string $namespace, string $cl if ($propertyType === 'object') { $fqcnn = '\\' . $rootNamespace . '\\' . $schemaRegistry->get($property, $className . '\\' . (new Convert($propertyName))->toPascal()); $propertyStmt->setType($nullable . $fqcnn); + $constructorParam->setType($nullable . $fqcnn); $setDefaylt = false; } @@ -222,6 +226,7 @@ private static function fillUpSchema(string $name, string $namespace, string $cl } $class->addStmt($propertyStmt); + $constructor->addParam($constructorParam); } if (count($constructDocBlock) > 0) {