Skip to content

Commit f7c8ac9

Browse files
committed
added a script that generates the swagger documentation, the commands now delete the temp file
1 parent 01f0705 commit f7c8ac9

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ coverage.html
2121
/run_server.bat
2222
/*.bat
2323
/filestorage
24+
app/V1Module/presenters/_autogenerated_annotations_temp.php

app/commands/GenerateSwagger.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,15 @@ protected function configure()
2525

2626
protected function execute(InputInterface $input, OutputInterface $output)
2727
{
28-
$openapi = \OpenApi\Generator::scan([__DIR__ . '/../V1Module/presenters/annotations.php']);
29-
// $openapi = \OpenApi\Generator::scan([__DIR__ . '/../']);
28+
$path = __DIR__ . '/../V1Module/presenters/_autogenerated_annotations_temp.php';
29+
$openapi = \OpenApi\Generator::scan([$path]);
3030

31-
header('Content-Type: application/x-yaml');
32-
echo $openapi->toYaml();
31+
header('Content-Type: application/x-yaml');
32+
$output->writeln($openapi->toYaml());
3333

34-
return Command::SUCCESS;
34+
# delete the temp file
35+
unlink($path);
36+
37+
return Command::SUCCESS;
3538
}
3639
}

app/commands/SwaggerAnnotator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class SwaggerAnnotator extends Command
1919
{
2020
protected static $defaultName = 'swagger:annotate';
2121
private static $presenterNamespace = 'App\V1Module\Presenters\\';
22-
private static $autogeneratedAnnotationFilePath = 'app/V1Module/presenters/annotations.php';
22+
private static $autogeneratedAnnotationFilePath = 'app/V1Module/presenters/_autogenerated_annotations_temp.php';
2323

2424
protected function configure(): void
2525
{
@@ -186,6 +186,8 @@ public function startClass(string $className, string $version, string $title) {
186186

187187
public function endClass(){
188188
fwrite($this->file, "}\n");
189+
fflush($this->file);
190+
fclose($this->file);
189191
}
190192

191193
public function addAnnotatedMethod(string $methodName, string $annotationLine) {

generate-swagger

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
./bin/console swagger:annotate
4+
./cleaner
5+
./bin/console swagger:generate

0 commit comments

Comments
 (0)