feat: Add Rust language generation support (experimental)#7571
Draft
darrelmiller wants to merge 6 commits intomainfrom
Draft
feat: Add Rust language generation support (experimental)#7571darrelmiller wants to merge 6 commits intomainfrom
darrelmiller wants to merge 6 commits intomainfrom
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>
Contributor
SummarySummary
Coveragekiota - 12.3%
Kiota.Builder - 82.1%
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.