Skip to content

Commit

Permalink
feat(scopes): Add ex_app scope
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Jul 2, 2024
1 parent 69ff6d5 commit 48cb793
Show file tree
Hide file tree
Showing 5 changed files with 383 additions and 0 deletions.
3 changes: 3 additions & 0 deletions generate-spec
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ foreach ($parsedRoutes as $key => $value) {
$isDeprecated = Helpers::classMethodHasAnnotationOrAttribute($methodFunction, "deprecated");
$isIgnored = Helpers::classMethodHasAnnotationOrAttribute($methodFunction, "IgnoreOpenAPI");
$isPasswordConfirmation = Helpers::classMethodHasAnnotationOrAttribute($methodFunction, "PasswordConfirmationRequired");
$isExApp = Helpers::classMethodHasAnnotationOrAttribute($methodFunction, "ExAppRequired");
$scopes = Helpers::getOpenAPIAttributeScopes($classMethod, $routeName);

if ($isIgnored) {
Expand All @@ -469,6 +470,8 @@ foreach ($parsedRoutes as $key => $value) {
if (empty($scopes)) {
if (!empty($controllerScopes)) {
$scopes = $controllerScopes;
} elseif ($isExApp) {
$scopes = ['ex_app'];
} elseif ($isAdmin) {
$scopes = ['administration'];
} else {
Expand Down
3 changes: 3 additions & 0 deletions tests/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
['name' => 'AdminSettings#movedToSettingsTag', 'url' => '/api/{apiVersion}/moved-with-tag', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'AdminSettings#movedToSettingsTagUnnamed', 'url' => '/api/{apiVersion}/moved-with-unnamed-tag', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],

['name' => 'ExAppSettings#exAppScopeAttribute', 'url' => '/api/{apiVersion}/ex-app-attribute', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'ExAppSettings#exAppScopeOverride', 'url' => '/api/{apiVersion}/ex-app-override', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],

['name' => 'Federation#federationByController', 'url' => '/api/{apiVersion}/controller-scope', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Federation#movedToDefaultScope', 'url' => '/api/{apiVersion}/default-scope', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],

Expand Down
39 changes: 39 additions & 0 deletions tests/lib/Controller/ExAppSettingsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace OCA\Notifications\Controller;

use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\ExAppRequired;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;

class ExAppSettingsController extends OCSController {
/**
* Route is in ex_app scope because of the attribute
*
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>
*
* 200: Personal settings updated
*/
#[ExAppRequired]
public function exAppScopeAttribute(): DataResponse {
return new DataResponse();
}

/**
* Route is in ex_app scope because of the override
*
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>
*
* 200: Personal settings updated
*/
#[NoAdminRequired]
#[OpenAPI(OpenAPI::SCOPE_EX_APP)]
public function exAppScopeOverride(): DataResponse {
return new DataResponse();
}
}
195 changes: 195 additions & 0 deletions tests/openapi-ex_app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
{
"openapi": "3.0.3",
"info": {
"title": "notifications-ex_app",
"version": "0.0.1",
"description": "This app provides a backend and frontend for the notification API available in Nextcloud.",
"license": {
"name": "agpl"
}
},
"components": {
"securitySchemes": {
"basic_auth": {
"type": "http",
"scheme": "basic"
},
"bearer_auth": {
"type": "http",
"scheme": "bearer"
}
},
"schemas": {
"OCSMeta": {
"type": "object",
"required": [
"status",
"statuscode"
],
"properties": {
"status": {
"type": "string"
},
"statuscode": {
"type": "integer"
},
"message": {
"type": "string"
},
"totalitems": {
"type": "string"
},
"itemsperpage": {
"type": "string"
}
}
}
}
},
"paths": {
"/ocs/v2.php/apps/notifications/api/{apiVersion}/ex-app-attribute": {
"post": {
"operationId": "ex_app_settings-ex-app-scope-attribute",
"summary": "Route is in ex_app scope because of the attribute",
"description": "This endpoint requires admin access",
"tags": [
"ex_app_settings"
],
"security": [
{
"bearer_auth": []
},
{
"basic_auth": []
}
],
"parameters": [
{
"name": "apiVersion",
"in": "path",
"required": true,
"schema": {
"type": "string",
"enum": [
"v2"
],
"default": "v2"
}
},
{
"name": "OCS-APIRequest",
"in": "header",
"description": "Required to be true for the API request to pass",
"required": true,
"schema": {
"type": "boolean",
"default": true
}
}
],
"responses": {
"200": {
"description": "Personal settings updated",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {}
}
}
}
}
}
}
}
}
}
},
"/ocs/v2.php/apps/notifications/api/{apiVersion}/ex-app-override": {
"post": {
"operationId": "ex_app_settings-ex-app-scope-override",
"summary": "Route is in ex_app scope because of the override",
"tags": [
"ex_app_settings"
],
"security": [
{
"bearer_auth": []
},
{
"basic_auth": []
}
],
"parameters": [
{
"name": "apiVersion",
"in": "path",
"required": true,
"schema": {
"type": "string",
"enum": [
"v2"
],
"default": "v2"
}
},
{
"name": "OCS-APIRequest",
"in": "header",
"description": "Required to be true for the API request to pass",
"required": true,
"schema": {
"type": "boolean",
"default": true
}
}
],
"responses": {
"200": {
"description": "Personal settings updated",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {}
}
}
}
}
}
}
}
}
}
}
},
"tags": []
}
Loading

0 comments on commit 48cb793

Please sign in to comment.