diff --git a/ApiDocGenerator.php b/ApiDocGenerator.php index 161e104..4ebafec 100644 --- a/ApiDocGenerator.php +++ b/ApiDocGenerator.php @@ -15,7 +15,6 @@ use Nelmio\ApiDocBundle\Describer\DescriberInterface; use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareInterface; use Nelmio\ApiDocBundle\Model\ModelRegistry; use Nelmio\ApiDocBundle\ModelDescriber\ModelDescriberInterface; -use Nelmio\ApiDocBundle\OpenApiPhp\DefaultOperationId; use Nelmio\ApiDocBundle\OpenApiPhp\ModelRegister; use Nelmio\ApiDocBundle\OpenApiPhp\Util; use OpenApi\Analysis; @@ -84,6 +83,14 @@ final class ApiDocGenerator } } + $generator = new Generator(); + // Remove OperationId processor as we use a lot of generated annotations which do not have enough information in their context + // to generate these ids properly. + // @see https://github.com/zircote/swagger-php/issues/1153 + $generator->setProcessors(array_filter($generator->getProcessors(), function ($processor) { + return !$processor instanceof \OpenApi\Processors\OperationId; + })); + $this->openApi = new OpenApi([]); $modelRegistry = new ModelRegistry($this->modelDescribers, $this->openApi, $this->alternativeNames); if (null !== $this->logger) { @@ -97,7 +104,12 @@ final class ApiDocGenerator $describer->describe($this->openApi); } - $context = Util::createContext(); + $context = Util::createContext( + // BC for for zircote/swagger-php < 4.2 + method_exists($generator, 'getVersion') + ? ['version' => $generator->getVersion()] + : [] + ); $analysis = new Analysis([], $context); $analysis->addAnnotation($this->openApi, $context); @@ -108,10 +120,7 @@ final class ApiDocGenerator // Calculate the associated schemas $modelRegistry->registerSchemas(); - $defaultOperationIdProcessor = new DefaultOperationId(); - $defaultOperationIdProcessor($analysis); - - $analysis->process((new Generator())->getProcessors()); + $analysis->process($generator->getProcessors()); $analysis->validate(); if (isset($item)) { diff --git a/OpenApiPhp/DefaultOperationId.php b/OpenApiPhp/DefaultOperationId.php deleted file mode 100644 index 0a30fce..0000000 --- a/OpenApiPhp/DefaultOperationId.php +++ /dev/null @@ -1,36 +0,0 @@ -getAnnotationsOfType(OA\Operation::class); - - foreach ($allOperations as $operation) { - if (Generator::UNDEFINED === $operation->operationId) { - $operation->operationId = null; - } - } - } -} diff --git a/OpenApiPhp/Util.php b/OpenApiPhp/Util.php index cb57de1..ea495e9 100644 --- a/OpenApiPhp/Util.php +++ b/OpenApiPhp/Util.php @@ -316,8 +316,6 @@ final class Util */ public static function createContext(array $properties = [], Context $parent = null): Context { - $properties['comment'] = ''; // TODO: remove this when https://github.com/zircote/swagger-php/commit/708a25208797ca05ebeae572bbccad8b13de14d8 is released - return new Context($properties, $parent); } diff --git a/Tests/Functional/TestKernel.php b/Tests/Functional/TestKernel.php index 58e893c..c9b8ee2 100644 --- a/Tests/Functional/TestKernel.php +++ b/Tests/Functional/TestKernel.php @@ -186,6 +186,20 @@ class TestKernel extends Kernel 'info' => [ 'title' => 'My Default App', ], + 'paths' => [ + // Ensures we can define routes in Yaml without defining OperationIds + // See https://github.com/zircote/swagger-php/issues/1153 + '/api/test-from-yaml' => ['get' => [ + 'responses' => [ + 200 => ['description' => 'success'], + ], + ]], + '/api/test-from-yaml2' => ['get' => [ + 'responses' => [ + 200 => ['description' => 'success'], + ], + ]], + ], 'components' => [ 'schemas' => [ 'Test' => [