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: Add comment about password confirmation required #87

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 2 additions & 1 deletion generate-spec
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ foreach ($parsedRoutes as $key => $value) {
$isAdmin = !Helpers::classMethodHasAnnotationOrAttribute($methodFunction, "NoAdminRequired") && !$isPublic;
$isDeprecated = Helpers::classMethodHasAnnotationOrAttribute($methodFunction, "deprecated");
$isIgnored = Helpers::classMethodHasAnnotationOrAttribute($methodFunction, "IgnoreOpenAPI");
$isPasswordConfirmation = Helpers::classMethodHasAnnotationOrAttribute($methodFunction, "PasswordConfirmationRequired");
$scopes = Helpers::getOpenAPIAttributeScopes($classMethod, $routeName);

if ($isIgnored) {
Expand Down Expand Up @@ -413,7 +414,7 @@ foreach ($parsedRoutes as $key => $value) {
];
}

$classMethodInfo = ControllerMethod::parse($routeName, $definitions, $methodFunction, $isAdmin, $isDeprecated);
$classMethodInfo = ControllerMethod::parse($routeName, $definitions, $methodFunction, $isAdmin, $isPasswordConfirmation, $isDeprecated);
if (count($classMethodInfo->returns) > 0) {
Logger::error($routeName, "Returns an invalid response");
continue;
Expand Down
7 changes: 5 additions & 2 deletions src/ControllerMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ControllerMethod {
public function __construct(public array $parameters, public array $responses, public array $returns, public array $responseDescription, public array $description, public ?string $summary, public bool $isDeprecated) {
}

public static function parse(string $context, array $definitions, ClassMethod $method, bool $isAdmin, bool $isDeprecated): ControllerMethod {
public static function parse(string $context, array $definitions, ClassMethod $method, bool $isAdmin, bool $isPasswordConfirmation, bool $isDeprecated): ControllerMethod {
global $phpDocParser, $lexer, $allowMissingDocs;

$parameters = [];
Expand Down Expand Up @@ -184,7 +184,10 @@ public static function parse(string $context, array $definitions, ClassMethod $m
}

if ($isAdmin) {
$methodDescription[] = "This endpoint requires admin access";
$methodDescription[] = "This endpoint requires admin access.";
}
if ($isPasswordConfirmation) {
$methodDescription[] = "This endpoint requires confirming the password.";
}

if (count($methodDescription) == 1) {
Expand Down
1 change: 1 addition & 0 deletions tests/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,6 @@
['name' => 'Settings#stringValueParameter', 'url' => '/api/{apiVersion}/string-value', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#intValueParameter', 'url' => '/api/{apiVersion}/int-value', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#numericParameter', 'url' => '/api/{apiVersion}/numeric', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#passwordConfirmationRequired', 'url' => '/api/{apiVersion}/password-confirmation', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
],
];
13 changes: 13 additions & 0 deletions tests/lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\IgnoreOpenAPI;
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;

Expand Down Expand Up @@ -386,4 +387,16 @@ public function intValueParameter(int $value): DataResponse {
public function numericParameter(mixed $value): DataResponse {
return new DataResponse();
}

/**
* A route with password confirmation required
*
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>
*
* 200: Admin settings updated
*/
#[PasswordConfirmationRequired]
public function passwordConfirmationRequired(): DataResponse {
return new DataResponse();
}
}
118 changes: 95 additions & 23 deletions tests/openapi-administration.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"post": {
"operationId": "admin_settings-admin-scope-implicit-from-admin-required",
"summary": "Route is only in the admin scope because there is no \"NoAdminRequired\" annotation or attribute",
"description": "This endpoint requires admin access",
"description": "This endpoint requires admin access.",
"tags": [
"admin_settings"
],
Expand Down Expand Up @@ -156,7 +156,7 @@
"post": {
"operationId": "settings-admin-settings-moved-to-settings-tag",
"summary": "Route in default scope with tags",
"description": "This endpoint requires admin access",
"description": "This endpoint requires admin access.",
"tags": [
"settings",
"admin-settings"
Expand Down Expand Up @@ -229,7 +229,7 @@
"post": {
"operationId": "settings-admin-settings-moved-to-settings-tag-unnamed",
"summary": "Route in default scope with tags but without named parameters on the attribute",
"description": "This endpoint requires admin access",
"description": "This endpoint requires admin access.",
"tags": [
"settings",
"admin-settings"
Expand Down Expand Up @@ -446,7 +446,7 @@
"post": {
"operationId": "settings-list-of-int-parameters",
"summary": "A route with a limited set of possible integers",
"description": "This endpoint requires admin access",
"description": "This endpoint requires admin access.",
"tags": [
"settings"
],
Expand Down Expand Up @@ -540,7 +540,7 @@
"post": {
"operationId": "settings-int-parameter-with-min-and-max",
"summary": "A route with a min and max integers",
"description": "This endpoint requires admin access",
"description": "This endpoint requires admin access.",
"tags": [
"settings"
],
Expand Down Expand Up @@ -624,7 +624,7 @@
"post": {
"operationId": "settings-int-parameter-with-min",
"summary": "A route with a min integers",
"description": "This endpoint requires admin access",
"description": "This endpoint requires admin access.",
"tags": [
"settings"
],
Expand Down Expand Up @@ -707,7 +707,7 @@
"post": {
"operationId": "settings-int-parameter-with-max",
"summary": "A route with a max integers",
"description": "This endpoint requires admin access",
"description": "This endpoint requires admin access.",
"tags": [
"settings"
],
Expand Down Expand Up @@ -790,7 +790,7 @@
"post": {
"operationId": "settings-int-parameter-non-negative",
"summary": "A route with a non negative integer",
"description": "This endpoint requires admin access",
"description": "This endpoint requires admin access.",
"tags": [
"settings"
],
Expand Down Expand Up @@ -873,7 +873,7 @@
"post": {
"operationId": "settings-int-parameter-positive",
"summary": "A route with a positive integer",
"description": "This endpoint requires admin access",
"description": "This endpoint requires admin access.",
"tags": [
"settings"
],
Expand Down Expand Up @@ -956,7 +956,7 @@
"post": {
"operationId": "settings-int-parameter-negative",
"summary": "A route with a negative integer",
"description": "This endpoint requires admin access",
"description": "This endpoint requires admin access.",
"tags": [
"settings"
],
Expand Down Expand Up @@ -1039,7 +1039,7 @@
"post": {
"operationId": "settings-int-parameter-non-positive",
"summary": "A route with a non positive integer",
"description": "This endpoint requires admin access",
"description": "This endpoint requires admin access.",
"tags": [
"settings"
],
Expand Down Expand Up @@ -1122,7 +1122,7 @@
"post": {
"operationId": "settings-list-of-int-string-and-one-bool",
"summary": "A route with a list of 2 integers, 2 strings and 1 boolean",
"description": "This endpoint requires admin access",
"description": "This endpoint requires admin access.",
"tags": [
"settings"
],
Expand Down Expand Up @@ -1224,7 +1224,7 @@
"post": {
"operationId": "settings-list-of-int-string-and-all-bools",
"summary": "A route with a list of 2 integers, 2 strings and 1 boolean",
"description": "This endpoint requires admin access",
"description": "This endpoint requires admin access.",
"tags": [
"settings"
],
Expand Down Expand Up @@ -1327,7 +1327,7 @@
"post": {
"operationId": "settings-boolean-parameter-required",
"summary": "A route with required boolean",
"description": "This endpoint requires admin access",
"description": "This endpoint requires admin access.",
"tags": [
"settings"
],
Expand Down Expand Up @@ -1412,7 +1412,7 @@
"post": {
"operationId": "settings-boolean-parameter-default-false",
"summary": "A route with boolean defaulting to false",
"description": "This endpoint requires admin access",
"description": "This endpoint requires admin access.",
"tags": [
"settings"
],
Expand Down Expand Up @@ -1497,7 +1497,7 @@
"post": {
"operationId": "settings-boolean-parameter-default-true",
"summary": "A route with boolean defaulting to true",
"description": "This endpoint requires admin access",
"description": "This endpoint requires admin access.",
"tags": [
"settings"
],
Expand Down Expand Up @@ -1582,7 +1582,7 @@
"post": {
"operationId": "settings-boolean-true-parameter",
"summary": "A route with boolean or true",
"description": "This endpoint requires admin access",
"description": "This endpoint requires admin access.",
"tags": [
"settings"
],
Expand Down Expand Up @@ -1667,7 +1667,7 @@
"post": {
"operationId": "settings-boolean-false-parameter",
"summary": "A route with boolean or false",
"description": "This endpoint requires admin access",
"description": "This endpoint requires admin access.",
"tags": [
"settings"
],
Expand Down Expand Up @@ -1752,7 +1752,7 @@
"post": {
"operationId": "settings-boolean-true-false-parameter",
"summary": "A route with boolean or true or false",
"description": "This endpoint requires admin access",
"description": "This endpoint requires admin access.",
"tags": [
"settings"
],
Expand Down Expand Up @@ -1837,7 +1837,7 @@
"post": {
"operationId": "settings-true-false-parameter",
"summary": "A route with true or false",
"description": "This endpoint requires admin access",
"description": "This endpoint requires admin access.",
"tags": [
"settings"
],
Expand Down Expand Up @@ -1922,7 +1922,7 @@
"post": {
"operationId": "settings-string-value-parameter",
"summary": "A route with string or 'test'",
"description": "This endpoint requires admin access",
"description": "This endpoint requires admin access.",
"tags": [
"settings"
],
Expand Down Expand Up @@ -2003,7 +2003,7 @@
"post": {
"operationId": "settings-int-value-parameter",
"summary": "A route with int or 0",
"description": "This endpoint requires admin access",
"description": "This endpoint requires admin access.",
"tags": [
"settings"
],
Expand Down Expand Up @@ -2085,7 +2085,7 @@
"post": {
"operationId": "settings-numeric-parameter",
"summary": "A route with numeric",
"description": "This endpoint requires admin access",
"description": "This endpoint requires admin access.",
"tags": [
"settings"
],
Expand Down Expand Up @@ -2161,6 +2161,78 @@
}
}
}
},
"/ocs/v2.php/apps/notifications/api/{apiVersion}/password-confirmation": {
"post": {
"operationId": "settings-password-confirmation-required",
"summary": "A route with password confirmation required",
"description": "This endpoint requires admin access.\nThis endpoint requires confirming the password.",
"tags": [
"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": "Admin 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": []
Expand Down
Loading