Disable the OperationId processor (#1685)

* Disable the OperationId processor

* Fix CS

* CS
This commit is contained in:
Guilhem Niot 2020-07-24 08:37:58 +02:00 committed by GitHub
parent a82a1c1416
commit 69df4c38b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 0 deletions

View File

@ -15,6 +15,7 @@ use Nelmio\ApiDocBundle\Describer\DescriberInterface;
use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareInterface; use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareInterface;
use Nelmio\ApiDocBundle\Model\ModelRegistry; use Nelmio\ApiDocBundle\Model\ModelRegistry;
use Nelmio\ApiDocBundle\ModelDescriber\ModelDescriberInterface; use Nelmio\ApiDocBundle\ModelDescriber\ModelDescriberInterface;
use Nelmio\ApiDocBundle\OpenApiPhp\DefaultOperationId;
use Nelmio\ApiDocBundle\OpenApiPhp\ModelRegister; use Nelmio\ApiDocBundle\OpenApiPhp\ModelRegister;
use OpenApi\Analysis; use OpenApi\Analysis;
use OpenApi\Annotations\OpenApi; use OpenApi\Annotations\OpenApi;
@ -98,6 +99,9 @@ final class ApiDocGenerator
// Calculate the associated schemas // Calculate the associated schemas
$modelRegistry->registerSchemas(); $modelRegistry->registerSchemas();
$defaultOperationIdProcessor = new DefaultOperationId();
$defaultOperationIdProcessor($analysis);
$analysis->process(); $analysis->process();
$analysis->validate(); $analysis->validate();

View File

@ -0,0 +1,35 @@
<?php
/*
* This file is part of the NelmioApiDocBundle package.
*
* (c) Nelmio
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nelmio\ApiDocBundle\OpenApiPhp;
use OpenApi\Analysis;
use OpenApi\Annotations as OA;
/**
* Disable the OperationId processor from zircote/swagger-php as it breaks our documentation by setting non-unique operation ids.
* See https://github.com/zircote/swagger-php/pull/483#issuecomment-360739260 for the solution used here.
*
* @internal
*/
final class DefaultOperationId
{
public function __invoke(Analysis $analysis)
{
$allOperations = $analysis->getAnnotationsOfType(OA\Operation::class);
foreach ($allOperations as $operation) {
if (OA\UNDEFINED === $operation->operationId) {
$operation->operationId = null;
}
}
}
}

View File

@ -456,4 +456,11 @@ class FunctionalTest extends WebTestCase
$operation = $this->getOperation('/api/invoke', 'get'); $operation = $this->getOperation('/api/invoke', 'get');
$this->assertSame('Invokable!', $this->getOperationResponse($operation, 200)->description); $this->assertSame('Invokable!', $this->getOperationResponse($operation, 200)->description);
} }
public function testDefaultOperationId()
{
$operation = $this->getOperation('/api/article/{id}', 'get');
var_dump($operation->operationId);
$this->assertNull($operation->operationId);
}
} }