[Schema] Stop rejecting elicitation schemas the specification allows (#437)

* [Schema] Stop rejecting elicitation schemas the specification allows

The specification makes `title` optional on every elicitation schema
definition. AbstractSchemaDefinition required it, so a client reading a
conformant server's elicitation/create refused the request - and a server
building one could not omit it either.

`title` is now nullable on all seven definitions, omitted from the
serialized form when absent, and rejected only when present and not a
string.

* Fix stale title docblocks; allow omitting title where safe

* Give Number's title param a default too

* Apply suggestions from code review

Co-authored-by: Christopher Hertel <mail@christopher-hertel.de>
This commit is contained in:
Christopher Hertel 2026-08-18 19:49:15 +02:00 • committed by GitHub
commit cf2c4d4ead
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -124,13 +124,23 @@ final class TitledEnumSchemaDefinitionTest extends TestCase
$this->assertSame('b', $schema->default);
}
public function testFromArrayWithMissingTitle(): void
public function testFromArrayWithoutTitleIsAccepted(): void
{
// `title` is optional in the specification, so a server that omits it
// must still be readable.
$schema = TitledEnumSchemaDefinition::fromArray(['oneOf' => [['const' => 'a', 'title' => 'A']]]);
$this->assertNull($schema->title);
$this->assertArrayNotHasKey('title', $schema->jsonSerialize());
}
public function testFromArrayRejectsNonStringTitle(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Missing or invalid "title"');
$this->expectExceptionMessage('Invalid "title" for titled enum schema definition.');
/* @phpstan-ignore argument.type */
TitledEnumSchemaDefinition::fromArray(['oneOf' => [['const' => 'a', 'title' => 'A']]]);
TitledEnumSchemaDefinition::fromArray(['title' => 42]);
}
public function testFromArrayWithMissingOneOf(): void