Skip to content

Commit bfee209

Browse files
feat: Extend Swagger Coverage for controller TimezonesApiController
1 parent 09fc7e3 commit bfee209

2 files changed

Lines changed: 97 additions & 0 deletions

File tree

app/Http/Controllers/Apis/TimezonesApiController.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php namespace App\Http\Controllers;
2+
23
/**
34
* Copyright 2021 OpenStack Foundation
45
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,6 +18,9 @@
1718
use models\exceptions\EntityNotFoundException;
1819
use models\exceptions\ValidationException;
1920
use utils\PagingResponse;
21+
use OpenApi\Attributes as OA;
22+
use Symfony\Component\HttpFoundation\Response;
23+
2024
/**
2125
* Class TimezonesApiController
2226
* @package App\Http\Controllers
@@ -26,6 +30,80 @@ final class TimezonesApiController extends JsonController
2630
/**
2731
* @return mixed
2832
*/
33+
#[OA\Get(
34+
path: '/api/v1/timezones',
35+
operationId: 'getTimezones',
36+
description: 'Retrieve all available timezones',
37+
tags: ['Timezones'],
38+
parameters: [
39+
new OA\Parameter(
40+
name: 'expand',
41+
description: 'Expansion parameters',
42+
in: 'query',
43+
required: false,
44+
schema: new OA\Schema(type: 'string')
45+
),
46+
new OA\Parameter(
47+
name: 'page',
48+
description: 'Page number',
49+
in: 'query',
50+
required: false,
51+
schema: new OA\Schema(type: 'integer', default: 1)
52+
),
53+
new OA\Parameter(
54+
name: 'per_page',
55+
description: 'Items per page',
56+
in: 'query',
57+
required: false,
58+
schema: new OA\Schema(type: 'integer', default: 10)
59+
),
60+
],
61+
responses: [
62+
new OA\Response(
63+
response: Response::HTTP_OK,
64+
description: 'List of timezones',
65+
content: new OA\JsonContent(
66+
properties: [
67+
new OA\Property(
68+
property: 'data',
69+
type: 'array',
70+
items: new OA\Items(
71+
type: 'string',
72+
example: 'America/New_York'
73+
),
74+
description: 'Array of timezone identifiers'
75+
),
76+
new OA\Property(
77+
property: 'total',
78+
type: 'integer',
79+
description: 'Total number of timezones',
80+
example: 427
81+
),
82+
new OA\Property(
83+
property: 'page',
84+
type: 'integer',
85+
description: 'Current page number',
86+
example: 1
87+
),
88+
new OA\Property(
89+
property: 'last_page',
90+
type: 'integer',
91+
description: 'Last page number',
92+
example: 1
93+
),
94+
]
95+
)
96+
),
97+
new OA\Response(
98+
response: Response::HTTP_PRECONDITION_FAILED,
99+
description: 'Validation Error'
100+
),
101+
new OA\Response(
102+
response: Response::HTTP_INTERNAL_SERVER_ERROR,
103+
description: 'Server Error'
104+
),
105+
]
106+
)]
29107
public function getAll(){
30108
try {
31109
$timezones = \DateTimeZone::listIdentifiers();

app/Swagger/schemas.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,3 +351,22 @@ class RSVPUpdateRequestSchema_{
351351
]
352352
)]
353353
class RSVPAdminAddRequestSchema {}
354+
355+
#[OA\Schema(
356+
schema: 'PaginatedTimezonesResponse',
357+
allOf: [
358+
new OA\Schema(ref: '#/components/schemas/PaginateDataSchemaResponse'),
359+
new OA\Schema(
360+
type: 'object',
361+
properties: [
362+
new OA\Property(
363+
property: 'data',
364+
type: 'array',
365+
items: new OA\Items(type: 'string', example: 'America/New_York'),
366+
description: 'Array of timezone identifiers'
367+
)
368+
]
369+
)
370+
]
371+
)]
372+
class PaginatedTimezonesResponseSchema {}

0 commit comments

Comments
 (0)