Fix a regression about manual paths in operation no longer being taken into account

This commit is contained in:
Guilhem Niot 2020-12-27 00:53:57 +01:00 committed by Guilhem Niot
parent ba3fe1cdfa
commit 42365c71cc
3 changed files with 27 additions and 0 deletions

View File

@ -87,6 +87,13 @@ final class OpenApiPhpDescriber
}
if ($annotation instanceof OA\Operation) {
if (!in_array($annotation->method, $httpMethods, true)) {
continue;
}
if (OA\UNDEFINED !== $annotation->path && $path->path !== $annotation->path) {
continue;
}
$operation = Util::getOperation($path, $annotation->method);
$operation->mergeProperties($annotation);

View File

@ -54,6 +54,14 @@ class ApiController
* @Operation(
* @OA\Response(response="201", description="An example resource")
* )
* @OA\Get(
* path="/api/swagger2",
* @OA\Parameter(name="Accept-Version", in="header", @OA\Schema(type="string"))
* )
* @OA\Post(
* path="/api/swagger2",
* @OA\Response(response="203", description="but 203 is not actually allowed (wrong method)")
* )
*/
public function swaggerAction()
{

View File

@ -80,6 +80,18 @@ class FunctionalTest extends WebTestCase
return [['/api/swagger'], ['/api/swagger2']];
}
public function testAnnotationWithManualPath()
{
$path = $this->getPath('/api/swagger2');
$this->assertSame(OA\UNDEFINED, $path->post);
$operation = $this->getOperation('/api/swagger', 'get');
$this->assertNotHasParameter('Accept-Version', 'header', $operation);
$operation = $this->getOperation('/api/swagger2', 'get');
$this->assertHasParameter('Accept-Version', 'header', $operation);
}
/**
* @dataProvider implicitSwaggerActionMethodsProvider
*/