diff --git a/publish/swagger.php b/publish/swagger.php index 88c19f9..7bbcae1 100644 --- a/publish/swagger.php +++ b/publish/swagger.php @@ -19,4 +19,7 @@ 'scan' => [ 'paths' => null, ], + 'processors' => [ + // users can append their own processors here + ], ]; diff --git a/src/Generator.php b/src/Generator.php index 834dc07..b9be3f7 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -14,6 +14,7 @@ use Hyperf\Codec\Json; use Hyperf\Contract\ConfigInterface; use Hyperf\Swagger\Processor\BuildPathsProcessor; +use InvalidArgumentException; use OpenApi\Processors; class Generator @@ -29,6 +30,11 @@ public function generate(): void $paths = $this->config->get('annotations.scan.paths', []); } + $userProcessors = $this->config->get('swagger.processors', []); + if (! is_array($userProcessors)) { + throw new InvalidArgumentException('The processors of swagger must be array.'); + } + $generator = new \OpenApi\Generator(); $openapi = $generator->setAliases(\OpenApi\Generator::DEFAULT_ALIASES) ->setNamespaces(\OpenApi\Generator::DEFAULT_NAMESPACES) @@ -49,6 +55,7 @@ public function generate(): void new Processors\MergeXmlContent(), new Processors\OperationId(), new Processors\CleanUnmerged(), + ...$userProcessors, ]) ->generate($paths, validate: false); diff --git a/src/Processor/BuildPathsProcessor.php b/src/Processor/BuildPathsProcessor.php index 01595be..af7e467 100644 --- a/src/Processor/BuildPathsProcessor.php +++ b/src/Processor/BuildPathsProcessor.php @@ -26,7 +26,6 @@ public function __invoke(Analysis $analysis) $paths = []; // Merge @OA\PathItems with the same path. if (! Generator::isDefault($analysis->openapi->paths)) { - var_dump(123123); foreach ($analysis->openapi->paths as $annotation) { if (empty($annotation->path)) { $annotation->_context->logger->warning($annotation->identity() . ' is missing required property "path" in ' . $annotation->_context);