1
0
Fork 0
mirror of synced 2024-05-20 04:32:37 +12:00

fix: validator class and spec generator

This commit is contained in:
Torsten Dittmann 2021-04-13 10:46:30 +02:00
parent 7d08c30672
commit 20e858dbfe
19 changed files with 373 additions and 55 deletions

View file

@ -3,12 +3,12 @@
global $utopia, $request, $response;
use Appwrite\Database\Document;
use Appwrite\Network\Validator\Host;
use Appwrite\Utopia\Response;
use Utopia\App;
use Utopia\Validator\Numeric;
use Utopia\Validator\Text;
use Utopia\Validator\ArrayList;
use Utopia\Validator\Host;
use Utopia\Storage\Validator\File;
App::get('/v1/mock/tests/foo')

View file

@ -37,7 +37,7 @@
"appwrite/php-clamav": "1.0.*",
"utopia-php/framework": "0.12.*",
"utopia-php/framework": "0.13.*",
"utopia-php/abuse": "0.4.*",
"utopia-php/analytics": "0.2.*",
"utopia-php/audit": "0.5.*",
@ -50,7 +50,7 @@
"utopia-php/domains": "0.2.*",
"utopia-php/swoole": "0.2.*",
"utopia-php/system": "0.4.*",
"utopia-php/storage": "0.4.*",
"utopia-php/storage": "0.5.*",
"utopia-php/image": "0.1.*",
"resque/php-resque": "1.3.6",

View file

@ -40,4 +40,28 @@ class Password extends Validator
return true;
}
/**
* Is array
*
* Function will return true if object is array.
*
* @return bool
*/
public function isArray(): bool
{
return false;
}
/**
* Get Type
*
* Returns validator type.
*
* @return string
*/
public function getType(): string
{
return self::TYPE_STRING;
}
}

View file

@ -188,4 +188,28 @@ class Authorization extends Validator
{
self::$status = self::$statusDefault;
}
/**
* Is array
*
* Function will return true if object is array.
*
* @return bool
*/
public function isArray(): bool
{
return false;
}
/**
* Get Type
*
* Returns validator type.
*
* @return string
*/
public function getType(): string
{
return self::TYPE_ARRAY;
}
}

View file

@ -78,4 +78,28 @@ class DocumentId extends Validator
return true;
}
/**
* Is array
*
* Function will return true if object is array.
*
* @return bool
*/
public function isArray(): bool
{
return false;
}
/**
* Get Type
*
* Returns validator type.
*
* @return string
*/
public function getType(): string
{
return self::TYPE_STRING;
}
}

View file

@ -48,4 +48,27 @@ class Key extends Validator
return true;
}
/**
* Is array
*
* Function will return true if object is array.
*
* @return bool
*/
public function isArray(): bool
{
return false;
}
/**
* Get Type
*
* Returns validator type.
*
* @return string
*/
public function getType(): string
{
return self::TYPE_STRING;
}
}

View file

@ -74,4 +74,27 @@ class Permissions extends Validator
return true;
}
/**
* Is array
*
* Function will return true if object is array.
*
* @return bool
*/
public function isArray(): bool
{
return false;
}
/**
* Get Type
*
* Returns validator type.
*
* @return string
*/
public function getType(): string
{
return self::TYPE_ARRAY;
}
}

View file

@ -285,4 +285,28 @@ class Structure extends Validator
{
return $this->database->getDocument($id);
}
/**
* Is array
*
* Function will return true if object is array.
*
* @return bool
*/
public function isArray(): bool
{
return false;
}
/**
* Get Type
*
* Returns validator type.
*
* @return string
*/
public function getType(): string
{
return self::TYPE_OBJECT;
}
}

View file

@ -43,4 +43,28 @@ class UID extends Validator
return true;
}
/**
* Is array
*
* Function will return true if object is array.
*
* @return bool
*/
public function isArray(): bool
{
return false;
}
/**
* Get Type
*
* Returns validator type.
*
* @return string
*/
public function getType(): string
{
return self::TYPE_STRING;
}
}

View file

@ -54,4 +54,28 @@ class CNAME extends Validator
return false;
}
/**
* Is array
*
* Function will return true if object is array.
*
* @return bool
*/
public function isArray(): bool
{
return false;
}
/**
* Get Type
*
* Returns validator type.
*
* @return string
*/
public function getType(): string
{
return self::TYPE_STRING;
}
}

View file

@ -51,4 +51,28 @@ class Domain extends Validator
return true;
}
/**
* Is array
*
* Function will return true if object is array.
*
* @return bool
*/
public function isArray(): bool
{
return false;
}
/**
* Get Type
*
* Returns validator type.
*
* @return string
*/
public function getType(): string
{
return self::TYPE_STRING;
}
}

View file

@ -25,18 +25,6 @@ class Email extends Validator
return 'Value must be a valid email address';
}
/**
* Get Type
*
* Returns validator type.
*
* @return string
*/
public function getType()
{
return 'string';
}
/**
* Is valid
*
@ -53,4 +41,28 @@ class Email extends Validator
return true;
}
/**
* Is array
*
* Function will return true if object is array.
*
* @return bool
*/
public function isArray(): bool
{
return false;
}
/**
* Get Type
*
* Returns validator type.
*
* @return string
*/
public function getType(): string
{
return self::TYPE_STRING;
}
}

View file

@ -35,18 +35,6 @@ class Host extends Validator
return 'URL host must be one of: ' . \implode(', ', $this->whitelist);
}
/**
* Get Type
*
* Returns validator type.
*
* @return string
*/
public function getType()
{
return 'string';
}
/**
* Is valid
*
@ -69,4 +57,28 @@ class Host extends Validator
return false;
}
/**
* Is array
*
* Function will return true if object is array.
*
* @return bool
*/
public function isArray(): bool
{
return false;
}
/**
* Get Type
*
* Returns validator type.
*
* @return string
*/
public function getType(): string
{
return self::TYPE_STRING;
}
}

View file

@ -51,18 +51,6 @@ class IP extends Validator
return 'Value must be a valid IP address';
}
/**
* Get Type
*
* Returns validator type.
*
* @return string
*/
public function getType()
{
return 'string';
}
/**
* Is valid
*
@ -99,4 +87,28 @@ class IP extends Validator
return false;
}
/**
* Is array
*
* Function will return true if object is array.
*
* @return bool
*/
public function isArray(): bool
{
return false;
}
/**
* Get Type
*
* Returns validator type.
*
* @return string
*/
public function getType(): string
{
return self::TYPE_STRING;
}
}

View file

@ -119,4 +119,28 @@ class Origin extends Validator
return false;
}
/**
* Is array
*
* Function will return true if object is array.
*
* @return bool
*/
public function isArray(): bool
{
return false;
}
/**
* Get Type
*
* Returns validator type.
*
* @return string
*/
public function getType(): string
{
return self::TYPE_STRING;
}
}

View file

@ -25,18 +25,6 @@ class URL extends Validator
return 'Value must be a valid URL';
}
/**
* Get Type
*
* Returns validator type.
*
* @return string
*/
public function getType()
{
return 'string';
}
/**
* Is valid
*
@ -53,4 +41,28 @@ class URL extends Validator
return true;
}
/**
* Is array
*
* Function will return true if object is array.
*
* @return bool
*/
public function isArray(): bool
{
return false;
}
/**
* Get Type
*
* Returns validator type.
*
* @return string
*/
public function getType(): string
{
return self::TYPE_STRING;
}
}

View file

@ -251,14 +251,18 @@ class OpenAPI3 extends Format
case 'Utopia\Validator\Length':
$node['schema']['type'] = 'string';
break;
case 'Utopia\Validator\Host':
case 'Appwrite\Network\Validator\Host':
$node['schema']['type'] = 'string';
$node['schema']['format'] = 'url';
$node['schema']['x-example'] = 'https://example.com';
break;
case 'Utopia\Validator\WhiteList': /** @var \Utopia\Validator\WhiteList $validator */
$node['schema']['type'] = 'string';
$node['schema']['type'] = $validator->getType();
$node['schema']['x-example'] = $validator->getList()[0];
if ($validator->getType() === 'integer') {
$node['format'] = 'int32';
}
break;
default:
$node['schema']['type'] = 'string';

View file

@ -248,14 +248,18 @@ class Swagger2 extends Format
case 'Utopia\Validator\Length':
$node['type'] = 'string';
break;
case 'Utopia\Validator\Host':
case 'Appwrite\Network\Validator\Host':
$node['type'] = 'string';
$node['format'] = 'url';
$node['x-example'] = 'https://example.com';
break;
case 'Utopia\Validator\WhiteList': /** @var \Utopia\Validator\WhiteList $validator */
$node['type'] = 'string';
$node['type'] = $validator->getType();
$node['x-example'] = $validator->getList()[0];
if ($validator->getType() === 'integer') {
$node['format'] = 'int32';
}
break;
default:
$node['type'] = 'string';

View file

@ -40,4 +40,28 @@ class Cron extends Validator
return true;
}
/**
* Is array
*
* Function will return true if object is array.
*
* @return bool
*/
public function isArray(): bool
{
return false;
}
/**
* Get Type
*
* Returns validator type.
*
* @return string
*/
public function getType(): string
{
return self::TYPE_STRING;
}
}