diff --git a/Describer/SwaggerPhpDescriber.php b/Describer/SwaggerPhpDescriber.php index 0a02fad..1b21659 100644 --- a/Describer/SwaggerPhpDescriber.php +++ b/Describer/SwaggerPhpDescriber.php @@ -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); + } + } } diff --git a/Tests/Functional/Controller/ApiController.php b/Tests/Functional/Controller/ApiController.php index 32dce72..b148caf 100644 --- a/Tests/Functional/Controller/ApiController.php +++ b/Tests/Functional/Controller/ApiController.php @@ -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() { diff --git a/Tests/Functional/FunctionalTest.php b/Tests/Functional/FunctionalTest.php index 92366ad..4272718 100644 --- a/Tests/Functional/FunctionalTest.php +++ b/Tests/Functional/FunctionalTest.php @@ -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'));