[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:
parent
1961414432
commit
cf2c4d4ead
1 changed files with 144 additions and 65 deletions
|
|
@ -114,13 +114,23 @@ final class StringSchemaDefinitionTest extends TestCase
|
|||
$this->assertSame(100, $schema->maxLength);
|
||||
}
|
||||
|
||||
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 = StringSchemaDefinition::fromArray([]);
|
||||
|
||||
$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 string schema definition.');
|
||||
|
||||
/* @phpstan-ignore argument.type */
|
||||
StringSchemaDefinition::fromArray([]);
|
||||
StringSchemaDefinition::fromArray(['title' => 42]);
|
||||
}
|
||||
|
||||
public function testJsonSerializeWithMinimalParams(): void
|
||||
|
|
|
|||
Loading…
Reference in a new issue