Skip to content

Commit da8fd46

Browse files
feat: Add OpenAPI documentation to "getAll" method
- Add controller's response to OpenAPI schema
1 parent 9ed27c0 commit da8fd46

File tree

2 files changed

+108
-2
lines changed

2 files changed

+108
-2
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: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,4 +348,36 @@ class RSVPUpdateRequestSchema_{
348348

349349
]
350350
)]
351-
class RSVPAdminAddRequestSchema {}
351+
class RSVPAdminAddRequestSchema {}
352+
353+
#[OA\Schema(
354+
schema: 'Group',
355+
type: 'object',
356+
properties: [
357+
new OA\Property(property: 'id', type: 'integer', example: 1, description: 'Unique identifier'),
358+
new OA\Property(property: 'created', type: 'integer', example: 1630500518, description: 'Creation timestamp (Unix epoch)'),
359+
new OA\Property(property: 'last_edited', type: 'integer', example: 1630500518, description: 'Last modification timestamp (Unix epoch)'),
360+
new OA\Property(property: 'title', type: 'string', example: 'Administrators', description: 'Group title'),
361+
new OA\Property(property: 'description', type: 'string', example: 'System administrators group', description: 'Group description', nullable: true),
362+
new OA\Property(property: 'code', type: 'string', example: 'administrators', description: 'Unique group code'),
363+
]
364+
)]
365+
class GroupSchema {}
366+
367+
#[OA\Schema(
368+
schema: 'PaginatedGroupsResponse',
369+
allOf: [
370+
new OA\Schema(ref: '#/components/schemas/PaginateDataSchemaResponse'),
371+
new OA\Schema(
372+
type: 'object',
373+
properties: [
374+
new OA\Property(
375+
property: 'data',
376+
type: 'array',
377+
items: new OA\Items(ref: '#/components/schemas/Group')
378+
)
379+
]
380+
)
381+
]
382+
)]
383+
class PaginatedGroupsResponseSchema {}

0 commit comments

Comments
 (0)