Skip to content

Commit

Permalink
Switch the command line tool to using reflection by default
Browse files Browse the repository at this point in the history
The legacy `TokenAnalyser` can be used by specifying the `--legacy` (`-l`) option.
  • Loading branch information
DerManoMann committed Nov 28, 2021
1 parent 4312d4f commit 8906ee3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ The `openapi` command line interface can be used to generate the documentation t
```bash
./vendor/bin/openapi --help
```
Starting with version 4 the default analyser used on the command line is the new `ReflectionAnalyser`.

Using the `--legacy` flag (`-l`) the legacy `TokenAnalyser` can still be used.

### Usage from the Deserializer

Expand Down
12 changes: 11 additions & 1 deletion bin/openapi
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env php
<?php

use OpenApi\Analysers\AttributeAnnotationFactory;
use OpenApi\Analysers\DocBlockAnnotationFactory;
use OpenApi\Analysers\ReflectionAnalyser;
use OpenApi\Analysers\TokenAnalyser;
use OpenApi\Generator;
use OpenApi\Util;
Expand All @@ -18,6 +21,7 @@ error_reporting(E_ALL);

// Possible options and their default values.
$options = [
'legacy' => false,
'output' => false,
'format' => 'auto',
'exclude' => [],
Expand All @@ -28,6 +32,7 @@ $options = [
'processor' => [],
];
$aliases = [
'l' => 'legacy',
'o' => 'output',
'e' => 'exclude',
'n' => 'pattern',
Expand Down Expand Up @@ -110,6 +115,7 @@ if ($options['help']) {
Usage: openapi [--option value] [/path/to/project ...]
Options:
--legacy (-l) Use legacy TokenAnalyser; default is the new ReflectionAnalyser
--output (-o) Path to store the generated documentation.
ex: --output openapi.yaml
--exclude (-e) Exclude path(s).
Expand Down Expand Up @@ -193,8 +199,12 @@ foreach ($options["processor"] as $processor) {
$generator->addProcessor($processor);
}

$analyser = $options['legacy']
? new TokenAnalyser()
: new ReflectionAnalyser([new DocBlockAnnotationFactory(), new AttributeAnnotationFactory()]);

$openapi = $generator
->setAnalyser(new TokenAnalyser())
->setAnalyser($analyser)
->generate(Util::finder($paths, $exclude, $pattern));

if ($logger->called()) {
Expand Down

0 comments on commit 8906ee3

Please sign in to comment.