Skip to content

Commit

Permalink
chore: refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
2002Bishwajeet committed Jul 18, 2023
1 parent 0ffeca4 commit 7557829
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 14 deletions.
10 changes: 5 additions & 5 deletions example.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ function getSSLPage($url) {
}

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

$spec = getSSLPage("https://raw.githubusercontent.com/appwrite/appwrite/master/app/config/specs/swagger2-latest-{$platform}.json");
$spec = getSSLPage("https://raw.githubusercontent.com/2002bishwajeet/appwrite/feat-whitelist-enums/app/config/specs/swagger2-latest-{$platform}.json");

if(empty($spec)) {
if (empty($spec)) {
throw new Exception('Failed to fetch spec from Appwrite server');
}

Expand Down
1 change: 1 addition & 0 deletions src/SDK/SDK.php
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ public function generate(string $target): void
$params['enum'] = [
'name' => $parameter['enum-name'] ?? $parameter['name'],
'enum' => $parameter['enum-values'],
'keys' => $parameter['enum-keys'],
];
$this->render($template, $destination, $block, $params, $minify);
}
Expand Down
1 change: 1 addition & 0 deletions src/Spec/Swagger2.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public function getMethods($service)
if (isset($parameter['enum'])) {
$param['enum-values'] = $parameter['enum'];
$param['enum-name'] = $parameter['x-enum-name'];
$param['enum-keys'] = $parameter['x-enum-keys'];
}

switch ($parameter['in']) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package {{ sdk.namespace | caseDot }}.enums

enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(val value: String) {
{% for value in enum.enum %}
{{value | caseUpper | replace({'-': ''})}}('{{value}}'){% if not loop.last %},
{% set key = enum.keys is empty ? value : enum.keys[loop.index0] %}
{{ key | caseUpper | replace({'-': ''})}}('{{value}}'){% if not loop.last %},
{% endif %}
{% endfor %}

Expand Down
3 changes: 2 additions & 1 deletion templates/dart/lib/src/enums/enum.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ part of {{ language.params.packageName }};

enum {{ enum.name | caseUcfirst | overrideIdentifier }} {
{% for value in enum.enum %}
{{value | caseCamel | replace({'-': ''})}}('{{ value }}'){% if not loop.last %},
{% set key = enum.keys is empty ? value : enum.keys[loop.index0] %}
{{ key | caseCamel | replace({'-': ''})}}('{{ value }}'){% if not loop.last %},
{% endif %}
{% if loop.last %};{% endif %}
{% endfor %}
Expand Down
3 changes: 2 additions & 1 deletion templates/deno/src/enums/enum.ts.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export enum {{ enum.name | caseUcfirst | overrideIdentifier }} {
{% for value in enum.enum %}
{{ value | caseUcfirst | replace({'-': ''}) }} = '{{ value }}',
{% set key = enum.keys is empty ? value : enum.keys[loop.index0] %}
{{ key | caseUcfirst | replace({'-': ''}) }} = '{{ value }}',
{% endfor %}
}
3 changes: 2 additions & 1 deletion templates/dotnet/src/Appwrite/Enums/Enums.cs.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ namespace {{ spec.title | caseUcfirst }}.Enums
public static class {{ enum.name | caseUcfirst | overrideIdentifier }}
{
{% for value in enum.enum %}
public static string {{ value | caseUcfirst | replace({'-': ''}) }} = "{{ value }}",
{% set key = enum.keys is empty ? value : enum.keys[loop.index0] %}
public static string {{ key | caseUcfirst | replace({'-': ''}) }} = "{{ value }}",
{% endfor %}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package {{ sdk.namespace | caseDot }}.enums

enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(val value: String) {
{% for value in enum.enum %}
{{value | caseUpper | replace({'-': ''})}}('{{value}}'){% if not loop.last %},
{% set key = enum.keys is empty ? value : enum.keys[loop.index0] %}
{{ key | caseUpper | replace({'-': ''})}}('{{value}}'){% if not loop.last %},
{% endif %}
{% endfor %}

Expand Down
3 changes: 2 additions & 1 deletion templates/node/lib/enums/enum.js.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const {{ enum.name | caseUcfirst | overrideIdentifier }} = {
{% for value in enum.enum %}
{{ value | caseLower | replace({'-': ''})}}: '{{value}}' {% if not loop.last %},
{% set key = enum.keys is empty ? value : enum.keys[loop.index0] %}
{{ key | caseLower | replace({'-': ''})}}: '{{value}}' {% if not loop.last %},
{% endif %}
{% endfor %}
}
Expand Down
3 changes: 2 additions & 1 deletion templates/php/src/Enums/Enum.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace {{ spec.title | caseUcfirst }}\Enums;
class {{ enum.name | caseUcfirst | overrideIdentifier }}
{
{% for value in enum.enum %}
public const {{value | caseUpper | replace({'-': ''})}} = '{{value}}';
{% set key = enum.keys is empty ? value : enum.keys[loop.index0] %}
public const {{ key | caseUpper | replace({'-': ''})}} = '{{value}}';
{% endfor %}
}
3 changes: 2 additions & 1 deletion templates/python/package/enums/enum.py.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ from enum import Enum

class {{ enum.name | caseUcfirst | overrideIdentifier }}(Enum):
{% for value in enum.enum %}
{{value | caseUpper | replace({'-': ''})}} = "{{ value }}"
{% set key = enum.keys is empty ? value : enum.keys[loop.index0] %}
{{ key | caseUpper | replace({'-': ''})}} = "{{ value }}"
{% endfor %}
3 changes: 2 additions & 1 deletion templates/web/src/enums/enum.ts.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export enum {{ enum.name | caseUcfirst }} {
{% for value in enum.enum %}
{{ value | caseUcfirst | replace({'-': ''})}} = '{{ value }}',
{% set key = enum.keys is empty ? value : enum.keys[loop.index0] %}
{{ key | caseUcfirst | replace({'-': ''})}} = '{{ value }}',
{% endfor %}
}

0 comments on commit 7557829

Please sign in to comment.