Skip to content

Fix Rust generated model type references#1615

Merged
ChiragAgg5k merged 1 commit into
mainfrom
codex/fix-rust-type-references
Jun 29, 2026
Merged

Fix Rust generated model type references#1615
ChiragAgg5k merged 1 commit into
mainfrom
codex/fix-rust-type-references

Conversation

@atharvadeosthale

Copy link
Copy Markdown
Member

Summary

This updates the Rust SDK generator so generated Rust type references use the same naming and any handling as the Rust model files that the templates emit.

The Rust model templates export structs with PascalCase names, for example estimation_item becomes EstimationItem. Several generator-side Rust type references were built with ucfirst(), which only capitalizes the first character and leaves underscores intact. This could emit references such as crate::models::Estimation_item, while the actual generated struct is crate::models::EstimationItem.

This PR also maps Appwrite any schema references to serde_json::Value in Rust type references. The any schema is intentionally not generated as a model, so references such as crate::models::Any cannot compile.

What Changed

  • Use toPascalCase() for Rust enum and model references produced by getTypeName().
  • Use toPascalCase() for Rust response model references produced by getReturnType().
  • Use toPascalCase() for Rust model property sub_schema references produced by getPropertyType().
  • Treat model = any, array item model = any, and property sub_schema = any as serde_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 any schema. 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::Value for open JSON values.

Repro Proof

I verified the issue with a local OpenAPI fixture containing:

  • a snake_case schema named estimation_item
  • a wrapper schema with items: { "$ref": "#/components/schemas/estimation_item" }
  • a wrapper schema with plan: { "type": "array", "items": { "$ref": "#/components/schemas/any" } }
  • a response model named repro_wrapper

Before this change, the generated Rust contained these invalid references:

pub items: Vec<crate::models::Estimation_item>
pub plan: Vec<crate::models::Any>

// service return type
crate::error::Result<crate::models::Repro_wrapper>

A clean cargo build failed with E0425 missing type errors for Estimation_item, Any, and Repro_wrapper.

With this change, the same fixture generates:

pub items: Vec<crate::models::EstimationItem>
pub plan: Vec<serde_json::Value>

// service return type
crate::error::Result<crate::models::ReproWrapper>

The generated crate then builds successfully.

Validation

Ran the repro fixture through example.php with SDK_GEN_SPEC_FILE and confirmed cargo clean && cargo build fails before the change and passes after it.

Also regenerated the normal Rust server SDK and ran:

docker run --rm -v "$PWD":/app -w /app php:8.5-cli php example.php rust server
cargo clean && cargo build
docker run --rm -v "$PWD":/app -w /app php:8.5-cli php -l src/SDK/Language/Rust.php
docker run --rm -v "$PWD":/app -w /app php:8.5-cli php vendor/bin/rector process --dry-run src/SDK/Language/Rust.php
docker run --rm -v "$PWD":/app -w /app php:8.5-cli php vendor/bin/phpunit --testsuite Unit

All final validation passed.

Note: this repo requires PHP >= 8.5, so PHP commands were run in the php:8.5-cli Docker image.

@greptile-apps

greptile-apps Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes Rust SDK code generation so that type references use toPascalCase() (matching the PascalCase struct names emitted by the model templates) instead of ucfirst(), and maps any schema references to serde_json::Value instead of the non-existent crate::models::Any.

  • ucfirsttoPascalCase in getTypeName(), getPropertyType(), and getReturnType() — fixes compile errors for any snake_case schema name (e.g. estimation_item was generating Estimation_item instead of EstimationItem).
  • any guards added in getTypeName() and getPropertyType() — short-circuits before the match/model-reference logic and returns serde_json::Value or Vec<serde_json::Value> to prevent E0425 missing-type errors on crate::models::Any.

Confidence Score: 4/5

Safe 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 any guards short-circuit before the model-reference logic exactly where the match statement would otherwise produce an unresolvable type. The ordering of the guards (after the itemsarray remapping, before the match) is correct. The getReturnType() path already had an any guard before this PR, so no regression there. No tests are bundled in the diff, but the author describes a manual cargo build repro cycle.

No files require special attention; the single changed file is self-contained.

Important Files Changed

Filename Overview
src/SDK/Language/Rust.php Replaces ucfirst() with toPascalCase() for all Rust type references and adds early-return guards mapping "any" schema references to serde_json::Value; logic is consistent with other language generators and with the parent toPascalCase() implementation

Reviews (1): Last reviewed commit: "Fix Rust generated model type references" | Re-trigger Greptile

@ChiragAgg5k ChiragAgg5k merged commit 63d1abf into main Jun 29, 2026
59 checks passed
@ChiragAgg5k ChiragAgg5k deleted the codex/fix-rust-type-references branch June 29, 2026 11:27
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.

2 participants