Skip to content

Commit 04d4dab

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

4 files changed

Lines changed: 125 additions & 0 deletions

File tree

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
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
/**
@@ -26,6 +29,55 @@ final class OAuth2GroupApiController extends OAuth2ProtectedController
2629
{
2730
use GetAllTrait;
2831

32+
#[OA\Get(
33+
path: '/api/v1/groups',
34+
operationId: 'getGroups',
35+
summary: 'Get all groups',
36+
description: 'Retrieves a paginated list of groups with optional filtering and ordering.',
37+
security: [new OA\SecurityRequirement(['OAuth2GroupsSecurity' => [IGroupScopes::ReadAll]])],
38+
tags: ['Groups'],
39+
parameters: [
40+
new OA\Parameter(
41+
name: 'page',
42+
in: 'query',
43+
description: 'Page number for pagination',
44+
required: false,
45+
schema: new OA\Schema(type: 'integer', minimum: 1, default: 1, example: 1)
46+
),
47+
new OA\Parameter(
48+
name: 'per_page',
49+
in: 'query',
50+
description: 'Number of items per page',
51+
required: false,
52+
schema: new OA\Schema(type: 'integer', minimum: 5, maximum: 100, default: 5, example: 10)
53+
),
54+
new OA\Parameter(
55+
name: 'filter',
56+
in: 'query',
57+
description: 'Filter criteria. Supported filters: slug== (exact match). Example: filter=slug==administrators',
58+
required: false,
59+
schema: new OA\Schema(type: 'string', example: 'slug==administrators')
60+
),
61+
new OA\Parameter(
62+
name: 'order',
63+
in: 'query',
64+
description: 'Ordering criteria. Supported fields: id, name, slug. Use + for ascending, - for descending. Example: +name or -id',
65+
required: false,
66+
schema: new OA\Schema(type: 'string', example: '+name')
67+
)
68+
],
69+
responses: [
70+
new OA\Response(
71+
response: Response::HTTP_OK,
72+
description: 'Successful response with paginated groups',
73+
content: new OA\JsonContent(ref: '#/components/schemas/PaginatedGroupResponse')
74+
),
75+
new OA\Response(response: Response::HTTP_NOT_FOUND, description: 'Not Found'),
76+
new OA\Response(response: Response::HTTP_PRECONDITION_FAILED, description: 'Validation failed'),
77+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: 'Server error')
78+
]
79+
)]
80+
2981
/**
3082
* OAuth2UserApiController constructor.
3183
* @param IGroupRepository $repository

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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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: [IGroupScopes::ReadAll => 'Read all groups']
18+
),
19+
]
20+
)]
21+
class OAuth2GroupApiControllerSecuritySchema
22+
{
23+
}

0 commit comments

Comments
 (0)