Skip to content

Commit 4c6be26

Browse files
Feat | Add OpenAPI documentation for OAuth2GroupApiController (#109)
* feat: Add OpenAPI documentation annotations for OAuth2GroupApiController v1 routes * chore: Add PR requested changes bullets 1 and 3
1 parent 5ad8c11 commit 4c6be26

4 files changed

Lines changed: 110 additions & 5 deletions

File tree

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

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?php namespace App\Http\Controllers\Api\OAuth2;
1+
<?php
2+
namespace App\Http\Controllers\Api\OAuth2;
23
/**
34
* Copyright 2025 OpenStack Foundation
45
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,8 +15,11 @@
1415

1516
use App\Http\Controllers\GetAllTrait;
1617
use App\libs\Auth\Repositories\IGroupRepository;
18+
use App\libs\OAuth2\IGroupScopes;
1719
use App\ModelSerializers\SerializerRegistry;
1820
use OAuth2\IResourceServerContext;
21+
use OpenApi\Attributes as OA;
22+
use Symfony\Component\HttpFoundation\Response;
1923
use Utils\Services\ILogService;
2024

2125
/**
@@ -27,7 +31,7 @@ final class OAuth2GroupApiController extends OAuth2ProtectedController
2731
use GetAllTrait;
2832

2933
/**
30-
* OAuth2UserApiController constructor.
34+
* OAuth2GroupApiController constructor.
3135
* @param IGroupRepository $repository
3236
* @param IResourceServerContext $resource_server_context
3337
* @param ILogService $log_service
@@ -37,12 +41,61 @@ public function __construct
3741
IGroupRepository $repository,
3842
IResourceServerContext $resource_server_context,
3943
ILogService $log_service,
40-
)
41-
{
44+
) {
4245
parent::__construct($resource_server_context, $log_service);
4346
$this->repository = $repository;
4447
}
4548

49+
#[OA\Get(
50+
path: '/api/v1/groups',
51+
operationId: 'getGroups',
52+
summary: 'Get all groups',
53+
description: 'Retrieves a paginated list of groups with optional filtering and ordering. No route-level middleware enforcement; requires valid OAuth2 bearer token only.',
54+
security: [['OAuth2GroupsSecurity' => [IGroupScopes::ReadAll]]],
55+
tags: ['Groups'],
56+
parameters: [
57+
new OA\Parameter(
58+
name: 'page',
59+
in: 'query',
60+
description: 'Page number for pagination',
61+
required: false,
62+
schema: new OA\Schema(type: 'integer', minimum: 1, default: 1, example: 1)
63+
),
64+
new OA\Parameter(
65+
name: 'per_page',
66+
in: 'query',
67+
description: 'Number of items per page',
68+
required: false,
69+
schema: new OA\Schema(type: 'integer', minimum: 5, maximum: 100, default: 5, example: 10)
70+
),
71+
new OA\Parameter(
72+
name: 'filter',
73+
in: 'query',
74+
description: 'Filter criteria. Supported filters: slug== (exact match). Example: filter=slug==administrators',
75+
required: false,
76+
schema: new OA\Schema(type: 'string', example: 'slug==administrators')
77+
),
78+
new OA\Parameter(
79+
name: 'order',
80+
in: 'query',
81+
description: 'Ordering criteria. Supported fields: id, name, slug. Use + for ascending, - for descending. Example: +name or -id',
82+
required: false,
83+
schema: new OA\Schema(type: 'string', example: '+name')
84+
)
85+
],
86+
responses: [
87+
new OA\Response(
88+
response: Response::HTTP_OK,
89+
description: 'Successful response with paginated groups',
90+
content: new OA\JsonContent(ref: '#/components/schemas/PaginatedGroupResponse')
91+
),
92+
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: 'Unauthorized'),
93+
new OA\Response(response: Response::HTTP_FORBIDDEN, description: 'Forbidden - insufficient scope'),
94+
new OA\Response(response: Response::HTTP_NOT_FOUND, description: 'Not Found'),
95+
new OA\Response(response: Response::HTTP_PRECONDITION_FAILED, description: 'Validation failed, invalid filter or order parameter'),
96+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: 'Server error')
97+
]
98+
)]
4699
protected function getAllSerializerType(): string
47100
{
48101
return SerializerRegistry::SerializerType_Public;

app/Swagger/Models/GroupSchema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@
2424
)]
2525
class GroupSchema
2626
{
27-
}
27+
}
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)