[Schema] Serialize a settingless extension as an object (#438)

* [Schema] Serialize a settingless extension as an object

An extension declaring support with no settings was advertised as `[]`, an
empty JSON array, which the wire schema rejects - `extensions` maps an id to
a settings *object*. Both ServerCapabilities and ClientCapabilities now cast
each entry, so it goes out as `{}`.

* Apply suggestion from @chr-hertel
This commit is contained in:
Christopher Hertel 2026-08-18 14:59:12 +02:00 • committed by GitHub
commit 08d332c7ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 2 deletions

View file

@ -188,7 +188,10 @@ class ClientCapabilities implements \JsonSerializable
}
if ($this->extensions) {
$data['extensions'] = (object) $this->extensions;
$data['extensions'] = (object) array_map(
static fn (mixed $settings): mixed => \is_array($settings) ? (object) $settings : $settings,
$this->extensions,
);
}
return $data ?: new \stdClass();

View file

@ -189,7 +189,12 @@ class ServerCapabilities implements \JsonSerializable
}
if ($this->extensions) {
$data['extensions'] = (object) $this->extensions;
// Each entry is a settings *object*; an extension with no settings
// declares `{}`, and an empty PHP array would serialize as `[]`.
$data['extensions'] = (object) array_map(
static fn (mixed $settings): mixed => \is_array($settings) ? (object) $settings : $settings,
$this->extensions,
);
}
return $data;