Skip to content

Commit f934a06

Browse files
committed
Refactor GenerateCommand and GenerateInput to use OpenApi annotations and simplify path exclusion handling
1 parent a4b34a0 commit f934a06

3 files changed

Lines changed: 5 additions & 46 deletions

File tree

src/Console/GenerateCommand.php

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66

77
namespace OpenApi\Console;
88

9-
use OpenApi\Analysers\AttributeAnnotationFactory;
10-
use OpenApi\Analysers\DocBlockAnnotationFactory;
11-
use OpenApi\Analysers\ReflectionAnalyser;
12-
use OpenApi\Annotations\OpenApi;
9+
use OpenApi\Annotations as OA;
1310
use OpenApi\Generator;
1411
use OpenApi\SourceFinder;
1512
use Symfony\Component\Console\Attribute\AsCommand;
@@ -68,7 +65,7 @@ public function __invoke(#[MapInput] GenerateInput $input, SymfonyStyle $io): in
6865
return $this->logger->hasErrored() ? 1 : 0;
6966
}
7067

71-
private function generate(GenerateInput $input): OpenApi
68+
private function generate(GenerateInput $input): OA\OpenApi
7269
{
7370
$generator = new Generator($this->logger);
7471

@@ -89,37 +86,9 @@ private function generate(GenerateInput $input): OpenApi
8986
$generator->getProcessorPipeline()->remove($class);
9087
}
9188

92-
$analyser = new ReflectionAnalyser([
93-
new AttributeAnnotationFactory(),
94-
new DocBlockAnnotationFactory(),
95-
]);
96-
$analyser->setGenerator($generator);
97-
9889
return $generator
9990
->setVersion($input->version)
10091
->setConfig($input->config)
101-
->setAnalyser($analyser)
102-
->generate(new SourceFinder($input->paths, $this->normalizeExcludePaths($input->exclude), $input->pattern));
103-
}
104-
105-
/**
106-
* @param list<string> $exclude
107-
*
108-
* @return list<string>
109-
*/
110-
private function normalizeExcludePaths(array $exclude): array
111-
{
112-
if (!$exclude) {
113-
return [];
114-
}
115-
116-
if (str_contains($exclude[0], ',')) {
117-
$exploded = explode(',', $exclude[0]);
118-
$this->logger->error('Comma-separated exclude paths are deprecated, use multiple --exclude statements: --exclude ' . $exploded[0] . ' --exclude ' . $exploded[1]);
119-
$exclude[0] = array_shift($exploded);
120-
$exclude = array_merge($exclude, $exploded);
121-
}
122-
123-
return $exclude;
92+
->generate(new SourceFinder($input->paths, $input->exclude, $input->pattern));
12493
}
12594
}

src/Console/GenerateInput.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace OpenApi\Console;
88

9-
use OpenApi\Annotations\OpenApi;
9+
use OpenApi\Annotations as OA;
1010
use Symfony\Component\Console\Attribute\Argument;
1111
use Symfony\Component\Console\Attribute\Option;
1212
use Symfony\Component\Console\Exception\InvalidArgumentException;
@@ -44,7 +44,7 @@ class GenerateInput
4444
public array $removeProcessor = [];
4545

4646
#[Option('The OpenAPI version')]
47-
public string $version = OpenApi::DEFAULT_VERSION;
47+
public string $version = OA\OpenApi::DEFAULT_VERSION;
4848

4949
#[Option('Show additional error information', shortcut: 'd')]
5050
public bool $debug = false;

tests/CommandlineTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,6 @@ public function testRemoveProcessor(): void
6868
$this->assertSame(0, $retval, $cmd . PHP_EOL . implode(PHP_EOL, $output));
6969
}
7070

71-
public function testExcludeListWarning(): void
72-
{
73-
$basePath = self::examplePath('petstore');
74-
$path = "{$basePath}/annotations";
75-
exec($this->getCommandToExecute(__DIR__ . '/../bin/openapi -e foo,bar ' . escapeshellarg($path) . ' 2>&1'), $output, $retval);
76-
$this->assertSame(1, $retval);
77-
$output = implode(PHP_EOL, $output);
78-
$this->assertStringContainsString('Comma-separated exclude paths are deprecated', $output);
79-
}
80-
8171
public function testMissingArg(): void
8272
{
8373
$basePath = self::examplePath('petstore');

0 commit comments

Comments
 (0)