Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Enum Whitelist #674

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
f2c7387
Add path keyword
Meldiron Feb 15, 2023
fb483b3
Merge branch 'master' of https://github.com/appwrite/sdk-generator in…
christyjacob4 Feb 21, 2023
fcb1ed8
Only allow current user to read/write CLI prefs
abnegate May 3, 2023
78fcd68
PR changes review
Meldiron May 11, 2023
cc2cad5
more review changes
Meldiron May 11, 2023
19b9f0e
Add reserved keyword to proper languages
Meldiron May 11, 2023
3bd342f
Merge branch 'master' into feat-add-path-keyword
Meldiron May 11, 2023
e76d305
feat: enum whitelist
2002Bishwajeet Jun 19, 2023
11441b6
(chore): fix common name renders
2002Bishwajeet Jul 12, 2023
3aff6bf
chore: add support for node,web,php,web,flutter
2002Bishwajeet Jul 12, 2023
622786e
Merge remote-tracking branch 'upstream/master' into feat-whitelist-enums
2002Bishwajeet Jul 12, 2023
df1a1bf
Update src/SDK/SDK.php
2002Bishwajeet Jul 13, 2023
fde8578
chore: remove appwrite specific method and fetch enum name from swagger
2002Bishwajeet Jul 13, 2023
00019e2
chore: fix casing in enums
2002Bishwajeet Jul 14, 2023
2b65a02
chore: add enums deno
2002Bishwajeet Jul 14, 2023
c8b9859
chore: use replace instead of str_replace
2002Bishwajeet Jul 14, 2023
4b2abbf
chore: add support for android and kotlin
2002Bishwajeet Jul 14, 2023
f3e010f
chore: export enums dart fixed
2002Bishwajeet Jul 15, 2023
0af2a86
chore: add exports in package.dart.twig
2002Bishwajeet Jul 17, 2023
63f7b83
chore: export enums in index.ts
2002Bishwajeet Jul 17, 2023
5e8d758
chore: add missing whitelist enums
2002Bishwajeet Jul 17, 2023
00bc2f9
Create .NET enums template
adityaoberai Jul 17, 2023
0ffeca4
Update src/SDK/Language/DotNet.php
adityaoberai Jul 17, 2023
0965751
Merge pull request #614 from appwrite/feat-add-path-keyword
eldadfux Jul 18, 2023
7557829
chore: refactors
2002Bishwajeet Jul 18, 2023
ea06f37
Revert "chore: refactors"
2002Bishwajeet Jul 18, 2023
d38abfb
Revert "Revert "chore: refactors""
2002Bishwajeet Jul 18, 2023
b1beb30
revert example.php
2002Bishwajeet Jul 18, 2023
f7bb7e9
Update templates/dart/lib/package.dart.twig
2002Bishwajeet Jul 19, 2023
61341f9
Merge branch 'appwrite:master' into feat-whitelist-enums
2002Bishwajeet Jul 19, 2023
3d475bd
change to camelCase
2002Bishwajeet Jul 21, 2023
7065a77
feat: docs
2002Bishwajeet Jul 21, 2023
405bceb
chore: fix doc generation flutter and web
2002Bishwajeet Jul 24, 2023
2267f4c
chore: fix import doc deno python php dotnet
2002Bishwajeet Jul 24, 2023
70e78d6
chore: fix node import
2002Bishwajeet Jul 24, 2023
549ab8c
chore: add import doc to kotlin and android
2002Bishwajeet Jul 24, 2023
fb17745
feat: swift +App
2002Bishwajeet Jul 24, 2023
cdffea8
Merge remote-tracking branch 'origin/master' into fix-prefs-permissions
abnegate Jul 24, 2023
ee12cb1
Merge pull request #695 from appwrite/fix-prefs-permissions
lohanidamodar Jul 25, 2023
0969f0c
refactor: single quotes to double quotes in kotlin
2002Bishwajeet Jul 26, 2023
ca3882f
chore: remove ;
2002Bishwajeet Jul 26, 2023
cda11c8
chore: add readonly c#
2002Bishwajeet Jul 26, 2023
d3b4220
Strip space instead of adding underscore
2002Bishwajeet Jul 26, 2023
bded653
refactor: convert this to module
2002Bishwajeet Jul 26, 2023
899b5b8
add Type support flutter,dart
2002Bishwajeet Aug 1, 2023
328fa6b
add enum types in services
2002Bishwajeet Aug 1, 2023
7141cc1
Merge branch 'appwrite:master' into feat-whitelist-enums
2002Bishwajeet Aug 3, 2023
1d827ee
fix imports php
2002Bishwajeet Aug 3, 2023
fc1e6ce
Merge branch 'feat-whitelist-enums' of https://github.com/2002Bishwaj…
2002Bishwajeet Aug 3, 2023
5e6e4ee
chore: revert changes
2002Bishwajeet Aug 4, 2023
f707669
chore: revert changes
2002Bishwajeet Aug 4, 2023
cfef322
Update templates/dotnet/src/Appwrite/Enums/Enums.cs.twig
2002Bishwajeet Aug 4, 2023
4dbd72c
Update templates/dotnet/src/Appwrite/Enums/Enums.cs.twig
2002Bishwajeet Aug 4, 2023
2ff035c
chore: remove empty last loop
2002Bishwajeet Aug 4, 2023
f9da819
fix enum addition when found in body
2002Bishwajeet Aug 11, 2023
453ffdb
fix: duplicate enums
2002Bishwajeet Aug 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/SDK/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,25 @@ protected function toCamelCase($str): string
$str = str_replace(" ", "", $str);
return lcfirst($str);
}

public function getEnumType(string $service, string $method): string
{
switch ($service) {
2002Bishwajeet marked this conversation as resolved.
Show resolved Hide resolved
case 'account':
switch ($method) {
case 'createOAuth2Session':
return 'Provider';
}
case 'avatars':
switch ($method) {
case 'getBrowser':
return 'Browser';
case 'getCreditCard':
return 'CreditCard';
case 'getFlag':
return 'Flag';
}
}
throw new \Exception('Enum type not found for service: ' . $service . ' method: ' . $method);
}
}
10 changes: 10 additions & 0 deletions src/SDK/Language/Dart.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,16 @@ public function getFiles(): array
'destination' => 'lib/src/input_file.dart',
'template' => 'dart/lib/src/input_file.dart.twig',
],
[
'scope' => 'enum',
'destination' => 'lib/src/enums/{{ enum.name | caseSnake }}.dart',
'template' => 'dart/lib/src/enums/enum.dart.twig',
],
[
'scope' => 'default',
'destination' => 'lib/enums.dart',
'template' => 'dart/lib/enums.dart.twig',
],
];
}

Expand Down
10 changes: 10 additions & 0 deletions src/SDK/Language/Flutter.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,16 @@ public function getFiles(): array
'destination' => '.travis.yml',
'template' => 'flutter/.travis.yml.twig',
],
[
'scope' => 'enum',
'destination' => 'lib/src/enums/{{ enum.name | caseSnake }}.dart',
'template' => 'dart/lib/src/enums/enum.dart.twig',
],
[
'scope' => 'default',
'destination' => 'lib/enums.dart',
'template' => 'dart/lib/enums.dart.twig',
],
];
}
}
5 changes: 5 additions & 0 deletions src/SDK/Language/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ public function getFiles(): array
'destination' => '.travis.yml',
'template' => 'node/.travis.yml.twig',
],
[
'scope' => 'enum',
'destination' => 'lib/enums/{{ enum.name | caseDash }}.js',
'template' => 'node/lib/enums/enum.js.twig',
],
];
}

Expand Down
5 changes: 5 additions & 0 deletions src/SDK/Language/PHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ public function getFiles(): array
'destination' => '/src/{{ spec.title | caseUcfirst}}/Services/{{service.name | caseUcfirst}}.php',
'template' => 'php/src/Services/Service.php.twig',
],
[
'scope' => 'enum',
'destination' => '/src/{{ spec.title | caseUcfirst}}/Enums/{{ enum.name | caseUcfirst }}.php',
'template' => 'php/src/Enums/Enum.php.twig',
],
];
}

Expand Down
5 changes: 5 additions & 0 deletions src/SDK/Language/Python.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ public function getFiles(): array
'destination' => '.travis.yml',
'template' => 'python/.travis.yml.twig',
],
[
'scope' => 'enum',
'destination' => '{{ spec.title | caseSnake}}/enums/{{ enum.name | caseSnake }}.py',
'template' => 'python/package/enums/enum.py.twig',
],
];
}

Expand Down
5 changes: 5 additions & 0 deletions src/SDK/Language/Web.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ public function getFiles(): array
'destination' => '.travis.yml',
'template' => 'web/.travis.yml.twig',
],
[
'scope' => 'enum',
'destination' => 'src/enums/{{ enum.name | caseDash }}.ts',
'template' => 'web/src/enums/enum.ts.twig',
],
];
}

Expand Down
25 changes: 25 additions & 0 deletions src/SDK/SDK.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ public function __construct(Language $language, Spec $spec)
$this->twig->addFilter(new TwigFilter('typeName', function ($value) {
return $this->language->getTypeName($value);
}, ['is_safe' => ['html']]));
$this->twig->addFilter(new TwigFilter('getEnumType', function ($service, $method) {
return $this->language->getEnumType($service, $method);
}, ['is_safe' => ['html']]));
$this->twig->addFilter(new TwigFilter('paramDefault', function ($value) {
return $this->language->getParamDefault($value);
}, ['is_safe' => ['html']]));
Expand Down Expand Up @@ -634,6 +637,28 @@ public function generate(string $target): void
}
}
break;
case 'enum':
foreach ($this->spec->getServices() as $key => $service) {
$methods = $this->spec->getMethods($key);

2002Bishwajeet marked this conversation as resolved.
Show resolved Hide resolved

foreach ($methods as $method) {
$params['method'] = $method;
$parameters = $method['parameters']['path'];

foreach ($parameters as $parameter) {
// Check if the enum field is defined
if ($parameter['enum'] != null) {
$params['enum'] = [
'name' => $this->language->getEnumType($service['name'], $method['name']),
'enum' => $parameter['enum'],
];
$this->render($template, $destination, $block, $params, $minify);
}
}
}
}
break;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Spec/Swagger2.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ public function getMethods($service)
$output['parameters']['header'][] = $param;
break;
case 'path':
$param['enum'] = $parameter['enum'] ?? null;
2002Bishwajeet marked this conversation as resolved.
Show resolved Hide resolved
$output['parameters']['path'][] = $param;
break;
case 'query':
Expand Down
5 changes: 5 additions & 0 deletions templates/dart/lib/enums.dart.twig
2002Bishwajeet marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
library {{ language.params.packageName }}.enums;

{% for enum in spec.enum %}
2002Bishwajeet marked this conversation as resolved.
Show resolved Hide resolved
part 'src/enums/{{enum.name | caseSnake}}.dart';
{% endfor %}
8 changes: 8 additions & 0 deletions templates/dart/lib/src/enums/enum.dart.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
part of {{ language.params.packageName }}.enums;

enum {{ enum.name | caseUcfirst | overrideIdentifier }} {
{% for value in enum.enum %}
{{value}}{% if not loop.last %},
{% endif %}
{% endfor %}
}
8 changes: 8 additions & 0 deletions templates/node/lib/enums/enum.js.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const {{ enum.name | caseUcfirst | overrideIdentifier }} = {
{% for value in enum.enum %}
{{value}}: '{{ value | caseLower | overrideIdentifier }}' {% if not loop.last %},
{% endif %}
{% endfor %}
}

module.exports = {{ enum.name | caseUcfirst | overrideIdentifier }};
9 changes: 9 additions & 0 deletions templates/php/src/Enums/Enum.php.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace {{ spec.title | caseUcfirst }}\Enums;

enum {{ enum.name | caseUcfirst | overrideIdentifier }} {
{% for value in enum.enum %}
case {{value}};
{% endfor %}
}
6 changes: 6 additions & 0 deletions templates/python/package/enums/enum.py.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from enum import Enum

class {{ enum.name | caseUcfirst | overrideIdentifier }}(Enum):
{% for value in enum.enum %}
{{value}}
{% endfor %}
5 changes: 5 additions & 0 deletions templates/web/src/enums/enum.ts.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum {{ enum.name | caseUcfirst | overrideIdentifier }} {
{% for value in enum.enum %}
{{ value | caseUcfirst | overrideIdentifier }},
{% endfor %}
}