mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-13 13:09:25 +03:00
Add log when there are no valid http methods
This commit is contained in:
parent
eb7e6b6803
commit
22c6eb5958
@ -95,6 +95,7 @@ final class NelmioApiDocExtension extends Extension implements PrependExtensionI
|
|||||||
new Reference(sprintf('nelmio_api_doc.routes.%s', $area)),
|
new Reference(sprintf('nelmio_api_doc.routes.%s', $area)),
|
||||||
new Reference('nelmio_api_doc.controller_reflector'),
|
new Reference('nelmio_api_doc.controller_reflector'),
|
||||||
new Reference('annotation_reader'),
|
new Reference('annotation_reader'),
|
||||||
|
new Reference('logger'),
|
||||||
])
|
])
|
||||||
->addTag(sprintf('nelmio_api_doc.describer.%s', $area), ['priority' => -200]);
|
->addTag(sprintf('nelmio_api_doc.describer.%s', $area), ['priority' => -200]);
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ use Nelmio\ApiDocBundle\Annotation\Security;
|
|||||||
use Nelmio\ApiDocBundle\SwaggerPhp\AddDefaults;
|
use Nelmio\ApiDocBundle\SwaggerPhp\AddDefaults;
|
||||||
use Nelmio\ApiDocBundle\SwaggerPhp\ModelRegister;
|
use Nelmio\ApiDocBundle\SwaggerPhp\ModelRegister;
|
||||||
use Nelmio\ApiDocBundle\Util\ControllerReflector;
|
use Nelmio\ApiDocBundle\Util\ControllerReflector;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
use Swagger\Analysis;
|
use Swagger\Analysis;
|
||||||
use Swagger\Annotations\AbstractAnnotation;
|
use Swagger\Annotations\AbstractAnnotation;
|
||||||
use Swagger\Annotations as SWG;
|
use Swagger\Annotations as SWG;
|
||||||
@ -31,13 +32,15 @@ final class SwaggerPhpDescriber implements ModelRegistryAwareInterface
|
|||||||
private $routeCollection;
|
private $routeCollection;
|
||||||
private $controllerReflector;
|
private $controllerReflector;
|
||||||
private $annotationReader;
|
private $annotationReader;
|
||||||
|
private $logger;
|
||||||
private $overwrite;
|
private $overwrite;
|
||||||
|
|
||||||
public function __construct(RouteCollection $routeCollection, ControllerReflector $controllerReflector, Reader $annotationReader, bool $overwrite = false)
|
public function __construct(RouteCollection $routeCollection, ControllerReflector $controllerReflector, Reader $annotationReader, LoggerInterface $logger, bool $overwrite = false)
|
||||||
{
|
{
|
||||||
$this->routeCollection = $routeCollection;
|
$this->routeCollection = $routeCollection;
|
||||||
$this->controllerReflector = $controllerReflector;
|
$this->controllerReflector = $controllerReflector;
|
||||||
$this->annotationReader = $annotationReader;
|
$this->annotationReader = $annotationReader;
|
||||||
|
$this->logger = $logger;
|
||||||
$this->overwrite = $overwrite;
|
$this->overwrite = $overwrite;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,13 +209,18 @@ final class SwaggerPhpDescriber implements ModelRegistryAwareInterface
|
|||||||
$path = $this->normalizePath($route->getPath());
|
$path = $this->normalizePath($route->getPath());
|
||||||
$httpMethods = $route->getMethods() ?: Swagger::$METHODS;
|
$httpMethods = $route->getMethods() ?: Swagger::$METHODS;
|
||||||
$httpMethods = array_map('strtolower', $httpMethods);
|
$httpMethods = array_map('strtolower', $httpMethods);
|
||||||
$httpMethods = array_intersect($httpMethods, Swagger::$METHODS);
|
$validHttpMethods = array_intersect($httpMethods, Swagger::$METHODS);
|
||||||
|
|
||||||
|
if (empty($validHttpMethods)) {
|
||||||
|
$this->logger->warning('No valid HTTP method for path', [
|
||||||
|
'path' => $path,
|
||||||
|
'methods' => $httpMethods,
|
||||||
|
]);
|
||||||
|
|
||||||
if (empty($httpMethods)) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
yield $method => [$path, $httpMethods];
|
yield $method => [$path, $validHttpMethods];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,9 @@ class ApiController
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Route("/swagger", methods={"GET"})
|
* The method LINK is not supported by OpenAPI so the method will be ignored.
|
||||||
|
*
|
||||||
|
* @Route("/swagger", methods={"GET", "LINK"})
|
||||||
* @Route("/swagger2", methods={"GET"})
|
* @Route("/swagger2", methods={"GET"})
|
||||||
* @Operation(
|
* @Operation(
|
||||||
* @SWG\Response(response="201", description="An example resource")
|
* @SWG\Response(response="201", description="An example resource")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user