Skip to content

Commit 16a5eb6

Browse files
feat: Add OpenAPI documentation annotations for OAuth2GroupApiController v1 routes
1 parent 0d6b7e3 commit 16a5eb6

File tree

4 files changed

+130
-1
lines changed

4 files changed

+130
-1
lines changed

app/Http/Controllers/Api/OAuth2/OAuth2GroupApiController.php

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,73 @@
1414

1515
use App\Http\Controllers\GetAllTrait;
1616
use App\libs\Auth\Repositories\IGroupRepository;
17+
use App\libs\OAuth2\IGroupScopes;
1718
use App\ModelSerializers\SerializerRegistry;
1819
use OAuth2\IResourceServerContext;
20+
use OpenApi\Attributes as OA;
21+
use Symfony\Component\HttpFoundation\Response;
1922
use Utils\Services\ILogService;
2023

2124
/**
2225
* Class OAuth2GroupApiController
2326
* @package App\Http\Controllers\Api\OAuth2
2427
*/
28+
#[OA\Get(
29+
path: '/api/v1/groups',
30+
operationId: 'getGroups',
31+
summary: 'Get all groups',
32+
description: 'Retrieves a paginated list of groups with optional filtering and ordering.',
33+
security: [['OAuth2GroupsSecurity' => [IGroupScopes::ReadAll]]],
34+
tags: ['Groups'],
35+
parameters: [
36+
new OA\Parameter(
37+
name: 'page',
38+
in: 'query',
39+
description: 'Page number for pagination',
40+
required: false,
41+
schema: new OA\Schema(type: 'integer', minimum: 1, default: 1, example: 1)
42+
),
43+
new OA\Parameter(
44+
name: 'per_page',
45+
in: 'query',
46+
description: 'Number of items per page',
47+
required: false,
48+
schema: new OA\Schema(type: 'integer', minimum: 5, maximum: 100, default: 5, example: 10)
49+
),
50+
new OA\Parameter(
51+
name: 'filter',
52+
in: 'query',
53+
description: 'Filter criteria. Supported filters: slug== (exact match). Example: filter=slug==administrators',
54+
required: false,
55+
schema: new OA\Schema(type: 'string', example: 'slug==administrators')
56+
),
57+
new OA\Parameter(
58+
name: 'order',
59+
in: 'query',
60+
description: 'Ordering criteria. Supported fields: id, name, slug. Use + for ascending, - for descending. Example: +name or -id',
61+
required: false,
62+
schema: new OA\Schema(type: 'string', example: '+name')
63+
)
64+
],
65+
responses: [
66+
new OA\Response(
67+
response: Response::HTTP_OK,
68+
description: 'Successful response with paginated groups',
69+
content: new OA\JsonContent(ref: '#/components/schemas/PaginatedGroupResponse')
70+
),
71+
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: 'Unauthorized'),
72+
new OA\Response(response: Response::HTTP_FORBIDDEN, description: 'Forbidden - insufficient scope'),
73+
new OA\Response(response: Response::HTTP_NOT_FOUND, description: 'Not Found'),
74+
new OA\Response(response: Response::HTTP_PRECONDITION_FAILED, description: 'Validation failed, invalid filter or order parameter'),
75+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: 'Server error')
76+
]
77+
)]
2578
final class OAuth2GroupApiController extends OAuth2ProtectedController
2679
{
2780
use GetAllTrait;
2881

2982
/**
30-
* OAuth2UserApiController constructor.
83+
* OAuth2GroupApiController constructor.
3184
* @param IGroupRepository $repository
3285
* @param IResourceServerContext $resource_server_context
3386
* @param ILogService $log_service

app/Swagger/Models/GroupSchema.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace App\Swagger\schemas;
4+
5+
use OpenApi\Attributes as OA;
6+
7+
#[OA\Schema(
8+
schema: 'Group',
9+
type: 'object',
10+
description: 'Group API response - serialized representation of a group',
11+
allOf: [
12+
new OA\Schema(ref: '#/components/schemas/Base'),
13+
new OA\Schema(
14+
type: 'object',
15+
properties: [
16+
new OA\Property(property: 'name', type: 'string', description: 'Group name', example: 'Administrators'),
17+
new OA\Property(property: 'slug', type: 'string', description: 'Group slug for URL-friendly identification', example: 'administrators'),
18+
new OA\Property(property: 'active', type: 'boolean', description: 'Whether the group is active', example: true),
19+
new OA\Property(property: 'default', type: 'boolean', description: 'Whether this is a default group', example: false),
20+
]
21+
)
22+
]
23+
)]
24+
class GroupSchema {}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace App\Swagger\schemas;
4+
5+
use OpenApi\Attributes as OA;
6+
7+
#[OA\Schema(
8+
schema: 'PaginatedGroupResponse',
9+
type: 'object',
10+
description: 'Paginated list of groups',
11+
allOf: [
12+
new OA\Schema(ref: '#/components/schemas/PaginateDataSchemaResponse'),
13+
new OA\Schema(
14+
type: 'object',
15+
properties: [
16+
new OA\Property(
17+
property: 'data',
18+
type: 'array',
19+
description: 'Array of group objects',
20+
items: new OA\Items(ref: '#/components/schemas/Group')
21+
)
22+
]
23+
)
24+
]
25+
)]
26+
class PaginatedGroupResponseSchema {}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace App\Swagger\schemas;
4+
5+
use App\libs\OAuth2\IGroupScopes;
6+
use OpenApi\Attributes as OA;
7+
8+
#[OA\SecurityScheme(
9+
securityScheme: 'OAuth2GroupsSecurity',
10+
type: 'oauth2',
11+
description: 'OAuth2 authentication for Group endpoints',
12+
flows: [
13+
new OA\Flow(
14+
flow: 'authorizationCode',
15+
authorizationUrl: L5_SWAGGER_CONST_AUTH_URL,
16+
tokenUrl: L5_SWAGGER_CONST_TOKEN_URL,
17+
scopes: [
18+
IGroupScopes::ReadAll => 'Read all groups',
19+
IGroupScopes::Write => 'Write group',
20+
]
21+
),
22+
]
23+
)]
24+
class OAuth2GroupApiControllerSecuritySchema
25+
{
26+
}

0 commit comments

Comments
 (0)