@@ -44,8 +44,8 @@ public static function generate(string $pathPrefix, Representation\Schema $schem
44
44
$ className = $ schema ->className ;
45
45
if (count ($ aliases ) > 0 ) {
46
46
$ className = ClassString::factory (
47
- $ className ->namespace ,
48
- 'Schema \\AliasAbstract \\Abstract ' . md5 (json_encode ($ schema ->schema ->getSerializableData ())),
47
+ $ className ->baseNamespaces ,
48
+ 'Schema \\AliasAbstract \\Tiet ' . implode ( '\\ Tiet ' , str_split ( strtoupper ( md5 (json_encode ($ schema ->schema ->getSerializableData ()))), 8 )),
49
49
);
50
50
$ aliases [] = $ schema ->className ;
51
51
}
@@ -133,6 +133,19 @@ public static function generate(string $pathPrefix, Representation\Schema $schem
133
133
$ types = [];
134
134
if ($ property ->type ->type === 'union ' && is_array ($ property ->type ->payload )) {
135
135
$ types [] = self ::buildUnionType ($ property ->type );
136
+ $ schemaClasses = [...self ::getUnionTypeSchemas ($ property ->type )];
137
+
138
+ if (count ($ schemaClasses ) > 0 ) {
139
+ $ castToUnionToType = ClassString::factory ($ schema ->className ->baseNamespaces , Utils::className ('Attribute \\CastUnionToType \\' . $ schema ->className ->relative . '\\' . $ property ->name ));
140
+
141
+ yield from CastUnionToType::generate ($ pathPrefix , $ castToUnionToType , ...$ schemaClasses );
142
+
143
+ $ constructorParam ->addAttribute (
144
+ new Node \Attribute (
145
+ new Node \Name ($ castToUnionToType ->fullyQualified ->source ),
146
+ ),
147
+ );
148
+ }
136
149
}
137
150
138
151
if ($ property ->type ->type === 'array ' && ! is_string ($ property ->type ->payload )) {
@@ -196,7 +209,11 @@ public static function generate(string $pathPrefix, Representation\Schema $schem
196
209
$ nullable = count ($ types ) > 1 || count (explode ('| ' , implode ('| ' , $ types ))) > 1 ? 'null| ' : '? ' ;
197
210
}
198
211
199
- $ constructor ->addParam ($ constructorParam ->setType ($ nullable . implode ('| ' , $ types )));
212
+ if (count ($ types ) > 0 ) {
213
+ $ constructorParam ->setType ($ nullable . implode ('| ' , $ types ));
214
+ }
215
+
216
+ $ constructor ->addParam ($ constructorParam );
200
217
}
201
218
202
219
if (count ($ constructDocBlock ) > 0 ) {
@@ -211,7 +228,7 @@ public static function generate(string $pathPrefix, Representation\Schema $schem
211
228
$ aliasTms = $ factory ->namespace ($ alias ->namespace ->source );
212
229
$ aliasClass = $ factory ->class ($ alias ->className )->makeFinal ()->makeReadonly ()->extend ($ className ->relative );
213
230
214
- yield new File ($ pathPrefix , $ alias ->className , $ aliasTms ->addStmt ($ aliasClass )->getNode ());
231
+ yield new File ($ pathPrefix , $ alias ->relative , $ aliasTms ->addStmt ($ aliasClass )->getNode ());
215
232
}
216
233
}
217
234
0 commit comments