@@ -77,6 +77,7 @@ public static function generate(string $name, string $namespace, string $classNa
77
77
)
78
78
)
79
79
);
80
+ $ setDefaylt = true ;
80
81
if (is_string ($ property ->type )) {
81
82
if ($ property ->type === 'array ' && $ property ->items instanceof OpenAPiSchema) {
82
83
if (array_key_exists (spl_object_hash ($ property ->items ), $ schemaClassNameMap )) {
@@ -90,6 +91,25 @@ public static function generate(string $name, string $namespace, string $classNa
90
91
$ docBlock [] = '@\WyriHaximus\Hydrator\Attribute\HydrateArray( \\' . $ namespace . '\\' . $ className . '\\' . (new Convert ($ propertyName ))->toPascal () . '::class) ' ;
91
92
}
92
93
}
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 )) {
93
113
$ t = str_replace ([
94
114
'object ' ,
95
115
'integer ' ,
@@ -102,7 +122,7 @@ public static function generate(string $name, string $namespace, string $classNa
102
122
'bool ' ,
103
123
], $ property ->type );
104
124
if ($ t !== '' ) {
105
- if ($ t === 'array ' ) {
125
+ if ($ t === 'array ' && $ setDefaylt === true ) {
106
126
$ propertyStmt ->setType ($ t )->setDefault ([]);
107
127
} else {
108
128
$ propertyStmt ->setType ($ t );
@@ -111,20 +131,6 @@ public static function generate(string $name, string $namespace, string $classNa
111
131
}
112
132
}
113
133
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
-
128
134
if (count ($ propertyDocBlock ) > 0 ) {
129
135
$ propertyStmt ->setDocComment ('/** ' . PHP_EOL . ' * ' . implode (PHP_EOL . ' * ' , $ propertyDocBlock ) . PHP_EOL .' */ ' );
130
136
}
0 commit comments