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 whitelist enums #700

Merged
merged 108 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 96 commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
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
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
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
8004657
Merge pull request #674 from 2002Bishwajeet/feat-whitelist-enums
abnegate Aug 15, 2023
c7613e1
Add ruby enum template
abnegate Aug 15, 2023
5ea227a
Fix Kotlin enums
abnegate Aug 15, 2023
996b1d1
Fix dotnet enums
abnegate Aug 15, 2023
9111b86
Fix web enums
abnegate Aug 15, 2023
8544575
Fix PHP enums
abnegate Aug 15, 2023
55164a0
Fix python enums
abnegate Aug 15, 2023
c5e70bf
Fix swift enums
abnegate Aug 15, 2023
98870d0
Fix enums
abnegate Aug 15, 2023
f2f97ff
Fix enums
abnegate Aug 15, 2023
9912b27
Fix tests
abnegate Aug 15, 2023
10b5323
Fix enums
abnegate Aug 16, 2023
2f5d5f5
Fix lint
abnegate Aug 16, 2023
b0bafd6
Fix tests
abnegate Aug 16, 2023
fd543a8
Merge remote-tracking branch 'origin/master' into feat-whitelist-enums
abnegate Sep 7, 2023
459e3d3
Add enum tests
abnegate Sep 8, 2023
951e5c9
Update mock specs
abnegate Sep 8, 2023
f786e95
Merge remote-tracking branch 'origin/master' into feat-whitelist-enums
abnegate Sep 8, 2023
37a7eb4
Fix node tests
abnegate Sep 8, 2023
dea507e
Fix Kotlin missing import
abnegate Sep 8, 2023
500df5f
Fix PHP missing import
abnegate Sep 8, 2023
f0a6352
WIP add dart enum library
abnegate Sep 8, 2023
70cb272
Merge remote-tracking branch 'origin/master' into feat-whitelist-enums
abnegate Sep 28, 2023
7eab791
Fix dart enums
abnegate Sep 28, 2023
e0614e4
Fix .NET enums
abnegate Oct 2, 2023
09536a8
Fix PHP enums
abnegate Oct 2, 2023
e649b30
Fix Python enums
abnegate Oct 2, 2023
1a8f151
Fix swift enums
abnegate Oct 2, 2023
35e69e7
Fix dart test
abnegate Oct 3, 2023
6c19700
Fix deno enums
abnegate Oct 3, 2023
8ad9cbc
Fix node 12 test
abnegate Oct 3, 2023
df4c5d6
Fix web enum tests
abnegate Oct 4, 2023
b0d9a63
Fix array type checks
abnegate Oct 4, 2023
55b4fa3
Fix swift escapes
abnegate Oct 4, 2023
d03c2eb
Fix .NET enum template name
abnegate Oct 4, 2023
cb7a6ad
Add spec to type name filter
abnegate Oct 4, 2023
8263763
Remove duplicate file from Apple
abnegate Oct 4, 2023
c3fd502
Add enum case key
abnegate Oct 17, 2023
1c86293
Fix lint
abnegate Oct 27, 2023
9439633
Fix PHP enum key case filter
abnegate Oct 27, 2023
fe9b523
Fix Python docs template syntax error
abnegate Oct 27, 2023
d37a6fc
Add missing file for flutter
abnegate Oct 27, 2023
7936e6a
Fix flutter missing import
abnegate Oct 27, 2023
321c9f4
Fix go tests
abnegate Oct 27, 2023
1d6fc0c
Fix swift + apple tests
abnegate Oct 27, 2023
39410e0
Fix flutter test enum casing
abnegate Oct 27, 2023
d11c78a
Remove invalid flutter package entries
abnegate Oct 27, 2023
530c44f
Fix chromium tests
abnegate Oct 27, 2023
f6dc423
Fix ruby tests
abnegate Oct 27, 2023
01cf1a3
Enable flutter realtime tests
abnegate Oct 27, 2023
4c28b96
Fix Android enum docs
abnegate Oct 30, 2023
c6b5686
Fix docs
abnegate Oct 30, 2023
7e22ef7
Merge remote-tracking branch 'origin/master' into feat-whitelist-enums
abnegate Oct 30, 2023
3738484
Fix Kotlin enum keys
abnegate Oct 30, 2023
e3cc1f5
Fix PHP enum keys
abnegate Oct 30, 2023
f7e69b1
Fix swift enum keys
abnegate Oct 30, 2023
c921cbb
Fix PHP
abnegate Nov 1, 2023
7716e90
Fix dotnet formatting
abnegate Nov 1, 2023
bf6c435
Use base class for dotnet enums to improve converter performance
abnegate Nov 1, 2023
36b5ffe
Fix PHP keys
abnegate Nov 1, 2023
2c70407
Use raw for swift escapes
abnegate Nov 1, 2023
751c423
Merge remote-tracking branch 'origin/master' into feat-whitelist-enums
abnegate Nov 7, 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
4 changes: 2 additions & 2 deletions example.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ function getSSLPage($url) {
}

// Leave the platform you want uncommented
$platform = 'client';
// $platform = 'console';
// $platform = 'client';
$platform = 'console';
// $platform = 'server';

$spec = getSSLPage("https://raw.githubusercontent.com/appwrite/appwrite/master/app/config/specs/swagger2-latest-{$platform}.json");
Expand Down
17 changes: 15 additions & 2 deletions src/SDK/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ abstract public function getFiles(): array;
* @param array $parameter
* @return string
*/
abstract public function getTypeName(array $parameter): string;
abstract public function getTypeName(array $parameter, array $spec = []): string;

/**
* @param array $param
Expand Down Expand Up @@ -84,7 +84,7 @@ public function getFilters(): array
return [];
}

protected function toUpperCaseWords(string $value): string
protected function toPascalCase(string $value): string
{
return ucfirst($this->toCamelCase($value));
}
Expand All @@ -97,4 +97,17 @@ protected function toCamelCase($str): string
$str = str_replace(" ", "", $str);
return lcfirst($str);
}

protected function toSnakeCase($str): string
{
$str = \preg_replace('/([a-z])([A-Z])/', '$1 $2', $str);
$str = \explode(' ', $str);
$str = \implode('_', $str);
return \strtolower($str);
}

protected function toUpperSnakeCase($str): string
{
return \strtoupper($this->toSnakeCase($str));
Comment on lines +109 to +111
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need this? Can we just not chain the twig filters directly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could chain them but I think it makes the templates/code easier to read if we just use one well-named filter

}
}
5 changes: 5 additions & 0 deletions src/SDK/Language/Android.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,11 @@ public function getFiles(): array
'destination' => 'library/src/main/java/io/appwrite/models/{{ definition.name | caseUcfirst }}.kt',
'template' => '/android/library/src/main/java/io/appwrite/models/Model.kt.twig',
],
[
'scope' => 'enum',
'destination' => 'library/src/main/java/io/appwrite/enums/{{ enum.name | caseUcfirst }}.kt',
'template' => '/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig',
],
];
}
}
37 changes: 31 additions & 6 deletions src/SDK/Language/Dart.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,28 @@ public function getKeywords(): array
*/
public function getIdentifierOverrides(): array
{
return ['Function' => 'Func', 'default' => 'xdefault', 'required' => 'xrequired', 'async' => 'xasync'];
return [
'Function' => 'Func',
'default' => 'xdefault',
'required' => 'xrequired',
'async' => 'xasync',
'enum' => 'xenum',
];
}

/**
* @param array $parameter
* @return string
*/
public function getTypeName(array $parameter): string
public function getTypeName(array $parameter, array $spec = []): string
{
switch ($parameter['type']) {
if (isset($parameter['enumName'])) {
return 'enums.' . \ucfirst($parameter['enumName']);
}
if (!empty($parameter['enumValues'])) {
return 'enums.' . \ucfirst($parameter['name']);
}
switch ($parameter['type'] ?? '') {
case self::TYPE_INTEGER:
return 'int';
case self::TYPE_STRING:
Expand All @@ -131,17 +143,17 @@ public function getTypeName(array $parameter): string
case self::TYPE_BOOLEAN:
return 'bool';
case self::TYPE_ARRAY:
if (!empty($parameter['array']['type'])) {
if (!empty(($parameter['array'] ?? [])['type']) && !\is_array($parameter['array']['type'])) {
return 'List<' . $this->getTypeName($parameter['array']) . '>';
}
return 'List';
case self::TYPE_OBJECT:
return 'Map';
case self::TYPE_NUMBER:
return 'double';
default:
return $parameter['type'];
}

return $parameter['type'];
}

/**
Expand Down Expand Up @@ -386,6 +398,11 @@ public function getFiles(): array
'destination' => '/lib/models.dart',
'template' => 'dart/lib/models.dart.twig',
],
[
'scope' => 'default',
'destination' => '/lib/enums.dart',
'template' => 'dart/lib/enums.dart.twig',
],
[
'scope' => 'service',
'destination' => '/lib/services/{{service.name | caseDash}}.dart',
Expand Down Expand Up @@ -466,6 +483,11 @@ 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',
],
];
}

Expand All @@ -479,6 +501,9 @@ public function getFilters(): array
}
return implode("\n", $value);
}, ['is_safe' => ['html']]),
new TwigFilter('caseEnumKey', function (string $value) {
return $this->toCamelCase($value);
}),
];
}
}
52 changes: 33 additions & 19 deletions src/SDK/Language/Deno.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Appwrite\SDK\Language;

use Twig\TwigFilter;

class Deno extends JS
{
/**
Expand Down Expand Up @@ -93,34 +95,37 @@ public function getFiles(): array
'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseDash}}.md',
'template' => 'deno/docs/example.md.twig',
],
[
'scope' => 'enum',
'destination' => 'src/enums/{{ enum.name | caseDash }}.ts',
'template' => 'deno/src/enums/enum.ts.twig',
],
];
}

/**
* @param array $parameter
* @return string
*/
public function getTypeName(array $parameter): string
public function getTypeName(array $parameter, array $spec = []): string
{
switch ($parameter['type']) {
case self::TYPE_INTEGER:
return 'number';
case self::TYPE_STRING:
return 'string';
case self::TYPE_FILE:
return 'InputFile';
case self::TYPE_BOOLEAN:
return 'boolean';
case self::TYPE_ARRAY:
if (!empty($parameter['array']['type'])) {
return $this->getTypeName($parameter['array']) . '[]';
}
return 'string[]';
case self::TYPE_OBJECT:
return 'object';
if (isset($parameter['enumName'])) {
return \ucfirst($parameter['enumName']);
}

return $parameter['type'];
if (!empty($parameter['enumValues'])) {
return \ucfirst($parameter['name']);
}
return match ($parameter['type']) {
self::TYPE_INTEGER => 'number',
self::TYPE_STRING => 'string',
self::TYPE_FILE => 'InputFile',
self::TYPE_BOOLEAN => 'boolean',
self::TYPE_ARRAY => (!empty(($parameter['array'] ?? [])['type']) && !\is_array($parameter['array']['type']))
? $this->getTypeName($parameter['array']) . '[]'
: 'string[]',
self::TYPE_OBJECT => 'object',
default => $parameter['type']
};
}

/**
Expand Down Expand Up @@ -176,4 +181,13 @@ public function getParamExample(array $param): string

return $output;
}

public function getFilters(): array
{
return [
new TwigFilter('caseEnumKey', function (string $value) {
return $this->toPascalCase($value);
}),
];
}
}
54 changes: 32 additions & 22 deletions src/SDK/Language/DotNet.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,29 +149,26 @@ public function getIdentifierOverrides(): array
* @param array $parameter
* @return string
*/
public function getTypeName(array $parameter): string
public function getTypeName(array $parameter, array $spec = []): string
{
switch ($parameter['type']) {
case self::TYPE_INTEGER:
return 'long';
case self::TYPE_NUMBER:
return 'double';
case self::TYPE_STRING:
return 'string';
case self::TYPE_FILE:
return 'InputFile';
case self::TYPE_BOOLEAN:
return 'bool';
case self::TYPE_ARRAY:
if (!empty($parameter['array']['type'])) {
return 'List<' . $this->getTypeName($parameter['array']) . '>';
}
return 'List<object>';
case self::TYPE_OBJECT:
return 'object';
if (isset($parameter['enumName'])) {
return \ucfirst($parameter['enumName']);
}

return $parameter['type'];
if (!empty($parameter['enumValues'])) {
return \ucfirst($parameter['name']);
}
return match ($parameter['type']) {
self::TYPE_INTEGER => 'long',
self::TYPE_NUMBER => 'double',
self::TYPE_STRING => 'string',
self::TYPE_BOOLEAN => 'bool',
self::TYPE_FILE => 'InputFile',
self::TYPE_ARRAY => (!empty(($parameter['array'] ?? [])['type']) && !\is_array($parameter['array']['type']))
? 'List<' . $this->getTypeName($parameter['array']) . '>'
: 'List<object>',
self::TYPE_OBJECT => 'object',
default => $parameter['type']
};
}

/**
Expand Down Expand Up @@ -361,6 +358,11 @@ public function getFiles(): array
'destination' => '/src/{{ spec.title | caseUcfirst }}/Role.cs',
'template' => 'dotnet/src/Appwrite/Role.cs.twig',
],
[
'scope' => 'default',
'destination' => '/src/{{ spec.title | caseUcfirst }}/Converters/ValueClassConverter.cs',
'template' => 'dotnet/src/Appwrite/Converters/ValueClassConverter.cs.twig',
],
[
'scope' => 'default',
'destination' => '/src/{{ spec.title | caseUcfirst }}/Extensions/Extensions.cs',
Expand Down Expand Up @@ -395,6 +397,11 @@ public function getFiles(): array
'scope' => 'definition',
'destination' => '/src/{{ spec.title | caseUcfirst }}/Models/{{ definition.name | caseUcfirst | overrideIdentifier }}.cs',
'template' => 'dotnet/src/Appwrite/Models/Model.cs.twig',
],
[
'scope' => 'enum',
'destination' => '/src/{{ spec.title | caseUcfirst }}/Enums/{{ enum.name | caseUcfirst | overrideIdentifier }}.cs',
'template' => 'dotnet/src/Appwrite/Enums/Enum.cs.twig',
]
];
}
Expand All @@ -408,7 +415,10 @@ public function getFilters(): array
$value[$key] = " /// " . wordwrap($line, 75, "\n /// ");
}
return implode("\n", $value);
}, ['is_safe' => ['html']])
}, ['is_safe' => ['html']]),
new TwigFilter('caseEnumKey', function (string $value) {
return $this->toPascalCase($value);
}),
];
}
}
10 changes: 10 additions & 0 deletions src/SDK/Language/Flutter.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public function getFiles(): array
'destination' => '/lib/models.dart',
'template' => 'dart/lib/models.dart.twig',
],
[
'scope' => 'default',
'destination' => '/lib/enums.dart',
'template' => 'dart/lib/enums.dart.twig',
],
[
'scope' => 'default',
'destination' => '/lib/permission.dart',
Expand Down Expand Up @@ -330,6 +335,11 @@ 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',
],
];
}
}
33 changes: 14 additions & 19 deletions src/SDK/Language/Go.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,25 +106,17 @@ public function getFiles(): array
* @param array $nestedTypes
* @return string
*/
public function getTypeName(array $parameter): string
public function getTypeName(array $parameter, array $spec = []): string
{
switch ($parameter['type']) {
case self::TYPE_INTEGER:
return 'int';
case self::TYPE_NUMBER:
return 'float64';
case self::TYPE_FILE:
case self::TYPE_STRING:
return 'string';
case self::TYPE_BOOLEAN:
return 'bool';
case self::TYPE_OBJECT:
return 'interface{}';
case self::TYPE_ARRAY:
return '[]interface{}';
}

return $parameter['type'];
return match ($parameter['type']) {
self::TYPE_INTEGER => 'int',
self::TYPE_NUMBER => 'float64',
self::TYPE_FILE, self::TYPE_STRING => 'string',
self::TYPE_BOOLEAN => 'bool',
self::TYPE_OBJECT => 'interface{}',
self::TYPE_ARRAY => '[]interface{}',
default => $parameter['type'],
};
}

/**
Expand Down Expand Up @@ -247,7 +239,10 @@ public function getFilters(): array
$value[$key] = "// " . wordwrap($line, 75, "\n// ");
}
return implode("\n", $value);
}, ['is_safe' => ['html']])
}, ['is_safe' => ['html']]),
new TwigFilter('caseEnumKey', function (string $value) {
return $this->toUpperSnakeCase($value);
}),
];
}
}
4 changes: 2 additions & 2 deletions src/SDK/Language/GraphQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function getName(): string
* @param $type
* @return string
*/
public function getTypeName(array $parameter): string
public function getTypeName(array $parameter, array $spec = []): string
{
$type = '';

Expand All @@ -34,7 +34,7 @@ public function getTypeName(array $parameter): string
$type = 'Bool';
break;
case self::TYPE_ARRAY:
if (!empty($parameter['array']['type'])) {
if (!empty(($parameter['array'] ?? [])['type']) && !\is_array($parameter['array']['type'])) {
$type = '[' . $this->getTypeName($parameter['array']) . ']';
break;
}
Expand Down
Loading