Skip to content
Closed
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
41 changes: 41 additions & 0 deletions lib/private/Route/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@
*/
namespace OC\Route;

use OCP\IConfig;
use OCP\Route\IRoute;
use OCP\Server;
use Symfony\Component\Routing\Route as SymfonyRoute;
use function OCP\Log\logger;

class Route extends SymfonyRoute implements IRoute {
/**
Expand Down Expand Up @@ -119,9 +122,47 @@ public function requirements($requirements) {
if ($method) {
$this->method($method);
}

if (\OC::$server->get(IConfig::class)->getSystemValueBool('debug')) {
$this->requirementOpenAPIValidator();
}

return $this;
}

protected function requirementOpenAPIValidator(): void {
foreach ($this->getRequirements() as $parameter => $requirement) {
if (str_starts_with($requirement, '^')) {
$this->logOpenAPIHelp('Starts with ^', $parameter, $requirement);
return;
}
if (str_ends_with($requirement, '$')) {
$this->logOpenAPIHelp('Ends with $', $parameter, $requirement);
return;
}
if (!str_starts_with($requirement, '[') && strpos($requirement, '[') > 0) {
$this->logOpenAPIHelp('Regex not full string', $parameter, $requirement);
return;
}
if (!str_starts_with($requirement, '\\') && strpos($requirement, '\\') > 0) {
$this->logOpenAPIHelp('Regex not full string', $parameter, $requirement);
return;
}
if (!str_starts_with($requirement, '(') && strpos($requirement, '(') > 0) {
$this->logOpenAPIHelp('Regex not full string', $parameter, $requirement);
return;
}
if (str_starts_with($requirement, '(') && !str_ends_with($requirement, ')')) {
$this->logOpenAPIHelp('Regex not full string', $parameter, $requirement);
return;
}
}
}

protected function logOpenAPIHelp(string $violation, string $parameter, string $requirement): void {
logger()->debug('Requirements for route ' . json_encode($this->getMethods()) . ' ' . $this->getPath() . ' is not compatible with OpenAPI export: "' . $parameter . '" - ' . $violation. ': "' . $requirement . '"');
}

/**
* The action to execute when this route matches
*
Expand Down