Fix Rust generated model type references#1615
Conversation
Greptile SummaryThis PR fixes Rust SDK code generation so that type references use
Confidence Score: 4/5Safe to merge — the changes are narrowly scoped to Rust type-reference generation, have no runtime side effects outside the code-generation path, and are consistent with how other language generators in the same codebase already use toPascalCase(). All six changed call sites are straightforward mechanical substitutions of ucfirst() → toPascalCase(), and the two new No files require special attention; the single changed file is self-contained. Important Files Changed
Reviews (1): Last reviewed commit: "Fix Rust generated model type references" | Re-trigger Greptile |
Summary
This updates the Rust SDK generator so generated Rust type references use the same naming and
anyhandling as the Rust model files that the templates emit.The Rust model templates export structs with PascalCase names, for example
estimation_itembecomesEstimationItem. Several generator-side Rust type references were built withucfirst(), which only capitalizes the first character and leaves underscores intact. This could emit references such ascrate::models::Estimation_item, while the actual generated struct iscrate::models::EstimationItem.This PR also maps Appwrite
anyschema references toserde_json::Valuein Rust type references. Theanyschema is intentionally not generated as a model, so references such ascrate::models::Anycannot compile.What Changed
toPascalCase()for Rust enum and model references produced bygetTypeName().toPascalCase()for Rust response model references produced bygetReturnType().toPascalCase()for Rust model propertysub_schemareferences produced bygetPropertyType().model = any, array itemmodel = any, and propertysub_schema = anyasserde_json::Value/Vec<serde_json::Value>.Why This Matters
Generated Rust crates can fail to compile when a schema name contains underscores or when a property/parameter points at the Appwrite
anyschema. These failures are compile-time missing type errors, and because they are emitted into model/service definitions they break the whole generated crate.The generator now emits references that match the actual Rust model exports and uses
serde_json::Valuefor open JSON values.Repro Proof
I verified the issue with a local OpenAPI fixture containing:
estimation_itemitems: { "$ref": "#/components/schemas/estimation_item" }plan: { "type": "array", "items": { "$ref": "#/components/schemas/any" } }repro_wrapperBefore this change, the generated Rust contained these invalid references:
A clean
cargo buildfailed withE0425missing type errors forEstimation_item,Any, andRepro_wrapper.With this change, the same fixture generates:
The generated crate then builds successfully.
Validation
Ran the repro fixture through
example.phpwithSDK_GEN_SPEC_FILEand confirmedcargo clean && cargo buildfails before the change and passes after it.Also regenerated the normal Rust server SDK and ran:
All final validation passed.
Note: this repo requires PHP >= 8.5, so PHP commands were run in the
php:8.5-cliDocker image.