mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-09 02:59:27 +03:00
Merge SWG annotations in manually created @Operation
(#1321)
* Merge SWG annotations in manually created `@Operation` * failing test * Fix tests
This commit is contained in:
parent
dbfa4ed8bd
commit
8db415afce
@ -130,6 +130,7 @@ final class SwaggerPhpDescriber implements ModelRegistryAwareInterface
|
||||
$nestedContext = clone $context;
|
||||
$nestedContext->nested = true;
|
||||
$implicitAnnotations = [];
|
||||
$operations = [];
|
||||
$tags = [];
|
||||
$security = [];
|
||||
foreach (array_merge($annotations, $classAnnotations[$declaringClass->getName()]) as $annotation) {
|
||||
@ -143,6 +144,7 @@ final class SwaggerPhpDescriber implements ModelRegistryAwareInterface
|
||||
$operation->path = $path;
|
||||
$operation->mergeProperties($annotation);
|
||||
|
||||
$operations[$httpMethod] = $operation;
|
||||
$analysis->addAnnotation($operation, null);
|
||||
}
|
||||
|
||||
@ -155,6 +157,7 @@ final class SwaggerPhpDescriber implements ModelRegistryAwareInterface
|
||||
$annotation->path = $path;
|
||||
}
|
||||
|
||||
$operations[$annotation->method] = $annotation;
|
||||
$analysis->addAnnotation($annotation, null);
|
||||
|
||||
continue;
|
||||
@ -185,6 +188,9 @@ final class SwaggerPhpDescriber implements ModelRegistryAwareInterface
|
||||
continue;
|
||||
}
|
||||
|
||||
// Registers new annotations
|
||||
$analysis->addAnnotations($implicitAnnotations, null);
|
||||
|
||||
foreach ($httpMethods as $httpMethod) {
|
||||
$annotationClass = $operationAnnotations[$httpMethod];
|
||||
$constructorArg = [
|
||||
@ -201,7 +207,11 @@ final class SwaggerPhpDescriber implements ModelRegistryAwareInterface
|
||||
}
|
||||
|
||||
$operation = new $annotationClass($constructorArg);
|
||||
$analysis->addAnnotation($operation, null);
|
||||
if (isset($operations[$httpMethod])) {
|
||||
$operations[$httpMethod]->mergeProperties($operation);
|
||||
} else {
|
||||
$analysis->addAnnotation($operation, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -196,4 +196,15 @@ class ApiController
|
||||
public function configReferenceAction()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/multi-annotations", methods={"GET", "POST"})
|
||||
* @SWG\Get(description="This is the get operation")
|
||||
* @SWG\Post(description="This is post")
|
||||
*
|
||||
* @SWG\Response(response=200, description="Worked well!", @Model(type=DummyType::class))
|
||||
*/
|
||||
public function operationsWithOtherAnnotations()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -362,4 +362,15 @@ class FunctionalTest extends WebTestCase
|
||||
$operation = $this->getOperation('/api/configReference', 'get');
|
||||
$this->assertEquals('#/definitions/Test', $operation->getResponses()->get('200')->getSchema()->getRef());
|
||||
}
|
||||
|
||||
public function testOperationsWithOtherAnnotationsAction()
|
||||
{
|
||||
$getOperation = $this->getOperation('/api/multi-annotations', 'get');
|
||||
$this->assertSame('This is the get operation', $getOperation->getDescription());
|
||||
$this->assertSame('Worked well!', $getOperation->getResponses()->get(200)->getDescription());
|
||||
|
||||
$postOperation = $this->getOperation('/api/multi-annotations', 'post');
|
||||
$this->assertSame('This is post', $postOperation->getDescription());
|
||||
$this->assertSame('Worked well!', $postOperation->getResponses()->get(200)->getDescription());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user