From 812a6e6a8770ac1d68ac36830dc9af1d81331383 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Tue, 10 Oct 2023 11:44:19 +0530 Subject: [PATCH 01/21] feat: added constants for Error Types - added logic in Swagger2.php to parse errors from APISpecs -> definitions->x-appwrite. - added Error enums in twig templates. Signed-off-by: Jay --- src/Spec/Swagger2.php | 13 +++++++++++++ .../java/io/appwrite/exceptions/Exception.kt.twig | 13 +++++++++++-- templates/dart/lib/src/exception.dart.twig | 7 +++++++ templates/deno/src/exception.ts.twig | 9 +++++++++ templates/dotnet/src/Appwrite/Exception.cs.twig | 8 ++++++++ .../io/appwrite/exceptions/Exception.kt.twig | 11 ++++++++++- templates/node/lib/exception.js.twig | 13 ++++++++++++- templates/php/src/Exception.php.twig | 9 +++++++++ templates/python/package/exception.py.twig | 14 +++++++++++++- templates/ruby/lib/container/exception.rb.twig | 7 +++++++ 10 files changed, 99 insertions(+), 5 deletions(-) diff --git a/src/Spec/Swagger2.php b/src/Spec/Swagger2.php index bf343ea83..c37a152ee 100644 --- a/src/Spec/Swagger2.php +++ b/src/Spec/Swagger2.php @@ -312,6 +312,7 @@ public function getDefinitions() "name" => $key, "properties" => $schema['properties'] ?? [], "description" => $schema['description'] ?? [], + "error_types" => $schema['x-appwrite']['types'] ?? [], "required" => $schema['required'] ?? [], "additionalProperties" => $schema['additionalProperties'] ?? [] ]; @@ -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'] + ]; + } + $sch['error_types'] = $types; + } $list[$key] = $sch; } return $list; diff --git a/templates/android/library/src/main/java/io/appwrite/exceptions/Exception.kt.twig b/templates/android/library/src/main/java/io/appwrite/exceptions/Exception.kt.twig index b081940d0..8ad029eac 100644 --- a/templates/android/library/src/main/java/io/appwrite/exceptions/Exception.kt.twig +++ b/templates/android/library/src/main/java/io/appwrite/exceptions/Exception.kt.twig @@ -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) \ No newline at end of file +) : 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 %} +} \ No newline at end of file diff --git a/templates/dart/lib/src/exception.dart.twig b/templates/dart/lib/src/exception.dart.twig index dfb1816f4..e0be90c22 100644 --- a/templates/dart/lib/src/exception.dart.twig +++ b/templates/dart/lib/src/exception.dart.twig @@ -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 %} +} diff --git a/templates/deno/src/exception.ts.twig b/templates/deno/src/exception.ts.twig index 61b90cff5..7cb84d47a 100644 --- a/templates/deno/src/exception.ts.twig +++ b/templates/deno/src/exception.ts.twig @@ -14,4 +14,13 @@ export class {{ spec.title | caseUcfirst}}Exception { public toString(): String { return `${this.message} - ${this.code} - ${this.type} - ${JSON.stringify(this.response)}`; } +} + +enum ErrorType { +{% for error in spec.definitions.appwriteException.error_types %} + /** + * {{ error.description }} + */ + {{ error.type|title|replace({'_': ''}) }} = "{{ error.type }}", +{% endfor %} } \ No newline at end of file diff --git a/templates/dotnet/src/Appwrite/Exception.cs.twig b/templates/dotnet/src/Appwrite/Exception.cs.twig index e78d78c2c..d03450d69 100644 --- a/templates/dotnet/src/Appwrite/Exception.cs.twig +++ b/templates/dotnet/src/Appwrite/Exception.cs.twig @@ -25,3 +25,11 @@ namespace {{spec.title | caseUcfirst}} } } +public enum ErrorType { +{% for error in spec.definitions.appwriteException.error_types %} + /// + /// {{ error.description }} + /// + {{ error.type|title|replace({'_': ''}) }}, +{% endfor %} +} diff --git a/templates/kotlin/src/main/kotlin/io/appwrite/exceptions/Exception.kt.twig b/templates/kotlin/src/main/kotlin/io/appwrite/exceptions/Exception.kt.twig index b081940d0..948f86bbe 100644 --- a/templates/kotlin/src/main/kotlin/io/appwrite/exceptions/Exception.kt.twig +++ b/templates/kotlin/src/main/kotlin/io/appwrite/exceptions/Exception.kt.twig @@ -7,4 +7,13 @@ class {{spec.title | caseUcfirst}}Exception( val code: Int? = null, val type: String? = null, val response: String? = null -) : Exception(message) \ No newline at end of file +) : 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 %} +} \ No newline at end of file diff --git a/templates/node/lib/exception.js.twig b/templates/node/lib/exception.js.twig index 4520954e7..dc51c82e9 100644 --- a/templates/node/lib/exception.js.twig +++ b/templates/node/lib/exception.js.twig @@ -7,4 +7,15 @@ class {{spec.title | caseUcfirst}}Exception extends Error { } } -module.exports = {{spec.title | caseUcfirst}}Exception; \ No newline at end of file +module.exports = {{spec.title | caseUcfirst}}Exception; + +enum ErrorType { +{% for error in spec.definitions.appwriteException.error_types %} + /** + * {{ error.description }} + */ + {{ error.type|title|replace({'_': ''}) }} = "{{ error.type }}", +{% endfor %} +} + +module.exports = ErrorType; \ No newline at end of file diff --git a/templates/php/src/Exception.php.twig b/templates/php/src/Exception.php.twig index 0507a70a6..d02f19e6e 100644 --- a/templates/php/src/Exception.php.twig +++ b/templates/php/src/Exception.php.twig @@ -43,4 +43,13 @@ class {{spec.title | caseUcfirst}}Exception extends Exception { { return $this->response; } +} + +class ErrorType { +{% for error in spec.definitions.appwriteException.error_types %} + /** + * {{ error.description }} + */ + const {{ error.type|title|replace({'_': ''}) }} = '{{ error.type }}'; +{% endfor %} } \ No newline at end of file diff --git a/templates/python/package/exception.py.twig b/templates/python/package/exception.py.twig index 6e5d4c8ff..707ff04f0 100644 --- a/templates/python/package/exception.py.twig +++ b/templates/python/package/exception.py.twig @@ -1,7 +1,19 @@ +from enum import Enum + + class {{spec.title | caseUcfirst}}Exception(Exception): def __init__(self, message, code = 0, type = None, response = None): self.message = message self.code = code self.type = type self.response = response - super().__init__(self.message) \ No newline at end of file + super().__init__(self.message) + + +class ErrorType(Enum): +{% for error in spec.definitions.appwriteException.error_types %} + """ + {{ error.description }} + """ + {{ error.type|title|replace({'_': ''}) }} = '{{ error.type }}' +{% endfor %} diff --git a/templates/ruby/lib/container/exception.rb.twig b/templates/ruby/lib/container/exception.rb.twig index 0712d8e65..bcfc20710 100644 --- a/templates/ruby/lib/container/exception.rb.twig +++ b/templates/ruby/lib/container/exception.rb.twig @@ -12,3 +12,10 @@ module {{spec.title | caseUcfirst}} end end end + +class ErrorType +{% for error in spec.definitions.appwriteException.error_types %} + # {{ error.description }} + {{ error.type|title|replace({'_': ''}) }} = '{{ error.type }}' +{% endfor %} +end From 061fea8bbbed87c8cc84655e5b87f6f40367afdc Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Sat, 21 Oct 2023 23:44:41 +0530 Subject: [PATCH 02/21] feat: added tests for Python ErrorEnums - added new test folder in python. - added test for Python ErrorEnums Signed-off-by: Jay --- src/SDK/Language/Python.php | 5 + .../test/package/test_exception.py.twig | 143 ++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 templates/python/test/package/test_exception.py.twig diff --git a/src/SDK/Language/Python.php b/src/SDK/Language/Python.php index c8d19e639..50c5af556 100644 --- a/src/SDK/Language/Python.php +++ b/src/SDK/Language/Python.php @@ -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/test/package/test_exception.py.twig', + ], ]; } diff --git a/templates/python/test/package/test_exception.py.twig b/templates/python/test/package/test_exception.py.twig new file mode 100644 index 000000000..0a235cefe --- /dev/null +++ b/templates/python/test/package/test_exception.py.twig @@ -0,0 +1,143 @@ +from ...{{ spec.title | caseSnake}}.exception import ErrorType +import unittest + + +class TestErrorEnum(unittest.TestCase): + + def test_enum_values(self): + self.assertEqual(ErrorType.GeneralMock.value, 'general_mock') + self.assertEqual(ErrorType.GeneralArgumentInvalid.value, 'general_argument_invalid') + self.assertEqual(ErrorType.GeneralQueryLimitExceeded.value, 'general_query_limit_exceeded') + self.assertEqual(ErrorType.GeneralQueryInvalid.value, 'general_query_invalid') + self.assertEqual(ErrorType.GeneralCursorNotFound.value, 'general_cursor_not_found') + self.assertEqual(ErrorType.UserPasswordMismatch.value, 'user_password_mismatch') + self.assertEqual(ErrorType.PasswordRecentlyUsed.value, 'password_recently_used') + self.assertEqual(ErrorType.PasswordPersonalData.value, 'password_personal_data') + self.assertEqual(ErrorType.UserPhoneNotFound.value, 'user_phone_not_found') + self.assertEqual(ErrorType.UserMissingId.value, 'user_missing_id') + self.assertEqual(ErrorType.UserOauth2BadRequest.value, 'user_oauth2_bad_request') + self.assertEqual(ErrorType.StorageDeviceNotFound.value, 'storage_device_not_found') + self.assertEqual(ErrorType.StorageFileEmpty.value, 'storage_file_empty') + self.assertEqual(ErrorType.StorageFileTypeUnsupported.value, 'storage_file_type_unsupported') + self.assertEqual(ErrorType.StorageInvalidFileSize.value, 'storage_invalid_file_size') + self.assertEqual(ErrorType.StorageInvalidContentRange.value, 'storage_invalid_content_range') + self.assertEqual(ErrorType.StorageInvalidAppwriteId.value, 'storage_invalid_appwrite_id') + self.assertEqual(ErrorType.GeneralProviderFailure.value, 'general_provider_failure') + self.assertEqual(ErrorType.BuildNotReady.value, 'build_not_ready') + self.assertEqual(ErrorType.BuildInProgress.value, 'build_in_progress') + self.assertEqual(ErrorType.CollectionLimitExceeded.value, 'collection_limit_exceeded') + self.assertEqual(ErrorType.DocumentInvalidStructure.value, 'document_invalid_structure') + self.assertEqual(ErrorType.DocumentMissingData.value, 'document_missing_data') + self.assertEqual(ErrorType.DocumentMissingPayload.value, 'document_missing_payload') + self.assertEqual(ErrorType.AttributeUnknown.value, 'attribute_unknown') + self.assertEqual(ErrorType.AttributeNotAvailable.value, 'attribute_not_available') + self.assertEqual(ErrorType.AttributeFormatUnsupported.value, 'attribute_format_unsupported') + self.assertEqual(ErrorType.AttributeDefaultUnsupported.value, 'attribute_default_unsupported') + self.assertEqual(ErrorType.AttributeLimitExceeded.value, 'attribute_limit_exceeded') + self.assertEqual(ErrorType.AttributeValueInvalid.value, 'attribute_value_invalid') + self.assertEqual(ErrorType.AttributeTypeInvalid.value, 'attribute_type_invalid') + self.assertEqual(ErrorType.IndexLimitExceeded.value, 'index_limit_exceeded') + self.assertEqual(ErrorType.IndexInvalid.value, 'index_invalid') + self.assertEqual(ErrorType.ProjectUnknown.value, 'project_unknown') + self.assertEqual(ErrorType.ProjectInvalidSuccessUrl.value, 'project_invalid_success_url') + self.assertEqual(ErrorType.ProjectInvalidFailureUrl.value, 'project_invalid_failure_url') + self.assertEqual(ErrorType.ProjectReservedProject.value, 'project_reserved_project') + self.assertEqual(ErrorType.ProjectSmtpConfigInvalid.value, 'project_smtp_config_invalid') + self.assertEqual(ErrorType.GraphqlNoQuery.value, 'graphql_no_query') + self.assertEqual(ErrorType.GraphqlTooManyQueries.value, 'graphql_too_many_queries') + self.assertEqual(ErrorType.GeneralAccessForbidden.value, 'general_access_forbidden') + self.assertEqual(ErrorType.GeneralUnauthorizedScope.value, 'general_unauthorized_scope') + self.assertEqual(ErrorType.UserJwtInvalid.value, 'user_jwt_invalid') + self.assertEqual(ErrorType.UserBlocked.value, 'user_blocked') + self.assertEqual(ErrorType.UserInvalidToken.value, 'user_invalid_token') + self.assertEqual(ErrorType.UserEmailNotWhitelisted.value, 'user_email_not_whitelisted') + self.assertEqual(ErrorType.UserInvalidCode.value, 'user_invalid_code') + self.assertEqual(ErrorType.UserIpNotWhitelisted.value, 'user_ip_not_whitelisted') + self.assertEqual(ErrorType.UserInvalidCredentials.value, 'user_invalid_credentials') + self.assertEqual(ErrorType.UserAnonymousConsoleProhibited.value, 'user_anonymous_console_prohibited') + self.assertEqual(ErrorType.UserSessionAlreadyExists.value, 'user_session_already_exists') + self.assertEqual(ErrorType.UserUnauthorized.value, 'user_unauthorized') + self.assertEqual(ErrorType.UserOauth2Unauthorized.value, 'user_oauth2_unauthorized') + self.assertEqual(ErrorType.TeamInvalidSecret.value, 'team_invalid_secret') + self.assertEqual(ErrorType.TeamInviteMismatch.value, 'team_invite_mismatch') + self.assertEqual(ErrorType.ProjectKeyExpired.value, 'project_key_expired') + self.assertEqual(ErrorType.RuleVerificationFailed.value, 'rule_verification_failed') + self.assertEqual(ErrorType.ProjectTemplateDefaultDeletion.value, 'project_template_default_deletion') + self.assertEqual(ErrorType.GeneralUnknownOrigin.value, 'general_unknown_origin') + self.assertEqual(ErrorType.StorageInvalidFile.value, 'storage_invalid_file') + self.assertEqual(ErrorType.DocumentDeleteRestricted.value, 'document_delete_restricted') + self.assertEqual(ErrorType.GeneralRouteNotFound.value, 'general_route_not_found') + self.assertEqual(ErrorType.UserNotFound.value, 'user_not_found') + self.assertEqual(ErrorType.UserSessionNotFound.value, 'user_session_not_found') + self.assertEqual(ErrorType.UserIdentityNotFound.value, 'user_identity_not_found') + self.assertEqual(ErrorType.TeamNotFound.value, 'team_not_found') + self.assertEqual(ErrorType.TeamInviteNotFound.value, 'team_invite_not_found') + self.assertEqual(ErrorType.TeamMembershipMismatch.value, 'team_membership_mismatch') + self.assertEqual(ErrorType.MembershipNotFound.value, 'membership_not_found') + self.assertEqual(ErrorType.AvatarSetNotFound.value, 'avatar_set_not_found') + self.assertEqual(ErrorType.AvatarNotFound.value, 'avatar_not_found') + self.assertEqual(ErrorType.AvatarImageNotFound.value, 'avatar_image_not_found') + self.assertEqual(ErrorType.AvatarRemoteUrlFailed.value, 'avatar_remote_url_failed') + self.assertEqual(ErrorType.AvatarIconNotFound.value, 'avatar_icon_not_found') + self.assertEqual(ErrorType.StorageFileNotFound.value, 'storage_file_not_found') + self.assertEqual(ErrorType.StorageBucketNotFound.value, 'storage_bucket_not_found') + self.assertEqual(ErrorType.InstallationNotFound.value, 'installation_not_found') + self.assertEqual(ErrorType.ProviderRepositoryNotFound.value, 'provider_repository_not_found') + self.assertEqual(ErrorType.RepositoryNotFound.value, 'repository_not_found') + self.assertEqual(ErrorType.FunctionNotFound.value, 'function_not_found') + self.assertEqual(ErrorType.FunctionRuntimeUnsupported.value, 'function_runtime_unsupported') + self.assertEqual(ErrorType.BuildNotFound.value, 'build_not_found') + self.assertEqual(ErrorType.DeploymentNotFound.value, 'deployment_not_found') + self.assertEqual(ErrorType.ExecutionNotFound.value, 'execution_not_found') + self.assertEqual(ErrorType.DatabaseNotFound.value, 'database_not_found') + self.assertEqual(ErrorType.CollectionNotFound.value, 'collection_not_found') + self.assertEqual(ErrorType.DocumentNotFound.value, 'document_not_found') + self.assertEqual(ErrorType.AttributeNotFound.value, 'attribute_not_found') + self.assertEqual(ErrorType.IndexNotFound.value, 'index_not_found') + self.assertEqual(ErrorType.ProjectNotFound.value, 'project_not_found') + self.assertEqual(ErrorType.RouterHostNotFound.value, 'router_host_not_found') + self.assertEqual(ErrorType.RuleResourceNotFound.value, 'rule_resource_not_found') + self.assertEqual(ErrorType.RuleNotFound.value, 'rule_not_found') + self.assertEqual(ErrorType.WebhookNotFound.value, 'webhook_not_found') + self.assertEqual(ErrorType.KeyNotFound.value, 'key_not_found') + self.assertEqual(ErrorType.PlatformNotFound.value, 'platform_not_found') + self.assertEqual(ErrorType.VariableNotFound.value, 'variable_not_found') + self.assertEqual(ErrorType.MigrationNotFound.value, 'migration_not_found') + self.assertEqual(ErrorType.GeneralNotImplemented.value, 'general_not_implemented') + self.assertEqual(ErrorType.UserAlreadyExists.value, 'user_already_exists') + self.assertEqual(ErrorType.UserEmailAlreadyExists.value, 'user_email_already_exists') + self.assertEqual(ErrorType.UserPhoneAlreadyExists.value, 'user_phone_already_exists') + self.assertEqual(ErrorType.TeamInviteAlreadyExists.value, 'team_invite_already_exists') + self.assertEqual(ErrorType.TeamAlreadyExists.value, 'team_already_exists') + self.assertEqual(ErrorType.MembershipAlreadyConfirmed.value, 'membership_already_confirmed') + self.assertEqual(ErrorType.StorageFileAlreadyExists.value, 'storage_file_already_exists') + self.assertEqual(ErrorType.StorageBucketAlreadyExists.value, 'storage_bucket_already_exists') + self.assertEqual(ErrorType.ProviderContributionConflict.value, 'provider_contribution_conflict') + self.assertEqual(ErrorType.DatabaseAlreadyExists.value, 'database_already_exists') + self.assertEqual(ErrorType.CollectionAlreadyExists.value, 'collection_already_exists') + self.assertEqual(ErrorType.DocumentAlreadyExists.value, 'document_already_exists') + self.assertEqual(ErrorType.DocumentUpdateConflict.value, 'document_update_conflict') + self.assertEqual(ErrorType.AttributeAlreadyExists.value, 'attribute_already_exists') + self.assertEqual(ErrorType.IndexAlreadyExists.value, 'index_already_exists') + self.assertEqual(ErrorType.ProjectAlreadyExists.value, 'project_already_exists') + self.assertEqual(ErrorType.RuleAlreadyExists.value, 'rule_already_exists') + self.assertEqual(ErrorType.VariableAlreadyExists.value, 'variable_already_exists') + self.assertEqual(ErrorType.MigrationAlreadyExists.value, 'migration_already_exists') + self.assertEqual(ErrorType.MigrationInProgress.value, 'migration_in_progress') + self.assertEqual(ErrorType.UserPasswordResetRequired.value, 'user_password_reset_required') + self.assertEqual(ErrorType.ProjectProviderDisabled.value, 'project_provider_disabled') + self.assertEqual(ErrorType.StorageInvalidRange.value, 'storage_invalid_range') + self.assertEqual(ErrorType.UserOAuth2ProviderError.value, 'user_oauth2_provider_error') + self.assertEqual(ErrorType.GeneralRateLimitExceeded.value, 'general_rate_limit_exceeded') + self.assertEqual(ErrorType.GeneralUnknown.value, 'general_unknown') + self.assertEqual(ErrorType.GeneralServerError.value, 'general_server_error') + self.assertEqual(ErrorType.GeneralProtocolUnsupported.value, 'general_protocol_unsupported') + self.assertEqual(ErrorType.GeneralCodesDisabled.value, 'general_codes_disabled') + self.assertEqual(ErrorType.RouterDomainNotConfigured.value, 'router_domain_not_configured') + self.assertEqual(ErrorType.GeneralUsageDisabled.value, 'general_usage_disabled') + self.assertEqual(ErrorType.UserCountExceeded.value, 'user_count_exceeded') + self.assertEqual(ErrorType.UserAuthMethodUnsupported.value, 'user_auth_method_unsupported') + self.assertEqual(ErrorType.ProjectProviderUnsupported.value, 'project_provider_unsupported') + self.assertEqual(ErrorType.GeneralServiceDisabled.value, 'general_service_disabled') + self.assertEqual(ErrorType.GeneralSMTPDisabled.value, 'general_smtp_disabled') + self.assertEqual(ErrorType.GeneralPhoneDisabled.value, 'general_phone_disabled') From 2c370985cfa938df17dbbde51061c1800fb355ac Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Wed, 25 Oct 2023 00:24:14 +0530 Subject: [PATCH 03/21] feat: add tests for Ruby ErrorEnums - add new gem test-unit Signed-off-by: Jay --- src/SDK/Language/Ruby.php | 5 + templates/ruby/Gemfile.twig | 3 +- .../test/lib/appwrite/test_exception.rb.twig | 144 ++++++++++++++++++ 3 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 templates/ruby/test/lib/appwrite/test_exception.rb.twig diff --git a/src/SDK/Language/Ruby.php b/src/SDK/Language/Ruby.php index eb50551b0..4511fea68 100644 --- a/src/SDK/Language/Ruby.php +++ b/src/SDK/Language/Ruby.php @@ -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/test/lib/appwrite/test_exception.rb.twig', + ], ]; } diff --git a/templates/ruby/Gemfile.twig b/templates/ruby/Gemfile.twig index cd8aa9e04..2f8fb142c 100644 --- a/templates/ruby/Gemfile.twig +++ b/templates/ruby/Gemfile.twig @@ -1,3 +1,4 @@ source 'https://rubygems.org' -gemspec \ No newline at end of file +gemspec +gem 'test-unit' \ No newline at end of file diff --git a/templates/ruby/test/lib/appwrite/test_exception.rb.twig b/templates/ruby/test/lib/appwrite/test_exception.rb.twig new file mode 100644 index 000000000..028027930 --- /dev/null +++ b/templates/ruby/test/lib/appwrite/test_exception.rb.twig @@ -0,0 +1,144 @@ +require 'test/unit' +require_relative '../../../lib/{{ spec.title | caseSnake }}/exception' # Ensure this path is correct + +class ErrorTypeTest < Test::Unit::TestCase + + def test_error_type_values + assert_equal('general_mock', ErrorType::GeneralMock) + assert_equal('general_argument_invalid', ErrorType::GeneralArgumentInvalid) + assert_equal('general_query_limit_exceeded', ErrorType::GeneralQueryLimitExceeded) + assert_equal('general_query_invalid', ErrorType::GeneralQueryInvalid) + assert_equal('general_cursor_not_found', ErrorType::GeneralCursorNotFound) + assert_equal('user_password_mismatch', ErrorType::UserPasswordMismatch) + assert_equal('password_recently_used', ErrorType::PasswordRecentlyUsed) + assert_equal('password_personal_data', ErrorType::PasswordPersonalData) + assert_equal('user_phone_not_found', ErrorType::UserPhoneNotFound) + assert_equal('user_missing_id', ErrorType::UserMissingId) + assert_equal('user_oauth2_bad_request', ErrorType::UserOauth2BadRequest) + assert_equal('storage_device_not_found', ErrorType::StorageDeviceNotFound) + assert_equal('storage_file_empty', ErrorType::StorageFileEmpty) + assert_equal('storage_file_type_unsupported', ErrorType::StorageFileTypeUnsupported) + assert_equal('storage_invalid_file_size', ErrorType::StorageInvalidFileSize) + assert_equal('storage_invalid_content_range', ErrorType::StorageInvalidContentRange) + assert_equal('storage_invalid_appwrite_id', ErrorType::StorageInvalidAppwriteId) + assert_equal('general_provider_failure', ErrorType::GeneralProviderFailure) + assert_equal('build_not_ready', ErrorType::BuildNotReady) + assert_equal('build_in_progress', ErrorType::BuildInProgress) + assert_equal('collection_limit_exceeded', ErrorType::CollectionLimitExceeded) + assert_equal('document_invalid_structure', ErrorType::DocumentInvalidStructure) + assert_equal('document_missing_data', ErrorType::DocumentMissingData) + assert_equal('document_missing_payload', ErrorType::DocumentMissingPayload) + assert_equal('attribute_unknown', ErrorType::AttributeUnknown) + assert_equal('attribute_not_available', ErrorType::AttributeNotAvailable) + assert_equal('attribute_format_unsupported', ErrorType::AttributeFormatUnsupported) + assert_equal('attribute_default_unsupported', ErrorType::AttributeDefaultUnsupported) + assert_equal('attribute_limit_exceeded', ErrorType::AttributeLimitExceeded) + assert_equal('attribute_value_invalid', ErrorType::AttributeValueInvalid) + assert_equal('attribute_type_invalid', ErrorType::AttributeTypeInvalid) + assert_equal('index_limit_exceeded', ErrorType::IndexLimitExceeded) + assert_equal('index_invalid', ErrorType::IndexInvalid) + assert_equal('project_unknown', ErrorType::ProjectUnknown) + assert_equal('project_invalid_success_url', ErrorType::ProjectInvalidSuccessUrl) + assert_equal('project_invalid_failure_url', ErrorType::ProjectInvalidFailureUrl) + assert_equal('project_reserved_project', ErrorType::ProjectReservedProject) + assert_equal('project_smtp_config_invalid', ErrorType::ProjectSmtpConfigInvalid) + assert_equal('graphql_no_query', ErrorType::GraphqlNoQuery) + assert_equal('graphql_too_many_queries', ErrorType::GraphqlTooManyQueries) + assert_equal('general_access_forbidden', ErrorType::GeneralAccessForbidden) + assert_equal('general_unauthorized_scope', ErrorType::GeneralUnauthorizedScope) + assert_equal('user_jwt_invalid', ErrorType::UserJwtInvalid) + assert_equal('user_blocked', ErrorType::UserBlocked) + assert_equal('user_invalid_token', ErrorType::UserInvalidToken) + assert_equal('user_email_not_whitelisted', ErrorType::UserEmailNotWhitelisted) + assert_equal('user_invalid_code', ErrorType::UserInvalidCode) + assert_equal('user_ip_not_whitelisted', ErrorType::UserIpNotWhitelisted) + assert_equal('user_invalid_credentials', ErrorType::UserInvalidCredentials) + assert_equal('user_anonymous_console_prohibited', ErrorType::UserAnonymousConsoleProhibited) + assert_equal('user_session_already_exists', ErrorType::UserSessionAlreadyExists) + assert_equal('user_unauthorized', ErrorType::UserUnauthorized) + assert_equal('user_oauth2_unauthorized', ErrorType::UserOauth2Unauthorized) + assert_equal('team_invalid_secret', ErrorType::TeamInvalidSecret) + assert_equal('team_invite_mismatch', ErrorType::TeamInviteMismatch) + assert_equal('project_key_expired', ErrorType::ProjectKeyExpired) + assert_equal('rule_verification_failed', ErrorType::RuleVerificationFailed) + assert_equal('project_template_default_deletion', ErrorType::ProjectTemplateDefaultDeletion) + assert_equal('general_unknown_origin', ErrorType::GeneralUnknownOrigin) + assert_equal('storage_invalid_file', ErrorType::StorageInvalidFile) + assert_equal('document_delete_restricted', ErrorType::DocumentDeleteRestricted) + assert_equal('general_route_not_found', ErrorType::GeneralRouteNotFound) + assert_equal('user_not_found', ErrorType::UserNotFound) + assert_equal('user_session_not_found', ErrorType::UserSessionNotFound) + assert_equal('user_identity_not_found', ErrorType::UserIdentityNotFound) + assert_equal('team_not_found', ErrorType::TeamNotFound) + assert_equal('team_invite_not_found', ErrorType::TeamInviteNotFound) + assert_equal('team_membership_mismatch', ErrorType::TeamMembershipMismatch) + assert_equal('membership_not_found', ErrorType::MembershipNotFound) + assert_equal('avatar_set_not_found', ErrorType::AvatarSetNotFound) + assert_equal('avatar_not_found', ErrorType::AvatarNotFound) + assert_equal('avatar_image_not_found', ErrorType::AvatarImageNotFound) + assert_equal('avatar_remote_url_failed', ErrorType::AvatarRemoteUrlFailed) + assert_equal('avatar_icon_not_found', ErrorType::AvatarIconNotFound) + assert_equal('storage_file_not_found', ErrorType::StorageFileNotFound) + assert_equal('storage_bucket_not_found', ErrorType::StorageBucketNotFound) + assert_equal('installation_not_found', ErrorType::InstallationNotFound) + assert_equal('provider_repository_not_found', ErrorType::ProviderRepositoryNotFound) + assert_equal('repository_not_found', ErrorType::RepositoryNotFound) + assert_equal('function_not_found', ErrorType::FunctionNotFound) + assert_equal('function_runtime_unsupported', ErrorType::FunctionRuntimeUnsupported) + assert_equal('build_not_found', ErrorType::BuildNotFound) + assert_equal('deployment_not_found', ErrorType::DeploymentNotFound) + assert_equal('execution_not_found', ErrorType::ExecutionNotFound) + assert_equal('database_not_found', ErrorType::DatabaseNotFound) + assert_equal('collection_not_found', ErrorType::CollectionNotFound) + assert_equal('document_not_found', ErrorType::DocumentNotFound) + assert_equal('attribute_not_found', ErrorType::AttributeNotFound) + assert_equal('index_not_found', ErrorType::IndexNotFound) + assert_equal('project_not_found', ErrorType::ProjectNotFound) + assert_equal('router_host_not_found', ErrorType::RouterHostNotFound) + assert_equal('rule_resource_not_found', ErrorType::RuleResourceNotFound) + assert_equal('rule_not_found', ErrorType::RuleNotFound) + assert_equal('webhook_not_found', ErrorType::WebhookNotFound) + assert_equal('key_not_found', ErrorType::KeyNotFound) + assert_equal('platform_not_found', ErrorType::PlatformNotFound) + assert_equal('variable_not_found', ErrorType::VariableNotFound) + assert_equal('migration_not_found', ErrorType::MigrationNotFound) + assert_equal('general_not_implemented', ErrorType::GeneralNotImplemented) + assert_equal('user_already_exists', ErrorType::UserAlreadyExists) + assert_equal('user_email_already_exists', ErrorType::UserEmailAlreadyExists) + assert_equal('user_phone_already_exists', ErrorType::UserPhoneAlreadyExists) + assert_equal('team_invite_already_exists', ErrorType::TeamInviteAlreadyExists) + assert_equal('team_already_exists', ErrorType::TeamAlreadyExists) + assert_equal('membership_already_confirmed', ErrorType::MembershipAlreadyConfirmed) + assert_equal('storage_file_already_exists', ErrorType::StorageFileAlreadyExists) + assert_equal('storage_bucket_already_exists', ErrorType::StorageBucketAlreadyExists) + assert_equal('provider_contribution_conflict', ErrorType::ProviderContributionConflict) + assert_equal('database_already_exists', ErrorType::DatabaseAlreadyExists) + assert_equal('collection_already_exists', ErrorType::CollectionAlreadyExists) + assert_equal('document_already_exists', ErrorType::DocumentAlreadyExists) + assert_equal('document_update_conflict', ErrorType::DocumentUpdateConflict) + assert_equal('attribute_already_exists', ErrorType::AttributeAlreadyExists) + assert_equal('index_already_exists', ErrorType::IndexAlreadyExists) + assert_equal('project_already_exists', ErrorType::ProjectAlreadyExists) + assert_equal('rule_already_exists', ErrorType::RuleAlreadyExists) + assert_equal('variable_already_exists', ErrorType::VariableAlreadyExists) + assert_equal('migration_already_exists', ErrorType::MigrationAlreadyExists) + assert_equal('migration_in_progress', ErrorType::MigrationInProgress) + assert_equal('user_password_reset_required', ErrorType::UserPasswordResetRequired) + assert_equal('project_provider_disabled', ErrorType::ProjectProviderDisabled) + assert_equal('storage_invalid_range', ErrorType::StorageInvalidRange) + assert_equal('user_oauth2_provider_error', ErrorType::UserOAuth2ProviderError) + assert_equal('general_rate_limit_exceeded', ErrorType::GeneralRateLimitExceeded) + assert_equal('general_unknown', ErrorType::GeneralUnknown) + assert_equal('general_server_error', ErrorType::GeneralServerError) + assert_equal('general_protocol_unsupported', ErrorType::GeneralProtocolUnsupported) + assert_equal('general_codes_disabled', ErrorType::GeneralCodesDisabled) + assert_equal('router_domain_not_configured', ErrorType::RouterDomainNotConfigured) + assert_equal('general_usage_disabled', ErrorType::GeneralUsageDisabled) + assert_equal('user_count_exceeded', ErrorType::UserCountExceeded) + assert_equal('user_auth_method_unsupported', ErrorType::UserAuthMethodUnsupported) + assert_equal('project_provider_unsupported', ErrorType::ProjectProviderUnsupported) + assert_equal('general_service_disabled', ErrorType::GeneralServiceDisabled) + assert_equal('general_smtp_disabled', ErrorType::GeneralSMTPDisabled) + assert_equal('general_phone_disabled', ErrorType::GeneralPhoneDisabled) + end +end From a07a4b6a487f3c56c720fd2b67c997e11389e2d9 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Wed, 25 Oct 2023 16:18:32 +0530 Subject: [PATCH 04/21] feat: add tests EnumTests - new tests for Node, Deno, web, swift, ruby, python, php, kotlin, dotnet, android Signed-off-by: Jay --- src/SDK/Language/Android.php | 5 + src/SDK/Language/Deno.php | 5 + src/SDK/Language/DotNet.php | 7 +- src/SDK/Language/Kotlin.php | 5 + src/SDK/Language/Node.php | 5 + src/SDK/Language/PHP.php | 5 + src/SDK/Language/Python.php | 2 +- src/SDK/Language/Ruby.php | 2 +- src/SDK/Language/Swift.php | 5 + src/SDK/Language/Web.php | 10 ++ src/SDK/SDK.php | 139 +++++++++++++++++ templates/android/tests/TestException.kt.twig | 15 ++ templates/deno/src/exception.ts.twig | 2 +- templates/deno/tests/test_exception.ts.twig | 9 ++ .../dotnet/src/Appwrite/Exception.cs.twig | 18 ++- templates/dotnet/tests/TestException.cs.twig | 14 ++ templates/kotlin/tests/TestException.kt.twig | 15 ++ templates/node/lib/exception.js.twig | 9 +- templates/node/tests/test_exception.js.twig | 12 ++ templates/php/tests/TestException.php.twig | 10 ++ .../test/package/test_exception.py.twig | 143 ----------------- .../test/lib/appwrite/test_exception.rb.twig | 144 ------------------ .../tests/lib/appwrite/test_exception.rb.twig | 11 ++ templates/swift/Sources/Exception.swift.twig | 6 + .../swift/Tests/TestException.swift.twig | 10 ++ templates/web/src/exception.ts.twig | 8 + templates/web/tests/test_exception.ts.twig | 12 ++ 27 files changed, 326 insertions(+), 302 deletions(-) create mode 100644 templates/android/tests/TestException.kt.twig create mode 100644 templates/deno/tests/test_exception.ts.twig create mode 100644 templates/dotnet/tests/TestException.cs.twig create mode 100644 templates/kotlin/tests/TestException.kt.twig create mode 100644 templates/node/tests/test_exception.js.twig create mode 100644 templates/php/tests/TestException.php.twig delete mode 100644 templates/python/test/package/test_exception.py.twig delete mode 100644 templates/ruby/test/lib/appwrite/test_exception.rb.twig create mode 100644 templates/ruby/tests/lib/appwrite/test_exception.rb.twig create mode 100644 templates/swift/Sources/Exception.swift.twig create mode 100644 templates/swift/Tests/TestException.swift.twig create mode 100644 templates/web/src/exception.ts.twig create mode 100644 templates/web/tests/test_exception.ts.twig diff --git a/src/SDK/Language/Android.php b/src/SDK/Language/Android.php index 5d3e90bb0..323fe5436 100644 --- a/src/SDK/Language/Android.php +++ b/src/SDK/Language/Android.php @@ -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', + ], ]; } } diff --git a/src/SDK/Language/Deno.php b/src/SDK/Language/Deno.php index 1fdef0c0d..8650cb216 100644 --- a/src/SDK/Language/Deno.php +++ b/src/SDK/Language/Deno.php @@ -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', + ], ]; } diff --git a/src/SDK/Language/DotNet.php b/src/SDK/Language/DotNet.php index f569225f2..8af0c4898 100644 --- a/src/SDK/Language/DotNet.php +++ b/src/SDK/Language/DotNet.php @@ -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', + ], ]; } diff --git a/src/SDK/Language/Kotlin.php b/src/SDK/Language/Kotlin.php index a7a4c5aea..be6e1cd4f 100644 --- a/src/SDK/Language/Kotlin.php +++ b/src/SDK/Language/Kotlin.php @@ -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', + ], ]; } diff --git a/src/SDK/Language/Node.php b/src/SDK/Language/Node.php index 435e1cce0..8dfd75e02 100644 --- a/src/SDK/Language/Node.php +++ b/src/SDK/Language/Node.php @@ -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', + ], ]; } diff --git a/src/SDK/Language/PHP.php b/src/SDK/Language/PHP.php index 99ad8740e..a04c0f63b 100644 --- a/src/SDK/Language/PHP.php +++ b/src/SDK/Language/PHP.php @@ -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', + ], ]; } diff --git a/src/SDK/Language/Python.php b/src/SDK/Language/Python.php index 50c5af556..9ea9581d4 100644 --- a/src/SDK/Language/Python.php +++ b/src/SDK/Language/Python.php @@ -187,7 +187,7 @@ public function getFiles(): array [ 'scope' => 'default', 'destination' => 'test/{{ spec.title | caseSnake}}/test_exception.py', - 'template' => 'python/test/package/test_exception.py.twig', + 'template' => 'python/tests/package/test_exception.py.twig', ], ]; } diff --git a/src/SDK/Language/Ruby.php b/src/SDK/Language/Ruby.php index 4511fea68..4caa1c578 100644 --- a/src/SDK/Language/Ruby.php +++ b/src/SDK/Language/Ruby.php @@ -185,7 +185,7 @@ public function getFiles(): array [ 'scope' => 'default', 'destination' => 'test/lib/{{ spec.title | caseDash }}/test_exception.rb', - 'template' => 'ruby/test/lib/appwrite/test_exception.rb.twig', + 'template' => 'ruby/tests/lib/appwrite/test_exception.rb.twig', ], ]; } diff --git a/src/SDK/Language/Swift.php b/src/SDK/Language/Swift.php index 9b2e08798..6e8bd6f7d 100644 --- a/src/SDK/Language/Swift.php +++ b/src/SDK/Language/Swift.php @@ -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', + ], ]; } diff --git a/src/SDK/Language/Web.php b/src/SDK/Language/Web.php index 26ec51136..e0fd13d96 100644 --- a/src/SDK/Language/Web.php +++ b/src/SDK/Language/Web.php @@ -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', + ], ]; } diff --git a/src/SDK/SDK.php b/src/SDK/SDK.php index 73a75ce39..45a9128d2 100644 --- a/src/SDK/SDK.php +++ b/src/SDK/SDK.php @@ -69,6 +69,144 @@ class SDK 'examples' => '', 'test' => 'false' ]; + private array $errorTypes = [ + '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. @@ -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) { diff --git a/templates/android/tests/TestException.kt.twig b/templates/android/tests/TestException.kt.twig new file mode 100644 index 000000000..ee9c14f25 --- /dev/null +++ b/templates/android/tests/TestException.kt.twig @@ -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 %} + assertEquals(ErrorType.{{ key }}.value), "{{ value }}") + {% endfor %} +} +} \ No newline at end of file diff --git a/templates/deno/src/exception.ts.twig b/templates/deno/src/exception.ts.twig index 7cb84d47a..4a459f93a 100644 --- a/templates/deno/src/exception.ts.twig +++ b/templates/deno/src/exception.ts.twig @@ -16,7 +16,7 @@ export class {{ spec.title | caseUcfirst}}Exception { } } -enum ErrorType { +export enum ErrorType { {% for error in spec.definitions.appwriteException.error_types %} /** * {{ error.description }} diff --git a/templates/deno/tests/test_exception.ts.twig b/templates/deno/tests/test_exception.ts.twig new file mode 100644 index 000000000..1f6892d14 --- /dev/null +++ b/templates/deno/tests/test_exception.ts.twig @@ -0,0 +1,9 @@ +// Assuming errorType.ts contains your ErrorType enum +import {assertEquals} from "https://deno.land/std/testing/asserts.ts"; +import {ErrorType} from "../src/exception.ts"; + +Deno.test("ErrorType values should match expected strings", () => { + {% for key, value in testData.enumData %} + assertEquals(ErrorType.{{ key }}, '{{ value }}'); + {% endfor %} +}) \ No newline at end of file diff --git a/templates/dotnet/src/Appwrite/Exception.cs.twig b/templates/dotnet/src/Appwrite/Exception.cs.twig index d03450d69..eb16117ab 100644 --- a/templates/dotnet/src/Appwrite/Exception.cs.twig +++ b/templates/dotnet/src/Appwrite/Exception.cs.twig @@ -23,13 +23,15 @@ namespace {{spec.title | caseUcfirst}} { } } -} -public enum ErrorType { -{% for error in spec.definitions.appwriteException.error_types %} - /// - /// {{ error.description }} - /// - {{ error.type|title|replace({'_': ''}) }}, -{% endfor %} + public enum ErrorType { + {% for error in spec.definitions.appwriteException.error_types %} + /// + /// {{ error.description }} + /// + {{ error.type|title|replace({'_': ''}) }}, + {% endfor %} + } } + + diff --git a/templates/dotnet/tests/TestException.cs.twig b/templates/dotnet/tests/TestException.cs.twig new file mode 100644 index 000000000..0c182592a --- /dev/null +++ b/templates/dotnet/tests/TestException.cs.twig @@ -0,0 +1,14 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using {{spec.title | caseUcfirst}}; + +[TestClass] +public class TestException +{ + [TestMethod] + public void TestEnumValues() + { + {% for key, value in testData.enumData %} + Assert.AreEqual(ErrorType.{{ key }}, "{{ value }}"); + {% endfor %} +} +} diff --git a/templates/kotlin/tests/TestException.kt.twig b/templates/kotlin/tests/TestException.kt.twig new file mode 100644 index 000000000..ee9c14f25 --- /dev/null +++ b/templates/kotlin/tests/TestException.kt.twig @@ -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 %} + assertEquals(ErrorType.{{ key }}.value), "{{ value }}") + {% endfor %} +} +} \ No newline at end of file diff --git a/templates/node/lib/exception.js.twig b/templates/node/lib/exception.js.twig index dc51c82e9..abebcc9d6 100644 --- a/templates/node/lib/exception.js.twig +++ b/templates/node/lib/exception.js.twig @@ -9,13 +9,16 @@ class {{spec.title | caseUcfirst}}Exception extends Error { module.exports = {{spec.title | caseUcfirst}}Exception; -enum ErrorType { +const ErrorType = { {% for error in spec.definitions.appwriteException.error_types %} /** * {{ error.description }} */ - {{ error.type|title|replace({'_': ''}) }} = "{{ error.type }}", + {{ error.type|title|replace({'_': ''}) }}: "{{ error.type }}", {% endfor %} } -module.exports = ErrorType; \ No newline at end of file +module.exports = { + {{spec.title | caseUcfirst}}Exception, + ErrorType +}; \ No newline at end of file diff --git a/templates/node/tests/test_exception.js.twig b/templates/node/tests/test_exception.js.twig new file mode 100644 index 000000000..4396dc4e1 --- /dev/null +++ b/templates/node/tests/test_exception.js.twig @@ -0,0 +1,12 @@ +const assert = require('assert'); +const ErrorType = require('../lib/exception.js'); + +try { +{% for key, value in testData.enumData %} + assert.strictEqual(ErrorType.{{ key }}, '{{ value }}'); +{% endfor %} + + console.log('All tests passed!'); +} catch (error) { + console.error('Test failed:', error); +} diff --git a/templates/php/tests/TestException.php.twig b/templates/php/tests/TestException.php.twig new file mode 100644 index 000000000..92cc98603 --- /dev/null +++ b/templates/php/tests/TestException.php.twig @@ -0,0 +1,10 @@ +use PHPUnit\Framework\TestCase; + +class TestErrorEnum extends TestCase { + + public function testEnumValues() { + {% for key, value in testData.enumData %} + $this->assertEquals(ErrorType::{{ key }}, '{{ value }}'); + {% endfor %} +} +} diff --git a/templates/python/test/package/test_exception.py.twig b/templates/python/test/package/test_exception.py.twig deleted file mode 100644 index 0a235cefe..000000000 --- a/templates/python/test/package/test_exception.py.twig +++ /dev/null @@ -1,143 +0,0 @@ -from ...{{ spec.title | caseSnake}}.exception import ErrorType -import unittest - - -class TestErrorEnum(unittest.TestCase): - - def test_enum_values(self): - self.assertEqual(ErrorType.GeneralMock.value, 'general_mock') - self.assertEqual(ErrorType.GeneralArgumentInvalid.value, 'general_argument_invalid') - self.assertEqual(ErrorType.GeneralQueryLimitExceeded.value, 'general_query_limit_exceeded') - self.assertEqual(ErrorType.GeneralQueryInvalid.value, 'general_query_invalid') - self.assertEqual(ErrorType.GeneralCursorNotFound.value, 'general_cursor_not_found') - self.assertEqual(ErrorType.UserPasswordMismatch.value, 'user_password_mismatch') - self.assertEqual(ErrorType.PasswordRecentlyUsed.value, 'password_recently_used') - self.assertEqual(ErrorType.PasswordPersonalData.value, 'password_personal_data') - self.assertEqual(ErrorType.UserPhoneNotFound.value, 'user_phone_not_found') - self.assertEqual(ErrorType.UserMissingId.value, 'user_missing_id') - self.assertEqual(ErrorType.UserOauth2BadRequest.value, 'user_oauth2_bad_request') - self.assertEqual(ErrorType.StorageDeviceNotFound.value, 'storage_device_not_found') - self.assertEqual(ErrorType.StorageFileEmpty.value, 'storage_file_empty') - self.assertEqual(ErrorType.StorageFileTypeUnsupported.value, 'storage_file_type_unsupported') - self.assertEqual(ErrorType.StorageInvalidFileSize.value, 'storage_invalid_file_size') - self.assertEqual(ErrorType.StorageInvalidContentRange.value, 'storage_invalid_content_range') - self.assertEqual(ErrorType.StorageInvalidAppwriteId.value, 'storage_invalid_appwrite_id') - self.assertEqual(ErrorType.GeneralProviderFailure.value, 'general_provider_failure') - self.assertEqual(ErrorType.BuildNotReady.value, 'build_not_ready') - self.assertEqual(ErrorType.BuildInProgress.value, 'build_in_progress') - self.assertEqual(ErrorType.CollectionLimitExceeded.value, 'collection_limit_exceeded') - self.assertEqual(ErrorType.DocumentInvalidStructure.value, 'document_invalid_structure') - self.assertEqual(ErrorType.DocumentMissingData.value, 'document_missing_data') - self.assertEqual(ErrorType.DocumentMissingPayload.value, 'document_missing_payload') - self.assertEqual(ErrorType.AttributeUnknown.value, 'attribute_unknown') - self.assertEqual(ErrorType.AttributeNotAvailable.value, 'attribute_not_available') - self.assertEqual(ErrorType.AttributeFormatUnsupported.value, 'attribute_format_unsupported') - self.assertEqual(ErrorType.AttributeDefaultUnsupported.value, 'attribute_default_unsupported') - self.assertEqual(ErrorType.AttributeLimitExceeded.value, 'attribute_limit_exceeded') - self.assertEqual(ErrorType.AttributeValueInvalid.value, 'attribute_value_invalid') - self.assertEqual(ErrorType.AttributeTypeInvalid.value, 'attribute_type_invalid') - self.assertEqual(ErrorType.IndexLimitExceeded.value, 'index_limit_exceeded') - self.assertEqual(ErrorType.IndexInvalid.value, 'index_invalid') - self.assertEqual(ErrorType.ProjectUnknown.value, 'project_unknown') - self.assertEqual(ErrorType.ProjectInvalidSuccessUrl.value, 'project_invalid_success_url') - self.assertEqual(ErrorType.ProjectInvalidFailureUrl.value, 'project_invalid_failure_url') - self.assertEqual(ErrorType.ProjectReservedProject.value, 'project_reserved_project') - self.assertEqual(ErrorType.ProjectSmtpConfigInvalid.value, 'project_smtp_config_invalid') - self.assertEqual(ErrorType.GraphqlNoQuery.value, 'graphql_no_query') - self.assertEqual(ErrorType.GraphqlTooManyQueries.value, 'graphql_too_many_queries') - self.assertEqual(ErrorType.GeneralAccessForbidden.value, 'general_access_forbidden') - self.assertEqual(ErrorType.GeneralUnauthorizedScope.value, 'general_unauthorized_scope') - self.assertEqual(ErrorType.UserJwtInvalid.value, 'user_jwt_invalid') - self.assertEqual(ErrorType.UserBlocked.value, 'user_blocked') - self.assertEqual(ErrorType.UserInvalidToken.value, 'user_invalid_token') - self.assertEqual(ErrorType.UserEmailNotWhitelisted.value, 'user_email_not_whitelisted') - self.assertEqual(ErrorType.UserInvalidCode.value, 'user_invalid_code') - self.assertEqual(ErrorType.UserIpNotWhitelisted.value, 'user_ip_not_whitelisted') - self.assertEqual(ErrorType.UserInvalidCredentials.value, 'user_invalid_credentials') - self.assertEqual(ErrorType.UserAnonymousConsoleProhibited.value, 'user_anonymous_console_prohibited') - self.assertEqual(ErrorType.UserSessionAlreadyExists.value, 'user_session_already_exists') - self.assertEqual(ErrorType.UserUnauthorized.value, 'user_unauthorized') - self.assertEqual(ErrorType.UserOauth2Unauthorized.value, 'user_oauth2_unauthorized') - self.assertEqual(ErrorType.TeamInvalidSecret.value, 'team_invalid_secret') - self.assertEqual(ErrorType.TeamInviteMismatch.value, 'team_invite_mismatch') - self.assertEqual(ErrorType.ProjectKeyExpired.value, 'project_key_expired') - self.assertEqual(ErrorType.RuleVerificationFailed.value, 'rule_verification_failed') - self.assertEqual(ErrorType.ProjectTemplateDefaultDeletion.value, 'project_template_default_deletion') - self.assertEqual(ErrorType.GeneralUnknownOrigin.value, 'general_unknown_origin') - self.assertEqual(ErrorType.StorageInvalidFile.value, 'storage_invalid_file') - self.assertEqual(ErrorType.DocumentDeleteRestricted.value, 'document_delete_restricted') - self.assertEqual(ErrorType.GeneralRouteNotFound.value, 'general_route_not_found') - self.assertEqual(ErrorType.UserNotFound.value, 'user_not_found') - self.assertEqual(ErrorType.UserSessionNotFound.value, 'user_session_not_found') - self.assertEqual(ErrorType.UserIdentityNotFound.value, 'user_identity_not_found') - self.assertEqual(ErrorType.TeamNotFound.value, 'team_not_found') - self.assertEqual(ErrorType.TeamInviteNotFound.value, 'team_invite_not_found') - self.assertEqual(ErrorType.TeamMembershipMismatch.value, 'team_membership_mismatch') - self.assertEqual(ErrorType.MembershipNotFound.value, 'membership_not_found') - self.assertEqual(ErrorType.AvatarSetNotFound.value, 'avatar_set_not_found') - self.assertEqual(ErrorType.AvatarNotFound.value, 'avatar_not_found') - self.assertEqual(ErrorType.AvatarImageNotFound.value, 'avatar_image_not_found') - self.assertEqual(ErrorType.AvatarRemoteUrlFailed.value, 'avatar_remote_url_failed') - self.assertEqual(ErrorType.AvatarIconNotFound.value, 'avatar_icon_not_found') - self.assertEqual(ErrorType.StorageFileNotFound.value, 'storage_file_not_found') - self.assertEqual(ErrorType.StorageBucketNotFound.value, 'storage_bucket_not_found') - self.assertEqual(ErrorType.InstallationNotFound.value, 'installation_not_found') - self.assertEqual(ErrorType.ProviderRepositoryNotFound.value, 'provider_repository_not_found') - self.assertEqual(ErrorType.RepositoryNotFound.value, 'repository_not_found') - self.assertEqual(ErrorType.FunctionNotFound.value, 'function_not_found') - self.assertEqual(ErrorType.FunctionRuntimeUnsupported.value, 'function_runtime_unsupported') - self.assertEqual(ErrorType.BuildNotFound.value, 'build_not_found') - self.assertEqual(ErrorType.DeploymentNotFound.value, 'deployment_not_found') - self.assertEqual(ErrorType.ExecutionNotFound.value, 'execution_not_found') - self.assertEqual(ErrorType.DatabaseNotFound.value, 'database_not_found') - self.assertEqual(ErrorType.CollectionNotFound.value, 'collection_not_found') - self.assertEqual(ErrorType.DocumentNotFound.value, 'document_not_found') - self.assertEqual(ErrorType.AttributeNotFound.value, 'attribute_not_found') - self.assertEqual(ErrorType.IndexNotFound.value, 'index_not_found') - self.assertEqual(ErrorType.ProjectNotFound.value, 'project_not_found') - self.assertEqual(ErrorType.RouterHostNotFound.value, 'router_host_not_found') - self.assertEqual(ErrorType.RuleResourceNotFound.value, 'rule_resource_not_found') - self.assertEqual(ErrorType.RuleNotFound.value, 'rule_not_found') - self.assertEqual(ErrorType.WebhookNotFound.value, 'webhook_not_found') - self.assertEqual(ErrorType.KeyNotFound.value, 'key_not_found') - self.assertEqual(ErrorType.PlatformNotFound.value, 'platform_not_found') - self.assertEqual(ErrorType.VariableNotFound.value, 'variable_not_found') - self.assertEqual(ErrorType.MigrationNotFound.value, 'migration_not_found') - self.assertEqual(ErrorType.GeneralNotImplemented.value, 'general_not_implemented') - self.assertEqual(ErrorType.UserAlreadyExists.value, 'user_already_exists') - self.assertEqual(ErrorType.UserEmailAlreadyExists.value, 'user_email_already_exists') - self.assertEqual(ErrorType.UserPhoneAlreadyExists.value, 'user_phone_already_exists') - self.assertEqual(ErrorType.TeamInviteAlreadyExists.value, 'team_invite_already_exists') - self.assertEqual(ErrorType.TeamAlreadyExists.value, 'team_already_exists') - self.assertEqual(ErrorType.MembershipAlreadyConfirmed.value, 'membership_already_confirmed') - self.assertEqual(ErrorType.StorageFileAlreadyExists.value, 'storage_file_already_exists') - self.assertEqual(ErrorType.StorageBucketAlreadyExists.value, 'storage_bucket_already_exists') - self.assertEqual(ErrorType.ProviderContributionConflict.value, 'provider_contribution_conflict') - self.assertEqual(ErrorType.DatabaseAlreadyExists.value, 'database_already_exists') - self.assertEqual(ErrorType.CollectionAlreadyExists.value, 'collection_already_exists') - self.assertEqual(ErrorType.DocumentAlreadyExists.value, 'document_already_exists') - self.assertEqual(ErrorType.DocumentUpdateConflict.value, 'document_update_conflict') - self.assertEqual(ErrorType.AttributeAlreadyExists.value, 'attribute_already_exists') - self.assertEqual(ErrorType.IndexAlreadyExists.value, 'index_already_exists') - self.assertEqual(ErrorType.ProjectAlreadyExists.value, 'project_already_exists') - self.assertEqual(ErrorType.RuleAlreadyExists.value, 'rule_already_exists') - self.assertEqual(ErrorType.VariableAlreadyExists.value, 'variable_already_exists') - self.assertEqual(ErrorType.MigrationAlreadyExists.value, 'migration_already_exists') - self.assertEqual(ErrorType.MigrationInProgress.value, 'migration_in_progress') - self.assertEqual(ErrorType.UserPasswordResetRequired.value, 'user_password_reset_required') - self.assertEqual(ErrorType.ProjectProviderDisabled.value, 'project_provider_disabled') - self.assertEqual(ErrorType.StorageInvalidRange.value, 'storage_invalid_range') - self.assertEqual(ErrorType.UserOAuth2ProviderError.value, 'user_oauth2_provider_error') - self.assertEqual(ErrorType.GeneralRateLimitExceeded.value, 'general_rate_limit_exceeded') - self.assertEqual(ErrorType.GeneralUnknown.value, 'general_unknown') - self.assertEqual(ErrorType.GeneralServerError.value, 'general_server_error') - self.assertEqual(ErrorType.GeneralProtocolUnsupported.value, 'general_protocol_unsupported') - self.assertEqual(ErrorType.GeneralCodesDisabled.value, 'general_codes_disabled') - self.assertEqual(ErrorType.RouterDomainNotConfigured.value, 'router_domain_not_configured') - self.assertEqual(ErrorType.GeneralUsageDisabled.value, 'general_usage_disabled') - self.assertEqual(ErrorType.UserCountExceeded.value, 'user_count_exceeded') - self.assertEqual(ErrorType.UserAuthMethodUnsupported.value, 'user_auth_method_unsupported') - self.assertEqual(ErrorType.ProjectProviderUnsupported.value, 'project_provider_unsupported') - self.assertEqual(ErrorType.GeneralServiceDisabled.value, 'general_service_disabled') - self.assertEqual(ErrorType.GeneralSMTPDisabled.value, 'general_smtp_disabled') - self.assertEqual(ErrorType.GeneralPhoneDisabled.value, 'general_phone_disabled') diff --git a/templates/ruby/test/lib/appwrite/test_exception.rb.twig b/templates/ruby/test/lib/appwrite/test_exception.rb.twig deleted file mode 100644 index 028027930..000000000 --- a/templates/ruby/test/lib/appwrite/test_exception.rb.twig +++ /dev/null @@ -1,144 +0,0 @@ -require 'test/unit' -require_relative '../../../lib/{{ spec.title | caseSnake }}/exception' # Ensure this path is correct - -class ErrorTypeTest < Test::Unit::TestCase - - def test_error_type_values - assert_equal('general_mock', ErrorType::GeneralMock) - assert_equal('general_argument_invalid', ErrorType::GeneralArgumentInvalid) - assert_equal('general_query_limit_exceeded', ErrorType::GeneralQueryLimitExceeded) - assert_equal('general_query_invalid', ErrorType::GeneralQueryInvalid) - assert_equal('general_cursor_not_found', ErrorType::GeneralCursorNotFound) - assert_equal('user_password_mismatch', ErrorType::UserPasswordMismatch) - assert_equal('password_recently_used', ErrorType::PasswordRecentlyUsed) - assert_equal('password_personal_data', ErrorType::PasswordPersonalData) - assert_equal('user_phone_not_found', ErrorType::UserPhoneNotFound) - assert_equal('user_missing_id', ErrorType::UserMissingId) - assert_equal('user_oauth2_bad_request', ErrorType::UserOauth2BadRequest) - assert_equal('storage_device_not_found', ErrorType::StorageDeviceNotFound) - assert_equal('storage_file_empty', ErrorType::StorageFileEmpty) - assert_equal('storage_file_type_unsupported', ErrorType::StorageFileTypeUnsupported) - assert_equal('storage_invalid_file_size', ErrorType::StorageInvalidFileSize) - assert_equal('storage_invalid_content_range', ErrorType::StorageInvalidContentRange) - assert_equal('storage_invalid_appwrite_id', ErrorType::StorageInvalidAppwriteId) - assert_equal('general_provider_failure', ErrorType::GeneralProviderFailure) - assert_equal('build_not_ready', ErrorType::BuildNotReady) - assert_equal('build_in_progress', ErrorType::BuildInProgress) - assert_equal('collection_limit_exceeded', ErrorType::CollectionLimitExceeded) - assert_equal('document_invalid_structure', ErrorType::DocumentInvalidStructure) - assert_equal('document_missing_data', ErrorType::DocumentMissingData) - assert_equal('document_missing_payload', ErrorType::DocumentMissingPayload) - assert_equal('attribute_unknown', ErrorType::AttributeUnknown) - assert_equal('attribute_not_available', ErrorType::AttributeNotAvailable) - assert_equal('attribute_format_unsupported', ErrorType::AttributeFormatUnsupported) - assert_equal('attribute_default_unsupported', ErrorType::AttributeDefaultUnsupported) - assert_equal('attribute_limit_exceeded', ErrorType::AttributeLimitExceeded) - assert_equal('attribute_value_invalid', ErrorType::AttributeValueInvalid) - assert_equal('attribute_type_invalid', ErrorType::AttributeTypeInvalid) - assert_equal('index_limit_exceeded', ErrorType::IndexLimitExceeded) - assert_equal('index_invalid', ErrorType::IndexInvalid) - assert_equal('project_unknown', ErrorType::ProjectUnknown) - assert_equal('project_invalid_success_url', ErrorType::ProjectInvalidSuccessUrl) - assert_equal('project_invalid_failure_url', ErrorType::ProjectInvalidFailureUrl) - assert_equal('project_reserved_project', ErrorType::ProjectReservedProject) - assert_equal('project_smtp_config_invalid', ErrorType::ProjectSmtpConfigInvalid) - assert_equal('graphql_no_query', ErrorType::GraphqlNoQuery) - assert_equal('graphql_too_many_queries', ErrorType::GraphqlTooManyQueries) - assert_equal('general_access_forbidden', ErrorType::GeneralAccessForbidden) - assert_equal('general_unauthorized_scope', ErrorType::GeneralUnauthorizedScope) - assert_equal('user_jwt_invalid', ErrorType::UserJwtInvalid) - assert_equal('user_blocked', ErrorType::UserBlocked) - assert_equal('user_invalid_token', ErrorType::UserInvalidToken) - assert_equal('user_email_not_whitelisted', ErrorType::UserEmailNotWhitelisted) - assert_equal('user_invalid_code', ErrorType::UserInvalidCode) - assert_equal('user_ip_not_whitelisted', ErrorType::UserIpNotWhitelisted) - assert_equal('user_invalid_credentials', ErrorType::UserInvalidCredentials) - assert_equal('user_anonymous_console_prohibited', ErrorType::UserAnonymousConsoleProhibited) - assert_equal('user_session_already_exists', ErrorType::UserSessionAlreadyExists) - assert_equal('user_unauthorized', ErrorType::UserUnauthorized) - assert_equal('user_oauth2_unauthorized', ErrorType::UserOauth2Unauthorized) - assert_equal('team_invalid_secret', ErrorType::TeamInvalidSecret) - assert_equal('team_invite_mismatch', ErrorType::TeamInviteMismatch) - assert_equal('project_key_expired', ErrorType::ProjectKeyExpired) - assert_equal('rule_verification_failed', ErrorType::RuleVerificationFailed) - assert_equal('project_template_default_deletion', ErrorType::ProjectTemplateDefaultDeletion) - assert_equal('general_unknown_origin', ErrorType::GeneralUnknownOrigin) - assert_equal('storage_invalid_file', ErrorType::StorageInvalidFile) - assert_equal('document_delete_restricted', ErrorType::DocumentDeleteRestricted) - assert_equal('general_route_not_found', ErrorType::GeneralRouteNotFound) - assert_equal('user_not_found', ErrorType::UserNotFound) - assert_equal('user_session_not_found', ErrorType::UserSessionNotFound) - assert_equal('user_identity_not_found', ErrorType::UserIdentityNotFound) - assert_equal('team_not_found', ErrorType::TeamNotFound) - assert_equal('team_invite_not_found', ErrorType::TeamInviteNotFound) - assert_equal('team_membership_mismatch', ErrorType::TeamMembershipMismatch) - assert_equal('membership_not_found', ErrorType::MembershipNotFound) - assert_equal('avatar_set_not_found', ErrorType::AvatarSetNotFound) - assert_equal('avatar_not_found', ErrorType::AvatarNotFound) - assert_equal('avatar_image_not_found', ErrorType::AvatarImageNotFound) - assert_equal('avatar_remote_url_failed', ErrorType::AvatarRemoteUrlFailed) - assert_equal('avatar_icon_not_found', ErrorType::AvatarIconNotFound) - assert_equal('storage_file_not_found', ErrorType::StorageFileNotFound) - assert_equal('storage_bucket_not_found', ErrorType::StorageBucketNotFound) - assert_equal('installation_not_found', ErrorType::InstallationNotFound) - assert_equal('provider_repository_not_found', ErrorType::ProviderRepositoryNotFound) - assert_equal('repository_not_found', ErrorType::RepositoryNotFound) - assert_equal('function_not_found', ErrorType::FunctionNotFound) - assert_equal('function_runtime_unsupported', ErrorType::FunctionRuntimeUnsupported) - assert_equal('build_not_found', ErrorType::BuildNotFound) - assert_equal('deployment_not_found', ErrorType::DeploymentNotFound) - assert_equal('execution_not_found', ErrorType::ExecutionNotFound) - assert_equal('database_not_found', ErrorType::DatabaseNotFound) - assert_equal('collection_not_found', ErrorType::CollectionNotFound) - assert_equal('document_not_found', ErrorType::DocumentNotFound) - assert_equal('attribute_not_found', ErrorType::AttributeNotFound) - assert_equal('index_not_found', ErrorType::IndexNotFound) - assert_equal('project_not_found', ErrorType::ProjectNotFound) - assert_equal('router_host_not_found', ErrorType::RouterHostNotFound) - assert_equal('rule_resource_not_found', ErrorType::RuleResourceNotFound) - assert_equal('rule_not_found', ErrorType::RuleNotFound) - assert_equal('webhook_not_found', ErrorType::WebhookNotFound) - assert_equal('key_not_found', ErrorType::KeyNotFound) - assert_equal('platform_not_found', ErrorType::PlatformNotFound) - assert_equal('variable_not_found', ErrorType::VariableNotFound) - assert_equal('migration_not_found', ErrorType::MigrationNotFound) - assert_equal('general_not_implemented', ErrorType::GeneralNotImplemented) - assert_equal('user_already_exists', ErrorType::UserAlreadyExists) - assert_equal('user_email_already_exists', ErrorType::UserEmailAlreadyExists) - assert_equal('user_phone_already_exists', ErrorType::UserPhoneAlreadyExists) - assert_equal('team_invite_already_exists', ErrorType::TeamInviteAlreadyExists) - assert_equal('team_already_exists', ErrorType::TeamAlreadyExists) - assert_equal('membership_already_confirmed', ErrorType::MembershipAlreadyConfirmed) - assert_equal('storage_file_already_exists', ErrorType::StorageFileAlreadyExists) - assert_equal('storage_bucket_already_exists', ErrorType::StorageBucketAlreadyExists) - assert_equal('provider_contribution_conflict', ErrorType::ProviderContributionConflict) - assert_equal('database_already_exists', ErrorType::DatabaseAlreadyExists) - assert_equal('collection_already_exists', ErrorType::CollectionAlreadyExists) - assert_equal('document_already_exists', ErrorType::DocumentAlreadyExists) - assert_equal('document_update_conflict', ErrorType::DocumentUpdateConflict) - assert_equal('attribute_already_exists', ErrorType::AttributeAlreadyExists) - assert_equal('index_already_exists', ErrorType::IndexAlreadyExists) - assert_equal('project_already_exists', ErrorType::ProjectAlreadyExists) - assert_equal('rule_already_exists', ErrorType::RuleAlreadyExists) - assert_equal('variable_already_exists', ErrorType::VariableAlreadyExists) - assert_equal('migration_already_exists', ErrorType::MigrationAlreadyExists) - assert_equal('migration_in_progress', ErrorType::MigrationInProgress) - assert_equal('user_password_reset_required', ErrorType::UserPasswordResetRequired) - assert_equal('project_provider_disabled', ErrorType::ProjectProviderDisabled) - assert_equal('storage_invalid_range', ErrorType::StorageInvalidRange) - assert_equal('user_oauth2_provider_error', ErrorType::UserOAuth2ProviderError) - assert_equal('general_rate_limit_exceeded', ErrorType::GeneralRateLimitExceeded) - assert_equal('general_unknown', ErrorType::GeneralUnknown) - assert_equal('general_server_error', ErrorType::GeneralServerError) - assert_equal('general_protocol_unsupported', ErrorType::GeneralProtocolUnsupported) - assert_equal('general_codes_disabled', ErrorType::GeneralCodesDisabled) - assert_equal('router_domain_not_configured', ErrorType::RouterDomainNotConfigured) - assert_equal('general_usage_disabled', ErrorType::GeneralUsageDisabled) - assert_equal('user_count_exceeded', ErrorType::UserCountExceeded) - assert_equal('user_auth_method_unsupported', ErrorType::UserAuthMethodUnsupported) - assert_equal('project_provider_unsupported', ErrorType::ProjectProviderUnsupported) - assert_equal('general_service_disabled', ErrorType::GeneralServiceDisabled) - assert_equal('general_smtp_disabled', ErrorType::GeneralSMTPDisabled) - assert_equal('general_phone_disabled', ErrorType::GeneralPhoneDisabled) - end -end diff --git a/templates/ruby/tests/lib/appwrite/test_exception.rb.twig b/templates/ruby/tests/lib/appwrite/test_exception.rb.twig new file mode 100644 index 000000000..d1181a7b9 --- /dev/null +++ b/templates/ruby/tests/lib/appwrite/test_exception.rb.twig @@ -0,0 +1,11 @@ +require 'test/unit' +require_relative '../../../lib/{{ spec.title | caseSnake }}/exception' # Ensure this path is correct + +class ErrorTypeTest < Test::Unit::TestCase + + def test_error_type_values + {% for key, value in testData.enumData %} + assert_equal('{{ value }}', ErrorType::{{ key }}) + {% endfor %} + end +end diff --git a/templates/swift/Sources/Exception.swift.twig b/templates/swift/Sources/Exception.swift.twig new file mode 100644 index 000000000..13e7880ec --- /dev/null +++ b/templates/swift/Sources/Exception.swift.twig @@ -0,0 +1,6 @@ +enum ErrorType: String { +{% for error in spec.definitions.appwriteException.error_types %} + /// {{ error.description }} + case {{ error.type|camelCase }} = "{{ error.type }}" +{% endfor %} +} diff --git a/templates/swift/Tests/TestException.swift.twig b/templates/swift/Tests/TestException.swift.twig new file mode 100644 index 000000000..cfe9aa45b --- /dev/null +++ b/templates/swift/Tests/TestException.swift.twig @@ -0,0 +1,10 @@ +import XCTest +@testable import {{spec.title | caseUcfirst}} + +class ErrorTypeTests: XCTestCase { + func testErrorTypeValues() { + {% for key, value in testData.enumData %} + XCTAssertEqual(ErrorType.{{ key }}.rawValue, "{{ value }}") + {% endfor %} +} +} \ No newline at end of file diff --git a/templates/web/src/exception.ts.twig b/templates/web/src/exception.ts.twig new file mode 100644 index 000000000..f8f285a85 --- /dev/null +++ b/templates/web/src/exception.ts.twig @@ -0,0 +1,8 @@ +export enum ErrorType { + {% for error in spec.definitions.appwriteException.error_types %} + /** + * {{ error.description }} + */ + {{ error.type|title|replace({'_': ''}) }} = "{{ error.type }}", +{% endfor %} +} \ No newline at end of file diff --git a/templates/web/tests/test_exception.ts.twig b/templates/web/tests/test_exception.ts.twig new file mode 100644 index 000000000..bf5b58f55 --- /dev/null +++ b/templates/web/tests/test_exception.ts.twig @@ -0,0 +1,12 @@ +import * as assert from "assert"; +import { ErrorType } from "../src/exception.ts" + +try { + {% for key, value in testData.enumData %} + assert.strictEqual(ErrorType.{{ key }}, '{{ value }}'); + {% endfor %} + + console.log('All tests passed!'); +} catch (error) { + console.error('Test failed:', error); +} \ No newline at end of file From 85fa20db381218ac23934be176d42874df225c9c Mon Sep 17 00:00:00 2001 From: Jay Date: Wed, 25 Oct 2023 16:37:15 +0530 Subject: [PATCH 05/21] feat: add tests for ErrorEnums - new tests for Dart and Flutter Signed-off-by: Jay --- src/SDK/Language/Flutter.php | 5 +++++ templates/dart/test/src/exception_test.dart.twig | 8 ++++++++ templates/flutter/lib/src/exception.dart.twig | 6 ++++++ .../flutter/test/src/exception_test.dart.twig | 16 ++++++++++++++++ 4 files changed, 35 insertions(+) create mode 100644 templates/flutter/lib/src/exception.dart.twig create mode 100644 templates/flutter/test/src/exception_test.dart.twig diff --git a/src/SDK/Language/Flutter.php b/src/SDK/Language/Flutter.php index 806e19054..f04de20be 100644 --- a/src/SDK/Language/Flutter.php +++ b/src/SDK/Language/Flutter.php @@ -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', + ], ]; } } diff --git a/templates/dart/test/src/exception_test.dart.twig b/templates/dart/test/src/exception_test.dart.twig index efaf713d5..0585b53a0 100644 --- a/templates/dart/test/src/exception_test.dart.twig +++ b/templates/dart/test/src/exception_test.dart.twig @@ -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 %} + }); } diff --git a/templates/flutter/lib/src/exception.dart.twig b/templates/flutter/lib/src/exception.dart.twig new file mode 100644 index 000000000..fdccf3e8c --- /dev/null +++ b/templates/flutter/lib/src/exception.dart.twig @@ -0,0 +1,6 @@ +enum ErrorType { +{% for error in spec.definitions.appwriteException.error_types %} + /// {{ error.description }} + {{ error.type|title|replace({'_': ''}) }}, +{% endfor %} +} \ No newline at end of file diff --git a/templates/flutter/test/src/exception_test.dart.twig b/templates/flutter/test/src/exception_test.dart.twig new file mode 100644 index 000000000..8b709eca0 --- /dev/null +++ b/templates/flutter/test/src/exception_test.dart.twig @@ -0,0 +1,16 @@ +import 'package:{{language.params.packageName}}/src/exception.dart'; +{% if 'dart' in language.params.packageName %} +import 'package:test/test.dart'; +{% else %} +import 'package:flutter_test/flutter_test.dart'; +{% endif %} + +void main() { + 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 %} + }); +} From 3f3afb0558d27394c65e5775daaeb2f94371ae07 Mon Sep 17 00:00:00 2001 From: Jay Date: Fri, 3 Nov 2023 00:41:20 +0530 Subject: [PATCH 06/21] update: update snake_case to camelCase Signed-off-by: Jay --- src/Spec/Swagger2.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Spec/Swagger2.php b/src/Spec/Swagger2.php index c37a152ee..77f84d902 100644 --- a/src/Spec/Swagger2.php +++ b/src/Spec/Swagger2.php @@ -312,7 +312,7 @@ public function getDefinitions() "name" => $key, "properties" => $schema['properties'] ?? [], "description" => $schema['description'] ?? [], - "error_types" => $schema['x-appwrite']['types'] ?? [], + "error_types" => $schema['x-appwrite']['types'] ?? null, "required" => $schema['required'] ?? [], "additionalProperties" => $schema['additionalProperties'] ?? [] ]; @@ -338,9 +338,9 @@ public function getDefinitions() } } } - if (isset($sch['error_types'])) { + if (isset($sch['errorTypes'])) { $types = []; - foreach ($sch['error_types'] as $type) { + foreach ($sch['errorTypes'] as $type) { $types[] = [ 'code' => $type['code'], @@ -348,7 +348,7 @@ public function getDefinitions() 'description' => $type['description'] ]; } - $sch['error_types'] = $types; + $sch['errorTypes'] = $types; } $list[$key] = $sch; } From 33fe9cf3f3e2a8ec2bf91af43364cb0797b6c3f1 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Sat, 4 Nov 2023 10:35:02 +0530 Subject: [PATCH 07/21] update: update test generator's data source. Signed-off-by: Jay --- src/SDK/SDK.php | 141 +----------------- src/Spec/Swagger2.php | 4 +- .../io/appwrite/exceptions/Exception.kt.twig | 4 +- templates/android/tests/TestException.kt.twig | 4 +- templates/dart/lib/src/exception.dart.twig | 4 +- .../dart/test/src/exception_test.dart.twig | 2 +- templates/deno/src/exception.ts.twig | 4 +- templates/deno/tests/test_exception.ts.twig | 4 +- .../dotnet/src/Appwrite/Exception.cs.twig | 4 +- templates/dotnet/tests/TestException.cs.twig | 4 +- templates/flutter/lib/src/exception.dart.twig | 4 +- .../flutter/test/src/exception_test.dart.twig | 4 +- .../io/appwrite/exceptions/Exception.kt.twig | 4 +- templates/kotlin/tests/TestException.kt.twig | 4 +- templates/node/lib/exception.js.twig | 4 +- templates/node/tests/test_exception.js.twig | 4 +- templates/php/src/Exception.php.twig | 4 +- templates/php/tests/TestException.php.twig | 4 +- templates/python/package/exception.py.twig | 4 +- .../ruby/lib/container/exception.rb.twig | 4 +- .../tests/lib/appwrite/test_exception.rb.twig | 4 +- templates/swift/Sources/Exception.swift.twig | 4 +- .../swift/Tests/TestException.swift.twig | 4 +- templates/web/src/exception.ts.twig | 4 +- templates/web/tests/test_exception.ts.twig | 4 +- 25 files changed, 48 insertions(+), 187 deletions(-) diff --git a/src/SDK/SDK.php b/src/SDK/SDK.php index 45a9128d2..b123520fe 100644 --- a/src/SDK/SDK.php +++ b/src/SDK/SDK.php @@ -69,144 +69,6 @@ class SDK 'examples' => '', 'test' => 'false' ]; - private array $errorTypes = [ - '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. @@ -693,8 +555,7 @@ public function generate(string $target): void 'name' => $this->language->getName(), 'params' => $this->language->getParams(), ], - 'sdk' => $this->getParams(), - 'testData' => ['enumData' => $this->errorTypes] + 'sdk' => $this->getParams() ]; foreach ($this->language->getFiles() as $file) { diff --git a/src/Spec/Swagger2.php b/src/Spec/Swagger2.php index 77f84d902..8d6632574 100644 --- a/src/Spec/Swagger2.php +++ b/src/Spec/Swagger2.php @@ -312,7 +312,7 @@ public function getDefinitions() "name" => $key, "properties" => $schema['properties'] ?? [], "description" => $schema['description'] ?? [], - "error_types" => $schema['x-appwrite']['types'] ?? null, + "errorTypes" => $schema['x-appwrite']['types'] ?? null, "required" => $schema['required'] ?? [], "additionalProperties" => $schema['additionalProperties'] ?? [] ]; @@ -345,7 +345,7 @@ public function getDefinitions() $types[] = [ 'code' => $type['code'], 'type' => $type['type'], - 'description' => $type['description'] + 'message' => $type['message'] ]; } $sch['errorTypes'] = $types; diff --git a/templates/android/library/src/main/java/io/appwrite/exceptions/Exception.kt.twig b/templates/android/library/src/main/java/io/appwrite/exceptions/Exception.kt.twig index 8ad029eac..84b6c4782 100644 --- a/templates/android/library/src/main/java/io/appwrite/exceptions/Exception.kt.twig +++ b/templates/android/library/src/main/java/io/appwrite/exceptions/Exception.kt.twig @@ -10,9 +10,9 @@ class {{spec.title | caseUcfirst}} Exception( ) : Exception(message) enum class ErrorType(val value: String) { -{% for error in spec.definitions.appwriteException.error_types %} +{% for error in spec.definitions.appwriteException.errorTypes %} /** - * {{ error.description }} + * {{ error.message }} */ {{ error.type|title|replace({'_': ''}) }}("{{ error.type }}"), {% endfor %} diff --git a/templates/android/tests/TestException.kt.twig b/templates/android/tests/TestException.kt.twig index ee9c14f25..db0078012 100644 --- a/templates/android/tests/TestException.kt.twig +++ b/templates/android/tests/TestException.kt.twig @@ -8,8 +8,8 @@ class TestException { @Test fun testEnumValues() { - {% for key, value in testData.enumData %} - assertEquals(ErrorType.{{ key }}.value), "{{ value }}") + {% for error in spec.definitions.appwriteException.errorTypes %} + assertEquals(ErrorType.{{ error.type|title|replace({'_': ''}) }}.value), "{{ error.type }}") {% endfor %} } } \ No newline at end of file diff --git a/templates/dart/lib/src/exception.dart.twig b/templates/dart/lib/src/exception.dart.twig index e0be90c22..068316a62 100644 --- a/templates/dart/lib/src/exception.dart.twig +++ b/templates/dart/lib/src/exception.dart.twig @@ -23,8 +23,8 @@ class {{spec.title | caseUcfirst}}Exception implements Exception { } enum ErrorType { -{% for error in spec.definitions.appwriteException.error_types %} - /// {{ error.description }} +{% for error in spec.definitions.appwriteException.errorTypes %} + /// {{ error.message }} {{ error.type|title|replace({'_': ''}) }}, {% endfor %} } diff --git a/templates/dart/test/src/exception_test.dart.twig b/templates/dart/test/src/exception_test.dart.twig index 0585b53a0..714e86a13 100644 --- a/templates/dart/test/src/exception_test.dart.twig +++ b/templates/dart/test/src/exception_test.dart.twig @@ -22,7 +22,7 @@ void main() { group('ErrorType Enum Test', () { {% for key, value in testData.enumData %} test('ErrorType.{{ key }} should have correct value', () { - expect(ErrorType.{{ key }}.toString(), equals('ErrorType.{{ value }}')); + expect(ErrorType.{{ error.type|title|replace({'_': ''}) }}.toString(), equals('ErrorType.{{ error.type }}')); }); {% endfor %} }); diff --git a/templates/deno/src/exception.ts.twig b/templates/deno/src/exception.ts.twig index 4a459f93a..cbac0c6b0 100644 --- a/templates/deno/src/exception.ts.twig +++ b/templates/deno/src/exception.ts.twig @@ -17,9 +17,9 @@ export class {{ spec.title | caseUcfirst}}Exception { } export enum ErrorType { -{% for error in spec.definitions.appwriteException.error_types %} +{% for error in spec.definitions.appwriteException.errorTypes %} /** - * {{ error.description }} + * {{ error.message }} */ {{ error.type|title|replace({'_': ''}) }} = "{{ error.type }}", {% endfor %} diff --git a/templates/deno/tests/test_exception.ts.twig b/templates/deno/tests/test_exception.ts.twig index 1f6892d14..4c0528020 100644 --- a/templates/deno/tests/test_exception.ts.twig +++ b/templates/deno/tests/test_exception.ts.twig @@ -3,7 +3,7 @@ import {assertEquals} from "https://deno.land/std/testing/asserts.ts"; import {ErrorType} from "../src/exception.ts"; Deno.test("ErrorType values should match expected strings", () => { - {% for key, value in testData.enumData %} - assertEquals(ErrorType.{{ key }}, '{{ value }}'); + {% for error in spec.definitions.appwriteException.errorTypes %} + assertEquals(ErrorType.{{ error.type|title|replace({'_': ''}) }}, '{{ error.type }}'); {% endfor %} }) \ No newline at end of file diff --git a/templates/dotnet/src/Appwrite/Exception.cs.twig b/templates/dotnet/src/Appwrite/Exception.cs.twig index eb16117ab..2b8c841a4 100644 --- a/templates/dotnet/src/Appwrite/Exception.cs.twig +++ b/templates/dotnet/src/Appwrite/Exception.cs.twig @@ -25,9 +25,9 @@ namespace {{spec.title | caseUcfirst}} } public enum ErrorType { - {% for error in spec.definitions.appwriteException.error_types %} + {% for error in spec.definitions.appwriteException.errorTypes %} /// - /// {{ error.description }} + /// {{ error.message }} /// {{ error.type|title|replace({'_': ''}) }}, {% endfor %} diff --git a/templates/dotnet/tests/TestException.cs.twig b/templates/dotnet/tests/TestException.cs.twig index 0c182592a..e0b0dd774 100644 --- a/templates/dotnet/tests/TestException.cs.twig +++ b/templates/dotnet/tests/TestException.cs.twig @@ -7,8 +7,8 @@ public class TestException [TestMethod] public void TestEnumValues() { - {% for key, value in testData.enumData %} - Assert.AreEqual(ErrorType.{{ key }}, "{{ value }}"); + {% for error in spec.definitions.appwriteException.errorTypes %} + Assert.AreEqual(ErrorType.{{ error.type|title|replace({'_': ''}) }}, "{{ error.type }}"); {% endfor %} } } diff --git a/templates/flutter/lib/src/exception.dart.twig b/templates/flutter/lib/src/exception.dart.twig index fdccf3e8c..b244e75bc 100644 --- a/templates/flutter/lib/src/exception.dart.twig +++ b/templates/flutter/lib/src/exception.dart.twig @@ -1,6 +1,6 @@ enum ErrorType { -{% for error in spec.definitions.appwriteException.error_types %} - /// {{ error.description }} +{% for error in spec.definitions.appwriteException.errorTypes %} + /// {{ error.message }} {{ error.type|title|replace({'_': ''}) }}, {% endfor %} } \ No newline at end of file diff --git a/templates/flutter/test/src/exception_test.dart.twig b/templates/flutter/test/src/exception_test.dart.twig index 8b709eca0..5315fd652 100644 --- a/templates/flutter/test/src/exception_test.dart.twig +++ b/templates/flutter/test/src/exception_test.dart.twig @@ -7,9 +7,9 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('ErrorType Enum Test', () { - {% for key, value in testData.enumData %} + {% for error in spec.definitions.appwriteException.errorTypes %} test('ErrorType.{{ key }} should have correct value', () { - expect(ErrorType.{{ key }}.toString(), equals('ErrorType.{{ value }}')); + expect(ErrorType.{{ error.type|title|replace({'_': ''}) }}.toString(), equals('ErrorType.{{ error.type }}')); }); {% endfor %} }); diff --git a/templates/kotlin/src/main/kotlin/io/appwrite/exceptions/Exception.kt.twig b/templates/kotlin/src/main/kotlin/io/appwrite/exceptions/Exception.kt.twig index 948f86bbe..43177ad6e 100644 --- a/templates/kotlin/src/main/kotlin/io/appwrite/exceptions/Exception.kt.twig +++ b/templates/kotlin/src/main/kotlin/io/appwrite/exceptions/Exception.kt.twig @@ -10,9 +10,9 @@ class {{spec.title | caseUcfirst}}Exception( ) : Exception(message) enum class ErrorType(val value: String) { -{% for error in spec.definitions.appwriteException.error_types %} +{% for error in spec.definitions.appwriteException.errorTypes %} /** - * {{ error.description }} + * {{ error.message }} */ {{ error.type|title|replace({'_': ''}) }}("{{ error.type }}"), {% endfor %} diff --git a/templates/kotlin/tests/TestException.kt.twig b/templates/kotlin/tests/TestException.kt.twig index ee9c14f25..db0078012 100644 --- a/templates/kotlin/tests/TestException.kt.twig +++ b/templates/kotlin/tests/TestException.kt.twig @@ -8,8 +8,8 @@ class TestException { @Test fun testEnumValues() { - {% for key, value in testData.enumData %} - assertEquals(ErrorType.{{ key }}.value), "{{ value }}") + {% for error in spec.definitions.appwriteException.errorTypes %} + assertEquals(ErrorType.{{ error.type|title|replace({'_': ''}) }}.value), "{{ error.type }}") {% endfor %} } } \ No newline at end of file diff --git a/templates/node/lib/exception.js.twig b/templates/node/lib/exception.js.twig index abebcc9d6..8783b1403 100644 --- a/templates/node/lib/exception.js.twig +++ b/templates/node/lib/exception.js.twig @@ -10,9 +10,9 @@ class {{spec.title | caseUcfirst}}Exception extends Error { module.exports = {{spec.title | caseUcfirst}}Exception; const ErrorType = { -{% for error in spec.definitions.appwriteException.error_types %} +{% for error in spec.definitions.appwriteException.errorTypes %} /** - * {{ error.description }} + * {{ error.message }} */ {{ error.type|title|replace({'_': ''}) }}: "{{ error.type }}", {% endfor %} diff --git a/templates/node/tests/test_exception.js.twig b/templates/node/tests/test_exception.js.twig index 4396dc4e1..4fe5c9518 100644 --- a/templates/node/tests/test_exception.js.twig +++ b/templates/node/tests/test_exception.js.twig @@ -2,8 +2,8 @@ const assert = require('assert'); const ErrorType = require('../lib/exception.js'); try { -{% for key, value in testData.enumData %} - assert.strictEqual(ErrorType.{{ key }}, '{{ value }}'); +{% for error in spec.definitions.appwriteException.errorTypes %} + assert.strictEqual(ErrorType.{{ error.type|title|replace({'_': ''}) }}, '{{ error.type }}'); {% endfor %} console.log('All tests passed!'); diff --git a/templates/php/src/Exception.php.twig b/templates/php/src/Exception.php.twig index d02f19e6e..3de60be97 100644 --- a/templates/php/src/Exception.php.twig +++ b/templates/php/src/Exception.php.twig @@ -46,9 +46,9 @@ class {{spec.title | caseUcfirst}}Exception extends Exception { } class ErrorType { -{% for error in spec.definitions.appwriteException.error_types %} +{% for error in spec.definitions.appwriteException.errorTypes %} /** - * {{ error.description }} + * {{ error.message }} */ const {{ error.type|title|replace({'_': ''}) }} = '{{ error.type }}'; {% endfor %} diff --git a/templates/php/tests/TestException.php.twig b/templates/php/tests/TestException.php.twig index 92cc98603..a5e9fd584 100644 --- a/templates/php/tests/TestException.php.twig +++ b/templates/php/tests/TestException.php.twig @@ -3,8 +3,8 @@ use PHPUnit\Framework\TestCase; class TestErrorEnum extends TestCase { public function testEnumValues() { - {% for key, value in testData.enumData %} - $this->assertEquals(ErrorType::{{ key }}, '{{ value }}'); + {% for error in spec.definitions.appwriteException.errorTypes %} + $this->assertEquals(ErrorType::{{ error.type|title|replace({'_': ''}) }}, '{{ error.type }}'); {% endfor %} } } diff --git a/templates/python/package/exception.py.twig b/templates/python/package/exception.py.twig index 707ff04f0..d360784d4 100644 --- a/templates/python/package/exception.py.twig +++ b/templates/python/package/exception.py.twig @@ -11,9 +11,9 @@ class {{spec.title | caseUcfirst}}Exception(Exception): class ErrorType(Enum): -{% for error in spec.definitions.appwriteException.error_types %} +{% for error in spec.definitions.appwriteException.errorTypes %} """ - {{ error.description }} + {{ error.message }} """ {{ error.type|title|replace({'_': ''}) }} = '{{ error.type }}' {% endfor %} diff --git a/templates/ruby/lib/container/exception.rb.twig b/templates/ruby/lib/container/exception.rb.twig index bcfc20710..53ec87cbc 100644 --- a/templates/ruby/lib/container/exception.rb.twig +++ b/templates/ruby/lib/container/exception.rb.twig @@ -14,8 +14,8 @@ module {{spec.title | caseUcfirst}} end class ErrorType -{% for error in spec.definitions.appwriteException.error_types %} - # {{ error.description }} +{% for error in spec.definitions.appwriteException.errorTypes %} + # {{ error.message }} {{ error.type|title|replace({'_': ''}) }} = '{{ error.type }}' {% endfor %} end diff --git a/templates/ruby/tests/lib/appwrite/test_exception.rb.twig b/templates/ruby/tests/lib/appwrite/test_exception.rb.twig index d1181a7b9..176f0f7da 100644 --- a/templates/ruby/tests/lib/appwrite/test_exception.rb.twig +++ b/templates/ruby/tests/lib/appwrite/test_exception.rb.twig @@ -4,8 +4,8 @@ require_relative '../../../lib/{{ spec.title | caseSnake }}/exception' # Ensure class ErrorTypeTest < Test::Unit::TestCase def test_error_type_values - {% for key, value in testData.enumData %} - assert_equal('{{ value }}', ErrorType::{{ key }}) + {% for error in spec.definitions.appwriteException.errorTypes %} + assert_equal('{{ error.type }}', ErrorType::{{ error.type|title|replace({'_': ''}) }}) {% endfor %} end end diff --git a/templates/swift/Sources/Exception.swift.twig b/templates/swift/Sources/Exception.swift.twig index 13e7880ec..e6181f8c9 100644 --- a/templates/swift/Sources/Exception.swift.twig +++ b/templates/swift/Sources/Exception.swift.twig @@ -1,6 +1,6 @@ enum ErrorType: String { -{% for error in spec.definitions.appwriteException.error_types %} - /// {{ error.description }} +{% for error in spec.definitions.appwriteException.errorTypes %} + /// {{ error.message }} case {{ error.type|camelCase }} = "{{ error.type }}" {% endfor %} } diff --git a/templates/swift/Tests/TestException.swift.twig b/templates/swift/Tests/TestException.swift.twig index cfe9aa45b..9e039fe32 100644 --- a/templates/swift/Tests/TestException.swift.twig +++ b/templates/swift/Tests/TestException.swift.twig @@ -3,8 +3,8 @@ import XCTest class ErrorTypeTests: XCTestCase { func testErrorTypeValues() { - {% for key, value in testData.enumData %} - XCTAssertEqual(ErrorType.{{ key }}.rawValue, "{{ value }}") + {% for error in spec.definitions.appwriteException.errorTypes %} + XCTAssertEqual(ErrorType.{{ error.type|title|replace({'_': ''}) }}.rawValue, "{{ error.type }}") {% endfor %} } } \ No newline at end of file diff --git a/templates/web/src/exception.ts.twig b/templates/web/src/exception.ts.twig index f8f285a85..98b157e43 100644 --- a/templates/web/src/exception.ts.twig +++ b/templates/web/src/exception.ts.twig @@ -1,7 +1,7 @@ export enum ErrorType { - {% for error in spec.definitions.appwriteException.error_types %} + {% for error in spec.definitions.appwriteException.errorTypes %} /** - * {{ error.description }} + * {{ error.message }} */ {{ error.type|title|replace({'_': ''}) }} = "{{ error.type }}", {% endfor %} diff --git a/templates/web/tests/test_exception.ts.twig b/templates/web/tests/test_exception.ts.twig index bf5b58f55..1dd3310a1 100644 --- a/templates/web/tests/test_exception.ts.twig +++ b/templates/web/tests/test_exception.ts.twig @@ -2,8 +2,8 @@ import * as assert from "assert"; import { ErrorType } from "../src/exception.ts" try { - {% for key, value in testData.enumData %} - assert.strictEqual(ErrorType.{{ key }}, '{{ value }}'); + {% for error in spec.definitions.appwriteException.errorTypes %} + assert.strictEqual(ErrorType.{{ error.type|title|replace({'_': ''}) }}, '{{ error.type }}'); {% endfor %} console.log('All tests passed!'); From 4f55b35eaf93f0d9625100733eb99361ad46701e Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Sun, 12 Nov 2023 08:39:36 +0530 Subject: [PATCH 08/21] feat: add test_exception.py.twig Signed-off-by: Jay --- .../python/tests/package/test_exception.py.twig | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 templates/python/tests/package/test_exception.py.twig diff --git a/templates/python/tests/package/test_exception.py.twig b/templates/python/tests/package/test_exception.py.twig new file mode 100644 index 000000000..7ba009d87 --- /dev/null +++ b/templates/python/tests/package/test_exception.py.twig @@ -0,0 +1,12 @@ +from ...{{ spec.title | caseSnake}}.exception import ErrorType +import unittest + + +class TestErrorEnum(unittest.TestCase): + + def test_enum_values(self): + {% for error in spec.definitions.appwriteException.errorTypes %} + self.assertEqual(ErrorType.{{ error.type|title|replace({'_': ''}) }}.value, '{{ error.type }}') + {% endfor %} + + From 273bb15a9853673ee1182e0185c8206d33ee4b51 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Sun, 12 Nov 2023 09:52:00 +0530 Subject: [PATCH 09/21] fix: fix AppwriteException Import Signed-off-by: Jay --- templates/node/lib/client.js.twig | 2 +- templates/node/lib/exception.js.twig | 2 -- templates/node/lib/services/service.js.twig | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/templates/node/lib/client.js.twig b/templates/node/lib/client.js.twig index c3b8130e5..71e4c02d6 100644 --- a/templates/node/lib/client.js.twig +++ b/templates/node/lib/client.js.twig @@ -3,7 +3,7 @@ const URL = require('url').URL; const https = require("https"); const axios = require('axios'); const FormData = require('form-data'); -const {{spec.title | caseUcfirst}}Exception = require('./exception.js'); +const { {{spec.title | caseUcfirst}}Exception } = require('./exception.js'); class Client { static CHUNK_SIZE = 5*1024*1024; // 5MB diff --git a/templates/node/lib/exception.js.twig b/templates/node/lib/exception.js.twig index 8783b1403..0e8f42f62 100644 --- a/templates/node/lib/exception.js.twig +++ b/templates/node/lib/exception.js.twig @@ -7,8 +7,6 @@ class {{spec.title | caseUcfirst}}Exception extends Error { } } -module.exports = {{spec.title | caseUcfirst}}Exception; - const ErrorType = { {% for error in spec.definitions.appwriteException.errorTypes %} /** diff --git a/templates/node/lib/services/service.js.twig b/templates/node/lib/services/service.js.twig index acfa340a3..09860aa40 100644 --- a/templates/node/lib/services/service.js.twig +++ b/templates/node/lib/services/service.js.twig @@ -1,5 +1,5 @@ const Service = require('../service.js'); -const {{spec.title | caseUcfirst}}Exception = require('../exception.js'); +const { {{spec.title | caseUcfirst}}Exception } = require('../exception.js'); const InputFile = require('../inputFile.js'); const client = require('../client.js'); const Stream = require('stream'); From c57715a2a1bc5c107deef8cddfbd48b3f4932a4a Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Fri, 17 Nov 2023 08:57:13 +0530 Subject: [PATCH 10/21] fix: tests and ErrorEnums generated only if spec has Error info - all the block of codes are wrapped within the if block. Signed-off-by: Jay --- .../src/main/java/io/appwrite/exceptions/Exception.kt.twig | 4 +++- templates/android/tests/TestException.kt.twig | 4 +++- templates/dart/lib/src/exception.dart.twig | 2 ++ templates/deno/src/exception.ts.twig | 4 +++- templates/deno/tests/test_exception.ts.twig | 5 +++-- templates/dotnet/src/Appwrite/Exception.cs.twig | 4 ++-- templates/dotnet/tests/TestException.cs.twig | 2 ++ templates/flutter/lib/src/exception.dart.twig | 4 +++- templates/flutter/test/src/exception_test.dart.twig | 2 ++ .../main/kotlin/io/appwrite/exceptions/Exception.kt.twig | 4 +++- templates/kotlin/tests/TestException.kt.twig | 4 +++- templates/node/lib/exception.js.twig | 4 ++++ templates/node/tests/test_exception.js.twig | 2 ++ templates/php/src/Exception.php.twig | 4 +++- templates/php/tests/TestException.php.twig | 2 ++ templates/python/package/exception.py.twig | 5 +++-- templates/python/tests/package/test_exception.py.twig | 6 +++--- templates/ruby/lib/container/exception.rb.twig | 2 ++ templates/ruby/tests/lib/appwrite/test_exception.rb.twig | 2 ++ templates/swift/Sources/Exception.swift.twig | 2 ++ templates/swift/Tests/TestException.swift.twig | 4 +++- templates/web/src/exception.ts.twig | 4 +++- templates/web/tests/test_exception.ts.twig | 4 +++- 23 files changed, 61 insertions(+), 19 deletions(-) diff --git a/templates/android/library/src/main/java/io/appwrite/exceptions/Exception.kt.twig b/templates/android/library/src/main/java/io/appwrite/exceptions/Exception.kt.twig index 84b6c4782..55b832363 100644 --- a/templates/android/library/src/main/java/io/appwrite/exceptions/Exception.kt.twig +++ b/templates/android/library/src/main/java/io/appwrite/exceptions/Exception.kt.twig @@ -9,6 +9,7 @@ class {{spec.title | caseUcfirst}} Exception( val response: String? = null ) : Exception(message) +{% if spec.definitions.appwriteException.errorTypes|length > 0 %} enum class ErrorType(val value: String) { {% for error in spec.definitions.appwriteException.errorTypes %} /** @@ -16,4 +17,5 @@ enum class ErrorType(val value: String) { */ {{ error.type|title|replace({'_': ''}) }}("{{ error.type }}"), {% endfor %} -} \ No newline at end of file +} +{% endif %} \ No newline at end of file diff --git a/templates/android/tests/TestException.kt.twig b/templates/android/tests/TestException.kt.twig index db0078012..d959bd55f 100644 --- a/templates/android/tests/TestException.kt.twig +++ b/templates/android/tests/TestException.kt.twig @@ -1,3 +1,4 @@ +{% if spec.definitions.appwriteException.errorTypes|length > 0 %} package tests import {{ sdk.namespace | caseDot }}.exceptions.ErrorType @@ -12,4 +13,5 @@ class TestException { assertEquals(ErrorType.{{ error.type|title|replace({'_': ''}) }}.value), "{{ error.type }}") {% endfor %} } -} \ No newline at end of file +} +{% endif %} \ No newline at end of file diff --git a/templates/dart/lib/src/exception.dart.twig b/templates/dart/lib/src/exception.dart.twig index 068316a62..7e5fb564d 100644 --- a/templates/dart/lib/src/exception.dart.twig +++ b/templates/dart/lib/src/exception.dart.twig @@ -22,9 +22,11 @@ class {{spec.title | caseUcfirst}}Exception implements Exception { } } +{% if spec.definitions.appwriteException.errorTypes|length > 0 %} enum ErrorType { {% for error in spec.definitions.appwriteException.errorTypes %} /// {{ error.message }} {{ error.type|title|replace({'_': ''}) }}, {% endfor %} } +{% endif %} diff --git a/templates/deno/src/exception.ts.twig b/templates/deno/src/exception.ts.twig index cbac0c6b0..6653a3552 100644 --- a/templates/deno/src/exception.ts.twig +++ b/templates/deno/src/exception.ts.twig @@ -16,6 +16,7 @@ export class {{ spec.title | caseUcfirst}}Exception { } } +{% if spec.definitions.appwriteException.errorTypes|length > 0 %} export enum ErrorType { {% for error in spec.definitions.appwriteException.errorTypes %} /** @@ -23,4 +24,5 @@ export enum ErrorType { */ {{ error.type|title|replace({'_': ''}) }} = "{{ error.type }}", {% endfor %} -} \ No newline at end of file +} +{% endif %} \ No newline at end of file diff --git a/templates/deno/tests/test_exception.ts.twig b/templates/deno/tests/test_exception.ts.twig index 4c0528020..d5ee138eb 100644 --- a/templates/deno/tests/test_exception.ts.twig +++ b/templates/deno/tests/test_exception.ts.twig @@ -1,4 +1,4 @@ -// Assuming errorType.ts contains your ErrorType enum +{% if spec.definitions.appwriteException.errorTypes|length > 0 %} import {assertEquals} from "https://deno.land/std/testing/asserts.ts"; import {ErrorType} from "../src/exception.ts"; @@ -6,4 +6,5 @@ Deno.test("ErrorType values should match expected strings", () => { {% for error in spec.definitions.appwriteException.errorTypes %} assertEquals(ErrorType.{{ error.type|title|replace({'_': ''}) }}, '{{ error.type }}'); {% endfor %} -}) \ No newline at end of file +}) +{% endif %} \ No newline at end of file diff --git a/templates/dotnet/src/Appwrite/Exception.cs.twig b/templates/dotnet/src/Appwrite/Exception.cs.twig index 2b8c841a4..f23d857d4 100644 --- a/templates/dotnet/src/Appwrite/Exception.cs.twig +++ b/templates/dotnet/src/Appwrite/Exception.cs.twig @@ -24,6 +24,7 @@ namespace {{spec.title | caseUcfirst}} } } +{% if spec.definitions.appwriteException.errorTypes|length > 0 %} public enum ErrorType { {% for error in spec.definitions.appwriteException.errorTypes %} /// @@ -33,5 +34,4 @@ namespace {{spec.title | caseUcfirst}} {% endfor %} } } - - +{% endif %} \ No newline at end of file diff --git a/templates/dotnet/tests/TestException.cs.twig b/templates/dotnet/tests/TestException.cs.twig index e0b0dd774..c1fb4d8e5 100644 --- a/templates/dotnet/tests/TestException.cs.twig +++ b/templates/dotnet/tests/TestException.cs.twig @@ -1,3 +1,4 @@ +{% if spec.definitions.appwriteException.errorTypes|length > 0 %} using Microsoft.VisualStudio.TestTools.UnitTesting; using {{spec.title | caseUcfirst}}; @@ -12,3 +13,4 @@ public class TestException {% endfor %} } } +{% endif %} diff --git a/templates/flutter/lib/src/exception.dart.twig b/templates/flutter/lib/src/exception.dart.twig index b244e75bc..2a05257e4 100644 --- a/templates/flutter/lib/src/exception.dart.twig +++ b/templates/flutter/lib/src/exception.dart.twig @@ -1,6 +1,8 @@ +{% if spec.definitions.appwriteException.errorTypes|length > 0 %} enum ErrorType { {% for error in spec.definitions.appwriteException.errorTypes %} /// {{ error.message }} {{ error.type|title|replace({'_': ''}) }}, {% endfor %} -} \ No newline at end of file +} +{% endif %} \ No newline at end of file diff --git a/templates/flutter/test/src/exception_test.dart.twig b/templates/flutter/test/src/exception_test.dart.twig index 5315fd652..3efdd965e 100644 --- a/templates/flutter/test/src/exception_test.dart.twig +++ b/templates/flutter/test/src/exception_test.dart.twig @@ -1,3 +1,4 @@ +{% if spec.definitions.appwriteException.errorTypes|length > 0 %} import 'package:{{language.params.packageName}}/src/exception.dart'; {% if 'dart' in language.params.packageName %} import 'package:test/test.dart'; @@ -14,3 +15,4 @@ void main() { {% endfor %} }); } +{% endif %} \ No newline at end of file diff --git a/templates/kotlin/src/main/kotlin/io/appwrite/exceptions/Exception.kt.twig b/templates/kotlin/src/main/kotlin/io/appwrite/exceptions/Exception.kt.twig index 43177ad6e..e62612cd1 100644 --- a/templates/kotlin/src/main/kotlin/io/appwrite/exceptions/Exception.kt.twig +++ b/templates/kotlin/src/main/kotlin/io/appwrite/exceptions/Exception.kt.twig @@ -9,6 +9,7 @@ class {{spec.title | caseUcfirst}}Exception( val response: String? = null ) : Exception(message) +{% if spec.definitions.appwriteException.errorTypes|length > 0 %} enum class ErrorType(val value: String) { {% for error in spec.definitions.appwriteException.errorTypes %} /** @@ -16,4 +17,5 @@ enum class ErrorType(val value: String) { */ {{ error.type|title|replace({'_': ''}) }}("{{ error.type }}"), {% endfor %} -} \ No newline at end of file +} +{% endif %} \ No newline at end of file diff --git a/templates/kotlin/tests/TestException.kt.twig b/templates/kotlin/tests/TestException.kt.twig index db0078012..d959bd55f 100644 --- a/templates/kotlin/tests/TestException.kt.twig +++ b/templates/kotlin/tests/TestException.kt.twig @@ -1,3 +1,4 @@ +{% if spec.definitions.appwriteException.errorTypes|length > 0 %} package tests import {{ sdk.namespace | caseDot }}.exceptions.ErrorType @@ -12,4 +13,5 @@ class TestException { assertEquals(ErrorType.{{ error.type|title|replace({'_': ''}) }}.value), "{{ error.type }}") {% endfor %} } -} \ No newline at end of file +} +{% endif %} \ No newline at end of file diff --git a/templates/node/lib/exception.js.twig b/templates/node/lib/exception.js.twig index 0e8f42f62..33b407d51 100644 --- a/templates/node/lib/exception.js.twig +++ b/templates/node/lib/exception.js.twig @@ -7,6 +7,7 @@ class {{spec.title | caseUcfirst}}Exception extends Error { } } +{% if spec.definitions.appwriteException.errorTypes|length > 0 %} const ErrorType = { {% for error in spec.definitions.appwriteException.errorTypes %} /** @@ -15,8 +16,11 @@ const ErrorType = { {{ error.type|title|replace({'_': ''}) }}: "{{ error.type }}", {% endfor %} } +{% endif %} module.exports = { {{spec.title | caseUcfirst}}Exception, +{% if spec.definitions.appwriteException.errorTypes|length > 0 %} ErrorType +{% endif %} }; \ No newline at end of file diff --git a/templates/node/tests/test_exception.js.twig b/templates/node/tests/test_exception.js.twig index 4fe5c9518..2897b6304 100644 --- a/templates/node/tests/test_exception.js.twig +++ b/templates/node/tests/test_exception.js.twig @@ -1,3 +1,4 @@ +{% if spec.definitions.appwriteException.errorTypes|length > 0 %} const assert = require('assert'); const ErrorType = require('../lib/exception.js'); @@ -10,3 +11,4 @@ try { } catch (error) { console.error('Test failed:', error); } +{% endif %} diff --git a/templates/php/src/Exception.php.twig b/templates/php/src/Exception.php.twig index 3de60be97..d5f207332 100644 --- a/templates/php/src/Exception.php.twig +++ b/templates/php/src/Exception.php.twig @@ -45,6 +45,7 @@ class {{spec.title | caseUcfirst}}Exception extends Exception { } } +{% if spec.definitions.appwriteException.errorTypes|length > 0 %} class ErrorType { {% for error in spec.definitions.appwriteException.errorTypes %} /** @@ -52,4 +53,5 @@ class ErrorType { */ const {{ error.type|title|replace({'_': ''}) }} = '{{ error.type }}'; {% endfor %} -} \ No newline at end of file +} +{% endif %} \ No newline at end of file diff --git a/templates/php/tests/TestException.php.twig b/templates/php/tests/TestException.php.twig index a5e9fd584..f8d76c525 100644 --- a/templates/php/tests/TestException.php.twig +++ b/templates/php/tests/TestException.php.twig @@ -1,3 +1,4 @@ +{% if spec.definitions.appwriteException.errorTypes|length > 0 %} use PHPUnit\Framework\TestCase; class TestErrorEnum extends TestCase { @@ -8,3 +9,4 @@ class TestErrorEnum extends TestCase { {% endfor %} } } +{% endif %} \ No newline at end of file diff --git a/templates/python/package/exception.py.twig b/templates/python/package/exception.py.twig index d360784d4..a11fd6b84 100644 --- a/templates/python/package/exception.py.twig +++ b/templates/python/package/exception.py.twig @@ -2,14 +2,14 @@ from enum import Enum class {{spec.title | caseUcfirst}}Exception(Exception): - def __init__(self, message, code = 0, type = None, response = None): + def __init__(self, message, code=0, type=None, response=None): self.message = message self.code = code self.type = type self.response = response super().__init__(self.message) - +{% if spec.definitions.appwriteException.errorTypes|length > 0 %} class ErrorType(Enum): {% for error in spec.definitions.appwriteException.errorTypes %} """ @@ -17,3 +17,4 @@ class ErrorType(Enum): """ {{ error.type|title|replace({'_': ''}) }} = '{{ error.type }}' {% endfor %} +{% endif %} \ No newline at end of file diff --git a/templates/python/tests/package/test_exception.py.twig b/templates/python/tests/package/test_exception.py.twig index 7ba009d87..a3aad0e5f 100644 --- a/templates/python/tests/package/test_exception.py.twig +++ b/templates/python/tests/package/test_exception.py.twig @@ -1,4 +1,5 @@ -from ...{{ spec.title | caseSnake}}.exception import ErrorType +{% if spec.definitions.appwriteException.errorTypes|length > 0 %} +from ...{{ spec.title | caseSnake}}.exception import (ErrorType) import unittest @@ -8,5 +9,4 @@ class TestErrorEnum(unittest.TestCase): {% for error in spec.definitions.appwriteException.errorTypes %} self.assertEqual(ErrorType.{{ error.type|title|replace({'_': ''}) }}.value, '{{ error.type }}') {% endfor %} - - +{% endif %} diff --git a/templates/ruby/lib/container/exception.rb.twig b/templates/ruby/lib/container/exception.rb.twig index 53ec87cbc..f1ac5e44c 100644 --- a/templates/ruby/lib/container/exception.rb.twig +++ b/templates/ruby/lib/container/exception.rb.twig @@ -13,9 +13,11 @@ module {{spec.title | caseUcfirst}} end end +{% if spec.definitions.appwriteException.errorTypes|length > 0 %} class ErrorType {% for error in spec.definitions.appwriteException.errorTypes %} # {{ error.message }} {{ error.type|title|replace({'_': ''}) }} = '{{ error.type }}' {% endfor %} end +{% endif %} \ No newline at end of file diff --git a/templates/ruby/tests/lib/appwrite/test_exception.rb.twig b/templates/ruby/tests/lib/appwrite/test_exception.rb.twig index 176f0f7da..6dc8fad15 100644 --- a/templates/ruby/tests/lib/appwrite/test_exception.rb.twig +++ b/templates/ruby/tests/lib/appwrite/test_exception.rb.twig @@ -1,3 +1,4 @@ +{% if spec.definitions.appwriteException.errorTypes|length > 0 %} require 'test/unit' require_relative '../../../lib/{{ spec.title | caseSnake }}/exception' # Ensure this path is correct @@ -9,3 +10,4 @@ class ErrorTypeTest < Test::Unit::TestCase {% endfor %} end end +{% endif %} diff --git a/templates/swift/Sources/Exception.swift.twig b/templates/swift/Sources/Exception.swift.twig index e6181f8c9..9d4b74f84 100644 --- a/templates/swift/Sources/Exception.swift.twig +++ b/templates/swift/Sources/Exception.swift.twig @@ -1,6 +1,8 @@ +{% if spec.definitions.appwriteException.errorTypes|length > 0 %} enum ErrorType: String { {% for error in spec.definitions.appwriteException.errorTypes %} /// {{ error.message }} case {{ error.type|camelCase }} = "{{ error.type }}" {% endfor %} } +{% endif %} \ No newline at end of file diff --git a/templates/swift/Tests/TestException.swift.twig b/templates/swift/Tests/TestException.swift.twig index 9e039fe32..33653caa9 100644 --- a/templates/swift/Tests/TestException.swift.twig +++ b/templates/swift/Tests/TestException.swift.twig @@ -1,3 +1,4 @@ +{% if spec.definitions.appwriteException.errorTypes|length > 0 %} import XCTest @testable import {{spec.title | caseUcfirst}} @@ -7,4 +8,5 @@ class ErrorTypeTests: XCTestCase { XCTAssertEqual(ErrorType.{{ error.type|title|replace({'_': ''}) }}.rawValue, "{{ error.type }}") {% endfor %} } -} \ No newline at end of file +} +{% endif %} \ No newline at end of file diff --git a/templates/web/src/exception.ts.twig b/templates/web/src/exception.ts.twig index 98b157e43..618b0d4e6 100644 --- a/templates/web/src/exception.ts.twig +++ b/templates/web/src/exception.ts.twig @@ -1,3 +1,4 @@ +{% if spec.definitions.appwriteException.errorTypes|length > 0 %} export enum ErrorType { {% for error in spec.definitions.appwriteException.errorTypes %} /** @@ -5,4 +6,5 @@ export enum ErrorType { */ {{ error.type|title|replace({'_': ''}) }} = "{{ error.type }}", {% endfor %} -} \ No newline at end of file +} +{% endif %} \ No newline at end of file diff --git a/templates/web/tests/test_exception.ts.twig b/templates/web/tests/test_exception.ts.twig index 1dd3310a1..ad9db34fe 100644 --- a/templates/web/tests/test_exception.ts.twig +++ b/templates/web/tests/test_exception.ts.twig @@ -1,3 +1,4 @@ +{% if spec.definitions.appwriteException.errorTypes|length > 0 %} import * as assert from "assert"; import { ErrorType } from "../src/exception.ts" @@ -9,4 +10,5 @@ try { console.log('All tests passed!'); } catch (error) { console.error('Test failed:', error); -} \ No newline at end of file +} +{% endif %} \ No newline at end of file From db22b05fc47ab77a4693940aabbf628c20574bdd Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Fri, 17 Nov 2023 10:32:08 +0530 Subject: [PATCH 11/21] feat: update tests/spec.json Signed-off-by: Jay --- tests/resources/spec.json | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/resources/spec.json b/tests/resources/spec.json index 772602681..8c3a420e1 100644 --- a/tests/resources/spec.json +++ b/tests/resources/spec.json @@ -1134,6 +1134,27 @@ } }, "required": ["result"] + }, + "appwriteException": { + "x-appwrite": { + "types": [ + { + "code": 400, + "type": "general_mock", + "message": "General errors thrown by the mock controller used for testing." + }, + { + "code": 409, + "type": "document_already_exists", + "message": "Document with the requested ID already exists. Try again with a different ID or use unique() to generate a unique ID." + }, + { + "code": 404, + "type": "avatar_not_found", + "message": "The request avatar could not be found." + } + ] + } } }, "externalDocs": { From c429aa0432aa70c3e987106b7e8bb42d12b4a903 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Fri, 17 Nov 2023 12:58:27 +0530 Subject: [PATCH 12/21] fix: update tests/spec.json and Node Import Signed-off-by: Jay --- templates/node/tests/test_exception.js.twig | 2 +- tests/resources/spec.json | 24 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/templates/node/tests/test_exception.js.twig b/templates/node/tests/test_exception.js.twig index 2897b6304..41b115253 100644 --- a/templates/node/tests/test_exception.js.twig +++ b/templates/node/tests/test_exception.js.twig @@ -1,6 +1,6 @@ {% if spec.definitions.appwriteException.errorTypes|length > 0 %} const assert = require('assert'); -const ErrorType = require('../lib/exception.js'); +const { ErrorType } = require('../lib/exception.js'); try { {% for error in spec.definitions.appwriteException.errorTypes %} diff --git a/tests/resources/spec.json b/tests/resources/spec.json index 8c3a420e1..5c7eb3c78 100644 --- a/tests/resources/spec.json +++ b/tests/resources/spec.json @@ -1136,6 +1136,30 @@ "required": ["result"] }, "appwriteException": { + "description": "Error Types", + "type": "object", + "properties": { + "description": { + "type": "string", + "description": "Error message.", + "x-example": "Invalid id: Parameter must be a valid number" + }, + "type": { + "type": "string", + "description": "Error type.", + "enum": [ + "general_mock", + "general_argument_invalid" + ], + "x-example": "argument_invalid" + }, + "code": { + "type": "integer", + "description": "Error code.", + "x-example": 400, + "format": "int32" + } + }, "x-appwrite": { "types": [ { From caf5d277bb410e28292f3ec6318557b7ac41358d Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Fri, 17 Nov 2023 23:54:38 +0530 Subject: [PATCH 13/21] fix: remove Model if name has Exception in it. Signed-off-by: Jay --- src/SDK/SDK.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/SDK/SDK.php b/src/SDK/SDK.php index b123520fe..aecba1304 100644 --- a/src/SDK/SDK.php +++ b/src/SDK/SDK.php @@ -602,6 +602,10 @@ public function generate(string $target): void foreach ($this->spec->getDefinitions() as $key => $definition) { $params['definition'] = $definition; + if (strpos($definition['name'], "Exception")){ + continue; + } + if ($this->exclude($file, $params)) { continue; } From dd855afe1f6d3e00fd5caf0f40e7ff299ec33f49 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Sat, 18 Nov 2023 00:21:34 +0530 Subject: [PATCH 14/21] fix: remove space from Android class name. Signed-off-by: Jay --- .../src/main/java/io/appwrite/exceptions/Exception.kt.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/android/library/src/main/java/io/appwrite/exceptions/Exception.kt.twig b/templates/android/library/src/main/java/io/appwrite/exceptions/Exception.kt.twig index 55b832363..e62612cd1 100644 --- a/templates/android/library/src/main/java/io/appwrite/exceptions/Exception.kt.twig +++ b/templates/android/library/src/main/java/io/appwrite/exceptions/Exception.kt.twig @@ -2,7 +2,7 @@ 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, From d22707a93fb3dbda11bd162690372d7907c0b715 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Sat, 18 Nov 2023 00:51:23 +0530 Subject: [PATCH 15/21] fix: remove space from Android class name. - add Exception generator to swift Signed-off-by: Jay --- src/SDK/Language/Swift.php | 5 +++++ templates/dart/lib/models.dart.twig | 2 ++ templates/ruby/lib/container/exception.rb.twig | 5 +++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/SDK/Language/Swift.php b/src/SDK/Language/Swift.php index 6e8bd6f7d..c9893cd10 100644 --- a/src/SDK/Language/Swift.php +++ b/src/SDK/Language/Swift.php @@ -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' => '/Sources/{{ spec.title | caseUcfirst}}/Exception.swift', + 'template' => 'swift/Sources/Exception.swift.twig', + ], [ 'scope' => 'default', 'destination' => '/Tests/{{ spec.title | caseUcfirst}}Tests/TestException.swift', diff --git a/templates/dart/lib/models.dart.twig b/templates/dart/lib/models.dart.twig index 1a15137f2..476c8c512 100644 --- a/templates/dart/lib/models.dart.twig +++ b/templates/dart/lib/models.dart.twig @@ -3,5 +3,7 @@ library {{ language.params.packageName }}.models; part 'src/models/model.dart'; {% for definition in spec.definitions %} +{% if 'Exception' not in definition.name %} part 'src/models/{{definition.name | caseSnake}}.dart'; +{% endif %} {% endfor %} \ No newline at end of file diff --git a/templates/ruby/lib/container/exception.rb.twig b/templates/ruby/lib/container/exception.rb.twig index f1ac5e44c..ec11b8e0d 100644 --- a/templates/ruby/lib/container/exception.rb.twig +++ b/templates/ruby/lib/container/exception.rb.twig @@ -11,7 +11,7 @@ module {{spec.title | caseUcfirst}} @response = response end end -end + {% if spec.definitions.appwriteException.errorTypes|length > 0 %} class ErrorType @@ -20,4 +20,5 @@ class ErrorType {{ error.type|title|replace({'_': ''}) }} = '{{ error.type }}' {% endfor %} end -{% endif %} \ No newline at end of file +{% endif %} +end \ No newline at end of file From c6b70d7c818bef53bf5aa49794a0718030e14814 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Sat, 18 Nov 2023 01:02:40 +0530 Subject: [PATCH 16/21] fix: fix camelCase to caseCamel in swift Signed-off-by: Jay --- templates/swift/Sources/Exception.swift.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/swift/Sources/Exception.swift.twig b/templates/swift/Sources/Exception.swift.twig index 9d4b74f84..6d1e557e9 100644 --- a/templates/swift/Sources/Exception.swift.twig +++ b/templates/swift/Sources/Exception.swift.twig @@ -2,7 +2,7 @@ enum ErrorType: String { {% for error in spec.definitions.appwriteException.errorTypes %} /// {{ error.message }} - case {{ error.type|camelCase }} = "{{ error.type }}" + case {{ error.type|caseCamel }} = "{{ error.type }}" {% endfor %} } {% endif %} \ No newline at end of file From 3350831f35383fa7364f095ff5754040cc53d2da Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Wed, 22 Nov 2023 12:49:54 +0530 Subject: [PATCH 17/21] fix: fix ruby imports Signed-off-by: Jay --- templates/ruby/tests/lib/appwrite/test_exception.rb.twig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/templates/ruby/tests/lib/appwrite/test_exception.rb.twig b/templates/ruby/tests/lib/appwrite/test_exception.rb.twig index 6dc8fad15..3197357db 100644 --- a/templates/ruby/tests/lib/appwrite/test_exception.rb.twig +++ b/templates/ruby/tests/lib/appwrite/test_exception.rb.twig @@ -1,7 +1,8 @@ {% if spec.definitions.appwriteException.errorTypes|length > 0 %} require 'test/unit' -require_relative '../../../lib/{{ spec.title | caseSnake }}/exception' # Ensure this path is correct +require_relative '../../../lib/{{ spec.title | caseSnake }}/exception' +module {{spec.title | caseUcfirst}} class ErrorTypeTest < Test::Unit::TestCase def test_error_type_values @@ -9,5 +10,7 @@ class ErrorTypeTest < Test::Unit::TestCase assert_equal('{{ error.type }}', ErrorType::{{ error.type|title|replace({'_': ''}) }}) {% endfor %} end + end end + {% endif %} From c19f7ea562269df8367f1ce108900dd4fa1d40ef Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Wed, 22 Nov 2023 13:07:51 +0530 Subject: [PATCH 18/21] fix: fix ruby imports to exclude AppwriteException Signed-off-by: Jay --- templates/ruby/lib/container.rb.twig | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/templates/ruby/lib/container.rb.twig b/templates/ruby/lib/container.rb.twig index 688d54357..e6f947f63 100644 --- a/templates/ruby/lib/container.rb.twig +++ b/templates/ruby/lib/container.rb.twig @@ -12,8 +12,10 @@ require_relative '{{ spec.title | caseSnake }}/permission' require_relative '{{ spec.title | caseSnake }}/role' require_relative '{{ spec.title | caseSnake }}/id' -{% for defintion in spec.definitions %} -require_relative '{{ spec.title | caseSnake }}/models/{{ defintion.name | caseSnake }}' +{% for definition in spec.definitions %} +{% if 'Exception' not in definition.name %} +require_relative '{{ spec.title | caseSnake }}/models/{{ definition.name | caseSnake }}' +{% endif %} {% endfor %} {% for service in spec.services %} From cac17d03cea8dca605a2c948f7af259142fd3512 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Wed, 22 Nov 2023 13:20:24 +0530 Subject: [PATCH 19/21] fix: change pascal case to camel case Signed-off-by: Jay --- templates/swift/Sources/Exception.swift.twig | 2 +- templates/swift/Tests/TestException.swift.twig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/swift/Sources/Exception.swift.twig b/templates/swift/Sources/Exception.swift.twig index 6d1e557e9..5b85909c0 100644 --- a/templates/swift/Sources/Exception.swift.twig +++ b/templates/swift/Sources/Exception.swift.twig @@ -2,7 +2,7 @@ enum ErrorType: String { {% for error in spec.definitions.appwriteException.errorTypes %} /// {{ error.message }} - case {{ error.type|caseCamel }} = "{{ error.type }}" + case {{ error.type | caseCamel }} = "{{ error.type }}" {% endfor %} } {% endif %} \ No newline at end of file diff --git a/templates/swift/Tests/TestException.swift.twig b/templates/swift/Tests/TestException.swift.twig index 33653caa9..4dd42fa12 100644 --- a/templates/swift/Tests/TestException.swift.twig +++ b/templates/swift/Tests/TestException.swift.twig @@ -5,7 +5,7 @@ import XCTest class ErrorTypeTests: XCTestCase { func testErrorTypeValues() { {% for error in spec.definitions.appwriteException.errorTypes %} - XCTAssertEqual(ErrorType.{{ error.type|title|replace({'_': ''}) }}.rawValue, "{{ error.type }}") + XCTAssertEqual(ErrorType.{{ error.type | caseCamel }}.rawValue, "{{ error.type }}") {% endfor %} } } From 2a9b36f44ceacdeccf4703564b2cc00653de0aef Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Wed, 22 Nov 2023 13:27:17 +0530 Subject: [PATCH 20/21] fix: fix lint errors Signed-off-by: Jay --- src/SDK/SDK.php | 2 +- src/Spec/Swagger2.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/SDK/SDK.php b/src/SDK/SDK.php index aecba1304..4294d9141 100644 --- a/src/SDK/SDK.php +++ b/src/SDK/SDK.php @@ -602,7 +602,7 @@ public function generate(string $target): void foreach ($this->spec->getDefinitions() as $key => $definition) { $params['definition'] = $definition; - if (strpos($definition['name'], "Exception")){ + if (strpos($definition['name'], "Exception")) { continue; } diff --git a/src/Spec/Swagger2.php b/src/Spec/Swagger2.php index 8d6632574..30fa693b6 100644 --- a/src/Spec/Swagger2.php +++ b/src/Spec/Swagger2.php @@ -341,7 +341,6 @@ public function getDefinitions() if (isset($sch['errorTypes'])) { $types = []; foreach ($sch['errorTypes'] as $type) { - $types[] = [ 'code' => $type['code'], 'type' => $type['type'], From 4271b7c3b7816dfb8247a42c2e63c954020e5cd6 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Wed, 29 Nov 2023 13:46:45 +0530 Subject: [PATCH 21/21] refactor: refactor flutter files Signed-off-by: Jay --- src/SDK/Language/Flutter.php | 5 ----- templates/flutter/lib/src/exception.dart.twig | 8 -------- .../flutter/test/src/exception_test.dart.twig | 18 ------------------ 3 files changed, 31 deletions(-) delete mode 100644 templates/flutter/lib/src/exception.dart.twig delete mode 100644 templates/flutter/test/src/exception_test.dart.twig diff --git a/src/SDK/Language/Flutter.php b/src/SDK/Language/Flutter.php index f04de20be..806e19054 100644 --- a/src/SDK/Language/Flutter.php +++ b/src/SDK/Language/Flutter.php @@ -330,11 +330,6 @@ 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', - ], ]; } } diff --git a/templates/flutter/lib/src/exception.dart.twig b/templates/flutter/lib/src/exception.dart.twig deleted file mode 100644 index 2a05257e4..000000000 --- a/templates/flutter/lib/src/exception.dart.twig +++ /dev/null @@ -1,8 +0,0 @@ -{% if spec.definitions.appwriteException.errorTypes|length > 0 %} -enum ErrorType { -{% for error in spec.definitions.appwriteException.errorTypes %} - /// {{ error.message }} - {{ error.type|title|replace({'_': ''}) }}, -{% endfor %} -} -{% endif %} \ No newline at end of file diff --git a/templates/flutter/test/src/exception_test.dart.twig b/templates/flutter/test/src/exception_test.dart.twig deleted file mode 100644 index 3efdd965e..000000000 --- a/templates/flutter/test/src/exception_test.dart.twig +++ /dev/null @@ -1,18 +0,0 @@ -{% if spec.definitions.appwriteException.errorTypes|length > 0 %} -import 'package:{{language.params.packageName}}/src/exception.dart'; -{% if 'dart' in language.params.packageName %} -import 'package:test/test.dart'; -{% else %} -import 'package:flutter_test/flutter_test.dart'; -{% endif %} - -void main() { - group('ErrorType Enum Test', () { - {% for error in spec.definitions.appwriteException.errorTypes %} - test('ErrorType.{{ key }} should have correct value', () { - expect(ErrorType.{{ error.type|title|replace({'_': ''}) }}.toString(), equals('ErrorType.{{ error.type }}')); - }); - {% endfor %} - }); -} -{% endif %} \ No newline at end of file