22
33namespace ApiClients \Tools \OpenApiClientGenerator ;
44
5+ use ApiClients \Tools \OpenApiClientGenerator \Generator \Client ;
6+ use ApiClients \Tools \OpenApiClientGenerator \Generator \Clients ;
57use ApiClients \Tools \OpenApiClientGenerator \Generator \Operation ;
68use ApiClients \Tools \OpenApiClientGenerator \Generator \Path ;
79use ApiClients \Tools \OpenApiClientGenerator \Generator \Schema ;
@@ -81,6 +83,7 @@ private function all(string $namespace): iterable
8183 }
8284 }
8385
86+ $ clients = [];
8487 if (count ($ this ->spec ->paths ?? []) > 0 ) {
8588 foreach ($ this ->spec ->paths as $ path => $ pathItem ) {
8689 $ pathClassName = $ this ->className ($ path );
@@ -97,7 +100,7 @@ private function all(string $namespace): iterable
97100 );
98101
99102 foreach ($ pathItem ->getOperations () as $ method => $ operation ) {
100- $ operationClassName = $ this ->className ((new Convert ($ operation ->operationId ))->fromTrain ()->toPascal ());
103+ $ operationClassName = $ this ->className ((new Convert ($ operation ->operationId ))->fromTrain ()->toPascal ()) . ' _ ' ;
101104 $ operations [$ method ] = $ operationClassName ;
102105 if (strlen ($ operationClassName ) === 0 ) {
103106 continue ;
@@ -110,10 +113,35 @@ private function all(string $namespace): iterable
110113 $ this ->basename ($ namespace . 'Operation/ ' . $ operationClassName ),
111114 $ operation
112115 );
116+
117+ [$ operationGroup , $ operationOperation ] = explode ('/ ' , $ operationClassName );
118+ if (!array_key_exists ($ operationGroup , $ clients )) {
119+ $ clients [$ operationGroup ] = [];
120+ }
121+ $ clients [$ operationGroup ][$ operationOperation ] = [
122+ 'class ' => $ operationClassName ,
123+ 'operation ' => $ operation ,
124+ ];
113125 }
114126 }
115127 }
116128
129+ yield from (function (array $ clients , string $ namespace ): \Generator {
130+ foreach ($ clients as $ operationGroup => $ operations ) {
131+ yield from Client::generate (
132+ $ operationGroup ,
133+ $ this ->dirname ($ namespace . 'Operation/ ' . $ operationGroup ),
134+ $ this ->basename ($ namespace . 'Operation/ ' . $ operationGroup ),
135+ $ operations ,
136+ );
137+
138+ }
139+ yield from Clients::generate (
140+ $ namespace ,
141+ $ clients ,
142+ );
143+ })($ clients , $ namespace );
144+
117145 if (count ($ this ->spec ->webhooks ?? []) > 0 ) {
118146 $ pathClassNameMapping = [];
119147 foreach ($ this ->spec ->webhooks as $ path => $ pathItem ) {
0 commit comments