Skip to content

Commit 4f80fca

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

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

app/Http/Controllers/Apis/TimezonesApiController.php

Lines changed: 48 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,50 @@ 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(ref: '#/components/schemas/PaginatedTimezonesResponse')
66+
),
67+
new OA\Response(
68+
response: Response::HTTP_PRECONDITION_FAILED,
69+
description: 'Validation Error'
70+
),
71+
new OA\Response(
72+
response: Response::HTTP_INTERNAL_SERVER_ERROR,
73+
description: 'Server Error'
74+
),
75+
]
76+
)]
2977
public function getAll(){
3078
try {
3179
$timezones = \DateTimeZone::listIdentifiers();

app/Swagger/TimezonesSchemas.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
namespace App\Swagger\schemas;
3+
4+
use OpenApi\Attributes as OA;
5+
6+
#[OA\Schema(
7+
schema: 'PaginatedTimezonesResponse',
8+
allOf: [
9+
new OA\Schema(ref: '#/components/schemas/PaginateDataSchemaResponse'),
10+
new OA\Schema(
11+
type: 'object',
12+
properties: [
13+
new OA\Property(
14+
property: 'data',
15+
type: 'array',
16+
items: new OA\Items(type: 'string', example: 'America/New_York'),
17+
description: 'Array of timezone identifiers'
18+
)
19+
]
20+
)
21+
]
22+
)]
23+
class PaginatedTimezonesResponseSchema {}

0 commit comments

Comments
 (0)