Skip to content

Commit f2f3545

Browse files
committed
Add custom paths to the configuration file.
1 parent 23f40ed commit f2f3545

File tree

2 files changed

+65
-18
lines changed

2 files changed

+65
-18
lines changed

config/openapi.php

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
'default' => [
88

99
'info' => [
10-
'title' => config('app.name'),
10+
'title' => config('app.name'),
1111
'description' => null,
12-
'version' => '1.0.0',
12+
'version' => '1.0.0',
1313
],
1414

1515
'servers' => [
@@ -27,14 +27,14 @@
2727

2828
],
2929

30-
'security' => [
30+
'security' => [
3131
// GoldSpecDigital\ObjectOrientedOAS\Objects\SecurityRequirement::create()->securityScheme('JWT'),
3232
],
3333

3434
// Route for exposing specification.
3535
// Leave uri null to disable.
36-
'route' => [
37-
'uri' => '/openapi',
36+
'route' => [
37+
'uri' => '/openapi',
3838
'middleware' => [],
3939
],
4040

@@ -49,4 +49,26 @@
4949

5050
],
5151

52+
'paths' => [
53+
'callbacks' => [
54+
//
55+
],
56+
57+
'request_bodies' => [
58+
//
59+
],
60+
61+
'responses' => [
62+
//
63+
],
64+
65+
'schemas' => [
66+
//
67+
],
68+
69+
'security_schemes' => [
70+
//
71+
],
72+
],
73+
5274
];

src/OpenApiServiceProvider.php

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Vyuldashev\LaravelOpenApi;
66

77
use Doctrine\Common\Annotations\AnnotationRegistry;
8+
use Illuminate\Support\Collection;
89
use Illuminate\Support\ServiceProvider;
910
use Vyuldashev\LaravelOpenApi\Builders\Components\CallbacksBuilder;
1011
use 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

Comments
 (0)