From b73c58772e2ba3b6edf28b83b6563637dc3687b6 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Fri, 2 Aug 2024 15:49:29 -0300 Subject: [PATCH] fix: use schemas only from request body Signed-off-by: Vitor Mattos Signed-off-by: provokateurin --- generate-spec | 16 ++++----- tests/lib/Controller/FederationController.php | 4 ++- tests/lib/ResponseDefinitions.php | 5 +++ tests/openapi-full.json | 34 +++++++++++++++++++ tests/openapi.json | 34 +++++++++++++++++++ 5 files changed, 83 insertions(+), 10 deletions(-) diff --git a/generate-spec b/generate-spec index 38f651e..1018c2d 100755 --- a/generate-spec +++ b/generate-spec @@ -955,20 +955,18 @@ foreach ($scopePaths as $scope => $paths) { foreach ($paths as $url => $urlRoutes) { foreach ($urlRoutes as $httpMethod => $routeData) { foreach ($routeData['responses'] as $statusCode => $responseData) { - if (empty($responseData['content'])) { - continue; - } - - foreach ($responseData['content'] as $contentType => $contentData) { - if (isset($contentData['schema']) && is_array($contentData['schema'])) { - $newSchemas = Helpers::collectUsedRefs($contentData['schema']); - $usedSchemas = array_merge($usedSchemas, $newSchemas); - } + if (!empty($responseData['content'])) { + $usedSchemas[] = Helpers::collectUsedRefs($responseData['content']); } } + if (!empty($routeData['requestBody']['content'])) { + $usedSchemas[] = Helpers::collectUsedRefs($routeData['requestBody']['content']); + } } } + $usedSchemas = array_merge(...$usedSchemas); + $scopedSchemas = []; while ($usedSchema = array_shift($usedSchemas)) { if (!str_starts_with($usedSchema, '#/components/schemas/')) { diff --git a/tests/lib/Controller/FederationController.php b/tests/lib/Controller/FederationController.php index a656530..18df858 100644 --- a/tests/lib/Controller/FederationController.php +++ b/tests/lib/Controller/FederationController.php @@ -36,6 +36,7 @@ * @psalm-import-type NotificationsPushDevice from ResponseDefinitions * @psalm-import-type NotificationsNotification from ResponseDefinitions * @psalm-import-type NotificationsCollection from ResponseDefinitions + * @psalm-import-type NotificationsRequestProperty from ResponseDefinitions */ #[OpenAPI(scope: OpenAPI::SCOPE_FEDERATION)] class FederationController extends OCSController { @@ -58,12 +59,13 @@ public function federationByController(): DataResponse { * * Route is only in the default scope (moved from federation) * + * @param NotificationsRequestProperty $property Property * @return DataResponse, array{}> * * 200: Personal settings updated */ #[OpenAPI] - public function movedToDefaultScope(): DataResponse { + public function movedToDefaultScope(array $property): DataResponse { return new DataResponse(); } } diff --git a/tests/lib/ResponseDefinitions.php b/tests/lib/ResponseDefinitions.php index 88b1b21..ae8eb73 100644 --- a/tests/lib/ResponseDefinitions.php +++ b/tests/lib/ResponseDefinitions.php @@ -70,6 +70,11 @@ * publicKey: string, * signature: string, * } + * + * @psalm-type NotificationsRequestProperty = array{ + * publicKey: string, + * signature: string, + * } */ class ResponseDefinitions { } diff --git a/tests/openapi-full.json b/tests/openapi-full.json index 9b692c6..ed91074 100644 --- a/tests/openapi-full.json +++ b/tests/openapi-full.json @@ -203,6 +203,21 @@ "type": "string" } } + }, + "RequestProperty": { + "type": "object", + "required": [ + "publicKey", + "signature" + ], + "properties": { + "publicKey": { + "type": "string" + }, + "signature": { + "type": "string" + } + } } } }, @@ -4367,6 +4382,25 @@ "basic_auth": [] } ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "property" + ], + "properties": { + "property": { + "$ref": "#/components/schemas/RequestProperty", + "description": "Property" + } + } + } + } + } + }, "parameters": [ { "name": "apiVersion", diff --git a/tests/openapi.json b/tests/openapi.json index b9cab64..4e60b80 100644 --- a/tests/openapi.json +++ b/tests/openapi.json @@ -170,6 +170,21 @@ "type": "string" } } + }, + "RequestProperty": { + "type": "object", + "required": [ + "publicKey", + "signature" + ], + "properties": { + "publicKey": { + "type": "string" + }, + "signature": { + "type": "string" + } + } } } }, @@ -261,6 +276,25 @@ "basic_auth": [] } ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "property" + ], + "properties": { + "property": { + "$ref": "#/components/schemas/RequestProperty", + "description": "Property" + } + } + } + } + } + }, "parameters": [ { "name": "apiVersion",