From c7ad4a7fc0f81d117ec7af369bf39c6317ff1323 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Mon, 31 Aug 2026 14:41:37 +0100 Subject: [PATCH] fix(spec): emit FCM service account JSON as an object, not a string The OpenAPI3 parameter switch matches on the concrete validator class, so Utopia\Validator\JSON\FCM fell through to the string default even though it reports TYPE_OBJECT and the controller still accepts an array, stdClass or JSON string. Swapping the FCM param's JSON validator for the stricter FCM one was meant to tighten validation, but it silently narrowed the published type and turned serviceAccountJSON into a string in every generated SDK. --- .../SDK/Specification/Format/OpenAPI3.php | 1 + tests/unit/SDK/Specification/FormatTest.php | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php index 1ee1babc96..53151e610c 100644 --- a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php +++ b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php @@ -733,6 +733,7 @@ class OpenAPI3 extends Format break; case \Utopia\Validator\JSON::class: case \Utopia\Validator\JSON\ObjectValidator::class: + case \Utopia\Validator\JSON\FCM::class: case \Utopia\Validator\Assoc::class: $node['schema']['type'] = 'object'; $node['schema']['default'] = (empty($param['default'])) ? new \stdClass() : $param['default']; diff --git a/tests/unit/SDK/Specification/FormatTest.php b/tests/unit/SDK/Specification/FormatTest.php index 96d05875cf..5601a70c1d 100644 --- a/tests/unit/SDK/Specification/FormatTest.php +++ b/tests/unit/SDK/Specification/FormatTest.php @@ -63,6 +63,7 @@ use Utopia\Validator\FloatValidator; use Utopia\Validator\HexColor; use Utopia\Validator\Integer as IntegerValidator; use Utopia\Validator\JSON; +use Utopia\Validator\JSON\FCM; use Utopia\Validator\Nullable; use Utopia\Validator\Range; use Utopia\Validator\Text; @@ -1040,6 +1041,31 @@ final class FormatTest extends TestCase $this->assertSame('object', $openApiQuery['type']); } + public function testObjectValidatorsOutsideTheSwitchAreNotEmittedAsStrings(): void + { + Method::$processed = []; + Method::$errors = []; + + $route = (new Route('POST', '/v1/tests/fcm')) + ->desc('Create FCM provider') + ->label('sdk', new Method( + namespace: 'test', + group: null, + name: 'createFcmProvider', + description: 'Create FCM provider.', + auth: [], + responses: [], + )) + ->param('serviceAccountJSON', null, new Nullable(new FCM()), 'FCM service account JSON.', true) + ->param('bareServiceAccountJSON', null, new FCM(), 'FCM service account JSON.', true); + + $spec = (new OpenAPI3(new Container(), [], [$route], [], [], 0, 'console'))->parse(); + $properties = $spec['paths']['/tests/fcm']['post']['requestBody']['content']['application/json']['schema']['properties']; + + $this->assertSame('object', $properties['serviceAccountJSON']['type']); + $this->assertSame('object', $properties['bareServiceAccountJSON']['type']); + } + public function testJsonAndNullableModelRulesEmitExpectedSchemas(): void { Method::$processed = [];