NelmioApiDocBundle/RouteDescriber/RouteMetadataDescriber.php

42 lines
1.2 KiB
PHP
Raw Normal View History

2016-06-30 23:30:37 +02:00
<?php
/*
* This file is part of the ApiDocBundle package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
2016-07-15 00:40:30 +02:00
namespace EXSyst\Bundle\ApiDocBundle\RouteDescriber;
2016-06-30 23:30:37 +02:00
2016-08-01 19:58:57 +02:00
use EXSyst\Component\Swagger\Swagger;
2016-06-30 23:30:37 +02:00
use Symfony\Component\Routing\Route;
2016-11-30 15:04:53 +01:00
final class RouteMetadataDescriber implements RouteDescriberInterface
2016-06-30 23:30:37 +02:00
{
2016-07-15 00:40:30 +02:00
use RouteDescriberTrait;
2016-06-30 23:30:37 +02:00
2016-07-15 00:40:30 +02:00
public function describe(Swagger $api, Route $route, \ReflectionMethod $reflectionMethod)
2016-06-30 23:30:37 +02:00
{
foreach ($this->getOperations($api, $route) as $operation) {
2016-07-29 18:40:56 +02:00
$operation->merge(['schemes' => $route->getSchemes()]);
2016-06-30 23:30:37 +02:00
2016-08-04 22:27:10 +02:00
$requirements = $route->getRequirements();
$compiledRoute = $route->compile();
// Don't include path variables
foreach ($compiledRoute->getPathVariables() as $pathVariable) {
$parameter = $operation->getParameters()->get($pathVariable, 'path');
2016-06-30 23:30:37 +02:00
$parameter->setRequired(true);
2016-07-28 10:20:59 +02:00
$parameter->setType('string');
2016-08-04 22:27:10 +02:00
if (isset($requirements[$pathVariable])) {
$parameter->setFormat($requirements[$pathVariable]);
}
2016-06-30 23:30:37 +02:00
}
}
}
}