mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 23:59:26 +03:00
Disable the OperationId processor (#1685)
* Disable the OperationId processor * Fix CS * CS
This commit is contained in:
parent
a82a1c1416
commit
69df4c38b5
@ -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();
|
||||||
|
|
||||||
|
35
OpenApiPhp/DefaultOperationId.php
Normal file
35
OpenApiPhp/DefaultOperationId.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user