55namespace Vyuldashev \LaravelOpenApi ;
66
77use Doctrine \Common \Annotations \AnnotationRegistry ;
8+ use Illuminate \Support \Collection ;
89use Illuminate \Support \ServiceProvider ;
910use Vyuldashev \LaravelOpenApi \Builders \Components \CallbacksBuilder ;
1011use Vyuldashev \LaravelOpenApi \Builders \Components \RequestBodiesBuilder ;
@@ -23,7 +24,7 @@ public function boot(): void
2324 {
2425 if ($ this ->app ->runningInConsole ()) {
2526 $ this ->publishes ([
26- __DIR__ . '/../config/openapi.php ' => config_path ('openapi.php ' ),
27+ __DIR__ . '/../config/openapi.php ' => config_path ('openapi.php ' ),
2728 ], 'openapi-config ' );
2829 }
2930
@@ -48,7 +49,7 @@ public function boot(): void
4849 );
4950 });
5051
51- $ this ->loadRoutesFrom (__DIR__ . '/../routes/api.php ' );
52+ $ this ->loadRoutesFrom (__DIR__ . '/../routes/api.php ' );
5253 }
5354
5455 public function register (): void
@@ -77,7 +78,7 @@ public function register(): void
7778
7879 protected function registerAnnotations (): void
7980 {
80- $ files = glob (__DIR__ . '/Annotations/*.php ' );
81+ $ files = glob (__DIR__ . '/Annotations/*.php ' );
8182
8283 foreach ($ files as $ file ) {
8384 AnnotationRegistry::registerFile ($ file );
@@ -86,36 +87,60 @@ protected function registerAnnotations(): void
8687
8788 protected function callbacksIn (): array
8889 {
89- return [
90+ $ directories = $ this ->getPathsFromConfig ('callbacks ' );
91+
92+ return array_merge ($ directories , [
9093 app_path ('OpenApi/Callbacks ' ),
91- ];
94+ ]) ;
9295 }
9396
9497 protected function requestBodiesIn (): array
9598 {
96- return [
99+ $ directories = $ this ->getPathsFromConfig ('request_bodies ' );
100+
101+ return array_merge ($ directories , [
97102 app_path ('OpenApi/RequestBodies ' ),
98- ];
103+ ]) ;
99104 }
100105
101106 protected function responsesIn (): array
102107 {
103- return [
108+ $ directories = $ this ->getPathsFromConfig ('responses ' );
109+
110+ return array_merge ($ directories , [
104111 app_path ('OpenApi/Responses ' ),
105- ];
112+ ]) ;
106113 }
107114
108115 protected function schemasIn (): array
109116 {
110- return [
117+ $ directories = $ this ->getPathsFromConfig ('schemas ' );
118+
119+ return array_merge ($ directories , [
111120 app_path ('OpenApi/Schemas ' ),
112- ];
121+ ]) ;
113122 }
114123
115124 protected function securitySchemesIn (): array
116125 {
117- return [
126+ $ directories = $ this ->getPathsFromConfig ('security_schemes ' );
127+
128+ return array_merge ($ directories , [
118129 app_path ('OpenApi/SecuritySchemes ' ),
119- ];
130+ ]);
131+ }
132+
133+ protected function getPathsFromConfig (string $ type ): array
134+ {
135+ $ directories = config ("openapi.paths. {$ type }" , []);
136+
137+ foreach ($ directories as &$ directory ) {
138+ $ directory = glob (app_path ($ directory ), GLOB_ONLYDIR );
139+ }
140+
141+ return (new Collection ($ directories ))
142+ ->flatten ()
143+ ->unique ()
144+ ->toArray ();
120145 }
121146}
0 commit comments