@@ -447,6 +447,12 @@ public function getFilters(): array
447
447
new TwigFilter ('returnType ' , function (array $ method , array $ spec , string $ namespace , string $ generic = 'T ' ) {
448
448
return $ this ->getReturnType ($ method , $ spec , $ namespace , $ generic );
449
449
}),
450
+ new TwigFilter ('modelType ' , function (array $ property , array $ spec , string $ generic = 'T ' ) {
451
+ return $ this ->getModelType ($ property , $ spec , $ generic );
452
+ }),
453
+ new TwigFilter ('propertyType ' , function (array $ property , array $ spec , string $ generic = 'T ' ) {
454
+ return $ this ->getPropertyType ($ property , $ spec , $ generic );
455
+ }),
450
456
new TwigFilter ('hasGenericType ' , function (string $ model , array $ spec ) {
451
457
return $ this ->hasGenericType ($ model , $ spec );
452
458
}),
@@ -477,6 +483,37 @@ protected function getReturnType(array $method, array $spec, string $namespace,
477
483
return $ namespace . '.models. ' . $ ret ;
478
484
}
479
485
486
+ protected function getModelType (array $ definition , array $ spec , string $ generic = 'T ' ): string
487
+ {
488
+ if ($ this ->hasGenericType ($ definition ['name ' ], $ spec )) {
489
+ return $ this ->toUpperCase ($ definition ['name ' ]) . '< ' . $ generic . '> ' ;
490
+ }
491
+ return $ this ->toUpperCase ($ definition ['name ' ]);
492
+ }
493
+
494
+ protected function getPropertyType (array $ property , array $ spec , string $ generic = 'T ' ): string
495
+ {
496
+ if (\array_key_exists ('sub_schema ' , $ property )) {
497
+ $ type = $ this ->toUpperCase ($ property ['sub_schema ' ]);
498
+
499
+ if ($ this ->hasGenericType ($ property ['sub_schema ' ], $ spec )) {
500
+ $ type .= '< ' . $ generic . '> ' ;
501
+ }
502
+
503
+ if ($ property ['type ' ] === 'array ' ) {
504
+ $ type = 'List< ' . $ type . '> ' ;
505
+ }
506
+ } else {
507
+ $ type = $ this ->getTypeName ($ property );
508
+ }
509
+
510
+ if (!$ property ['required ' ]) {
511
+ $ type .= '? ' ;
512
+ }
513
+
514
+ return $ type ;
515
+ }
516
+
480
517
protected function hasGenericType (?string $ model , array $ spec ): string
481
518
{
482
519
if (empty ($ model )) {
0 commit comments