Skip to content

Commit 83f563b

Browse files
matiasperrone-exosmarcetmatiasperrone
authored
Feature | Extend Swagger Coverage for controller OAuth2ChunkedFilesApiController (#366)
* fix: improve ticket csv serializer performance fix: improve ticket repository performance remove not needed extra joins fix: set fetchJoinCollection to false for ticket repo fix: get always owner to avoid N+1 on ticket repository fix: improve get tickets generic pagination * chore: refactor DoctrineSummitEventRepository to suppport 2 phase paging chore: fix .gitmessage.txt chore: increase header size to 150 * feat: Add OpenAPI documentation to "getAll" method - Add controller's response to OpenAPI schema * chore: Add schemas to the main file * fix: conflicts issue with main * chore: Revert to main version due to conflicts with rebase * chore: Create a schema for request body validation --------- Co-authored-by: smarcet <smarcet@gmail.com> Co-authored-by: Matias Perrone <github@matiasperrone.com>
1 parent 2dc8cf0 commit 83f563b

File tree

2 files changed

+87
-2
lines changed

2 files changed

+87
-2
lines changed

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

Lines changed: 34 additions & 2 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 2020 OpenStack Foundation
45
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,8 +13,10 @@
1213
* limitations under the License.
1314
**/
1415
use Illuminate\Http\JsonResponse;
16+
use Illuminate\Http\Response;
1517
use Illuminate\Http\UploadedFile;
1618
use Illuminate\Support\Facades\Storage;
19+
use OpenApi\Attributes as OA;
1720
use Pion\Laravel\ChunkUpload\Exceptions\UploadMissingFileException;
1821
use Pion\Laravel\ChunkUpload\Handler\AbstractHandler;
1922
use Pion\Laravel\ChunkUpload\Receiver\FileReceiver;
@@ -33,6 +36,35 @@ class OAuth2ChunkedFilesApiController extends UploadController
3336
* @throws UploadMissingFileException
3437
*
3538
*/
39+
#[OA\Post(
40+
path: "/api/public/v1/files/upload",
41+
description: "Upload files using chunked upload mechanism. Supports large file uploads by splitting them into smaller chunks. The endpoint handles both complete uploads and chunked progress updates.",
42+
summary: 'Upload file with chunked upload support',
43+
operationId: 'uploadChunkedFile',
44+
tags: ['Files'],
45+
requestBody: new OA\RequestBody(
46+
required: true,
47+
content: new OA\MediaType(
48+
mediaType: 'multipart/form-data',
49+
schema: new OA\Schema(ref: '#/components/schemas/ChunkedFileUploadRequest')
50+
)
51+
),
52+
responses: [
53+
new OA\Response(
54+
response: 200,
55+
description: 'Success - Upload in progress (chunk uploaded)',
56+
content: new OA\JsonContent(ref: '#/components/schemas/ChunkedFileUploadProgressResponse')
57+
),
58+
new OA\Response(
59+
response: 201,
60+
description: 'Success - Upload complete (all chunks received)',
61+
content: new OA\JsonContent(ref: '#/components/schemas/ChunkedFileUploadCompleteResponse')
62+
),
63+
new OA\Response(response: Response::HTTP_BAD_REQUEST, description: "Bad Request - Invalid file or missing parameters"),
64+
new OA\Response(response: Response::HTTP_UNPROCESSABLE_ENTITY, description: "Unprocessable Entity - Upload missing file exception"),
65+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error - Upload failed")
66+
]
67+
)]
3668
public function uploadFile(FileReceiver $receiver)
3769
{
3870
// check if the upload is success, throw exception or return response you need
@@ -57,4 +89,4 @@ public function uploadFile(FileReceiver $receiver)
5789
]);
5890
}
5991

60-
}
92+
}

app/Swagger/schemas.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,56 @@ class RSVPUpdateRequestSchema_{
350350
]
351351
)]
352352
class RSVPAdminAddRequestSchema {}
353+
354+
#[OA\Schema(
355+
schema: 'ChunkedFileUploadProgressResponse',
356+
type: 'object',
357+
properties: [
358+
new OA\Property(property: 'done', type: 'number', format: 'float', example: 45.5, description: 'Upload progress percentage (0-100)'),
359+
]
360+
)]
361+
class ChunkedFileUploadProgressResponseSchema {}
362+
363+
#[OA\Schema(
364+
schema: 'ChunkedFileUploadCompleteResponse',
365+
type: 'object',
366+
properties: [
367+
new OA\Property(property: 'path', type: 'string', example: 'upload/image-jpeg/2025-09-30/', description: 'Directory path where the file was saved'),
368+
new OA\Property(property: 'name', type: 'string', example: 'myfile_abc123def456.jpg', description: 'Generated filename with timestamp hash'),
369+
new OA\Property(property: 'mime_type', type: 'string', example: 'image-jpeg', description: 'MIME type of the uploaded file (slashes replaced with hyphens)'),
370+
]
371+
)]
372+
class ChunkedFileUploadCompleteResponseSchema {}
373+
374+
#[OA\Schema(
375+
schema: 'ChunkedFileUploadRequest',
376+
type: 'object',
377+
required: ['file'],
378+
properties: [
379+
new OA\Property(
380+
property: 'file',
381+
type: 'string',
382+
format: 'binary',
383+
description: 'File to upload (can be a chunk of a larger file)'
384+
),
385+
new OA\Property(
386+
property: 'resumableChunkNumber',
387+
type: 'integer',
388+
description: 'Current chunk number (for resumable.js library)',
389+
example: 1
390+
),
391+
new OA\Property(
392+
property: 'resumableTotalChunks',
393+
type: 'integer',
394+
description: 'Total number of chunks (for resumable.js library)',
395+
example: 5
396+
),
397+
new OA\Property(
398+
property: 'resumableIdentifier',
399+
type: 'string',
400+
description: 'Unique identifier for the file upload session (for resumable.js library)',
401+
example: '12345-myfile-jpg'
402+
),
403+
]
404+
)]
405+
class ChunkedFileUploadRequestSchema {}

0 commit comments

Comments
 (0)