1
0
Fork 0
mirror of synced 2024-09-29 08:51:28 +13:00

chore: implement blacklist and regenerate specs

This commit is contained in:
Bishwajeet Parhi 2023-08-11 13:13:46 +05:30
parent 528846c35e
commit 5c8618410b
7 changed files with 70 additions and 6 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -39,6 +39,17 @@ abstract class Format
'license.url' => '',
];
/*
* blackList to omit the enum types for the given method
* */
protected array $blacklist = [
[
'namespace' => 'users',
'method' => 'getUsage',
'parameter' => 'provider'
]
];
public function __construct(App $app, array $services, array $routes, array $models, array $keys, int $authCount)
{
$this->app = $app;
@ -130,6 +141,31 @@ abstract class Format
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;
}
return null;
}

View file

@ -411,7 +411,18 @@ class OpenAPI3 extends Format
/** @var \Utopia\Validator\WhiteList $validator */
$node['schema']['type'] = $validator->getType();
$node['schema']['x-example'] = $validator->getList()[0];
if (!($route->getLabel('sdk.namespace', '') == 'users' && $route->getLabel('sdk.method', '') == 'getUsage' && $name == 'provider')) {
//Iterate from the blackList. If it matches with the current one, then it is a blackList
// Do not add the enum
$isBlackList = false;
foreach ($this->blacklist as $blacklist) {
if ($blacklist['namespace'] == $route->getLabel('sdk.namespace', '') && $blacklist['method'] == $route->getLabel('sdk.method', '') && $blacklist['parameter'] == $name) {
$isBlackList = true;
break;
}
}
if (!$isBlackList) {
$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);
@ -446,6 +457,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'];
}

View file

@ -415,7 +415,17 @@ class Swagger2 extends Format
$node['type'] = $validator->getType();
$node['x-example'] = $validator->getList()[0];
if (!($route->getLabel('sdk.namespace', '') == 'users' && $route->getLabel('sdk.method', '') == 'getUsage' && $name == 'provider')) {
//Iterate from the blackList. If it matches with the current one, then it is a blackList
// Do not add the enum
$isBlackList = false;
foreach ($this->blacklist as $blacklist) {
if ($blacklist['namespace'] == $route->getLabel('sdk.namespace', '') && $blacklist['method'] == $route->getLabel('sdk.method', '') && $blacklist['parameter'] == $name) {
$isBlackList = true;
break;
}
}
if (!$isBlackList) {
$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);