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

feat(generate-spec): Ignore index.php routes by default #192

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
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
20 changes: 11 additions & 9 deletions generate-spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,18 +463,11 @@
Logger::panic($routeName, 'Route is marked as ignore but also has other scopes');
}

if (in_array('ignore', $scopes, true)) {
if (count($scopes) === 1) {
Logger::debug($routeName, 'Route ignored because of OpenAPI attribute');
continue;
}

Logger::panic($routeName, 'Route is marked as ignore but also has other scopes');
}

if ($scopes === []) {
if ($controllerScopes !== []) {
$scopes = $controllerScopes;
} elseif (!$isOCS) {
$scopes = ['ignore'];
} elseif ($isExApp) {
$scopes = ['ex_app'];
} elseif ($isAdmin) {
Expand All @@ -484,6 +477,15 @@
}
}

if (in_array('ignore', $scopes, true)) {
if (count($scopes) === 1) {
Logger::debug($routeName, 'Route ignored because of OpenAPI attribute');
continue;
}

Logger::panic($routeName, 'Route is marked as ignore but also has other scopes');
}

$routeTags = Helpers::getOpenAPIAttributeTagsByScope($classMethod, $routeName, $tagName, reset($scopes));

if ($isOCS && !array_key_exists('OCSMeta', $schemas)) {
Expand Down
40 changes: 40 additions & 0 deletions tests/lib/Controller/PlainController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Notifications\Controller;

use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\Response;

class PlainController extends Controller {
#[NoCSRFRequired]
#[FrontpageRoute(verb: 'GET', url: '/plain/ignored')]
public function ignored(): Response {
return new Response();
}


/**
* Route with manual scope to not get ignored
*
* @return Response<Http::STATUS_OK, array{}>
*
* 200: Response returned
*/
#[NoCSRFRequired]
#[OpenAPI(scope: OpenAPI::SCOPE_DEFAULT)]
#[FrontpageRoute(verb: 'GET', url: '/plain/with-scope')]
public function withScope(): Response {
return new Response();
}
}
23 changes: 23 additions & 0 deletions tests/openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -5485,6 +5485,29 @@
}
}
},
"/index.php/apps/notifications/plain/with-scope": {
"get": {
"operationId": "plain-with-scope",
"summary": "Route with manual scope to not get ignored",
"description": "This endpoint requires admin access",
"tags": [
"plain"
],
"security": [
{
"bearer_auth": []
},
{
"basic_auth": []
}
],
"responses": {
"200": {
"description": "Response returned"
}
}
}
},
"/ocs/v2.php/apps/notifications/api/{apiVersion}/ex-app-attribute": {
"post": {
"operationId": "ex_app_settings-ex-app-scope-attribute",
Expand Down
23 changes: 23 additions & 0 deletions tests/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,29 @@
}
}
}
},
"/index.php/apps/notifications/plain/with-scope": {
"get": {
"operationId": "plain-with-scope",
"summary": "Route with manual scope to not get ignored",
"description": "This endpoint requires admin access",
"tags": [
"plain"
],
"security": [
{
"bearer_auth": []
},
{
"basic_auth": []
}
],
"responses": {
"200": {
"description": "Response returned"
}
}
}
}
},
"tags": []
Expand Down
Loading