Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Simplify OCS check #67

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions generate-spec
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,13 @@ if (count($parsedRoutes) == 0) {

$routes = [];
foreach ($parsedRoutes as $key => $value) {
if ($key != "routes" && $key != "ocs") {
$isOCS = $key === "ocs";
provokateurin marked this conversation as resolved.
Show resolved Hide resolved
$isIndex = $key === "routes";

if (!$isOCS && !$isIndex) {
continue;
}

foreach ($value as $route) {
$routeName = $route["name"];

Expand All @@ -253,10 +257,10 @@ foreach ($parsedRoutes as $key => $value) {
if (str_ends_with($url, "/")) {
$url = substr($url, 0, -1);
}
if ($key == "routes") {
if ($isIndex) {
$url = "/index.php" . $root . $url;
}
if ($key == "ocs") {
if ($isOCS) {
$url = "/ocs/v2.php" . $root . $url;
}

Expand Down Expand Up @@ -320,7 +324,6 @@ foreach ($parsedRoutes as $key => $value) {
}

$isCSRFRequired = !Helpers::classMethodHasAnnotationOrAttribute($methodFunction, "NoCSRFRequired");
$isOCS = $controllerClass->extends != "Controller" && $controllerClass->extends != "ApiController";
if ($isCSRFRequired && !$isOCS) {
Logger::debug($routeName, "Route ignored because of required CSRF in a non-OCS controller");
continue;
Expand Down