Skip to content

Commit b18eede

Browse files
Feature | Extend Swagger Coverage for controller OAuth2SummitMetricsApiController (#414)
* feat: Extend Swagger Coverage for controller `OAuth2SummitMetricsApiController` * chore: Add the correct security and x attributes and create security schema, fix path routes and change schema to be defined as requested * feat: Add changes requested --------- Co-authored-by: Matias Perrone <github@matiasperrone.com>
1 parent bd563c4 commit b18eede

File tree

3 files changed

+422
-2
lines changed

3 files changed

+422
-2
lines changed

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

Lines changed: 294 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@
1212
* limitations under the License.
1313
**/
1414

15+
use App\Models\Foundation\Main\IGroup;
1516
use App\ModelSerializers\SerializerUtils;
1617
use App\Rules\Boolean;
18+
use App\Security\SummitScopes;
1719
use App\Services\Model\ISummitMetricService;
20+
use Illuminate\Http\Response;
1821
use models\main\IMemberRepository;
1922
use models\oauth2\IResourceServerContext;
2023
use models\summit\ISummitMetricType;
2124
use models\summit\ISummitRepository;
2225
use ModelSerializers\SerializerRegistry;
26+
use OpenApi\Attributes as OA;
2327

2428
/**
2529
* Class OAuth2SummitMetricsApiController
@@ -68,6 +72,42 @@ public function __construct
6872
* @param $event_id
6973
* @return mixed
7074
*/
75+
#[OA\Put(
76+
path: "/api/v1/summits/{id}/metrics/enter",
77+
operationId: 'enter',
78+
summary: "Record a metric entry (enter)",
79+
security: [["summit_metrics_oauth2" => [SummitScopes::EnterEvent, SummitScopes::WriteMetrics]]],
80+
tags: ["Summit Metrics"],
81+
parameters: [
82+
new OA\Parameter(
83+
name: "id",
84+
in: "path",
85+
required: true,
86+
schema: new OA\Schema(type: "integer"),
87+
description: "The summit id"
88+
)
89+
],
90+
requestBody: new OA\RequestBody(
91+
required: true,
92+
content: new OA\MediaType(
93+
mediaType: "application/json",
94+
schema: new OA\Schema(ref: "#/components/schemas/SummitMetricEnterRequest")
95+
)
96+
),
97+
responses: [
98+
new OA\Response(
99+
response: 200,
100+
description: "OK",
101+
content: new OA\JsonContent(ref: "#/components/schemas/SummitMetric")
102+
),
103+
new OA\Response(response: Response::HTTP_BAD_REQUEST, description: "Bad Request"),
104+
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized"),
105+
new OA\Response(response: Response::HTTP_FORBIDDEN, description: "Forbidden"),
106+
new OA\Response(response: Response::HTTP_NOT_FOUND, description: "Not Found"),
107+
new OA\Response(response: Response::HTTP_PRECONDITION_FAILED, description: "Validation Error"),
108+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error")
109+
]
110+
)]
71111
public function enter($summit_id)
72112
{
73113
return $this->processRequest(function () use ($summit_id) {
@@ -101,6 +141,42 @@ public function enter($summit_id)
101141
* @param $event_id
102142
* @return mixed
103143
*/
144+
#[OA\Post(
145+
path: "/api/v1/summits/{id}/metrics/leave",
146+
operationId: 'leave',
147+
summary: "Record a metric exit (leave)",
148+
security: [["summit_metrics_oauth2" => [SummitScopes::LeaveEvent, SummitScopes::WriteMetrics]]],
149+
tags: ["Summit Metrics"],
150+
parameters: [
151+
new OA\Parameter(
152+
name: "id",
153+
in: "path",
154+
required: true,
155+
schema: new OA\Schema(type: "integer"),
156+
description: "The summit id"
157+
)
158+
],
159+
requestBody: new OA\RequestBody(
160+
required: true,
161+
content: new OA\MediaType(
162+
mediaType: "application/json",
163+
schema: new OA\Schema(ref: "#/components/schemas/SummitMetricLeaveRequest")
164+
)
165+
),
166+
responses: [
167+
new OA\Response(
168+
response: 200,
169+
description: "OK",
170+
content: new OA\JsonContent(ref: "#/components/schemas/SummitMetric")
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+
)]
104180
public function leave($summit_id)
105181
{
106182
return $this->processRequest(function () use ($summit_id) {
@@ -134,6 +210,49 @@ public function leave($summit_id)
134210
* @param $event_id
135211
* @return mixed
136212
*/
213+
#[OA\Put(
214+
path: "/api/v1/summits/{id}/members/{member_id}/schedule/{event_id}/enter",
215+
operationId: 'enterToEvent',
216+
summary: "Record a metric entry to a specific event",
217+
security: [["summit_metrics_oauth2" => [SummitScopes::EnterEvent]]],
218+
tags: ["Summit Metrics"],
219+
parameters: [
220+
new OA\Parameter(
221+
name: "id",
222+
in: "path",
223+
required: true,
224+
schema: new OA\Schema(type: "integer"),
225+
description: "The summit id"
226+
),
227+
new OA\Parameter(
228+
name: "member_id",
229+
in: "path",
230+
required: true,
231+
schema: new OA\Schema(type: "string", enum: ["me"]),
232+
description: "The member id (must be 'me')"
233+
),
234+
new OA\Parameter(
235+
name: "event_id",
236+
in: "path",
237+
required: true,
238+
schema: new OA\Schema(type: "integer"),
239+
description: "The event id"
240+
)
241+
],
242+
responses: [
243+
new OA\Response(
244+
response: 200,
245+
description: "OK",
246+
content: new OA\JsonContent(ref: "#/components/schemas/SummitMetric")
247+
),
248+
new OA\Response(response: Response::HTTP_BAD_REQUEST, description: "Bad Request"),
249+
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized"),
250+
new OA\Response(response: Response::HTTP_FORBIDDEN, description: "Forbidden"),
251+
new OA\Response(response: Response::HTTP_NOT_FOUND, description: "Not Found"),
252+
new OA\Response(response: Response::HTTP_PRECONDITION_FAILED, description: "Validation Error"),
253+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error")
254+
]
255+
)]
137256
public function enterToEvent($summit_id, $member_id, $event_id)
138257
{
139258
return $this->processRequest(function () use ($summit_id, $member_id, $event_id) {
@@ -162,6 +281,49 @@ public function enterToEvent($summit_id, $member_id, $event_id)
162281
* @param $event_id
163282
* @return mixed
164283
*/
284+
#[OA\Post(
285+
path: "/api/v1/summits/{id}/members/{member_id}/schedule/{event_id}/leave",
286+
operationId: 'leaveFromEvent',
287+
summary: "Record a metric exit from a specific event",
288+
security: [["summit_metrics_oauth2" => [SummitScopes::LeaveEvent]]],
289+
tags: ["Summit Metrics"],
290+
parameters: [
291+
new OA\Parameter(
292+
name: "id",
293+
in: "path",
294+
required: true,
295+
schema: new OA\Schema(type: "integer"),
296+
description: "The summit id"
297+
),
298+
new OA\Parameter(
299+
name: "member_id",
300+
in: "path",
301+
required: true,
302+
schema: new OA\Schema(type: "string", enum: ["me"]),
303+
description: "The member id (must be 'me')"
304+
),
305+
new OA\Parameter(
306+
name: "event_id",
307+
in: "path",
308+
required: true,
309+
schema: new OA\Schema(type: "integer"),
310+
description: "The event id"
311+
)
312+
],
313+
responses: [
314+
new OA\Response(
315+
response: 200,
316+
description: "OK",
317+
content: new OA\JsonContent(ref: "#/components/schemas/SummitMetric")
318+
),
319+
new OA\Response(response: Response::HTTP_BAD_REQUEST, description: "Bad Request"),
320+
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized"),
321+
new OA\Response(response: Response::HTTP_FORBIDDEN, description: "Forbidden"),
322+
new OA\Response(response: Response::HTTP_NOT_FOUND, description: "Not Found"),
323+
new OA\Response(response: Response::HTTP_PRECONDITION_FAILED, description: "Validation Error"),
324+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error")
325+
]
326+
)]
165327
public function leaveFromEvent($summit_id, $member_id, $event_id)
166328
{
167329
return $this->processRequest(function () use ($summit_id, $member_id, $event_id) {
@@ -184,6 +346,45 @@ public function leaveFromEvent($summit_id, $member_id, $event_id)
184346
});
185347
}
186348

349+
#[OA\Put(
350+
path: "/api/v1/summits/{id}/metrics/onsite/enter",
351+
operationId: 'onSiteEnter',
352+
summary: "Record an on-site metric entry (for attendees entering venue/room)",
353+
security: [["summit_metrics_oauth2" => [SummitScopes::WriteMetrics]]],
354+
tags: ["Summit Metrics"],
355+
x: [
356+
"required-groups" => [IGroup::SummitAccessControl]
357+
],
358+
parameters: [
359+
new OA\Parameter(
360+
name: "id",
361+
in: "path",
362+
required: true,
363+
schema: new OA\Schema(type: "integer"),
364+
description: "The summit id"
365+
)
366+
],
367+
requestBody: new OA\RequestBody(
368+
required: true,
369+
content: new OA\MediaType(
370+
mediaType: "application/json",
371+
schema: new OA\Schema(ref: "#/components/schemas/SummitMetricOnSiteEnterRequest")
372+
)
373+
),
374+
responses: [
375+
new OA\Response(
376+
response: 200,
377+
description: "OK",
378+
content: new OA\JsonContent(ref: "#/components/schemas/SummitMetric")
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_PRECONDITION_FAILED, description: "Validation Error"),
385+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error")
386+
]
387+
)]
187388
public function onSiteEnter($summit_id)
188389
{
189390
return $this->processRequest(function () use ($summit_id) {
@@ -213,7 +414,59 @@ public function onSiteEnter($summit_id)
213414
});
214415
}
215416

216-
417+
#[OA\Get(
418+
path: "/api/v1/summits/{id}/metrics/onsite/enter",
419+
operationId: 'checkOnSiteEnter',
420+
summary: "Check if on-site entry is allowed for an attendee (validation only, does not record entry)",
421+
security: [["summit_metrics_oauth2" => [SummitScopes::ReadAllSummitData, SummitScopes::ReadSummitData, SummitScopes::ReadMetrics]]],
422+
tags: ["Summit Metrics"],
423+
x: [
424+
"required-groups" => [IGroup::SummitAccessControl]
425+
],
426+
parameters: [
427+
new OA\Parameter(
428+
name: "id",
429+
in: "path",
430+
required: true,
431+
schema: new OA\Schema(type: "integer"),
432+
description: "The summit id"
433+
),
434+
new OA\Parameter(
435+
name: "attendee_id",
436+
in: "query",
437+
required: true,
438+
schema: new OA\Schema(type: "integer"),
439+
description: "The attendee id"
440+
),
441+
new OA\Parameter(
442+
name: "room_id",
443+
in: "query",
444+
required: false,
445+
schema: new OA\Schema(type: "integer"),
446+
description: "The room id"
447+
),
448+
new OA\Parameter(
449+
name: "event_id",
450+
in: "query",
451+
required: false,
452+
schema: new OA\Schema(type: "integer"),
453+
description: "The event id"
454+
)
455+
],
456+
responses: [
457+
new OA\Response(
458+
response: 200,
459+
description: "OK",
460+
content: new OA\JsonContent(ref: "#/components/schemas/SummitMetric")
461+
),
462+
new OA\Response(response: Response::HTTP_BAD_REQUEST, description: "Bad Request"),
463+
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized"),
464+
new OA\Response(response: Response::HTTP_FORBIDDEN, description: "Forbidden"),
465+
new OA\Response(response: Response::HTTP_NOT_FOUND, description: "Not Found"),
466+
new OA\Response(response: Response::HTTP_PRECONDITION_FAILED, description: "Validation Error"),
467+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error")
468+
]
469+
)]
217470
public function checkOnSiteEnter($summit_id)
218471
{
219472
return $this->processRequest(function () use ($summit_id) {
@@ -240,6 +493,45 @@ public function checkOnSiteEnter($summit_id)
240493
});
241494
}
242495

496+
#[OA\Post(
497+
path: "/api/v1/summits/{id}/metrics/onsite/leave",
498+
operationId: 'onSiteLeave',
499+
summary: "Record an on-site metric exit (for attendees leaving venue/room)",
500+
security: [["summit_metrics_oauth2" => [SummitScopes::WriteMetrics]]],
501+
tags: ["Summit Metrics"],
502+
x: [
503+
"required-groups" => [IGroup::SummitAccessControl]
504+
],
505+
parameters: [
506+
new OA\Parameter(
507+
name: "id",
508+
in: "path",
509+
required: true,
510+
schema: new OA\Schema(type: "integer"),
511+
description: "The summit id"
512+
)
513+
],
514+
requestBody: new OA\RequestBody(
515+
required: true,
516+
content: new OA\MediaType(
517+
mediaType: "application/json",
518+
schema: new OA\Schema(ref: "#/components/schemas/SummitMetricOnSiteLeaveRequest")
519+
)
520+
),
521+
responses: [
522+
new OA\Response(
523+
response: 200,
524+
description: "OK",
525+
content: new OA\JsonContent(ref: "#/components/schemas/SummitMetric")
526+
),
527+
new OA\Response(response: Response::HTTP_BAD_REQUEST, description: "Bad Request"),
528+
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized"),
529+
new OA\Response(response: Response::HTTP_FORBIDDEN, description: "Forbidden"),
530+
new OA\Response(response: Response::HTTP_NOT_FOUND, description: "Not Found"),
531+
new OA\Response(response: Response::HTTP_PRECONDITION_FAILED, description: "Validation Error"),
532+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error")
533+
]
534+
)]
243535
public function onSiteLeave($summit_id)
244536
{
245537
return $this->processRequest(function () use ($summit_id) {
@@ -265,4 +557,4 @@ public function onSiteLeave($summit_id)
265557
));
266558
});
267559
}
268-
}
560+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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: 'summit_metrics_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::EnterEvent => 'Enter Event',
19+
SummitScopes::LeaveEvent => 'Leave Event',
20+
SummitScopes::WriteMetrics => 'Write Metrics',
21+
SummitScopes::ReadMetrics => 'Read Metrics',
22+
SummitScopes::ReadAllSummitData => 'Read All Summit Data',
23+
SummitScopes::ReadSummitData => 'Read Summit Data',
24+
],
25+
),
26+
],
27+
)
28+
]
29+
class SummitMetricsAuthSchema {}

0 commit comments

Comments
 (0)