Skip to content

Commit

Permalink
Added config processors for swagger. (#6338)
Browse files Browse the repository at this point in the history

Co-authored-by: Lu Fei <[email protected]>
Co-authored-by: 李铭昕 <[email protected]>
  • Loading branch information
3 people authored Nov 30, 2023
1 parent 2299847 commit afbc76d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions publish/swagger.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@
'scan' => [
'paths' => null,
],
'processors' => [
// users can append their own processors here
],
];
7 changes: 7 additions & 0 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Hyperf\Codec\Json;
use Hyperf\Contract\ConfigInterface;
use Hyperf\Swagger\Processor\BuildPathsProcessor;
use InvalidArgumentException;
use OpenApi\Processors;

class Generator
Expand All @@ -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)
Expand All @@ -49,6 +55,7 @@ public function generate(): void
new Processors\MergeXmlContent(),
new Processors\OperationId(),
new Processors\CleanUnmerged(),
...$userProcessors,
])
->generate($paths, validate: false);

Expand Down
1 change: 0 additions & 1 deletion src/Processor/BuildPathsProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit afbc76d

Please sign in to comment.