1
0
Fork 0
mirror of synced 2024-09-28 07:21:35 +12:00

Fix functions vars default response

Changed default from array to class
This commit is contained in:
Bradley Schofield 2022-01-18 15:12:26 +00:00
parent 8d92d32112
commit f85970fa3d
2 changed files with 22 additions and 2 deletions

View file

@ -45,7 +45,7 @@ App::post('/v1/functions')
->param('name', '', new Text(128), 'Function name. Max length: 128 chars.')
->param('execute', [], new ArrayList(new Text(64)), 'An array of strings with execution permissions. By default no user is granted with any execute permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.')
->param('runtime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Execution runtime.')
->param('vars', [], new Assoc(), 'Key-value JSON object that will be passed to the function as environment variables.', true)
->param('vars', new stdClass(), new Assoc(), 'Key-value JSON object that will be passed to the function as environment variables.', true)
->param('events', [], new ArrayList(new WhiteList(array_keys(Config::getParam('events')), true)), 'Events list.', true)
->param('schedule', '', new Cron(), 'Schedule CRON syntax.', true)
->param('timeout', 15, new Range(1, 900), 'Function maximum execution time in seconds.', true)

View file

@ -4,6 +4,8 @@ namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model;
use stdClass;
use Utopia\Database\Document;
class Func extends Model
{
@ -62,7 +64,7 @@ class Func extends Model
->addRule('vars', [
'type' => self::TYPE_JSON,
'description' => 'Function environment variables.',
'default' => new \stdClass,
'default' => new \stdClass(),
'example' => ['key' => 'value'],
])
->addRule('events', [
@ -118,4 +120,22 @@ class Func extends Model
{
return Response::MODEL_FUNCTION;
}
/**
* Get Collection
*
* @return string
*/
public function filter(Document $document): Document
{
$prefs = $document->getAttribute('vars');
if($prefs instanceof Document) {
$prefs = $prefs->getArrayCopy();
}
if(is_array($prefs) && empty($prefs)) {
$document->setAttribute('vars', new stdClass);
}
return $document;
}
}