Skip to content

Commit cba8aee

Browse files
matiasperrone-exomatiasperrone
authored andcommitted
feat: Extend Swagger Coverage for controller UploadController
1 parent ca920e2 commit cba8aee

2 files changed

Lines changed: 62 additions & 10 deletions

File tree

app/Http/Controllers/Apis/Protected/Main/UploadController.php

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
* See the License for the specific language governing permissions and
1212
* limitations under the License.
1313
**/
14+
use Illuminate\Http\Response;
1415
use Illuminate\Routing\Controller as BaseController;
1516
use Illuminate\Http\JsonResponse;
1617
use Illuminate\Support\Facades\Config;
18+
use OpenApi\Attributes as OA;
1719
use Pion\Laravel\ChunkUpload\Exceptions\UploadFailedException;
1820
use Illuminate\Support\Facades\Storage;
1921
use Illuminate\Http\Request;
@@ -28,16 +30,45 @@
2830
*/
2931
class UploadController extends BaseController
3032
{
31-
/**
32-
* Handles the file upload
33-
*
34-
* @param Request $request
35-
*
36-
* @return JsonResponse
37-
*
38-
* @throws UploadMissingFileException
39-
* @throws UploadFailedException
40-
*/
33+
#[OA\Post(
34+
path: '/api/v1/files/upload',
35+
summary: 'Upload file with chunked support',
36+
description: 'Handles file uploads with support for chunked uploads. Returns file metadata on completion or upload progress for chunks.',
37+
security: [['bearer' => []]],
38+
tags: ['files'],
39+
requestBody: new OA\RequestBody(
40+
required: true,
41+
content: new OA\MediaType(
42+
mediaType: 'multipart/form-data',
43+
schema: new OA\Schema(
44+
required: ['file'],
45+
properties: [
46+
new OA\Property(
47+
property: 'file',
48+
type: 'string',
49+
format: 'binary',
50+
description: 'File to upload'
51+
),
52+
]
53+
)
54+
)
55+
),
56+
responses: [
57+
new OA\Response(
58+
response: Response::HTTP_OK,
59+
description: 'File uploaded successfully or chunk progress',
60+
content: new OA\JsonContent(
61+
oneOf: [
62+
new OA\Schema(ref: '#/components/schemas/FileUploadCompleteResponse'),
63+
new OA\Schema(ref: '#/components/schemas/FileUploadProgressResponse'),
64+
]
65+
)
66+
),
67+
new OA\Response(response: Response::HTTP_BAD_REQUEST, description: 'Bad Request'),
68+
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: 'Unauthorized'),
69+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: 'Server Error'),
70+
]
71+
)]
4172
public function upload(Request $request) {
4273
// create the file receiver
4374
$receiver = new FileReceiver("file", $request, HandlerFactory::classFromRequest($request));

app/Swagger/schemas.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,3 +599,24 @@ class PaymentGatewayProfileUpdateRequestSchema
599599
]
600600
)]
601601
class PaginatedUserStoriesResponseSchema {}
602+
603+
#[OA\Schema(
604+
schema: 'FileUploadCompleteResponse',
605+
type: 'object',
606+
properties: [
607+
new OA\Property(property: 'path', type: 'string', example: 'upload/application-pdf/2025-10-24/', description: 'File path'),
608+
new OA\Property(property: 'name', type: 'string', example: 'document_abc123def456.pdf', description: 'Generated filename'),
609+
new OA\Property(property: 'mime_type', type: 'string', example: 'application-pdf', description: 'MIME type (normalized with dashes)'),
610+
]
611+
)]
612+
class FileUploadCompleteResponseSchema {}
613+
614+
#[OA\Schema(
615+
schema: 'FileUploadProgressResponse',
616+
type: 'object',
617+
properties: [
618+
new OA\Property(property: 'done', type: 'number', format: 'float', example: 45.5, description: 'Upload progress percentage'),
619+
new OA\Property(property: 'status', type: 'boolean', example: true, description: 'Upload status'),
620+
]
621+
)]
622+
class FileUploadProgressResponseSchema {}

0 commit comments

Comments
 (0)