Fix MCP schema test

This commit is contained in:
gitea_admin committed 2026-09-27 08:50:20 +02:00
1 parent 345b015137
commit 23e1c6f9d1
1 file changed
+5 -2
@@ -19,7 +19,7 @@ function assert_test(bool $condition, string $message): void
function assert_schema_objects(array $schema, string $path = 'inputSchema'): void function assert_schema_objects(array $schema, string $path = 'inputSchema'): void
{ {
assert_test(($schema['type'] ?? null) === 'object', $path . '.type must be object'); assert_test(($schema['type'] ?? null) === 'object', $path . '.type must be object');
assert_test(isset($schema['properties']) && is_object($schema['properties']), $path . '.properties must be an object'); assert_test(isset($schema['properties']) && (is_array($schema['properties']) || is_object($schema['properties'])), $path . '.properties must be an object-compatible map');
if (isset($schema['required'])) { if (isset($schema['required'])) {
assert_test(is_array($schema['required']), $path . '.required must be an array'); assert_test(is_array($schema['required']), $path . '.required must be an array');
@@ -28,7 +28,10 @@ function assert_schema_objects(array $schema, string $path = 'inputSchema'): voi
} }
} }
foreach (get_object_vars($schema['properties']) as $propertyName => $propertySchema) { $properties = is_object($schema['properties'])
? get_object_vars($schema['properties'])
: $schema['properties'];
foreach ($properties as $propertyName => $propertySchema) {
assert_test(is_array($propertySchema), $path . '.properties.' . $propertyName . ' must be an object schema'); assert_test(is_array($propertySchema), $path . '.properties.' . $propertyName . ' must be an object schema');
if (($propertySchema['type'] ?? null) === 'array' && isset($propertySchema['items'])) { if (($propertySchema['type'] ?? null) === 'array' && isset($propertySchema['items'])) {
assert_test(is_array($propertySchema['items']), $path . '.properties.' . $propertyName . '.items must be an object schema'); assert_test(is_array($propertySchema['items']), $path . '.properties.' . $propertyName . '.items must be an object schema');