Skip to content

fix(templates): enum constants, null serialization, and object conversion - #1681

Merged
ChiragAgg5k merged 1 commit into
mainfrom
fix-template-enum-null-object-handling
Jul 23, 2026
Merged

ChiragAgg5k merged 1 commit into
mainfrom
fix-template-enum-null-object-handling

Conversation

@ChiragAgg5k

Copy link
Copy Markdown
Member

Fixes three template bugs surfaced by Greptile reviews on the 1.9.x SDK release PRs (appwrite/sdk-for-ruby#68, appwrite/sdk-for-dart#122, appwrite/sdk-for-dotnet#100).

Ruby: invalid enum constant references in model validation

model.rb.twig / request_model.rb.twig built enum constant references with value | caseUpper, while the enum module itself is generated with caseEnumKey. For hyphenated enum values this produced invalid Ruby — DatabaseStatus::FAILING-OVER parses as subtraction between two undefined constants, so any Database response with a non-null status raised NameError. Both templates now use the same keys-aware caseEnumKey conversion as the enum module.

Dart/Flutter: optional nullable params serialized as explicit JSON null

The map_parameter macro only null-guarded optionals when not parameter.nullable. Dart has no undefined, so omitted nullable optionals were sent as explicit "key": null — e.g. oauth2.authorizePost sent max_age: null, and organization.updateInstallation sent authorizationDetails: null (which the server can interpret as clearing the field). Every non-required parameter is now guarded with if (x != null); required nullable parameters are still always sent.

.NET: object-typed model properties corrupted by ToString()

Model.cs.twig's From() had no branch for plain object-typed properties, so they fell into the string fallback and were converted with .ToString() — AppInstallation.authorizationDetails came back as a type-name string instead of the structured data. Added an object branch that passes the raw map value through unchanged.

Validation

Regenerated the server Ruby, Dart, and .NET SDKs plus the client Flutter SDK against the Appwrite Cloud 1.9.x spec with these templates:

  • Ruby: DatabaseStatus::FAILING_OVER generated correctly; ruby -c passes on all generated models
  • Dart: if (maxAge != null), if (authorizationDetails != null), if (replicas != null), if (targetReplicaId != null) guards now emitted in all previously affected methods
  • .NET: authorizationDetails: map["authorizationDetails"] passed through raw; all other property kinds unchanged

…t conversion

- ruby: model enum validation referenced constants via caseUpper, producing
  invalid Ruby for hyphenated enum values (FAILING-OVER parses as
  subtraction). Use the same keys-aware caseEnumKey the enum module uses.
- dart/flutter: optional nullable parameters were serialized as explicit
  JSON null instead of being omitted; Dart cannot distinguish omitted from
  null, so guard every non-required parameter.
- dotnet: object-typed model properties fell into the string fallback and
  were converted with ToString(), corrupting structured data such as
  AppInstallation.authorizationDetails. Pass the raw value through.
@greptile-apps

greptile-apps Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Fixes generated SDK behavior across three languages:

  • Ruby model validators now derive enum constant names using the same key-aware normalization as generated enum modules.
  • Dart and Flutter request maps now omit every non-required parameter when its value is null while preserving explicit nulls for required nullable parameters.
  • .NET model conversion now preserves raw values for plain object-typed properties instead of converting them to strings.

Confidence Score: 5/5

The PR appears safe to merge, with no concrete changed-code failures identified.

The updated templates consistently preserve optional-parameter omission semantics, raw .NET object values, and Ruby enum constant naming while leaving required-nullable and non-object paths intact.

Important Files Changed

Filename Overview
templates/dart/base/utils.twig Correctly guards all optional parameters before adding them to Dart request maps; guarded enum and model conversions remain valid under Dart null promotion.
templates/flutter/base/utils.twig Mirrors the Dart serialization correction so omitted nullable optionals are excluded from Flutter request maps.
templates/dotnet/Package/Models/Model.cs.twig Preserves deserialized dictionaries, lists, primitives, and nulls behind object-typed model properties without affecting other conversion branches.
templates/ruby/lib/container/models/model.rb.twig Aligns response-model enum validation references with the key-aware constant naming used by Ruby enum generation.
templates/ruby/lib/container/models/request_model.rb.twig Applies the same enum-key normalization fix to generated Ruby request-model validators.

Reviews (1): Last reviewed commit: "fix(templates): correct enum constants, ..." | Re-trigger Greptile

@ChiragAgg5k
ChiragAgg5k merged commit 86710bf into main Jul 23, 2026
60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant