Skip to content

Commit bd563c4

Browse files
Feature | Extend Swagger Coverage for controller OAuth2SpeakerOrganizationalRoleApiController (#374)
* feat: Extend Swagger Coverage for controller Apis/Protected/Summit/OAuth2SpeakerOrganizationalRoleApiController.php * fix: incorrect types and descriptions for errors * fix: Move schema to the new file * fix: add the right security schema * fix: security scopes * fix: Security schema * chore: Move the security schema for the controller to its own file --------- Co-authored-by: Matias Perrone <github@matiasperrone.com>
1 parent b055bf1 commit bd563c4

File tree

3 files changed

+102
-3
lines changed

3 files changed

+102
-3
lines changed

app/Http/Controllers/Apis/Protected/Summit/OAuth2SpeakerOrganizationalRoleApiController.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@
1212
* limitations under the License.
1313
**/
1414
use App\Models\Foundation\Summit\Repositories\ISpeakerOrganizationalRoleRepository;
15+
use App\Security\SummitScopes;
1516
use models\oauth2\IResourceServerContext;
1617
use Illuminate\Support\Facades\Log;
1718
use models\exceptions\EntityNotFoundException;
1819
use models\exceptions\ValidationException;
20+
use Symfony\Component\HttpFoundation\Response;
1921
use utils\PagingResponse;
2022
use Illuminate\Support\Facades\Request;
23+
use OpenApi\Attributes as OA;
24+
2125
/**
2226
* Class OAuth2SpeakerOrganizationalRoleApiController
2327
* @package App\Http\Controllers
@@ -40,6 +44,36 @@ public function __construct
4044
$this->repository = $repository;
4145
}
4246

47+
#[OA\Get(
48+
path: '/api/v1/speakers/organizational-roles',
49+
summary: 'Get all default speaker organizational roles',
50+
description: 'Retrieves a list of default organizational roles for speakers. These are predefined role types that speakers can select to describe their position or role within an organization (e.g., "Developer", "Manager", "Architect", "Executive").',
51+
operationId: 'getAllSpeakerOrganizationalRoles',
52+
security: [['speaker_organizational_role_oauth2' => [
53+
SummitScopes::ReadSummitData,
54+
SummitScopes::ReadAllSummitData
55+
]]],
56+
tags: ['Speakers'],
57+
parameters: [
58+
new OA\Parameter(
59+
name: 'expand',
60+
in: 'query',
61+
required: false,
62+
description: 'Comma-separated list of related resources to expand',
63+
schema: new OA\Schema(type: 'string', example: '')
64+
),
65+
],
66+
responses: [
67+
new OA\Response(
68+
response: 200,
69+
description: 'Organizational roles retrieved successfully',
70+
content: new OA\JsonContent(ref: '#/components/schemas/SpeakerOrganizationalRolesResponse')
71+
),
72+
new OA\Response(response: Response::HTTP_NOT_FOUND, description: "not found"),
73+
new OA\Response(response: Response::HTTP_PRECONDITION_FAILED, description: "Validation Error"),
74+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"),
75+
]
76+
)]
4377
/**
4478
* @return mixed
4579
*/
@@ -68,4 +102,4 @@ public function getAll()
68102
return $this->error500($ex);
69103
}
70104
}
71-
}
105+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace App\Swagger\schemas;
4+
5+
use App\Security\SummitScopes;
6+
use OpenApi\Attributes as OA;
7+
8+
9+
#[OA\SecurityScheme(
10+
type: 'oauth2',
11+
securityScheme: 'speaker_organizational_role_oauth2',
12+
flows: [
13+
new OA\Flow(
14+
authorizationUrl: L5_SWAGGER_CONST_AUTH_URL,
15+
tokenUrl: L5_SWAGGER_CONST_TOKEN_URL,
16+
flow: 'authorizationCode',
17+
scopes: [
18+
SummitScopes::ReadAllSummitData => 'Read All Summit Data',
19+
SummitScopes::ReadSummitData => 'Read Summit Data',
20+
],
21+
),
22+
],
23+
)
24+
]
25+
class SpeakerOrganizationalRoleAuthSchema{}

app/Swagger/SummitSpeakersSchemas.php

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use OpenApi\Attributes as OA;
66

7+
//
8+
79
#[OA\Schema(
810
schema: 'SpeakerActiveInvolvement',
911
type: 'object',
@@ -15,7 +17,9 @@
1517
new OA\Property(property: 'is_default', type: 'boolean', example: true),
1618
]
1719
)]
18-
class SpeakerActiveInvolvementSchema {}
20+
class SpeakerActiveInvolvementSchema
21+
{
22+
}
1923

2024
#[OA\Schema(
2125
schema: 'SpeakerActiveInvolvementsResponse',
@@ -32,4 +36,40 @@ class SpeakerActiveInvolvementSchema {}
3236
),
3337
]
3438
)]
35-
class SpeakerActiveInvolvementsResponseSchema {}
39+
class SpeakerActiveInvolvementsResponseSchema
40+
{
41+
}
42+
43+
#[OA\Schema(
44+
schema: 'SpeakerOrganizationalRole',
45+
type: 'object',
46+
properties: [
47+
new OA\Property(property: 'id', type: 'integer', example: 1),
48+
new OA\Property(property: 'created', type: 'integer', format: 'int64', example: 1633024800),
49+
new OA\Property(property: 'last_edited', type: 'integer', format: 'int64', example: 1633024800),
50+
new OA\Property(property: 'role', type: 'string', example: 'Developer'),
51+
new OA\Property(property: 'is_default', type: 'boolean', example: true),
52+
]
53+
)]
54+
class SpeakerOrganizationalRoleSchema
55+
{
56+
}
57+
58+
#[OA\Schema(
59+
schema: 'SpeakerOrganizationalRolesResponse',
60+
type: 'object',
61+
properties: [
62+
new OA\Property(property: 'total', type: 'integer', example: 8),
63+
new OA\Property(property: 'per_page', type: 'integer', example: 8),
64+
new OA\Property(property: 'current_page', type: 'integer', example: 1),
65+
new OA\Property(property: 'last_page', type: 'integer', example: 1),
66+
new OA\Property(
67+
property: 'data',
68+
type: 'array',
69+
items: new OA\Items(ref: '#/components/schemas/SpeakerOrganizationalRole')
70+
),
71+
]
72+
)]
73+
class SpeakerOrganizationalRolesResponseSchema
74+
{
75+
}

0 commit comments

Comments
 (0)