mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 23:59:26 +03:00
Merge pull request #1297 from magnetik/class
Load class NelmioApiDocBundle annotations
This commit is contained in:
commit
473a8ccd01
@ -96,7 +96,17 @@ final class SwaggerPhpDescriber implements ModelRegistryAwareInterface
|
||||
'head' => SWG\Head::class,
|
||||
];
|
||||
|
||||
$classAnnotations = [];
|
||||
|
||||
foreach ($this->getMethodsToParse() as $method => list($path, $httpMethods)) {
|
||||
$declaringClass = $method->getDeclaringClass();
|
||||
if (!array_key_exists($declaringClass->getName(), $classAnnotations)) {
|
||||
$classAnnotations = array_filter($this->annotationReader->getClassAnnotations($declaringClass), function ($v) {
|
||||
return $v instanceof SWG\AbstractAnnotation;
|
||||
});
|
||||
$classAnnotations[$declaringClass->getName()] = $classAnnotations;
|
||||
}
|
||||
|
||||
$annotations = array_filter($this->annotationReader->getMethodAnnotations($method), function ($v) {
|
||||
return $v instanceof SWG\AbstractAnnotation;
|
||||
});
|
||||
@ -105,7 +115,6 @@ final class SwaggerPhpDescriber implements ModelRegistryAwareInterface
|
||||
continue;
|
||||
}
|
||||
|
||||
$declaringClass = $method->getDeclaringClass();
|
||||
$context = new Context([
|
||||
'namespace' => $method->getNamespaceName(),
|
||||
'class' => $declaringClass->getShortName(),
|
||||
@ -117,7 +126,7 @@ final class SwaggerPhpDescriber implements ModelRegistryAwareInterface
|
||||
$implicitAnnotations = [];
|
||||
$tags = [];
|
||||
$security = [];
|
||||
foreach ($annotations as $annotation) {
|
||||
foreach (array_merge($annotations, $classAnnotations[$declaringClass->getName()]) as $annotation) {
|
||||
$annotation->_context = $context;
|
||||
$this->updateNestedAnnotations($annotation, $nestedContext);
|
||||
|
||||
|
31
Tests/Functional/Controller/ClassApiController.php
Normal file
31
Tests/Functional/Controller/ClassApiController.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?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\Tests\Functional\Controller;
|
||||
|
||||
use Nelmio\ApiDocBundle\Annotation\Security;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Swagger\Annotations as SWG;
|
||||
|
||||
/**
|
||||
* @Route("/api", host="api.example.com")
|
||||
* @Security(name="basic")
|
||||
*/
|
||||
class ClassApiController
|
||||
{
|
||||
/**
|
||||
* @Route("/security/class")
|
||||
* @SWG\Response(response="201", description="")
|
||||
*/
|
||||
public function securityAction()
|
||||
{
|
||||
}
|
||||
}
|
@ -276,6 +276,16 @@ class FunctionalTest extends WebTestCase
|
||||
$this->assertEquals($expected, $operation->getSecurity());
|
||||
}
|
||||
|
||||
public function testClassSecurityAction()
|
||||
{
|
||||
$operation = $this->getOperation('/api/security/class', 'get');
|
||||
|
||||
$expected = [
|
||||
['basic' => []],
|
||||
];
|
||||
$this->assertEquals($expected, $operation->getSecurity());
|
||||
}
|
||||
|
||||
public function testSymfonyConstraintDocumentation()
|
||||
{
|
||||
$this->assertEquals([
|
||||
|
@ -66,6 +66,7 @@ class TestKernel extends Kernel
|
||||
{
|
||||
$routes->import(__DIR__.'/Controller/TestController.php', '/', 'annotation');
|
||||
$routes->import(__DIR__.'/Controller/ApiController.php', '/', 'annotation');
|
||||
$routes->import(__DIR__.'/Controller/ClassApiController.php', '/', 'annotation');
|
||||
$routes->import(__DIR__.'/Controller/UndocumentedController.php', '/', 'annotation');
|
||||
$routes->import('', '/api', 'api_platform');
|
||||
$routes->add('/docs/{area}', 'nelmio_api_doc.controller.swagger_ui')->setDefault('area', 'default');
|
||||
|
Loading…
x
Reference in New Issue
Block a user