From 3318631d9de7b8e884a73f45feb593f07bc69d0d Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 20 May 2021 12:27:20 +0545 Subject: [PATCH 1/8] converting to numeric validator --- app/controllers/api/storage.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index f0c63ce7b..1cbad48e8 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -22,6 +22,7 @@ use Utopia\Image\Image; use Appwrite\OpenSSL\OpenSSL; use Appwrite\Utopia\Response; use Utopia\Config\Config; +use Utopia\Validator\Numeric; App::post('/v1/storage/files') ->desc('Create File') @@ -245,7 +246,7 @@ App::get('/v1/storage/files/:fileId/preview') ->param('borderWidth', 0, new Range(0, 100), 'Preview image border in pixels. Pass an integer between 0 to 100. Defaults to 0.', true) ->param('borderColor', '', new HexColor(), 'Preview image border color. Use a valid HEX color, no # is needed for prefix.', true) ->param('borderRadius', 0, new Range(0, 4000), 'Preview image border radius in pixels. Pass an integer between 0 to 4000.', true) - ->param('opacity', 1, new Range(0,1), 'Preview image opacity. Only works with images having an alpha channel (like png). Pass a number between 0 to 1.', true) + ->param('opacity', 1, new Numeric(), 'Preview image opacity. Only works with images having an alpha channel (like png). Pass a number between 0 to 1.', true) ->param('rotation', 0, new Range(0,360), 'Preview image rotation in degrees. Pass an integer between 0 and 360.', true) ->param('background', '', new HexColor(), 'Preview image background color. Only works with transparent images (png). Use a valid HEX color, no # is needed for prefix.', true) ->param('output', '', new WhiteList(\array_keys(Config::getParam('storage-outputs')), true), 'Output format type (jpeg, jpg, png, gif and webp).', true) From 4199dcc1f43de4153734d80e6e0c1f28580d8d44 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 21 May 2021 12:38:20 +0545 Subject: [PATCH 2/8] updated framework --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index 294149be3..bc67fdf9f 100644 --- a/composer.lock +++ b/composer.lock @@ -1693,16 +1693,16 @@ }, { "name": "utopia-php/framework", - "version": "0.14.0", + "version": "0.14.1", "source": { "type": "git", "url": "https://github.com/utopia-php/framework.git", - "reference": "92d4a36f3b0e22393a31877c5317c96e01760339" + "reference": "632113288bebe41cbef79f0d355bd91609767b8c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/framework/zipball/92d4a36f3b0e22393a31877c5317c96e01760339", - "reference": "92d4a36f3b0e22393a31877c5317c96e01760339", + "url": "https://api.github.com/repos/utopia-php/framework/zipball/632113288bebe41cbef79f0d355bd91609767b8c", + "reference": "632113288bebe41cbef79f0d355bd91609767b8c", "shasum": "" }, "require": { @@ -1736,9 +1736,9 @@ ], "support": { "issues": "https://github.com/utopia-php/framework/issues", - "source": "https://github.com/utopia-php/framework/tree/0.14.0" + "source": "https://github.com/utopia-php/framework/tree/0.14.1" }, - "time": "2021-04-15T21:01:44+00:00" + "time": "2021-05-21T06:41:45+00:00" }, { "name": "utopia-php/image", From c03e3709a612984257567a67670968ffb82df39b Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 21 May 2021 12:42:43 +0545 Subject: [PATCH 3/8] proper range validator for opacity --- app/controllers/api/storage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 1cbad48e8..b3060eaf4 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -246,7 +246,7 @@ App::get('/v1/storage/files/:fileId/preview') ->param('borderWidth', 0, new Range(0, 100), 'Preview image border in pixels. Pass an integer between 0 to 100. Defaults to 0.', true) ->param('borderColor', '', new HexColor(), 'Preview image border color. Use a valid HEX color, no # is needed for prefix.', true) ->param('borderRadius', 0, new Range(0, 4000), 'Preview image border radius in pixels. Pass an integer between 0 to 4000.', true) - ->param('opacity', 1, new Numeric(), 'Preview image opacity. Only works with images having an alpha channel (like png). Pass a number between 0 to 1.', true) + ->param('opacity', 1, new Range(0,1, Range::TYPE_FLOAT), 'Preview image opacity. Only works with images having an alpha channel (like png). Pass a number between 0 to 1.', true) ->param('rotation', 0, new Range(0,360), 'Preview image rotation in degrees. Pass an integer between 0 and 360.', true) ->param('background', '', new HexColor(), 'Preview image background color. Only works with transparent images (png). Use a valid HEX color, no # is needed for prefix.', true) ->param('output', '', new WhiteList(\array_keys(Config::getParam('storage-outputs')), true), 'Output format type (jpeg, jpg, png, gif and webp).', true) From 54fdc647c2425bd35864e171a7f0d69c104f9bfc Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 21 May 2021 12:53:53 +0545 Subject: [PATCH 4/8] updated specs to get validator getType --- .../Specification/Format/OpenAPI3.php | 29 ++++++++++--------- .../Specification/Format/Swagger2.php | 29 ++++++++++--------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/Appwrite/Specification/Format/OpenAPI3.php b/src/Appwrite/Specification/Format/OpenAPI3.php index b5724a0ee..fb93f4ada 100644 --- a/src/Appwrite/Specification/Format/OpenAPI3.php +++ b/src/Appwrite/Specification/Format/OpenAPI3.php @@ -5,6 +5,7 @@ namespace Appwrite\Specification\Format; use Appwrite\Specification\Format; use Appwrite\Template\Template; use stdClass; +use Utopia\Validator; class OpenAPI3 extends Format { @@ -230,24 +231,24 @@ class OpenAPI3 extends Format switch ((!empty($validator)) ? \get_class($validator) : '') { case 'Utopia\Validator\Text': - $node['schema']['type'] = 'string'; + $node['schema']['type'] = $validator->getType(); $node['schema']['x-example'] = '['.\strtoupper(Template::fromCamelCaseToSnake($node['name'])).']'; break; case 'Utopia\Validator\Boolean': - $node['schema']['type'] = 'boolean'; + $node['schema']['type'] = $validator->getType(); $node['schema']['x-example'] = false; break; case 'Appwrite\Database\Validator\UID': - $node['schema']['type'] = 'string'; + $node['schema']['type'] = $validator->getType(); $node['schema']['x-example'] = '['.\strtoupper(Template::fromCamelCaseToSnake($node['name'])).']'; break; case 'Appwrite\Network\Validator\Email': - $node['schema']['type'] = 'string'; + $node['schema']['type'] = $validator->getType(); $node['schema']['format'] = 'email'; $node['schema']['x-example'] = 'email@example.com'; break; case 'Appwrite\Network\Validator\URL': - $node['schema']['type'] = 'string'; + $node['schema']['type'] = $validator->getType(); $node['schema']['format'] = 'url'; $node['schema']['x-example'] = 'https://example.com'; break; @@ -255,40 +256,40 @@ class OpenAPI3 extends Format case 'Utopia\Validator\Mock': case 'Utopia\Validator\Assoc': $param['default'] = (empty($param['default'])) ? new stdClass() : $param['default']; - $node['schema']['type'] = 'object'; + $node['schema']['type'] = $validator->getType(); $node['schema']['x-example'] = '{}'; //$node['schema']['format'] = 'json'; break; case 'Utopia\Storage\Validator\File': $consumes = ['multipart/form-data']; - $node['schema']['type'] = 'string'; + $node['schema']['type'] = $validator->getType(); $node['schema']['format'] = 'binary'; break; case 'Utopia\Validator\ArrayList': - $node['schema']['type'] = 'array'; + $node['schema']['type'] = $validator->getType(); $node['schema']['items'] = [ 'type' => 'string', ]; break; case 'Appwrite\Auth\Validator\Password': - $node['schema']['type'] = 'string'; + $node['schema']['type'] = $validator->getType(); $node['schema']['format'] = 'format'; $node['schema']['x-example'] = 'password'; break; case 'Utopia\Validator\Range': /** @var \Utopia\Validator\Range $validator */ - $node['schema']['type'] = 'integer'; - $node['schema']['format'] = 'int32'; + $node['schema']['type'] = $validator->getType(); + $node['schema']['format'] = $validator->getType() == Validator::TYPE_INTEGER ? 'int32' : 'float'; $node['schema']['x-example'] = $validator->getMin(); break; case 'Utopia\Validator\Numeric': - $node['schema']['type'] = 'integer'; + $node['schema']['type'] = $validator->getType(); $node['schema']['format'] = 'int32'; break; case 'Utopia\Validator\Length': - $node['schema']['type'] = 'string'; + $node['schema']['type'] = $validator->getType(); break; case 'Appwrite\Network\Validator\Host': - $node['schema']['type'] = 'string'; + $node['schema']['type'] = $validator->getType(); $node['schema']['format'] = 'url'; $node['schema']['x-example'] = 'https://example.com'; break; diff --git a/src/Appwrite/Specification/Format/Swagger2.php b/src/Appwrite/Specification/Format/Swagger2.php index c63be0a70..11538da97 100644 --- a/src/Appwrite/Specification/Format/Swagger2.php +++ b/src/Appwrite/Specification/Format/Swagger2.php @@ -6,6 +6,7 @@ use Appwrite\Specification\Format; use Appwrite\Template\Template; use Appwrite\Utopia\Response\Model; use stdClass; +use Utopia\Validator; class Swagger2 extends Format { @@ -227,65 +228,65 @@ class Swagger2 extends Format switch ((!empty($validator)) ? \get_class($validator) : '') { case 'Utopia\Validator\Text': - $node['type'] = 'string'; + $node['type'] = $validator->getType(); $node['x-example'] = '['.\strtoupper(Template::fromCamelCaseToSnake($node['name'])).']'; break; case 'Utopia\Validator\Boolean': - $node['type'] = 'boolean'; + $node['type'] = $validator->getType(); $node['x-example'] = false; break; case 'Appwrite\Database\Validator\UID': - $node['type'] = 'string'; + $node['type'] = $validator->getType(); $node['x-example'] = '['.\strtoupper(Template::fromCamelCaseToSnake($node['name'])).']'; break; case 'Appwrite\Network\Validator\Email': - $node['type'] = 'string'; + $node['type'] = $validator->getType(); $node['format'] = 'email'; $node['x-example'] = 'email@example.com'; break; case 'Appwrite\Network\Validator\URL': - $node['type'] = 'string'; + $node['type'] = $validator->getType(); $node['format'] = 'url'; $node['x-example'] = 'https://example.com'; break; case 'Utopia\Validator\JSON': case 'Utopia\Validator\Mock': case 'Utopia\Validator\Assoc': - $node['type'] = 'object'; + $node['type'] = $validator->getType(); $param['default'] = (empty($param['default'])) ? new stdClass() : $param['default']; $node['x-example'] = '{}'; //$node['format'] = 'json'; break; case 'Utopia\Storage\Validator\File': $consumes = ['multipart/form-data']; - $node['type'] = 'file'; + $node['type'] = $validator->getType(); break; case 'Utopia\Validator\ArrayList': - $node['type'] = 'array'; + $node['type'] = $validator->getType(); $node['collectionFormat'] = 'multi'; $node['items'] = [ 'type' => 'string', ]; break; case 'Appwrite\Auth\Validator\Password': - $node['type'] = 'string'; + $node['type'] = $validator->getType(); $node['format'] = 'format'; $node['x-example'] = 'password'; break; case 'Utopia\Validator\Range': /** @var \Utopia\Validator\Range $validator */ - $node['type'] = 'integer'; - $node['format'] = 'int32'; + $node['type'] = $validator->getType(); + $node['format'] = $validator->getType() == Validator::TYPE_INTEGER ? 'int32' : 'float'; $node['x-example'] = $validator->getMin(); break; case 'Utopia\Validator\Numeric': - $node['type'] = 'integer'; + $node['type'] = $validator->getType(); $node['format'] = 'int32'; break; case 'Utopia\Validator\Length': - $node['type'] = 'string'; + $node['type'] = $validator->getType(); break; case 'Appwrite\Network\Validator\Host': - $node['type'] = 'string'; + $node['type'] = $validator->getType(); $node['format'] = 'url'; $node['x-example'] = 'https://example.com'; break; From 87bbcff3a7d086ea3c5c23037559568f0aa7ff41 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 21 May 2021 13:04:19 +0545 Subject: [PATCH 5/8] fix wrong type value --- src/Appwrite/Specification/Format/OpenAPI3.php | 2 +- src/Appwrite/Specification/Format/Swagger2.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Specification/Format/OpenAPI3.php b/src/Appwrite/Specification/Format/OpenAPI3.php index fb93f4ada..2ea31d4ce 100644 --- a/src/Appwrite/Specification/Format/OpenAPI3.php +++ b/src/Appwrite/Specification/Format/OpenAPI3.php @@ -277,7 +277,7 @@ class OpenAPI3 extends Format $node['schema']['x-example'] = 'password'; break; case 'Utopia\Validator\Range': /** @var \Utopia\Validator\Range $validator */ - $node['schema']['type'] = $validator->getType(); + $node['type'] = $validator->getType() == Validator::TYPE_FLOAT ? 'number': $validator->getType(); $node['schema']['format'] = $validator->getType() == Validator::TYPE_INTEGER ? 'int32' : 'float'; $node['schema']['x-example'] = $validator->getMin(); break; diff --git a/src/Appwrite/Specification/Format/Swagger2.php b/src/Appwrite/Specification/Format/Swagger2.php index 11538da97..858a18f7c 100644 --- a/src/Appwrite/Specification/Format/Swagger2.php +++ b/src/Appwrite/Specification/Format/Swagger2.php @@ -274,7 +274,7 @@ class Swagger2 extends Format $node['x-example'] = 'password'; break; case 'Utopia\Validator\Range': /** @var \Utopia\Validator\Range $validator */ - $node['type'] = $validator->getType(); + $node['type'] = $validator->getType() == Validator::TYPE_FLOAT ? 'number': $validator->getType(); $node['format'] = $validator->getType() == Validator::TYPE_INTEGER ? 'int32' : 'float'; $node['x-example'] = $validator->getMin(); break; From fd509ad282ae6d7718f9a4319bf415da3bebea67 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 21 May 2021 13:16:49 +0545 Subject: [PATCH 6/8] fix password format --- src/Appwrite/Specification/Format/Swagger2.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Specification/Format/Swagger2.php b/src/Appwrite/Specification/Format/Swagger2.php index 858a18f7c..2148342bb 100644 --- a/src/Appwrite/Specification/Format/Swagger2.php +++ b/src/Appwrite/Specification/Format/Swagger2.php @@ -270,7 +270,7 @@ class Swagger2 extends Format break; case 'Appwrite\Auth\Validator\Password': $node['type'] = $validator->getType(); - $node['format'] = 'format'; + $node['format'] = 'password'; $node['x-example'] = 'password'; break; case 'Utopia\Validator\Range': /** @var \Utopia\Validator\Range $validator */ From 09874e9c5d80e75f9b977d1a4cec84a77794066b Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 21 May 2021 14:29:51 +0545 Subject: [PATCH 7/8] fix spec type mismatch --- src/Appwrite/Specification/Format/OpenAPI3.php | 8 ++++---- src/Appwrite/Specification/Format/Swagger2.php | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Appwrite/Specification/Format/OpenAPI3.php b/src/Appwrite/Specification/Format/OpenAPI3.php index 2ea31d4ce..ac5234eec 100644 --- a/src/Appwrite/Specification/Format/OpenAPI3.php +++ b/src/Appwrite/Specification/Format/OpenAPI3.php @@ -256,7 +256,7 @@ class OpenAPI3 extends Format case 'Utopia\Validator\Mock': case 'Utopia\Validator\Assoc': $param['default'] = (empty($param['default'])) ? new stdClass() : $param['default']; - $node['schema']['type'] = $validator->getType(); + $node['schema']['type'] = 'object'; $node['schema']['x-example'] = '{}'; //$node['schema']['format'] = 'json'; break; @@ -266,18 +266,18 @@ class OpenAPI3 extends Format $node['schema']['format'] = 'binary'; break; case 'Utopia\Validator\ArrayList': - $node['schema']['type'] = $validator->getType(); + $node['schema']['type'] = 'array'; $node['schema']['items'] = [ 'type' => 'string', ]; break; case 'Appwrite\Auth\Validator\Password': $node['schema']['type'] = $validator->getType(); - $node['schema']['format'] = 'format'; + $node['schema']['format'] = 'password'; $node['schema']['x-example'] = 'password'; break; case 'Utopia\Validator\Range': /** @var \Utopia\Validator\Range $validator */ - $node['type'] = $validator->getType() == Validator::TYPE_FLOAT ? 'number': $validator->getType(); + $node['type'] = $validator->getType() === Validator::TYPE_FLOAT ? 'number': $validator->getType(); $node['schema']['format'] = $validator->getType() == Validator::TYPE_INTEGER ? 'int32' : 'float'; $node['schema']['x-example'] = $validator->getMin(); break; diff --git a/src/Appwrite/Specification/Format/Swagger2.php b/src/Appwrite/Specification/Format/Swagger2.php index 2148342bb..c53e099a6 100644 --- a/src/Appwrite/Specification/Format/Swagger2.php +++ b/src/Appwrite/Specification/Format/Swagger2.php @@ -252,7 +252,7 @@ class Swagger2 extends Format case 'Utopia\Validator\JSON': case 'Utopia\Validator\Mock': case 'Utopia\Validator\Assoc': - $node['type'] = $validator->getType(); + $node['type'] = 'object'; $param['default'] = (empty($param['default'])) ? new stdClass() : $param['default']; $node['x-example'] = '{}'; //$node['format'] = 'json'; @@ -262,7 +262,7 @@ class Swagger2 extends Format $node['type'] = $validator->getType(); break; case 'Utopia\Validator\ArrayList': - $node['type'] = $validator->getType(); + $node['type'] = 'array'; $node['collectionFormat'] = 'multi'; $node['items'] = [ 'type' => 'string', @@ -274,7 +274,7 @@ class Swagger2 extends Format $node['x-example'] = 'password'; break; case 'Utopia\Validator\Range': /** @var \Utopia\Validator\Range $validator */ - $node['type'] = $validator->getType() == Validator::TYPE_FLOAT ? 'number': $validator->getType(); + $node['type'] = $validator->getType() === Validator::TYPE_FLOAT ? 'number': $validator->getType(); $node['format'] = $validator->getType() == Validator::TYPE_INTEGER ? 'int32' : 'float'; $node['x-example'] = $validator->getMin(); break; From 546214012dd8047471790b601df5655e57947236 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 21 May 2021 16:32:08 +0545 Subject: [PATCH 8/8] fix openAPI spec --- src/Appwrite/Specification/Format/OpenAPI3.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Specification/Format/OpenAPI3.php b/src/Appwrite/Specification/Format/OpenAPI3.php index ac5234eec..b14134cdf 100644 --- a/src/Appwrite/Specification/Format/OpenAPI3.php +++ b/src/Appwrite/Specification/Format/OpenAPI3.php @@ -277,7 +277,7 @@ class OpenAPI3 extends Format $node['schema']['x-example'] = 'password'; break; case 'Utopia\Validator\Range': /** @var \Utopia\Validator\Range $validator */ - $node['type'] = $validator->getType() === Validator::TYPE_FLOAT ? 'number': $validator->getType(); + $node['schema']['type'] = $validator->getType() === Validator::TYPE_FLOAT ? 'number': $validator->getType(); $node['schema']['format'] = $validator->getType() == Validator::TYPE_INTEGER ? 'int32' : 'float'; $node['schema']['x-example'] = $validator->getMin(); break;