mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-03-11 18:16:13 +03:00
Reproduce and fix duplicate operation id errors (#1972)
* Replicate and fix duplicate operation id errors * Fix CS
This commit is contained in:
parent
9cd417efb4
commit
8111ce645b
@ -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)) {
|
||||
|
@ -1,36 +0,0 @@
|
||||
<?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;
|
||||
use OpenApi\Generator;
|
||||
|
||||
/**
|
||||
* 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 (Generator::UNDEFINED === $operation->operationId) {
|
||||
$operation->operationId = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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' => [
|
||||
|
Loading…
x
Reference in New Issue
Block a user