Skip to content

Commit 519673e

Browse files
feat: Add OpenAPI documentation to "getAll" method
- Add controller's response to OpenAPI schema
1 parent 9654260 commit 519673e

File tree

2 files changed

+107
-1
lines changed

2 files changed

+107
-1
lines changed

app/Http/Controllers/Apis/Protected/Main/OAuth2GroupsApiController.php

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212
* limitations under the License.
1313
**/
1414

15+
use App\Security\SummitScopes;
16+
use Illuminate\Http\Response;
1517
use models\main\IGroupRepository;
1618
use models\oauth2\IResourceServerContext;
1719
use ModelSerializers\SerializerRegistry;
20+
use OpenApi\Attributes as OA;
1821

1922
/**
2023
* Class OAuth2GroupsApiController
@@ -40,6 +43,77 @@ public function __construct
4043
$this->repository = $group_repository;
4144
}
4245

46+
#[OA\Get(
47+
path: "/api/v1/groups",
48+
description: "Get all groups with filtering and pagination. Groups are used for access control and organization of members. Requires OAuth2 authentication with appropriate scope.",
49+
summary: 'Get all groups',
50+
operationId: 'getAllGroups',
51+
tags: ['Groups'],
52+
security: [['summit_rsvp_oauth2' => [
53+
SummitScopes::ReadAllSummitData,
54+
]]],
55+
parameters: [
56+
new OA\Parameter(
57+
name: 'access_token',
58+
in: 'query',
59+
required: false,
60+
description: 'OAuth2 access token (alternative to Authorization: Bearer)',
61+
schema: new OA\Schema(type: 'string', example: 'eyJhbGciOi...')
62+
),
63+
new OA\Parameter(
64+
name: 'page',
65+
in: 'query',
66+
required: false,
67+
description: 'Page number for pagination',
68+
schema: new OA\Schema(type: 'integer', example: 1)
69+
),
70+
new OA\Parameter(
71+
name: 'per_page',
72+
in: 'query',
73+
required: false,
74+
description: 'Items per page',
75+
schema: new OA\Schema(type: 'integer', example: 10, maximum: 100)
76+
),
77+
new OA\Parameter(
78+
name: 'filter[]',
79+
in: 'query',
80+
required: false,
81+
description: 'Filter expressions. Format: field<op>value. Available fields: code (=@, ==, @@), title (=@, ==, @@). Operators: == (equals), =@ (starts with), @@ (contains)',
82+
style: 'form',
83+
explode: true,
84+
schema: new OA\Schema(
85+
type: 'array',
86+
items: new OA\Items(type: 'string', example: 'code==administrators')
87+
)
88+
),
89+
new OA\Parameter(
90+
name: 'order',
91+
in: 'query',
92+
required: false,
93+
description: 'Order by field(s). Available fields: code, title, id. Use "-" prefix for descending order.',
94+
schema: new OA\Schema(type: 'string', example: 'title')
95+
),
96+
new OA\Parameter(
97+
name: 'expand',
98+
in: 'query',
99+
required: false,
100+
description: 'Comma-separated list of related resources to include. Available relations: members',
101+
schema: new OA\Schema(type: 'string', example: 'members')
102+
),
103+
],
104+
responses: [
105+
new OA\Response(
106+
response: 200,
107+
description: 'Success - Returns paginated list of groups',
108+
content: new OA\JsonContent(ref: '#/components/schemas/PaginatedGroupsResponse')
109+
),
110+
new OA\Response(response: Response::HTTP_BAD_REQUEST, description: "Bad Request - Invalid parameters"),
111+
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized - Invalid or missing access token"),
112+
new OA\Response(response: Response::HTTP_FORBIDDEN, description: "Forbidden - Insufficient permissions"),
113+
new OA\Response(response: Response::HTTP_PRECONDITION_FAILED, description: "Validation Error"),
114+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error")
115+
]
116+
)]
43117
public function getAll()
44118
{
45119
return $this->_getAll(
@@ -71,4 +145,4 @@ function () {
71145
);
72146
}
73147

74-
}
148+
}

app/Swagger/schemas.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,3 +376,35 @@ class RSVPUpdateRequestSchema_{
376376
]
377377
)]
378378
class RSVPAdminAddRequestSchema {}
379+
380+
#[OA\Schema(
381+
schema: 'Group',
382+
type: 'object',
383+
properties: [
384+
new OA\Property(property: 'id', type: 'integer', example: 1, description: 'Unique identifier'),
385+
new OA\Property(property: 'created', type: 'integer', example: 1630500518, description: 'Creation timestamp (Unix epoch)'),
386+
new OA\Property(property: 'last_edited', type: 'integer', example: 1630500518, description: 'Last modification timestamp (Unix epoch)'),
387+
new OA\Property(property: 'title', type: 'string', example: 'Administrators', description: 'Group title'),
388+
new OA\Property(property: 'description', type: 'string', example: 'System administrators group', description: 'Group description', nullable: true),
389+
new OA\Property(property: 'code', type: 'string', example: 'administrators', description: 'Unique group code'),
390+
]
391+
)]
392+
class GroupSchema {}
393+
394+
#[OA\Schema(
395+
schema: 'PaginatedGroupsResponse',
396+
allOf: [
397+
new OA\Schema(ref: '#/components/schemas/PaginateDataSchemaResponse'),
398+
new OA\Schema(
399+
type: 'object',
400+
properties: [
401+
new OA\Property(
402+
property: 'data',
403+
type: 'array',
404+
items: new OA\Items(ref: '#/components/schemas/Group')
405+
)
406+
]
407+
)
408+
]
409+
)]
410+
class PaginatedGroupsResponseSchema {}

0 commit comments

Comments
 (0)