1
0
Fork 0
mirror of synced 2024-05-20 12:42:39 +12:00

feat: filter response models in swagger spec

This commit is contained in:
Torsten Dittmann 2021-04-08 10:39:44 +02:00
parent 3ff66179c5
commit d8fd30cffa

View file

@ -81,7 +81,9 @@ class Swagger2 extends Format
$output['securityDefinitions']['Mode']['x-appwrite'] = ['demo' => ''];
}
foreach ($this->routes as $route) { /* @var $route \Utopia\Route */
$usedModels = [];
foreach ($this->routes as $route) { /** @var \Utopia\Route $route */
$url = \str_replace('/v1', '', $route->getURL());
$scope = $route->getLabel('scope', '');
$hide = $route->getLabel('sdk.hide', false);
@ -148,6 +150,7 @@ class Swagger2 extends Format
],
];
} else {
$usedModels[] = $model->getType();
$temp['responses'][(string)$route->getLabel('sdk.response.code', '500')] = [
'description' => $model->getName(),
'schema' => [
@ -232,7 +235,7 @@ class Swagger2 extends Format
$node['format'] = 'format';
$node['x-example'] = 'password';
break;
case 'Utopia\Validator\Range': /* @var $validator \Utopia\Validator\Range */
case 'Utopia\Validator\Range': /** @var \Utopia\Validator\Range $validator */
$node['type'] = 'integer';
$node['format'] = 'int32';
$node['x-example'] = $validator->getMin();
@ -249,7 +252,7 @@ class Swagger2 extends Format
$node['format'] = 'url';
$node['x-example'] = 'https://example.com';
break;
case 'Utopia\Validator\WhiteList': /* @var $validator \Utopia\Validator\WhiteList */
case 'Utopia\Validator\WhiteList': /** @var \Utopia\Validator\WhiteList $validator */
$node['type'] = 'string';
$node['x-example'] = $validator->getList()[0];
break;
@ -310,6 +313,10 @@ class Swagger2 extends Format
}
foreach ($this->models as $model) {
if (!in_array($model->getType(), $usedModels)) {
continue;
}
$required = $model->getRequired();
$rules = $model->getRules();