mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
resolve merge conflicts
This commit is contained in:
@@ -113,6 +113,7 @@ class Exception extends \Exception
|
||||
public const STORAGE_BUCKET_NOT_FOUND = 'storage_bucket_not_found';
|
||||
public const STORAGE_INVALID_CONTENT_RANGE = 'storage_invalid_content_range';
|
||||
public const STORAGE_INVALID_RANGE = 'storage_invalid_range';
|
||||
public const STORAGE_INVALID_APPWRITE_ID = 'storage_invalid_appwrite_id';
|
||||
|
||||
/** Functions */
|
||||
public const FUNCTION_NOT_FOUND = 'function_not_found';
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Appwrite\Specification;
|
||||
|
||||
use Utopia\App;
|
||||
use Utopia\Config\Config;
|
||||
use Utopia\Route;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
@@ -38,6 +39,17 @@ abstract class Format
|
||||
'license.url' => '',
|
||||
];
|
||||
|
||||
/*
|
||||
* Blacklist to omit the enum types for the given route's parameter
|
||||
*/
|
||||
protected array $enumBlacklist = [
|
||||
[
|
||||
'namespace' => 'users',
|
||||
'method' => 'getUsage',
|
||||
'parameter' => 'provider'
|
||||
]
|
||||
];
|
||||
|
||||
public function __construct(App $app, array $services, array $routes, array $models, array $keys, int $authCount)
|
||||
{
|
||||
$this->app = $app;
|
||||
@@ -97,4 +109,141 @@ abstract class Format
|
||||
{
|
||||
return $this->params[$key] ?? $default;
|
||||
}
|
||||
|
||||
protected function getEnumName(string $service, string $method, string $param): ?string
|
||||
{
|
||||
switch ($service) {
|
||||
case 'account':
|
||||
switch ($method) {
|
||||
case 'createOAuth2Session':
|
||||
return 'Provider';
|
||||
}
|
||||
break;
|
||||
case 'avatars':
|
||||
switch ($method) {
|
||||
case 'getBrowser':
|
||||
return 'Browser';
|
||||
case 'getCreditCard':
|
||||
return 'CreditCard';
|
||||
case 'getFlag':
|
||||
return 'Flag';
|
||||
}
|
||||
break;
|
||||
case 'storage':
|
||||
switch ($method) {
|
||||
case 'getFilePreview':
|
||||
switch ($param) {
|
||||
case 'gravity':
|
||||
return 'ImageGravity';
|
||||
case 'output':
|
||||
return 'ImageFormat';
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'databases':
|
||||
switch ($method) {
|
||||
case 'createRelationshipAttribute':
|
||||
switch ($param) {
|
||||
case 'type':
|
||||
return 'RelationshipType';
|
||||
case 'onDelete':
|
||||
return 'RelationMutate';
|
||||
}
|
||||
break;
|
||||
case 'updateRelationshipAttribute':
|
||||
switch ($param) {
|
||||
case 'onDelete':
|
||||
return 'RelationMutate';
|
||||
}
|
||||
break;
|
||||
case 'createIndex':
|
||||
switch ($param) {
|
||||
case 'type':
|
||||
return 'IndexType';
|
||||
case 'orders':
|
||||
return 'OrderBy';
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'projects':
|
||||
switch ($method) {
|
||||
case 'createPlatform':
|
||||
switch ($param) {
|
||||
case 'type':
|
||||
return 'PlatformType';
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public function getEnumKeys(string $service, string $method, string $param): array
|
||||
{
|
||||
$values = [];
|
||||
switch ($service) {
|
||||
case 'avatars':
|
||||
switch ($method) {
|
||||
case 'getBrowser':
|
||||
$codes = Config::getParam('avatar-browsers');
|
||||
foreach ($codes as $code => $value) {
|
||||
$values[] = $value['name'];
|
||||
}
|
||||
return $values;
|
||||
case 'getCreditCard':
|
||||
$codes = Config::getParam('avatar-credit-cards');
|
||||
foreach ($codes as $code => $value) {
|
||||
$values[] = $value['name'];
|
||||
}
|
||||
return $values;
|
||||
case 'getFlag':
|
||||
$codes = Config::getParam('avatar-flags');
|
||||
foreach ($codes as $code => $value) {
|
||||
$values[] = $value['name'];
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
break;
|
||||
case 'databases':
|
||||
switch ($method) {
|
||||
case 'getUsage':
|
||||
case 'getCollectionUsage':
|
||||
case 'getDatabaseUsage':
|
||||
// Range Enum Keys
|
||||
$values = ['Twenty Four Hours', 'Seven Days', 'Thirty Days', 'Ninety Days'];
|
||||
return $values;
|
||||
}
|
||||
break;
|
||||
case 'function':
|
||||
switch ($method) {
|
||||
case 'getUsage':
|
||||
case 'getFunctionUsage':
|
||||
// Range Enum Keys
|
||||
$values = ['Twenty Four Hours', 'Seven Days', 'Thirty Days', 'Ninety Days'];
|
||||
return $values;
|
||||
}
|
||||
break;
|
||||
case 'users':
|
||||
switch ($method) {
|
||||
case 'getUsage':
|
||||
case 'getUserUsage':
|
||||
// Range Enum Keys
|
||||
if ($param == 'range') {
|
||||
$values = ['Twenty Four Hours', 'Seven Days', 'Thirty Days', 'Ninety Days'];
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'storage':
|
||||
switch ($method) {
|
||||
case 'getUsage':
|
||||
case 'getBucketUsage':
|
||||
// Range Enum Keys
|
||||
$values = ['Twenty Four Hours', 'Seven Days', 'Thirty Days', 'Ninety Days'];
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -414,6 +414,25 @@ class OpenAPI3 extends Format
|
||||
$node['schema']['type'] = $validator->getType();
|
||||
$node['schema']['x-example'] = $validator->getList()[0];
|
||||
|
||||
//Iterate from the blackList. If it matches with the current one, then it is a blackList
|
||||
// Do not add the enum
|
||||
$allowed = true;
|
||||
foreach ($this->enumBlacklist as $blacklist) {
|
||||
if (
|
||||
$blacklist['namespace'] == $route->getLabel('sdk.namespace', '')
|
||||
&& $blacklist['method'] == $route->getLabel('sdk.method', '')
|
||||
&& $blacklist['parameter'] == $name
|
||||
) {
|
||||
$allowed = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($allowed) {
|
||||
$node['schema']['enum'] = $validator->getList();
|
||||
$node['schema']['x-enum-name'] = $this->getEnumName($route->getLabel('sdk.namespace', ''), $route->getLabel('sdk.method', ''), $name);
|
||||
$node['schema']['x-enum-keys'] = $this->getEnumKeys($route->getLabel('sdk.namespace', ''), $route->getLabel('sdk.method', ''), $name);
|
||||
}
|
||||
if ($validator->getType() === 'integer') {
|
||||
$node['format'] = 'int32';
|
||||
}
|
||||
@@ -444,6 +463,13 @@ class OpenAPI3 extends Format
|
||||
'x-example' => $node['schema']['x-example'] ?? null
|
||||
];
|
||||
|
||||
if (isset($node['schema']['enum'])) {
|
||||
/// If the enum flag is Set, add the enum values to the body
|
||||
$body['content'][$consumes[0]]['schema']['properties'][$name]['enum'] = $node['schema']['enum'];
|
||||
$body['content'][$consumes[0]]['schema']['properties'][$name]['x-enum-name'] = $node['schema']['x-enum-name'] ?? null;
|
||||
$body['content'][$consumes[0]]['schema']['properties'][$name]['x-enum-keys'] = $node['schema']['x-enum-keys'] ?? null;
|
||||
}
|
||||
|
||||
if ($node['schema']['x-upload-id'] ?? false) {
|
||||
$body['content'][$consumes[0]]['schema']['properties'][$name]['x-upload-id'] = $node['schema']['x-upload-id'];
|
||||
}
|
||||
|
||||
@@ -293,6 +293,7 @@ class Swagger2 extends Format
|
||||
$validator = $validator->getValidator();
|
||||
}
|
||||
|
||||
|
||||
switch ((!empty($validator)) ? \get_class($validator) : '') {
|
||||
case 'Utopia\Validator\Text':
|
||||
$node['type'] = $validator->getType();
|
||||
@@ -416,6 +417,22 @@ class Swagger2 extends Format
|
||||
$node['type'] = $validator->getType();
|
||||
$node['x-example'] = $validator->getList()[0];
|
||||
|
||||
//Iterate from the blackList. If it matches with the current one, then it is a blackList
|
||||
// Do not add the enum
|
||||
$allowed = true;
|
||||
foreach ($this->enumBlacklist as $blacklist) {
|
||||
if ($blacklist['namespace'] == $route->getLabel('sdk.namespace', '') && $blacklist['method'] == $route->getLabel('sdk.method', '') && $blacklist['parameter'] == $name) {
|
||||
$allowed = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($allowed) {
|
||||
$node['enum'] = $validator->getList();
|
||||
$node['x-enum-name'] = $this->getEnumName($route->getLabel('sdk.namespace', ''), $route->getLabel('sdk.method', ''), $name);
|
||||
$node['x-enum-keys'] = $this->getEnumKeys($route->getLabel('sdk.namespace', ''), $route->getLabel('sdk.method', ''), $name);
|
||||
}
|
||||
|
||||
if ($validator->getType() === 'integer') {
|
||||
$node['format'] = 'int32';
|
||||
}
|
||||
@@ -454,6 +471,13 @@ class Swagger2 extends Format
|
||||
'x-example' => $node['x-example'] ?? null,
|
||||
];
|
||||
|
||||
if (isset($node['enum'])) {
|
||||
/// If the enum flag is Set, add the enum values to the body
|
||||
$body['schema']['properties'][$name]['enum'] = $node['enum'];
|
||||
$body['schema']['properties'][$name]['x-enum-name'] = $node['x-enum-name'] ?? null;
|
||||
$body['schema']['properties'][$name]['x-enum-keys'] = $node['x-enum-keys'] ?? null;
|
||||
}
|
||||
|
||||
if ($node['x-global'] ?? false) {
|
||||
$body['schema']['properties'][$name]['x-global'] = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user