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 = [];