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.
This commit is contained in:
Chirag Aggarwal committed 2026-08-31 14:41:37 +01:00
1 parent 79d81a99b6
commit c7ad4a7fc0
2 files changed
+27

No files matched your search

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