This commit is contained in:
Guilhem Niot 2017-06-02 21:30:31 +02:00
parent 4c882d3c8c
commit 2422156f27
3 changed files with 20 additions and 0 deletions

View File

@ -20,6 +20,7 @@ use Nelmio\ApiDocBundle\Util\ControllerReflector;
use Swagger\Analysis;
use Swagger\Annotations as SWG;
use Swagger\Context;
use Swagger\Annotations\AbstractAnnotation;
use Symfony\Component\Routing\RouteCollection;
final class SwaggerPhpDescriber extends ExternalDocDescriber implements ModelRegistryAwareInterface
@ -86,10 +87,13 @@ final class SwaggerPhpDescriber extends ExternalDocDescriber implements ModelReg
'method' => $method->name,
'filename' => $method->getFileName(),
]);
$nestedContext = clone $context;
$nestedContext->nested = true;
$implicitAnnotations = [];
$tags = [];
foreach ($annotations as $annotation) {
$annotation->_context = $context;
$this->updateNestedAnnotations($annotation, $nestedContext);
if ($annotation instanceof Operation) {
foreach ($httpMethods as $httpMethod) {
@ -170,4 +174,16 @@ final class SwaggerPhpDescriber extends ExternalDocDescriber implements ModelReg
return $path;
}
private function updateNestedAnnotations($value, Context $context) {
if ($value instanceof AbstractAnnotation) {
$value->_context = $context;
} elseif (!is_array($value)) {
return;
}
foreach ($value as $v) {
$this->updateNestedAnnotations($v, $context);
}
}
}

View File

@ -59,6 +59,9 @@ class ApiController
/**
* @Route("/test/{user}", methods={"GET"}, schemes={"https"}, requirements={"user"="/foo/"})
* @Operation(
* @SWG\Response(response=200, description="sucessful")
* )
*/
public function userAction()
{

View File

@ -92,6 +92,7 @@ class FunctionalTest extends WebTestCase
$this->assertEmpty($operation->getSummary());
$this->assertEmpty($operation->getDescription());
$this->assertNull($operation->getDeprecated());
$this->assertTrue($operation->getResponses()->has(200));
$parameters = $operation->getParameters();
$this->assertTrue($parameters->has('user', 'path'));