Skip to content

Commit b40e00a

Browse files
feat: Add OpenAPI documentation annotations for OAuth2GroupApiController
Signed-off-by: matiasperrone-exo <matias.perrone@exomindset.co>
1 parent 7f63bee commit b40e00a

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use App\libs\Auth\Repositories\IGroupRepository;
1717
use App\ModelSerializers\SerializerRegistry;
1818
use OAuth2\IResourceServerContext;
19+
use OpenApi\Attributes as OA;
20+
use Symfony\Component\HttpFoundation\Response;
1921
use Utils\Services\ILogService;
2022

2123
/**
@@ -26,6 +28,54 @@ final class OAuth2GroupApiController extends OAuth2ProtectedController
2628
{
2729
use GetAllTrait;
2830

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

0 commit comments

Comments
 (0)