Skip to content

Commit 119cfcc

Browse files
committed
Changing swagger annotator to skip deprecated routes (to remove duplicate operations).
1 parent 72e885b commit 119cfcc

3 files changed

Lines changed: 46 additions & 30 deletions

File tree

app/V1Module/router/RouterFactory.php

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ class RouterFactory
1818
{
1919
use Nette\StaticClass;
2020

21+
private static $strictMode = false;
22+
23+
public static function setStrictMode(bool $strict = true): void
24+
{
25+
self::$strictMode = $strict;
26+
}
27+
2128
/**
2229
* Create router with all routes for V1 module.
2330
* @return Router
@@ -177,26 +184,28 @@ private static function createExercisesRoutes(string $prefix): RouteList
177184
// special download route for file link by its key
178185
$router[] = new GetRoute("$prefix/<id>/file-download/<linkKey>", "UploadedFiles:downloadExerciseFileLinkByKey");
179186

180-
// deprecated routes for supplementary-files (replaced with `files`)
181-
$router[] = new GetRoute("$prefix/<id>/supplementary-files", "ExerciseFiles:getExerciseFiles");
182-
$router[] = new PostRoute("$prefix/<id>/supplementary-files", "ExerciseFiles:uploadExerciseFiles");
183-
$router[] = new DeleteRoute(
184-
"$prefix/<id>/supplementary-files/<fileId>",
185-
"ExerciseFiles:deleteExerciseFile"
186-
);
187-
$router[] = new GetRoute(
188-
"$prefix/<id>/supplementary-files/download-archive",
189-
"ExerciseFiles:downloadExerciseFilesArchive"
190-
);
191-
192-
// deprecated (will be removed with AttachmentFile entity, unified with exercise-files)
193-
$router[] = new GetRoute("$prefix/<id>/attachment-files", "ExerciseFiles:getAttachmentFiles");
194-
$router[] = new PostRoute("$prefix/<id>/attachment-files", "ExerciseFiles:uploadAttachmentFiles");
195-
$router[] = new DeleteRoute("$prefix/<id>/attachment-files/<fileId>", "ExerciseFiles:deleteAttachmentFile");
196-
$router[] = new GetRoute(
197-
"$prefix/<id>/attachment-files/download-archive",
198-
"ExerciseFiles:downloadAttachmentFilesArchive"
199-
);
187+
if (!self::$strictMode) {
188+
// deprecated routes for supplementary-files (replaced with `files`)
189+
$router[] = new GetRoute("$prefix/<id>/supplementary-files", "ExerciseFiles:getExerciseFiles");
190+
$router[] = new PostRoute("$prefix/<id>/supplementary-files", "ExerciseFiles:uploadExerciseFiles");
191+
$router[] = new DeleteRoute(
192+
"$prefix/<id>/supplementary-files/<fileId>",
193+
"ExerciseFiles:deleteExerciseFile"
194+
);
195+
$router[] = new GetRoute(
196+
"$prefix/<id>/supplementary-files/download-archive",
197+
"ExerciseFiles:downloadExerciseFilesArchive"
198+
);
199+
200+
// deprecated (will be removed with AttachmentFile entity, unified with exercise-files)
201+
$router[] = new GetRoute("$prefix/<id>/attachment-files", "ExerciseFiles:getAttachmentFiles");
202+
$router[] = new PostRoute("$prefix/<id>/attachment-files", "ExerciseFiles:uploadAttachmentFiles");
203+
$router[] = new DeleteRoute("$prefix/<id>/attachment-files/<fileId>", "ExerciseFiles:deleteAttachmentFile");
204+
$router[] = new GetRoute(
205+
"$prefix/<id>/attachment-files/download-archive",
206+
"ExerciseFiles:downloadAttachmentFilesArchive"
207+
);
208+
}
200209

201210
$router[] = new GetRoute("$prefix/<id>/tests", "ExercisesConfig:getTests");
202211
$router[] = new PostRoute("$prefix/<id>/tests", "ExercisesConfig:setTests");
@@ -483,8 +492,10 @@ private static function createUploadedFilesRoutes(string $prefix): RouteList
483492
$router[] = new GetRoute("$prefix/<id>/content", "UploadedFiles:content");
484493
$router[] = new GetRoute("$prefix/<id>/digest", "UploadedFiles:digest");
485494

486-
// deprecated (should be handled by generic download)
487-
$router[] = new GetRoute("$prefix/supplementary-file/<id>/download", "UploadedFiles:downloadExerciseFile");
495+
if (!self::$strictMode) {
496+
// deprecated (should be handled by generic download)
497+
$router[] = new GetRoute("$prefix/supplementary-file/<id>/download", "UploadedFiles:downloadExerciseFile");
498+
}
488499
return $router;
489500
}
490501

@@ -600,10 +611,12 @@ private static function createPipelinesRoutes(string $prefix): RouteList
600611
$router[] = new DeleteRoute("$prefix/<id>/exercise-files/<fileId>", "Pipelines:deleteExerciseFile");
601612
$router[] = new GetRoute("$prefix/<id>/exercises", "Pipelines:getPipelineExercises");
602613

603-
// deprecated routes for supplementary files
604-
$router[] = new GetRoute("$prefix/<id>/supplementary-files", "Pipelines:getExerciseFiles");
605-
$router[] = new PostRoute("$prefix/<id>/supplementary-files", "Pipelines:uploadExerciseFiles");
606-
$router[] = new DeleteRoute("$prefix/<id>/supplementary-files/<fileId>", "Pipelines:deleteExerciseFile");
614+
if (!self::$strictMode) {
615+
// deprecated routes for supplementary files
616+
$router[] = new GetRoute("$prefix/<id>/supplementary-files", "Pipelines:getExerciseFiles");
617+
$router[] = new PostRoute("$prefix/<id>/supplementary-files", "Pipelines:uploadExerciseFiles");
618+
$router[] = new DeleteRoute("$prefix/<id>/supplementary-files/<fileId>", "Pipelines:deleteExerciseFile");
619+
}
607620
return $router;
608621
}
609622

@@ -674,8 +687,10 @@ private static function createWorkerFilesRoutes(string $prefix): RouteList
674687
$router[] = new GetRoute("$prefix/exercise-file/<hash>", "WorkerFiles:downloadExerciseFile");
675688
$router[] = new PutRoute("$prefix/result/<type>/<id>", "WorkerFiles:uploadResultsFile");
676689

677-
// deprecated route for supplementary files
678-
$router[] = new GetRoute("$prefix/supplementary-file/<hash>", "WorkerFiles:downloadExerciseFile");
690+
if (!self::$strictMode) {
691+
// deprecated route for supplementary files
692+
$router[] = new GetRoute("$prefix/supplementary-file/<hash>", "WorkerFiles:downloadExerciseFile");
693+
}
679694
return $router;
680695
}
681696

app/helpers/Swagger/AnnotationHelper.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ public static function filterAnnotations(array $annotations, string $type)
470470
*/
471471
public static function getRoutesMetadata(): array
472472
{
473+
RouterFactory::setStrictMode(); // no deprecated (duplicate) routes
473474
$router = RouterFactory::createRouter();
474475

475476
// find all route object using a queue

recodex-api.spec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
%define short_name api
33
%define install_dir /opt/%{name}
44
%define version 2.21.0
5-
%define unmangled_version e9d22c1efcb382e27c45ddda6ebe6bcce552a46d
6-
%define release 1
5+
%define unmangled_version 72e885b67bbfaa7c680ee0b6b23845cc21eecd6d
6+
%define release 2
77

88
Summary: ReCodEx core API component
99
Name: %{name}

0 commit comments

Comments
 (0)