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: added constants for Error Types #724

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
812a6e6
feat: added constants for Error Types
35C4n0r Oct 10, 2023
061fea8
feat: added tests for Python ErrorEnums
35C4n0r Oct 21, 2023
2c37098
feat: add tests for Ruby ErrorEnums
35C4n0r Oct 24, 2023
a07a4b6
feat: add tests EnumTests
35C4n0r Oct 25, 2023
85fa20d
feat: add tests for ErrorEnums
35C4n0r Oct 25, 2023
3f3afb0
update: update snake_case to camelCase
35C4n0r Nov 2, 2023
33fe9cf
update: update test generator's data source.
35C4n0r Nov 4, 2023
ecb6742
Merge branch 'master' into feat-error-enum
35C4n0r Nov 12, 2023
4f55b35
feat: add test_exception.py.twig
35C4n0r Nov 12, 2023
273bb15
fix: fix AppwriteException Import
35C4n0r Nov 12, 2023
c57715a
fix: tests and ErrorEnums generated only if spec has Error info
35C4n0r Nov 17, 2023
677f4cf
Merge branch 'master' into feat-error-enum
35C4n0r Nov 17, 2023
db22b05
feat: update tests/spec.json
35C4n0r Nov 17, 2023
c429aa0
fix: update tests/spec.json and Node Import
35C4n0r Nov 17, 2023
caf5d27
fix: remove Model if name has Exception in it.
35C4n0r Nov 17, 2023
dd855af
fix: remove space from Android class name.
35C4n0r Nov 17, 2023
d22707a
fix: remove space from Android class name.
35C4n0r Nov 17, 2023
c6b70d7
fix: fix camelCase to caseCamel in swift
35C4n0r Nov 17, 2023
3350831
fix: fix ruby imports
35C4n0r Nov 22, 2023
c19f7ea
fix: fix ruby imports to exclude AppwriteException
35C4n0r Nov 22, 2023
cac17d0
fix: change pascal case to camel case
35C4n0r Nov 22, 2023
2a9b36f
fix: fix lint errors
35C4n0r Nov 22, 2023
cd5111b
Merge branch 'master' into feat-error-enum
35C4n0r Nov 22, 2023
4271b7c
refactor: refactor flutter files
35C4n0r Nov 29, 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
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' => 'default',
'destination' => 'tests/TestException.kt',
'template' => '/android/tests/TestException.kt.twig',
],
];
}
}
5 changes: 5 additions & 0 deletions src/SDK/Language/Deno.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ public function getFiles(): array
'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseDash}}.md',
'template' => 'deno/docs/example.md.twig',
],
[
'scope' => 'default',
'destination' => 'tests/test_exception.ts',
'template' => 'deno/tests/test_exception.ts.twig',
],
];
}

Expand Down
7 changes: 6 additions & 1 deletion src/SDK/Language/DotNet.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,12 @@ 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' => 'default',
'destination' => 'tests/Test{{ spec.title | caseUcfirst }}Exception.cs',
'template' => 'dotnet/tests/TestException.cs.twig',
],
];
}

Expand Down
5 changes: 5 additions & 0 deletions src/SDK/Language/Flutter.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@ public function getFiles(): array
'destination' => '.travis.yml',
'template' => 'flutter/.travis.yml.twig',
],
[
'scope' => 'default',
'destination' => '/test/src/exception_test.dart',
'template' => 'flutter/test/src/exception_test.dart.twig',
],
];
}
}
5 changes: 5 additions & 0 deletions src/SDK/Language/Kotlin.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,11 @@ public function getFiles(): array
'destination' => '/src/main/kotlin/{{ sdk.namespace | caseSlash }}/models/{{ definition.name | caseUcfirst }}.kt',
'template' => '/kotlin/src/main/kotlin/io/appwrite/models/Model.kt.twig',
],
[
'scope' => 'default',
'destination' => 'tests/TestException.kt',
'template' => '/kotlin/tests/TestException.kt.twig',
],
];
}

Expand Down
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' => 'default',
'destination' => '/tests/test_exception.js',
'template' => 'node/tests/test_exception.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 @@ -212,6 +212,11 @@ public function getFiles(): array
'destination' => '/src/{{ spec.title | caseUcfirst}}/Services/{{service.name | caseUcfirst}}.php',
'template' => 'php/src/Services/Service.php.twig',
],
[
'scope' => 'default',
'destination' => 'tests/TestException.php',
'template' => 'php/tests/TestException.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' => 'default',
'destination' => 'test/{{ spec.title | caseSnake}}/test_exception.py',
'template' => 'python/tests/package/test_exception.py.twig',
],
];
}

Expand Down
5 changes: 5 additions & 0 deletions src/SDK/Language/Ruby.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ public function getFiles(): array
'destination' => '/lib/{{ spec.title | caseDash }}/models/{{ definition.name | caseSnake }}.rb',
'template' => 'ruby/lib/container/models/model.rb.twig',
],
[
'scope' => 'default',
'destination' => 'test/lib/{{ spec.title | caseDash }}/test_exception.rb',
'template' => 'ruby/tests/lib/appwrite/test_exception.rb.twig',
],
];
}

Expand Down
5 changes: 5 additions & 0 deletions src/SDK/Language/Swift.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ public function getFiles(): array
'destination' => '/Sources/{{ spec.title | caseUcfirst}}Models/{{ definition.name | caseUcfirst }}.swift',
'template' => '/swift/Sources/Models/Model.swift.twig',
],
[
'scope' => 'default',
'destination' => '/Tests/{{ spec.title | caseUcfirst}}Tests/TestException.swift',
'template' => 'swift/Tests/TestException.swift.twig',
],
];
}

Expand Down
10 changes: 10 additions & 0 deletions src/SDK/Language/Web.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ public function getFiles(): array
'destination' => '.travis.yml',
'template' => 'web/.travis.yml.twig',
],
[
'scope' => 'default',
'destination' => 'tests/test_exception.ts',
'template' => 'web/tests/test_exception.ts.twig',
],
[
'scope' => 'default',
'destination' => 'src/exception.ts',
'template' => 'web/src/exception.ts.twig',
],
];
}

Expand Down
139 changes: 139 additions & 0 deletions src/SDK/SDK.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,144 @@ class SDK
'examples' => '',
'test' => 'false'
];
private array $errorTypes = [
35C4n0r marked this conversation as resolved.
Show resolved Hide resolved
'GeneralMock' => 'general_mock',
'GeneralArgumentInvalid' => 'general_argument_invalid',
'GeneralQueryLimitExceeded' => 'general_query_limit_exceeded',
'GeneralQueryInvalid' => 'general_query_invalid',
'GeneralCursorNotFound' => 'general_cursor_not_found',
'UserPasswordMismatch' => 'user_password_mismatch',
'PasswordRecentlyUsed' => 'password_recently_used',
'PasswordPersonalData' => 'password_personal_data',
'UserPhoneNotFound' => 'user_phone_not_found',
'UserMissingId' => 'user_missing_id',
'UserOauth2BadRequest' => 'user_oauth2_bad_request',
'StorageDeviceNotFound' => 'storage_device_not_found',
'StorageFileEmpty' => 'storage_file_empty',
'StorageFileTypeUnsupported' => 'storage_file_type_unsupported',
'StorageInvalidFileSize' => 'storage_invalid_file_size',
'StorageInvalidContentRange' => 'storage_invalid_content_range',
'StorageInvalidAppwriteId' => 'storage_invalid_appwrite_id',
'GeneralProviderFailure' => 'general_provider_failure',
'BuildNotReady' => 'build_not_ready',
'BuildInProgress' => 'build_in_progress',
'CollectionLimitExceeded' => 'collection_limit_exceeded',
'DocumentInvalidStructure' => 'document_invalid_structure',
'DocumentMissingData' => 'document_missing_data',
'DocumentMissingPayload' => 'document_missing_payload',
'AttributeUnknown' => 'attribute_unknown',
'AttributeNotAvailable' => 'attribute_not_available',
'AttributeFormatUnsupported' => 'attribute_format_unsupported',
'AttributeDefaultUnsupported' => 'attribute_default_unsupported',
'AttributeLimitExceeded' => 'attribute_limit_exceeded',
'AttributeValueInvalid' => 'attribute_value_invalid',
'AttributeTypeInvalid' => 'attribute_type_invalid',
'IndexLimitExceeded' => 'index_limit_exceeded',
'IndexInvalid' => 'index_invalid',
'ProjectUnknown' => 'project_unknown',
'ProjectInvalidSuccessUrl' => 'project_invalid_success_url',
'ProjectInvalidFailureUrl' => 'project_invalid_failure_url',
'ProjectReservedProject' => 'project_reserved_project',
'ProjectSmtpConfigInvalid' => 'project_smtp_config_invalid',
'GraphqlNoQuery' => 'graphql_no_query',
'GraphqlTooManyQueries' => 'graphql_too_many_queries',
'GeneralAccessForbidden' => 'general_access_forbidden',
'GeneralUnauthorizedScope' => 'general_unauthorized_scope',
'UserJwtInvalid' => 'user_jwt_invalid',
'UserBlocked' => 'user_blocked',
'UserInvalidToken' => 'user_invalid_token',
'UserEmailNotWhitelisted' => 'user_email_not_whitelisted',
'UserInvalidCode' => 'user_invalid_code',
'UserIpNotWhitelisted' => 'user_ip_not_whitelisted',
'UserInvalidCredentials' => 'user_invalid_credentials',
'UserAnonymousConsoleProhibited' => 'user_anonymous_console_prohibited',
'UserSessionAlreadyExists' => 'user_session_already_exists',
'UserUnauthorized' => 'user_unauthorized',
'UserOauth2Unauthorized' => 'user_oauth2_unauthorized',
'TeamInvalidSecret' => 'team_invalid_secret',
'TeamInviteMismatch' => 'team_invite_mismatch',
'ProjectKeyExpired' => 'project_key_expired',
'RuleVerificationFailed' => 'rule_verification_failed',
'ProjectTemplateDefaultDeletion' => 'project_template_default_deletion',
'GeneralUnknownOrigin' => 'general_unknown_origin',
'StorageInvalidFile' => 'storage_invalid_file',
'DocumentDeleteRestricted' => 'document_delete_restricted',
'GeneralRouteNotFound' => 'general_route_not_found',
'UserNotFound' => 'user_not_found',
'UserSessionNotFound' => 'user_session_not_found',
'UserIdentityNotFound' => 'user_identity_not_found',
'TeamNotFound' => 'team_not_found',
'TeamInviteNotFound' => 'team_invite_not_found',
'TeamMembershipMismatch' => 'team_membership_mismatch',
'MembershipNotFound' => 'membership_not_found',
'AvatarSetNotFound' => 'avatar_set_not_found',
'AvatarNotFound' => 'avatar_not_found',
'AvatarImageNotFound' => 'avatar_image_not_found',
'AvatarRemoteUrlFailed' => 'avatar_remote_url_failed',
'AvatarIconNotFound' => 'avatar_icon_not_found',
'StorageFileNotFound' => 'storage_file_not_found',
'StorageBucketNotFound' => 'storage_bucket_not_found',
'InstallationNotFound' => 'installation_not_found',
'ProviderRepositoryNotFound' => 'provider_repository_not_found',
'RepositoryNotFound' => 'repository_not_found',
'FunctionNotFound' => 'function_not_found',
'FunctionRuntimeUnsupported' => 'function_runtime_unsupported',
'BuildNotFound' => 'build_not_found',
'DeploymentNotFound' => 'deployment_not_found',
'ExecutionNotFound' => 'execution_not_found',
'DatabaseNotFound' => 'database_not_found',
'CollectionNotFound' => 'collection_not_found',
'DocumentNotFound' => 'document_not_found',
'AttributeNotFound' => 'attribute_not_found',
'IndexNotFound' => 'index_not_found',
'ProjectNotFound' => 'project_not_found',
'RouterHostNotFound' => 'router_host_not_found',
'RuleResourceNotFound' => 'rule_resource_not_found',
'RuleNotFound' => 'rule_not_found',
'WebhookNotFound' => 'webhook_not_found',
'KeyNotFound' => 'key_not_found',
'PlatformNotFound' => 'platform_not_found',
'VariableNotFound' => 'variable_not_found',
'MigrationNotFound' => 'migration_not_found',
'GeneralNotImplemented' => 'general_not_implemented',
'UserAlreadyExists' => 'user_already_exists',
'UserEmailAlreadyExists' => 'user_email_already_exists',
'UserPhoneAlreadyExists' => 'user_phone_already_exists',
'TeamInviteAlreadyExists' => 'team_invite_already_exists',
'TeamAlreadyExists' => 'team_already_exists',
'MembershipAlreadyConfirmed' => 'membership_already_confirmed',
'StorageFileAlreadyExists' => 'storage_file_already_exists',
'StorageBucketAlreadyExists' => 'storage_bucket_already_exists',
'ProviderContributionConflict' => 'provider_contribution_conflict',
'DatabaseAlreadyExists' => 'database_already_exists',
'CollectionAlreadyExists' => 'collection_already_exists',
'DocumentAlreadyExists' => 'document_already_exists',
'DocumentUpdateConflict' => 'document_update_conflict',
'AttributeAlreadyExists' => 'attribute_already_exists',
'IndexAlreadyExists' => 'index_already_exists',
'ProjectAlreadyExists' => 'project_already_exists',
'RuleAlreadyExists' => 'rule_already_exists',
'VariableAlreadyExists' => 'variable_already_exists',
'MigrationAlreadyExists' => 'migration_already_exists',
'MigrationInProgress' => 'migration_in_progress',
'UserPasswordResetRequired' => 'user_password_reset_required',
'ProjectProviderDisabled' => 'project_provider_disabled',
'StorageInvalidRange' => 'storage_invalid_range',
'UserOAuth2ProviderError' => 'user_oauth2_provider_error',
'GeneralRateLimitExceeded' => 'general_rate_limit_exceeded',
'GeneralUnknown' => 'general_unknown',
'GeneralServerError' => 'general_server_error',
'GeneralProtocolUnsupported' => 'general_protocol_unsupported',
'GeneralCodesDisabled' => 'general_codes_disabled',
'RouterDomainNotConfigured' => 'router_domain_not_configured',
'GeneralUsageDisabled' => 'general_usage_disabled',
'UserCountExceeded' => 'user_count_exceeded',
'UserAuthMethodUnsupported' => 'user_auth_method_unsupported',
'ProjectProviderUnsupported' => 'project_provider_unsupported',
'GeneralServiceDisabled' => 'general_service_disabled',
'GeneralSMTPDisabled' => 'general_smtp_disabled',
'GeneralPhoneDisabled' => 'general_phone_disabled'
];

/**
* SDK constructor.
Expand Down Expand Up @@ -556,6 +694,7 @@ public function generate(string $target): void
'params' => $this->language->getParams(),
],
'sdk' => $this->getParams(),
'testData' => ['enumData' => $this->errorTypes]
];

foreach ($this->language->getFiles() as $file) {
Expand Down
13 changes: 13 additions & 0 deletions src/Spec/Swagger2.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ public function getDefinitions()
"name" => $key,
"properties" => $schema['properties'] ?? [],
"description" => $schema['description'] ?? [],
"error_types" => $schema['x-appwrite']['types'] ?? [],
35C4n0r marked this conversation as resolved.
Show resolved Hide resolved
"required" => $schema['required'] ?? [],
"additionalProperties" => $schema['additionalProperties'] ?? []
];
Expand All @@ -337,6 +338,18 @@ public function getDefinitions()
}
}
}
if (isset($sch['error_types'])) {
$types = [];
foreach ($sch['error_types'] as $type) {

$types[] = [
'code' => $type['code'],
'type' => $type['type'],
'description' => $type['description']
35C4n0r marked this conversation as resolved.
Show resolved Hide resolved
];
}
$sch['error_types'] = $types;
35C4n0r marked this conversation as resolved.
Show resolved Hide resolved
}
$list[$key] = $sch;
}
return $list;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@ package {{ sdk.namespace | caseDot }}.exceptions

import java.lang.Exception

class {{spec.title | caseUcfirst}}Exception(
class {{spec.title | caseUcfirst}} Exception(
override val message: String? = null,
val code: Int? = null,
val type: String? = null,
val response: String? = null
) : Exception(message)
) : Exception(message)

enum class ErrorType(val value: String) {
{% for error in spec.definitions.appwriteException.error_types %}
/**
* {{ error.description }}
*/
{{ error.type|title|replace({'_': ''}) }}("{{ error.type }}"),
{% endfor %}
}
15 changes: 15 additions & 0 deletions templates/android/tests/TestException.kt.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package tests

import {{ sdk.namespace | caseDot }}.exceptions.ErrorType
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class TestException {

@Test
fun testEnumValues() {
{% for key, value in testData.enumData %}
35C4n0r marked this conversation as resolved.
Show resolved Hide resolved
assertEquals(ErrorType.{{ key }}.value), "{{ value }}")
{% endfor %}
}
}
7 changes: 7 additions & 0 deletions templates/dart/lib/src/exception.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,10 @@ class {{spec.title | caseUcfirst}}Exception implements Exception {
return "{{spec.title | caseUcfirst}}Exception: ${type ?? ''}, $message (${code ?? 0})";
}
}

enum ErrorType {
{% for error in spec.definitions.appwriteException.error_types %}
/// {{ error.description }}
{{ error.type|title|replace({'_': ''}) }},
{% endfor %}
}
8 changes: 8 additions & 0 deletions templates/dart/test/src/exception_test.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,12 @@ void main() {
expect(exception3.toString(), equals('{{spec.title | caseUcfirst}}Exception: ValidationError, Invalid request (400)'));
});
});

group('ErrorType Enum Test', () {
{% for key, value in testData.enumData %}
test('ErrorType.{{ key }} should have correct value', () {
expect(ErrorType.{{ key }}.toString(), equals('ErrorType.{{ value }}'));
});
{% endfor %}
});
}
9 changes: 9 additions & 0 deletions templates/deno/src/exception.ts.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,13 @@ export class {{ spec.title | caseUcfirst}}Exception {
public toString(): String {
return `${this.message} - ${this.code} - ${this.type} - ${JSON.stringify(this.response)}`;
}
}

export enum ErrorType {
{% for error in spec.definitions.appwriteException.error_types %}
/**
* {{ error.description }}
*/
{{ error.type|title|replace({'_': ''}) }} = "{{ error.type }}",
{% endfor %}
}
Loading