From e1837c01d59ef7a6a197d46aa6a3f16d56f08993 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 12 Nov 2020 07:12:14 +0200 Subject: [PATCH] Added option to hide some models from the docs --- app/controllers/web/home.php | 8 ++++++-- src/Appwrite/Utopia/Response.php | 12 ++++++------ src/Appwrite/Utopia/Response/Model.php | 17 +++++++++++++++++ src/Appwrite/Utopia/Response/Model/BaseList.php | 11 ++++++++++- src/Appwrite/Utopia/Response/Model/Domain.php | 5 +++++ src/Appwrite/Utopia/Response/Model/Key.php | 5 +++++ src/Appwrite/Utopia/Response/Model/Platform.php | 5 +++++ src/Appwrite/Utopia/Response/Model/Project.php | 5 +++++ src/Appwrite/Utopia/Response/Model/Task.php | 5 +++++ src/Appwrite/Utopia/Response/Model/Webhook.php | 5 +++++ 10 files changed, 69 insertions(+), 9 deletions(-) diff --git a/app/controllers/web/home.php b/app/controllers/web/home.php index 7043c94e8..10e0ec1e1 100644 --- a/app/controllers/web/home.php +++ b/app/controllers/web/home.php @@ -276,8 +276,6 @@ App::get('/specs/:format') foreach ($utopia->getRoutes() as $key => $method) { foreach ($method as $route) { /** @var \Utopia\Route $route */ - var_dump($route->getURL()); - if (!$route->getLabel('docs', true)) { continue; } @@ -305,6 +303,12 @@ App::get('/specs/:format') $models = $response->getModels(); + foreach ($models as $key => $value) { + if($platform !== APP_PLATFORM_CONSOLE && !$value->isPublic()) { + unset($models[$key]); + } + } + switch ($format) { case 'swagger2': $format = new Swagger2($utopia, $routes, $models, $keys[$platform], $security[$platform]); diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index 7c9c66779..ec19e186d 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -141,12 +141,12 @@ class Response extends SwooleResponse ->setModel(new BaseList('Functions List', self::MODEL_FUNCTION_LIST, 'functions', self::MODEL_FUNCTION)) ->setModel(new BaseList('Tags List', self::MODEL_TAG_LIST, 'tags', self::MODEL_TAG)) ->setModel(new BaseList('Executions List', self::MODEL_EXECUTION_LIST, 'executions', self::MODEL_EXECUTION)) - ->setModel(new BaseList('Projects List', self::MODEL_PROJECT_LIST, 'projects', self::MODEL_PROJECT)) - ->setModel(new BaseList('Webhooks List', self::MODEL_WEBHOOK_LIST, 'webhooks', self::MODEL_WEBHOOK)) - ->setModel(new BaseList('API Keys List', self::MODEL_KEY_LIST, 'keys', self::MODEL_KEY)) - ->setModel(new BaseList('Tasks List', self::MODEL_TASK_LIST, 'tasks', self::MODEL_TASK)) - ->setModel(new BaseList('Platforms List', self::MODEL_PLATFORM_LIST, 'platforms', self::MODEL_PLATFORM)) - ->setModel(new BaseList('Domains List', self::MODEL_DOMAIN_LIST, 'domains', self::MODEL_DOMAIN)) + ->setModel(new BaseList('Projects List', self::MODEL_PROJECT_LIST, 'projects', self::MODEL_PROJECT, true, false)) + ->setModel(new BaseList('Webhooks List', self::MODEL_WEBHOOK_LIST, 'webhooks', self::MODEL_WEBHOOK, true, false)) + ->setModel(new BaseList('API Keys List', self::MODEL_KEY_LIST, 'keys', self::MODEL_KEY, true, false)) + ->setModel(new BaseList('Tasks List', self::MODEL_TASK_LIST, 'tasks', self::MODEL_TASK, true, false)) + ->setModel(new BaseList('Platforms List', self::MODEL_PLATFORM_LIST, 'platforms', self::MODEL_PLATFORM, true, false)) + ->setModel(new BaseList('Domains List', self::MODEL_DOMAIN_LIST, 'domains', self::MODEL_DOMAIN, true, false)) ->setModel(new BaseList('Countries List', self::MODEL_COUNTRY_LIST, 'countries', self::MODEL_COUNTRY)) ->setModel(new BaseList('Continents List', self::MODEL_CONTINENT_LIST, 'continents', self::MODEL_CONTINENT)) ->setModel(new BaseList('Languages List', self::MODEL_LANGUAGE_LIST, 'languages', self::MODEL_LANGUAGE)) diff --git a/src/Appwrite/Utopia/Response/Model.php b/src/Appwrite/Utopia/Response/Model.php index 3257e88d8..af71a5759 100644 --- a/src/Appwrite/Utopia/Response/Model.php +++ b/src/Appwrite/Utopia/Response/Model.php @@ -20,6 +20,11 @@ abstract class Model */ protected $any = false; + /** + * @var bool + */ + protected $public = true; + /** * @var array */ @@ -102,4 +107,16 @@ abstract class Model { return $this->any; } + + /** + * Is Public + * + * Should this model be publicly available in docs and spec files? + * + * @return bool + */ + public function isPublic(): bool + { + return $this->public; + } } \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/BaseList.php b/src/Appwrite/Utopia/Response/Model/BaseList.php index d1b64d220..caf405640 100644 --- a/src/Appwrite/Utopia/Response/Model/BaseList.php +++ b/src/Appwrite/Utopia/Response/Model/BaseList.php @@ -17,10 +17,19 @@ class BaseList extends Model */ protected $type = ''; - public function __construct(string $name, string $type, string $key, string $model, bool $paging = true) + /** + * @param string $name + * @param string $type + * @param string $key + * @param string $model + * @param bool $paging + * @param bool $public + */ + public function __construct(string $name, string $type, string $key, string $model, bool $paging = true, bool $public = true) { $this->name = $name; $this->type = $type; + $this->public = $public; if ($paging) { $this->addRule('sum', [ diff --git a/src/Appwrite/Utopia/Response/Model/Domain.php b/src/Appwrite/Utopia/Response/Model/Domain.php index ee0445e37..2e58a3053 100644 --- a/src/Appwrite/Utopia/Response/Model/Domain.php +++ b/src/Appwrite/Utopia/Response/Model/Domain.php @@ -7,6 +7,11 @@ use Appwrite\Utopia\Response\Model; class Domain extends Model { + /** + * @var bool + */ + protected $public = false; + public function __construct() { $this diff --git a/src/Appwrite/Utopia/Response/Model/Key.php b/src/Appwrite/Utopia/Response/Model/Key.php index 40e3b58a7..28be3adbf 100644 --- a/src/Appwrite/Utopia/Response/Model/Key.php +++ b/src/Appwrite/Utopia/Response/Model/Key.php @@ -7,6 +7,11 @@ use Appwrite\Utopia\Response\Model; class Key extends Model { + /** + * @var bool + */ + protected $public = false; + public function __construct() { $this diff --git a/src/Appwrite/Utopia/Response/Model/Platform.php b/src/Appwrite/Utopia/Response/Model/Platform.php index 1abe520b9..06c61d3e1 100644 --- a/src/Appwrite/Utopia/Response/Model/Platform.php +++ b/src/Appwrite/Utopia/Response/Model/Platform.php @@ -7,6 +7,11 @@ use Appwrite\Utopia\Response\Model; class Platform extends Model { + /** + * @var bool + */ + protected $public = false; + public function __construct() { $this diff --git a/src/Appwrite/Utopia/Response/Model/Project.php b/src/Appwrite/Utopia/Response/Model/Project.php index f57e70131..e48163189 100644 --- a/src/Appwrite/Utopia/Response/Model/Project.php +++ b/src/Appwrite/Utopia/Response/Model/Project.php @@ -8,6 +8,11 @@ use Utopia\Config\Config; class Project extends Model { + /** + * @var bool + */ + protected $public = false; + public function __construct() { $this diff --git a/src/Appwrite/Utopia/Response/Model/Task.php b/src/Appwrite/Utopia/Response/Model/Task.php index 043ac951e..53ec1474e 100644 --- a/src/Appwrite/Utopia/Response/Model/Task.php +++ b/src/Appwrite/Utopia/Response/Model/Task.php @@ -7,6 +7,11 @@ use Appwrite\Utopia\Response\Model; class Task extends Model { + /** + * @var bool + */ + protected $public = false; + public function __construct() { $this diff --git a/src/Appwrite/Utopia/Response/Model/Webhook.php b/src/Appwrite/Utopia/Response/Model/Webhook.php index a58f3fe05..f8b8ac743 100644 --- a/src/Appwrite/Utopia/Response/Model/Webhook.php +++ b/src/Appwrite/Utopia/Response/Model/Webhook.php @@ -7,6 +7,11 @@ use Appwrite\Utopia\Response\Model; class Webhook extends Model { + /** + * @var bool + */ + protected $public = false; + public function __construct() { $this