Skip to content

Commit f42c177

Browse files
committed
fixes after review
1 parent ccb238a commit f42c177

File tree

4 files changed

+10
-16
lines changed

4 files changed

+10
-16
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ The following [extension properties](https://github.com/OAI/OpenAPI-Specificatio
4848
```
4949
x-lg-handler: '\App\Http\Controllers\CustomersController@create' // Optional. Path is ignored if this field is empty. You can use :: instead of @ if you want
5050
x-lg-route-name: 'createCustomer' // Optional. Translates to `->name('createCustomer')`
51-
x-lg-middleware: 'auth,web' // Optional. Translates to `->middleware(['auth', 'web'])`
51+
x-lg-middleware: '\App\Http\Middleware\Authenticate::class,web' // Optional. Translates to `->middleware([\App\Http\Middleware\Authenticate::class, 'web'])`
5252
```
5353

5454
`route.php` file IS overriden with each generation.

src/Commands/GenerateServer.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
use cebe\openapi\Reader;
66
use cebe\openapi\SpecObjectInterface;
7-
use Greensight\LaravelOpenApiServerGenerator\Generators\EnumsGenerator;
8-
use Greensight\LaravelOpenApiServerGenerator\Generators\RoutesGenerator;
97
use Illuminate\Console\Command;
10-
use Illuminate\Filesystem\Filesystem;
118
use LogicException;
129

1310
class GenerateServer extends Command
@@ -23,11 +20,8 @@ class GenerateServer extends Command
2320

2421
private array $enabledEntities = [];
2522

26-
public function __construct(
27-
private Filesystem $filesystem,
28-
private RoutesGenerator $routesGenerator,
29-
private EnumsGenerator $enumsGenerator
30-
) {
23+
public function __construct()
24+
{
3125
parent::__construct();
3226

3327
$this->config = config('openapi-server-generator', []);
@@ -36,7 +30,7 @@ public function __construct(
3630
/**
3731
* Execute the console command.
3832
*
39-
* @return void
33+
* @return int
4034
*/
4135
public function handle()
4236
{

src/Generators/ControllersGenerator.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ private function createControllersFiles(array $controllers, string $template): v
7878
$namespace = $controller['namespace'];
7979
$className = $controller['className'];
8080

81+
$filePath = $this->getNamespacedFilePath($className, $namespace);
82+
if ($this->filesystem->exists($filePath)) {
83+
continue;
84+
}
85+
8186
$methodsString = '';
8287
foreach ($controller['actions'] as $action) {
8388
$methodName = $action['name'];
@@ -93,11 +98,6 @@ public function {$methodName}({$paramsString})
9398
}
9499
$methodsString = trim($methodsString, "\n");
95100

96-
$filePath = $this->getNamespacedFilePath($className, $namespace);
97-
if ($this->filesystem->exists($filePath)) {
98-
continue;
99-
}
100-
101101
$this->filesystem->put(
102102
$filePath,
103103
$this->replacePlaceholders($template, [

src/Generators/RoutesGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private function formatMiddleware(string $middleware): string
5959
$parts = array_map(function ($m) {
6060
$trimmedMiddleware = trim($m);
6161

62-
return "'{$trimmedMiddleware}'";
62+
return str_ends_with($trimmedMiddleware, '::class') ? "{$trimmedMiddleware}" : "'{$trimmedMiddleware}'";
6363
}, explode(",", $middleware));
6464

6565
return '[' . implode(', ', $parts) . ']';

0 commit comments

Comments
 (0)