Added service descriptions to Swagger and OpenAPI3 specs
This commit is contained in:
parent
c62d33c683
commit
237973bcb9
|
@ -2,98 +2,126 @@
|
|||
|
||||
return [
|
||||
'/' => [
|
||||
'key' => 'homepage',
|
||||
'name' => 'Homepage',
|
||||
'controller' => 'web/home.php',
|
||||
'sdk' => false,
|
||||
'docs' => false,
|
||||
'tests' => false,
|
||||
],
|
||||
'console/' => [
|
||||
'key' => 'console',
|
||||
'name' => 'Console',
|
||||
'controller' => 'web/console.php',
|
||||
'sdk' => false,
|
||||
'docs' => false,
|
||||
'tests' => false,
|
||||
],
|
||||
'v1/account' => [
|
||||
'key' => 'account',
|
||||
'name' => 'Account',
|
||||
'description' => '/docs/services/account.md',
|
||||
'controller' => 'api/account.php',
|
||||
'sdk' => true,
|
||||
'docs' => true,
|
||||
'tests' => false,
|
||||
],
|
||||
'v1/avatars' => [
|
||||
'key' => 'avatars',
|
||||
'name' => 'Avatars',
|
||||
'description' => '/docs/services/avatars.md',
|
||||
'controller' => 'api/avatars.php',
|
||||
'sdk' => true,
|
||||
'docs' => true,
|
||||
'tests' => false,
|
||||
],
|
||||
'v1/database' => [
|
||||
'key' => 'database',
|
||||
'name' => 'Database',
|
||||
'description' => '/docs/services/database.md',
|
||||
'controller' => 'api/database.php',
|
||||
'sdk' => true,
|
||||
'docs' => true,
|
||||
'tests' => false,
|
||||
],
|
||||
'v1/locale' => [
|
||||
'key' => 'locale',
|
||||
'name' => 'Locale',
|
||||
'description' => '/docs/services/locale.md',
|
||||
'controller' => 'api/locale.php',
|
||||
'sdk' => true,
|
||||
'docs' => true,
|
||||
'tests' => false,
|
||||
],
|
||||
'v1/health' => [
|
||||
'key' => 'health',
|
||||
'name' => 'Health',
|
||||
'description' => '/docs/services/health.md',
|
||||
'controller' => 'api/health.php',
|
||||
'sdk' => true,
|
||||
'docs' => true,
|
||||
'tests' => false,
|
||||
],
|
||||
'v1/projects' => [
|
||||
'key' => 'projects',
|
||||
'name' => 'Projects',
|
||||
'controller' => 'api/projects.php',
|
||||
'sdk' => true,
|
||||
'docs' => true,
|
||||
'tests' => false,
|
||||
],
|
||||
'v1/storage' => [
|
||||
'key' => 'storage',
|
||||
'name' => 'Storage',
|
||||
'description' => '/docs/services/storage.md',
|
||||
'controller' => 'api/storage.php',
|
||||
'sdk' => true,
|
||||
'docs' => true,
|
||||
'tests' => false,
|
||||
],
|
||||
'v1/teams' => [
|
||||
'key' => 'teams',
|
||||
'name' => 'Teams',
|
||||
'description' => '/docs/services/teams.md',
|
||||
'controller' => 'api/teams.php',
|
||||
'sdk' => true,
|
||||
'docs' => true,
|
||||
'tests' => false,
|
||||
],
|
||||
'v1/users' => [
|
||||
'key' => 'users',
|
||||
'name' => 'Users',
|
||||
'description' => '/docs/services/users.md',
|
||||
'controller' => 'api/users.php',
|
||||
'sdk' => true,
|
||||
'docs' => true,
|
||||
'tests' => false,
|
||||
],
|
||||
'v1/functions' => [
|
||||
'name' => 'Users',
|
||||
'key' => 'functions',
|
||||
'name' => 'Functions',
|
||||
'description' => '/docs/services/functions.md',
|
||||
'controller' => 'api/functions.php',
|
||||
'sdk' => true,
|
||||
'docs' => true,
|
||||
'tests' => false,
|
||||
],
|
||||
'v1/mock' => [
|
||||
'key' => 'mock',
|
||||
'name' => 'Mock',
|
||||
'description' => '',
|
||||
'controller' => 'mock.php',
|
||||
'sdk' => false,
|
||||
'docs' => false,
|
||||
'tests' => true,
|
||||
],
|
||||
'v1/graphql' => [
|
||||
'key' => 'graphql',
|
||||
'name' => 'GraphQL',
|
||||
'description' => 'GraphQL Endpoint',
|
||||
'controller' => 'api/graphql.php',
|
||||
'sdk' => false,
|
||||
'docs' => false,
|
||||
'tests' => false,
|
||||
],
|
||||
];
|
||||
|
|
|
@ -216,6 +216,7 @@ App::get('/specs/:format')
|
|||
|
||||
$routes = [];
|
||||
$models = [];
|
||||
$services = [];
|
||||
|
||||
$keys = [
|
||||
APP_PLATFORM_CLIENT => [
|
||||
|
@ -317,6 +318,20 @@ App::get('/specs/:format')
|
|||
}
|
||||
}
|
||||
|
||||
foreach (Config::getParam('services', []) as $key => $service) {
|
||||
if(!isset($service['docs']) // Skip service if not part of the public API
|
||||
|| !isset($service['sdk'])
|
||||
|| !$service['docs']
|
||||
|| !$service['sdk']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$services[] = [
|
||||
'name' => $service['key'] ?? '',
|
||||
'description' => (!empty($service['description'])) ? file_get_contents(realpath(__DIR__.'/../../..'.$service['description'])) : '',
|
||||
];
|
||||
}
|
||||
|
||||
$models = $response->getModels();
|
||||
|
||||
foreach ($models as $key => $value) {
|
||||
|
@ -327,11 +342,11 @@ App::get('/specs/:format')
|
|||
|
||||
switch ($format) {
|
||||
case 'swagger2':
|
||||
$format = new Swagger2($utopia, $routes, $models, $keys[$platform], $security[$platform]);
|
||||
$format = new Swagger2($utopia, $services, $routes, $models, $keys[$platform], $security[$platform]);
|
||||
break;
|
||||
|
||||
case 'open-api3':
|
||||
$format = new OpenAPI3($utopia, $routes, $models, $keys[$platform], $security[$platform]);
|
||||
$format = new OpenAPI3($utopia, $services, $routes, $models, $keys[$platform], $security[$platform]);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -13,6 +13,11 @@ abstract class Format
|
|||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $services;
|
||||
|
||||
/**
|
||||
* @var Route[]
|
||||
*/
|
||||
|
@ -53,14 +58,16 @@ abstract class Format
|
|||
|
||||
/**
|
||||
* @param App $app
|
||||
* @param array $services
|
||||
* @param Route[] $routes
|
||||
* @param Model[] $models
|
||||
* @param array $keys
|
||||
* @param array $security
|
||||
*/
|
||||
public function __construct(App $app, array $routes, array $models, array $keys, array $security)
|
||||
public function __construct(App $app, array $services, array $routes, array $models, array $keys, array $security)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->services = $services;
|
||||
$this->routes = $routes;
|
||||
$this->models = $models;
|
||||
$this->keys = $keys;
|
||||
|
|
|
@ -56,6 +56,7 @@ class OpenAPI3 extends Format
|
|||
],
|
||||
],
|
||||
'paths' => [],
|
||||
'tags' => $this->services,
|
||||
'components' => [
|
||||
'schemas' => [],
|
||||
'securitySchemes' => $this->keys,
|
||||
|
|
|
@ -57,6 +57,7 @@ class Swagger2 extends Format
|
|||
'produces' => ['application/json'],
|
||||
'securityDefinitions' => $this->keys,
|
||||
'paths' => [],
|
||||
'tags' => $this->services,
|
||||
'definitions' => [],
|
||||
'externalDocs' => [
|
||||
'description' => $this->getParam('docs.description'),
|
||||
|
|
Loading…
Reference in a new issue