diff --git a/generate-spec b/generate-spec index 9131bda..bbaf1b6 100755 --- a/generate-spec +++ b/generate-spec @@ -444,6 +444,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) { @@ -493,7 +494,7 @@ foreach ($parsedRoutes as $key => $value) { ]; } - $classMethodInfo = ControllerMethod::parse($routeName, $definitions, $methodFunction, $isAdmin, $isDeprecated); + $classMethodInfo = ControllerMethod::parse($routeName, $definitions, $methodFunction, $isAdmin, $isDeprecated, $isPasswordConfirmation); if (count($classMethodInfo->returns) > 0) { Logger::error($routeName, "Returns an invalid response"); continue; diff --git a/src/ControllerMethod.php b/src/ControllerMethod.php index 5039bb5..90a7d35 100644 --- a/src/ControllerMethod.php +++ b/src/ControllerMethod.php @@ -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 $isDeprecated, bool $isPasswordConfirmation): ControllerMethod { global $phpDocParser, $lexer, $allowMissingDocs; $parameters = []; @@ -192,6 +192,10 @@ public static function parse(string $context, array $definitions, ClassMethod $m $methodDescription[] = "This endpoint requires admin access"; } + if ($isPasswordConfirmation) { + $methodDescription[] = "This endpoint requires password confirmation"; + } + if (count($methodDescription) == 1) { $methodSummary = $methodDescription[0]; $methodDescription = []; diff --git a/tests/appinfo/routes.php b/tests/appinfo/routes.php index 7d86bf3..794154b 100644 --- a/tests/appinfo/routes.php +++ b/tests/appinfo/routes.php @@ -67,5 +67,7 @@ ['name' => 'Settings#throwingOther', 'url' => '/api/{apiVersion}/throwing/other', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']], ['name' => 'Settings#empty204', 'url' => '/api/{apiVersion}/204', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']], ['name' => 'Settings#empty304', 'url' => '/api/{apiVersion}/304', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']], + ['name' => 'Settings#passwordConfirmationAnnotation', 'url' => '/api/{apiVersion}/passwordConfirmationAnnotation', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']], + ['name' => 'Settings#passwordConfirmationAttribute', 'url' => '/api/{apiVersion}/passwordConfirmationAttribute', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']], ], ]; diff --git a/tests/lib/Controller/SettingsController.php b/tests/lib/Controller/SettingsController.php index 3508478..4ea8dbd 100644 --- a/tests/lib/Controller/SettingsController.php +++ b/tests/lib/Controller/SettingsController.php @@ -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\OCS\OCSNotFoundException; use OCP\AppFramework\OCSController; @@ -461,4 +462,28 @@ public function empty204(): DataResponse { public function empty304(): DataResponse { return new DataResponse(); } + + /** + * Route with password confirmation annotation + * + * @return DataResponse, array{}> + * @PasswordConfirmationRequired + * + * 200: OK + */ + public function passwordConfirmationAnnotation(): DataResponse { + return new DataResponse(); + } + + /** + * Route with password confirmation attribute + * + * @return DataResponse, array{}> + * + * 200: OK + */ + #[PasswordConfirmationRequired] + public function passwordConfirmationAttribute(): DataResponse { + return new DataResponse(); + } } diff --git a/tests/openapi-administration.json b/tests/openapi-administration.json index d1bcdf2..8f2bbf5 100644 --- a/tests/openapi-administration.json +++ b/tests/openapi-administration.json @@ -2429,6 +2429,150 @@ } } }, + "/ocs/v2.php/apps/notifications/api/{apiVersion}/passwordConfirmationAnnotation": { + "post": { + "operationId": "settings-password-confirmation-annotation", + "summary": "Route with password confirmation annotation", + "description": "This endpoint requires admin access\nThis endpoint requires password confirmation", + "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": "OK", + "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}/passwordConfirmationAttribute": { + "post": { + "operationId": "settings-password-confirmation-attribute", + "summary": "Route with password confirmation attribute", + "description": "This endpoint requires admin access\nThis endpoint requires password confirmation", + "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": "OK", + "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/tests/attribute-ocs/{param}": { "get": { "operationId": "routing-attributeocs-route", diff --git a/tests/openapi-full.json b/tests/openapi-full.json index f4c88bc..9f9528e 100644 --- a/tests/openapi-full.json +++ b/tests/openapi-full.json @@ -2556,6 +2556,150 @@ } } }, + "/ocs/v2.php/apps/notifications/api/{apiVersion}/passwordConfirmationAnnotation": { + "post": { + "operationId": "settings-password-confirmation-annotation", + "summary": "Route with password confirmation annotation", + "description": "This endpoint requires admin access\nThis endpoint requires password confirmation", + "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": "OK", + "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}/passwordConfirmationAttribute": { + "post": { + "operationId": "settings-password-confirmation-attribute", + "summary": "Route with password confirmation attribute", + "description": "This endpoint requires admin access\nThis endpoint requires password confirmation", + "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": "OK", + "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/tests/attribute-ocs/{param}": { "get": { "operationId": "routing-attributeocs-route",