1
0
Fork 0
mirror of synced 2024-06-03 03:14:50 +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' => '']; $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()); $url = \str_replace('/v1', '', $route->getURL());
$scope = $route->getLabel('scope', ''); $scope = $route->getLabel('scope', '');
$hide = $route->getLabel('sdk.hide', false); $hide = $route->getLabel('sdk.hide', false);
@ -148,6 +150,7 @@ class Swagger2 extends Format
], ],
]; ];
} else { } else {
$usedModels[] = $model->getType();
$temp['responses'][(string)$route->getLabel('sdk.response.code', '500')] = [ $temp['responses'][(string)$route->getLabel('sdk.response.code', '500')] = [
'description' => $model->getName(), 'description' => $model->getName(),
'schema' => [ 'schema' => [
@ -232,7 +235,7 @@ class Swagger2 extends Format
$node['format'] = 'format'; $node['format'] = 'format';
$node['x-example'] = 'password'; $node['x-example'] = 'password';
break; break;
case 'Utopia\Validator\Range': /* @var $validator \Utopia\Validator\Range */ case 'Utopia\Validator\Range': /** @var \Utopia\Validator\Range $validator */
$node['type'] = 'integer'; $node['type'] = 'integer';
$node['format'] = 'int32'; $node['format'] = 'int32';
$node['x-example'] = $validator->getMin(); $node['x-example'] = $validator->getMin();
@ -249,7 +252,7 @@ class Swagger2 extends Format
$node['format'] = 'url'; $node['format'] = 'url';
$node['x-example'] = 'https://example.com'; $node['x-example'] = 'https://example.com';
break; break;
case 'Utopia\Validator\WhiteList': /* @var $validator \Utopia\Validator\WhiteList */ case 'Utopia\Validator\WhiteList': /** @var \Utopia\Validator\WhiteList $validator */
$node['type'] = 'string'; $node['type'] = 'string';
$node['x-example'] = $validator->getList()[0]; $node['x-example'] = $validator->getList()[0];
break; break;
@ -310,6 +313,10 @@ class Swagger2 extends Format
} }
foreach ($this->models as $model) { foreach ($this->models as $model) {
if (!in_array($model->getType(), $usedModels)) {
continue;
}
$required = $model->getRequired(); $required = $model->getRequired();
$rules = $model->getRules(); $rules = $model->getRules();