Skip to content

Commit 0a43dbd

Browse files
Feature | Extend Swagger Coverage for controller OAuth2SummitPresentationActionTypeApiController (#392)
* feat: Extend Swagger Coverage for controller `OAuth2SummitPresentationActionTypeApiController` * chore: Add the security schema for the controller to its own file * chore: add description for complex expand models. Fix issues on params * chore: add operationId and fix namespace in security schema --------- Co-authored-by: Matias Perrone <github@matiasperrone.com>
1 parent 192344b commit 0a43dbd

3 files changed

Lines changed: 410 additions & 9 deletions

File tree

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

Lines changed: 321 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?php namespace App\Http\Controllers;
1+
<?php
2+
namespace App\Http\Controllers;
23
/**
34
* Copyright 2021 OpenStack Foundation
45
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,24 +14,27 @@
1314
**/
1415

1516
use App\Http\Utils\EpochCellFormatter;
17+
use App\Models\Foundation\Main\IGroup;
1618
use App\Models\Foundation\Summit\Repositories\IPresentationActionTypeRepository;
19+
use App\Security\SummitScopes;
1720
use App\Services\Model\ISummitPresentationActionTypeService;
21+
use Illuminate\Http\Response;
1822
use Illuminate\Support\Facades\Input;
1923
use models\exceptions\ValidationException;
2024
use models\oauth2\IResourceServerContext;
2125
use models\summit\ISummitRepository;
2226
use models\summit\Summit;
2327
use models\utils\IEntity;
2428
use ModelSerializers\SerializerRegistry;
29+
use OpenApi\Attributes as OA;
2530
use utils\Filter;
2631
use utils\FilterElement;
2732

2833
/**
2934
* Class OAuth2SummitPresentationActionTypeApiController
3035
* @package App\Http\Controllers
3136
*/
32-
final class OAuth2SummitPresentationActionTypeApiController
33-
extends OAuth2ProtectedController
37+
final class OAuth2SummitPresentationActionTypeApiController extends OAuth2ProtectedController
3438
{
3539
/**
3640
* @var ISummitRepository
@@ -55,8 +59,7 @@ public function __construct
5559
IPresentationActionTypeRepository $repository,
5660
ISummitRepository $summit_repository,
5761
IResourceServerContext $resource_server_context
58-
)
59-
{
62+
) {
6063
parent::__construct($resource_server_context);
6164
$this->repository = $repository;
6265
$this->summit_repository = $summit_repository;
@@ -84,7 +87,7 @@ protected function addChild(Summit $summit, array $payload): IEntity
8487
/**
8588
* @inheritDoc
8689
*/
87-
function getAddValidationRules(array $payload): array
90+
public function getAddValidationRules(array $payload): array
8891
{
8992
return SummitPresentationActionTypeValidationRulesFactory::build($payload, false);
9093
}
@@ -116,7 +119,7 @@ protected function getChildFromSummit(Summit $summit, $child_id): ?IEntity
116119
/**
117120
* @inheritDoc
118121
*/
119-
function getUpdateValidationRules(array $payload): array
122+
public function getUpdateValidationRules(array $payload): array
120123
{
121124
return SummitPresentationActionTypeValidationRulesFactory::build($payload, true);
122125
}
@@ -133,10 +136,259 @@ protected function updateChild(Summit $summit, int $child_id, array $payload): I
133136
* @param $summit_id
134137
* @return \Illuminate\Http\JsonResponse|mixed
135138
*/
139+
#[OA\Post(
140+
path: '/api/v1/summits/{id}/presentation-action-types',
141+
summary: 'Create a new presentation action type',
142+
operationId: 'createPresentationActionType',
143+
x: [
144+
'required-groups' => [
145+
IGroup::SuperAdmins,
146+
IGroup::Administrators,
147+
IGroup::SummitAdministrators,
148+
IGroup::TrackChairsAdmins,
149+
]
150+
],
151+
security: [
152+
[
153+
'presentation_action_types_oauth2' => [
154+
SummitScopes::WriteSummitData,
155+
]
156+
]
157+
],
158+
tags: ['Summits', 'Presentation Action Types'],
159+
parameters: [
160+
new OA\Parameter(name: 'id', in: 'path', required: true, description: 'Summit ID', schema: new OA\Schema(type: 'integer')),
161+
],
162+
requestBody: new OA\RequestBody(
163+
required: true,
164+
content: new OA\JsonContent(ref: '#/components/schemas/PresentationActionTypeCreateRequest')
165+
),
166+
responses: [
167+
new OA\Response(
168+
response: Response::HTTP_CREATED,
169+
description: 'Presentation action type created',
170+
content: new OA\JsonContent(ref: '#/components/schemas/PresentationActionType')
171+
),
172+
new OA\Response(response: Response::HTTP_BAD_REQUEST, description: "Bad Request"),
173+
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized"),
174+
new OA\Response(response: Response::HTTP_FORBIDDEN, description: "Forbidden"),
175+
new OA\Response(response: Response::HTTP_NOT_FOUND, description: "Not found"),
176+
new OA\Response(response: Response::HTTP_PRECONDITION_FAILED, description: "Validation Error"),
177+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"),
178+
]
179+
)]
180+
public function add($summit_id)
181+
{
182+
return parent::add($summit_id);
183+
}
184+
185+
/**
186+
* @param $summit_id
187+
* @param $action_id
188+
* @return \Illuminate\Http\JsonResponse|mixed
189+
*/
190+
#[OA\Get(
191+
path: '/api/v1/summits/{id}/presentation-action-types/{action_id}',
192+
summary: 'Get a presentation action type by ID',
193+
operationId: 'getPresentationActionType',
194+
x: [
195+
'required-groups' => [
196+
IGroup::SuperAdmins,
197+
IGroup::Administrators,
198+
IGroup::SummitAdministrators,
199+
IGroup::TrackChairsAdmins,
200+
]
201+
],
202+
security: [
203+
[
204+
'presentation_action_types_oauth2' => [
205+
SummitScopes::ReadAllSummitData,
206+
SummitScopes::ReadSummitData,
207+
]
208+
]
209+
],
210+
tags: ['Summits', 'Presentation Action Types'],
211+
parameters: [
212+
new OA\Parameter(name: 'id', in: 'path', required: true, description: 'Summit ID', schema: new OA\Schema(type: 'integer')),
213+
new OA\Parameter(name: 'action_id', in: 'path', required: true, description: 'Presentation Action Type ID', schema: new OA\Schema(type: 'integer')),
214+
],
215+
responses: [
216+
new OA\Response(
217+
response: Response::HTTP_OK,
218+
description: 'Successful response',
219+
content: new OA\JsonContent(ref: '#/components/schemas/PresentationActionType')
220+
),
221+
new OA\Response(response: Response::HTTP_BAD_REQUEST, description: "Bad Request"),
222+
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized"),
223+
new OA\Response(response: Response::HTTP_FORBIDDEN, description: "Forbidden"),
224+
new OA\Response(response: Response::HTTP_NOT_FOUND, description: "Not found"),
225+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"),
226+
]
227+
)]
228+
public function get($summit_id, $action_id)
229+
{
230+
return parent::get($summit_id, $action_id);
231+
}
232+
233+
/**
234+
* @param $summit_id
235+
* @param $action_id
236+
* @return \Illuminate\Http\JsonResponse|mixed
237+
*/
238+
#[OA\Put(
239+
path: '/api/v1/summits/{id}/presentation-action-types/{action_id}',
240+
summary: 'Update a presentation action type',
241+
operationId: 'updatePresentationActionType',
242+
x: [
243+
'required-groups' => [
244+
IGroup::SuperAdmins,
245+
IGroup::Administrators,
246+
IGroup::SummitAdministrators,
247+
IGroup::TrackChairsAdmins,
248+
]
249+
],
250+
security: [
251+
[
252+
'presentation_action_types_oauth2' => [
253+
SummitScopes::WriteSummitData,
254+
]
255+
]
256+
],
257+
tags: ['Summits', 'Presentation Action Types'],
258+
parameters: [
259+
new OA\Parameter(name: 'id', in: 'path', required: true, description: 'Summit ID', schema: new OA\Schema(type: 'integer')),
260+
new OA\Parameter(name: 'action_id', in: 'path', required: true, description: 'Presentation Action Type ID', schema: new OA\Schema(type: 'integer')),
261+
],
262+
requestBody: new OA\RequestBody(
263+
required: true,
264+
content: new OA\JsonContent(ref: '#/components/schemas/PresentationActionTypeUpdateRequest')
265+
),
266+
responses: [
267+
new OA\Response(
268+
response: Response::HTTP_OK,
269+
description: 'Presentation action type updated',
270+
content: new OA\JsonContent(ref: '#/components/schemas/PresentationActionType')
271+
),
272+
new OA\Response(response: Response::HTTP_BAD_REQUEST, description: "Bad Request"),
273+
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized"),
274+
new OA\Response(response: Response::HTTP_FORBIDDEN, description: "Forbidden"),
275+
new OA\Response(response: Response::HTTP_NOT_FOUND, description: "Not found"),
276+
new OA\Response(response: Response::HTTP_PRECONDITION_FAILED, description: "Validation Error"),
277+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"),
278+
]
279+
)]
280+
public function update($summit_id, $action_id)
281+
{
282+
return parent::update($summit_id, $action_id);
283+
}
284+
285+
/**
286+
* @param $summit_id
287+
* @param $action_id
288+
* @return \Illuminate\Http\JsonResponse|mixed
289+
*/
290+
#[OA\Delete(
291+
path: '/api/v1/summits/{id}/presentation-action-types/{action_id}',
292+
summary: 'Delete a presentation action type',
293+
operationId: 'deletePresentationActionType',
294+
x: [
295+
'required-groups' => [
296+
IGroup::SuperAdmins,
297+
IGroup::Administrators,
298+
IGroup::SummitAdministrators,
299+
IGroup::TrackChairsAdmins,
300+
]
301+
],
302+
security: [
303+
[
304+
'presentation_action_types_oauth2' => [
305+
SummitScopes::WriteSummitData,
306+
]
307+
]
308+
],
309+
tags: ['Summits', 'Presentation Action Types'],
310+
parameters: [
311+
new OA\Parameter(name: 'id', in: 'path', required: true, description: 'Summit ID', schema: new OA\Schema(type: 'integer')),
312+
new OA\Parameter(name: 'action_id', in: 'path', required: true, description: 'Presentation Action Type ID', schema: new OA\Schema(type: 'integer')),
313+
],
314+
responses: [
315+
new OA\Response(response: Response::HTTP_NO_CONTENT, description: "No Content"),
316+
new OA\Response(response: Response::HTTP_BAD_REQUEST, description: "Bad Request"),
317+
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized"),
318+
new OA\Response(response: Response::HTTP_FORBIDDEN, description: "Forbidden"),
319+
new OA\Response(response: Response::HTTP_NOT_FOUND, description: "Not found"),
320+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"),
321+
]
322+
)]
323+
public function delete($summit_id, $action_id)
324+
{
325+
return parent::delete($summit_id, $action_id);
326+
}
327+
328+
/**
329+
* @param $summit_id
330+
* @return \Illuminate\Http\JsonResponse|mixed
331+
*/
332+
#[OA\Get(
333+
path: '/api/v1/summits/{id}/presentation-action-types',
334+
summary: 'Get all presentation action types for a summit',
335+
operationId: 'getAllPresentationActionTypes',
336+
x: [
337+
'required-groups' => [
338+
IGroup::SuperAdmins,
339+
IGroup::Administrators,
340+
IGroup::SummitAdministrators,
341+
IGroup::TrackChairsAdmins,
342+
IGroup::TrackChairs,
343+
]
344+
],
345+
security: [
346+
[
347+
'presentation_action_types_oauth2' => [
348+
SummitScopes::ReadAllSummitData,
349+
SummitScopes::ReadSummitData,
350+
]
351+
]
352+
],
353+
tags: ['Summits', 'Presentation Action Types'],
354+
parameters: [
355+
new OA\Parameter(
356+
name: 'page',
357+
in: 'query',
358+
required: false,
359+
description: 'Page number for pagination',
360+
schema: new OA\Schema(type: 'integer', example: 1)
361+
),
362+
new OA\Parameter(
363+
name: 'per_page',
364+
in: 'query',
365+
required: false,
366+
description: 'Items per page',
367+
schema: new OA\Schema(type: 'integer', example: 10, maximum: 100)
368+
),
369+
new OA\Parameter(name: 'id', in: 'path', required: true, description: 'Summit ID', schema: new OA\Schema(type: 'integer')),
370+
new OA\Parameter(name: 'filter', in: 'query', description: 'Filter by label (label=@value, label==value)', schema: new OA\Schema(type: 'string')),
371+
new OA\Parameter(name: 'order', in: 'query', description: 'Order by: +/-id, +/-label, +/-order', schema: new OA\Schema(type: 'string')),
372+
new OA\Parameter(name: 'selection_plan_id', in: 'query', description: 'Filter by selection plan and include order field', schema: new OA\Schema(type: 'integer')),
373+
],
374+
responses: [
375+
new OA\Response(
376+
response: Response::HTTP_OK,
377+
description: 'Successful response',
378+
content: new OA\JsonContent(ref: '#/components/schemas/PaginatedPresentationActionTypesResponse')
379+
),
380+
new OA\Response(response: Response::HTTP_BAD_REQUEST, description: "Bad Request"),
381+
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized"),
382+
new OA\Response(response: Response::HTTP_FORBIDDEN, description: "Forbidden"),
383+
new OA\Response(response: Response::HTTP_NOT_FOUND, description: "Not found"),
384+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"),
385+
]
386+
)]
136387
public function getAllBySummit($summit_id)
137388
{
138389
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->getResourceServerContext())->find($summit_id);
139-
if (is_null($summit)) return $this->error404();
390+
if (is_null($summit))
391+
return $this->error404();
140392

141393
return $this->_getAll(
142394
function () {
@@ -178,10 +430,70 @@ function () {
178430
* @param $summit_id
179431
* @return \Illuminate\Http\JsonResponse|mixed
180432
*/
433+
#[OA\Get(
434+
path: '/api/v1/summits/{id}/presentation-action-types/csv',
435+
summary: 'Get all presentation action types for a summit in CSV format',
436+
operationId: 'getAllPresentationActionTypesCSV',
437+
x: [
438+
'required-groups' => [
439+
IGroup::SuperAdmins,
440+
IGroup::Administrators,
441+
IGroup::SummitAdministrators,
442+
IGroup::TrackChairsAdmins,
443+
]
444+
],
445+
security: [
446+
[
447+
'presentation_action_types_oauth2' => [
448+
SummitScopes::ReadAllSummitData,
449+
SummitScopes::ReadSummitData,
450+
]
451+
]
452+
],
453+
tags: ['Summits', 'Presentation Action Types'],
454+
parameters: [
455+
new OA\Parameter(
456+
name: 'page',
457+
in: 'query',
458+
required: false,
459+
description: 'Page number for pagination',
460+
schema: new OA\Schema(type: 'integer', example: 1)
461+
),
462+
new OA\Parameter(
463+
name: 'per_page',
464+
in: 'query',
465+
required: false,
466+
description: 'Items per page',
467+
schema: new OA\Schema(type: 'integer', example: 10, maximum: 100)
468+
),
469+
new OA\Parameter(name: 'id', in: 'path', required: true, description: 'Summit ID', schema: new OA\Schema(type: 'integer')),
470+
new OA\Parameter(name: 'filter', in: 'query', description: 'Filter by label (label=@value, label==value)', schema: new OA\Schema(type: 'string')),
471+
new OA\Parameter(name: 'order', in: 'query', description: 'Order by: +/-id, +/-label, +/-order', schema: new OA\Schema(type: 'string')),
472+
new OA\Parameter(name: 'selection_plan_id', in: 'query', description: 'Filter by selection plan and include order field', schema: new OA\Schema(type: 'integer')),
473+
new OA\Parameter(name: 'columns', in: 'query', description: 'Comma-separated list of columns (allowed: id, created, last_edited, label, order)', schema: new OA\Schema(type: 'string')),
474+
],
475+
responses: [
476+
new OA\Response(
477+
response: Response::HTTP_OK,
478+
description: 'CSV file',
479+
content: new OA\MediaType(
480+
mediaType: 'text/csv',
481+
schema: new OA\Schema(type: 'string', format: 'binary')
482+
)
483+
),
484+
new OA\Response(response: Response::HTTP_BAD_REQUEST, description: "Bad Request"),
485+
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized"),
486+
new OA\Response(response: Response::HTTP_FORBIDDEN, description: "Forbidden"),
487+
new OA\Response(response: Response::HTTP_NOT_FOUND, description: "Not found"),
488+
new OA\Response(response: Response::HTTP_PRECONDITION_FAILED, description: "Validation Error"),
489+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"),
490+
]
491+
)]
181492
public function getAllBySummitCSV($summit_id)
182493
{
183494
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->getResourceServerContext())->find($summit_id);
184-
if (is_null($summit)) return $this->error404();
495+
if (is_null($summit))
496+
return $this->error404();
185497

186498
return $this->_getAllCSV(
187499
function () {

0 commit comments

Comments
 (0)