feat: Add Rust language generation support (experimental)#7571
feat: Add Rust language generation support (experimental)#7571darrelmiller wants to merge 6 commits into
Conversation
Add initial Rust code generation targeting the Kiota pipeline: Generator components: - RustWriter with 5 element writers (class, property, method, enum, block end) - RustConventionService with Rust type mappings and naming conventions - RustRefiner for snake_case naming, reserved word escaping, type replacements - RustPathSegmenter for .rs file output with snake_case directories - RustReservedNamesProvider covering Rust keywords and std types Pipeline registrations: - GenerationLanguage.Rust enum member - LanguageWriter, ILanguageRefiner, PublicAPIExportService factory entries - appsettings.json with Experimental/Community maturity level Test coverage: - 31 new tests across 7 test files covering writers and refiner - All 1909 existing tests continue to pass Known limitations: - Generated code has type casing issues (Chrono vs chrono) - Request builder struct fields lost due to base-type movement - No mod.rs generation for module hierarchy - Import statements need refinement Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Fix import paths: use clientNamespaceName instead of walking to root - Move inner classes (query params) to namespace level for Rust compatibility - Only register JSON serialization modules (form/text don't exist yet) - Use Box<dyn Error + Send + Sync> consistently for error types - Replace generic enum methods with serde-based string conversion - Add serde_json::from_value deserialization in request executor body - Use serde serialization for request body instead of Parsable trait - Fix Option<String>.to_string() in raw URL constructor - Suppress unused mut warnings in constructors without mutations - Add proper derives for query parameter classes Generated PetStore client now compiles with zero errors and zero warnings. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Replace RequestBuilder properties with methods in RustRefiner (navigation props like .ip(), .uuid(), .pet() now generated correctly) - Handle complex/object types via serde_json raw values instead of generic get_object_value/write_object_value (dyn-compatible) - Handle primitive collections with concrete method names - Handle enum/object collections via serde raw value serialization - Support Getter/Setter method kinds for navigation and fields - Both httpbin.org and petstore demos run successfully against live APIs Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
SummarySummary
Coveragekiota - 12.3%
Kiota.Builder - 82.1%
|
|
Hi @darrelmiller, this is excellent work! I've been studying the Kiota codebase with the goal of contributing Rust support, and I'm glad to see this experimental implementation already landing. I'd love to help move this from Experimental to Stable. I've been working through the codebase and have a few observations on the known limitations you listed: 1. Enum variant casing — I can contribute a proper 2. Error mapping in request executors — This is critical for production use. I'm thinking of a 3. Inherited serialization/deserialization chaining — Since Rust doesn't have inheritance, I'd propose using trait default methods + a 4. Stream response handling — I've also started work on the companion crates that this generator will need:
Would you be open to contributions on any of these areas? I'm particularly interested in the abstractions crate since it's the foundation everything else depends on. Also, I noticed the |
|
@Ashutosh0x we'd need somebody to drive the implementation work here. Darrel won't have the bandwidth to complete it. If you want to drive this, please get in touch with @andreaTP. You'll find a lot of additional context in:
Let me know if you have any additional comments or questions. |
|
@baywet Thank you for the clear direction! I'd love to drive the Rust implementation work. I'll reach out to @andreaTP to coordinate. Here's my plan for the kiota-community crates: Phase 1: Core Abstractions (
Phase 2: Serialization (
Phase 3: HTTP Client (
Phase 4: Integration & Validation
I've already reviewed the referenced issues and will study:
I've also submitted a proposal to the Interledger Foundation SDK Grant Program to fund this work, which would allow me to dedicate focused time over 6 months. Looking forward to collaborating! |
|
Hi @andreaTP, @baywet pointed me to you regarding driving the Rust implementation for Kiota (ref: #7571 (comment)). I'd love to take ownership of the Rust companion crates under Crates to build:
My background:
Questions:
Looking forward to collaborating! |
🦀 Rust Companion Crates — All 6 PublishedFollowing up on this PR, I've built the complete set of Rust companion crates that the generated code depends on. All crates compile on Rust 1.96.0 stable with 27 passing tests. Repositories
Abstractions Surface CoverageThe abstractions crate matches the full kiota-dart surface:
Happy to transfer these to \kiota-community\ when the namespace is confirmed. @andreaTP @baywet |
Correction to my previous commentI want to be precise about the current state: What actually works today:
What's honest about the scope: Disclosure: These crates were developed with the assistance of generative AI (GitHub Copilot / Gemini). All code has been reviewed, compiled, and tested by me. Happy to discuss scope, requirements, and merge expectations whenever you're ready. @andreaTP @baywet |
|
@Ashutosh0x please join the discord server, especially the rust channel. While we'll keep all the implementation work on issues and pull requests on the multiple repositories, the discord server has been instrumental getting the coordination in place for the dart implementation across repositories. |
|
Nice work on this! I'm building the runtime crates that generated code would depend on — abstractions, JSON serialization, and HTTP client (reqwest-based). They're at kiota-community/kiota-rust#19 with 57 tests passing. I'd like to make sure the trait signatures match what the writer emits here. For example:
Happy to adjust the runtime API to fit. Let me know if there's a sample of generated Rust output I can test against. |
fixes #4436
Summary
Adds experimental Rust language generation support to Kiota, enabling SDK generation targeting Rust from OpenAPI descriptions.
Changes
New Files (13)
RustPathSegmenter.cs— snake_case file/namespace namingRustRefiner.cs,RustReservedNamesProvider.cs,RustExceptionsReservedNamesProvider.cs— Rust-specific code DOM refinement pipelineRustWriter.cs,RustConventionService.cs,CodeMethodWriter.cs,CodeClassDeclarationWriter.cs,CodeEnumWriter.cs,CodePropertyWriter.cs,CodeBlockEndWriter.csIntegration Points
GenerationLanguage.cs— addedRustenum valueILanguageRefiner.cs— wiredRustRefinerLanguageWriter.cs— wiredRustWriterPublicAPIExportService.cs— wiredRustConventionServiceappsettings.json— Rust dependency config (kiota-abstractions, kiota-http-reqwest, kiota-serialization-json/text/form)Design Decisions
MoveRequestBuilderPropertiesToBaseType)CorrectCoreType/ReplacePropertyNames) to avoid lookup failuresSerialize/Deserializewith#[serde(rename)]for property mappingchronocrate types; GUIDs touuid::Uuidr#name)Known Limitations
This is an experimental/community-supported first pass. Known areas for future improvement:
ToFirstCharacterUpperCase()rather than full PascalCase conversion (e.g.some_value→Some_valueinstead ofSomeValue)TrimStart("Option<")inRustConventionServiceuses char-based trimming rather than prefix strippingMaturity
Marked as Experimental with Community support experience in
appsettings.json.