diff --git a/src/Appwrite/Utopia/Response/Model/Collection.php b/src/Appwrite/Utopia/Response/Model/Collection.php index 398bcf770f..f023be261f 100644 --- a/src/Appwrite/Utopia/Response/Model/Collection.php +++ b/src/Appwrite/Utopia/Response/Model/Collection.php @@ -4,6 +4,7 @@ namespace Appwrite\Utopia\Response\Model; use Appwrite\Utopia\Response; use Appwrite\Utopia\Response\Model; +use Utopia\Database\Document; use stdClass; class Collection extends Model @@ -48,7 +49,21 @@ class Collection extends Model 'description' => 'Collection attributes.', 'default' => [], 'example' => new stdClass, - 'array' => true + 'array' => true, + 'getNestedType' => function(Document $attribute) { + return match($attribute->getAttribute('type')) { + self::TYPE_BOOLEAN => Response::MODEL_ATTRIBUTE_BOOLEAN, + self::TYPE_INTEGER => Response::MODEL_ATTRIBUTE_INTEGER, + self::TYPE_FLOAT => Response::MODEL_ATTRIBUTE_FLOAT, + self::TYPE_STRING => match($attribute->getAttribute('format')) { + APP_DATABASE_ATTRIBUTE_EMAIL => Response::MODEL_ATTRIBUTE_EMAIL, + APP_DATABASE_ATTRIBUTE_IP => Response::MODEL_ATTRIBUTE_IP, + APP_DATABASE_ATTRIBUTE_URL => Response::MODEL_ATTRIBUTE_URL, + default => Response::MODEL_ATTRIBUTE_STRING, + }, + default => Response::MODEL_ATTRIBUTE, + }; + }, ]) ->addRule('indexes', [ 'type' => Response::MODEL_INDEX,