/
OperationIdController.php
69 lines (59 loc) · 2.72 KB
/
OperationIdController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
declare(strict_types=1);
/*
* 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 OpenApi\Attributes as OA;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;
/*
* Not all operationIds were generated properly. This test case covers the following scenarios:
* - routes with unnamed symfony route annotations (fall back to SF naming strategy)
* - routes combined with OA\Get annotations
* - routes with OA\Get annotations and additional ApiDoc root annotations
* - routes with operationId explicitly set
*/
class OperationIdController
{
// a route with only a symfony route annotation (generates GET Operation using available metadata as operationId)
#[Route(path: '/generate/operation_id_route_unnamed', methods: 'GET')]
public function getMustGenerateOperationIdByUnnamedRouteAnnotation(): JsonResponse
{
return new JsonResponse();
}
// a route with a named symfony route annotation (generates GET Operation using route name as operationId)
#[Route(path: '/generate/operation_id_route', name: 'named_route', methods: 'GET')]
public function getMustGenerateOperationIdByRouteAnnotation(): JsonResponse
{
return new JsonResponse();
}
// a route with an OA\Get annotation and a separate ApiDoc Annotation(extends GET operation with operationId)
#[Route(path: '/generate/operation_id_with_security/', name: 'with_security', methods: 'GET')]
#[OA\Get('OperationId must be generated automatically when additional OA/nelmio root annotations are present')]
#[Security(name: 'bearerAuth')] // additioanl root annotations
public function getWithAdditionalAnnotationsGeneratesOperationId(): JsonResponse
{
return new JsonResponse();
}
// a route with an OA\GET annotation (extends GET operation with operationId)
#[Route(path: '/generate/operation_id_get', name: 'get_annotation', methods: 'GET')]
#[OA\Get(summary: 'OperationId must be generated automatically if not provided')]
public function getMustGenerateOperationIByGetAnnotation(): JsonResponse
{
return new JsonResponse();
}
// custom operationId is used when set explicitly
#[Route(path: '/has/explicit/operationid', name: 'customOperationId', methods: 'GET')]
#[OA\Get(summary: 'Custom operation id must be used if provided', operationId: 'customOperationId')]
public function getWithCustomOperationId(): JsonResponse
{
return new JsonResponse();
}
}