@@ -77,6 +77,7 @@ public static function generate(string $name, string $namespace, string $classNa
7777 )
7878 )
7979 );
80+ $ setDefaylt = true ;
8081 if (is_string ($ property ->type )) {
8182 if ($ property ->type === 'array ' && $ property ->items instanceof OpenAPiSchema) {
8283 if (array_key_exists (spl_object_hash ($ property ->items ), $ schemaClassNameMap )) {
@@ -90,6 +91,25 @@ public static function generate(string $name, string $namespace, string $classNa
9091 $ docBlock [] = '@\WyriHaximus\Hydrator\Attribute\HydrateArray( \\' . $ namespace . '\\' . $ className . '\\' . (new Convert ($ propertyName ))->toPascal () . '::class) ' ;
9192 }
9293 }
94+ }
95+
96+ if (is_array ($ property ->anyOf ) && $ property ->anyOf [0 ] instanceof OpenAPiSchema && array_key_exists (spl_object_hash ($ property ->anyOf [0 ]), $ schemaClassNameMap )) {
97+ $ fqcnn = '\\' . $ rootNamespace . '\\' . $ schemaClassNameMap [spl_object_hash ($ property ->anyOf [0 ])];
98+ $ propertyStmt ->setType ( $ fqcnn );
99+ $ method ->setReturnType ( $ fqcnn );
100+ $ propertyDocBlock [] = '@\WyriHaximus\Hydrator\Attribute\Hydrate( ' . $ fqcnn . '::class) ' ;
101+ $ setDefaylt = false ;
102+ }
103+
104+ if ($ property ->type === 'object ' && $ property instanceof OpenAPiSchema && array_key_exists (spl_object_hash ($ property ), $ schemaClassNameMap )) {
105+ $ fqcnn = '\\' . $ rootNamespace . '\\' . $ schemaClassNameMap [spl_object_hash ($ property )];
106+ $ propertyStmt ->setType ( $ fqcnn );
107+ $ method ->setReturnType ( $ fqcnn );
108+ $ propertyDocBlock [] = '@\WyriHaximus\Hydrator\Attribute\Hydrate( ' . $ fqcnn . '::class) ' ;
109+ $ setDefaylt = false ;
110+ }
111+
112+ if (is_string ($ property ->type )) {
93113 $ t = str_replace ([
94114 'object ' ,
95115 'integer ' ,
@@ -102,7 +122,7 @@ public static function generate(string $name, string $namespace, string $classNa
102122 'bool ' ,
103123 ], $ property ->type );
104124 if ($ t !== '' ) {
105- if ($ t === 'array ' ) {
125+ if ($ t === 'array ' && $ setDefaylt === true ) {
106126 $ propertyStmt ->setType ($ t )->setDefault ([]);
107127 } else {
108128 $ propertyStmt ->setType ($ t );
@@ -111,20 +131,6 @@ public static function generate(string $name, string $namespace, string $classNa
111131 }
112132 }
113133
114- if (is_array ($ property ->anyOf ) && $ property ->anyOf [0 ] instanceof OpenAPiSchema && array_key_exists (spl_object_hash ($ property ->anyOf [0 ]), $ schemaClassNameMap )) {
115- $ fqcnn = '\\' . $ rootNamespace . '\\' . $ schemaClassNameMap [spl_object_hash ($ property ->anyOf [0 ])];
116- $ propertyStmt ->setType ( $ fqcnn );
117- $ method ->setReturnType ( $ fqcnn );
118- $ propertyDocBlock [] = '@\WyriHaximus\Hydrator\Attribute\Hydrate( ' . $ fqcnn . '::class) ' ;
119- }
120-
121- if ($ property ->type === 'object ' && $ property instanceof OpenAPiSchema && array_key_exists (spl_object_hash ($ property ), $ schemaClassNameMap )) {
122- $ fqcnn = '\\' . $ rootNamespace . '\\' . $ schemaClassNameMap [spl_object_hash ($ property )];
123- $ propertyStmt ->setType ( $ fqcnn );
124- $ method ->setReturnType ( $ fqcnn );
125- $ propertyDocBlock [] = '@\WyriHaximus\Hydrator\Attribute\Hydrate( ' . $ fqcnn . '::class) ' ;
126- }
127-
128134 if (count ($ propertyDocBlock ) > 0 ) {
129135 $ propertyStmt ->setDocComment ('/** ' . PHP_EOL . ' * ' . implode (PHP_EOL . ' * ' , $ propertyDocBlock ) . PHP_EOL .' */ ' );
130136 }
0 commit comments