mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-10-14 00:13:50 +00:00
* feat(rust): Add anyOf support to Rust client generator This commit adds support for anyOf schemas in the Rust client generator by treating them similarly to oneOf schemas, generating untagged enums instead of empty structs. The implementation reuses the existing oneOf logic since Rust's serde untagged enum will deserialize to the first matching variant, which aligns well with anyOf semantics where one or more schemas must match. Fixes the issue where anyOf schemas would generate empty unusable structs. * test(rust): Add test for anyOf support This commit adds a test case to verify that anyOf schemas generate proper untagged enums instead of empty structs in the Rust client generator. The test includes: - A test OpenAPI spec with anyOf schemas - Unit test that verifies the generated code structure - Assertions to ensure enums are created instead of empty structs * Fix anyOf support for Rust generator - Fixed template closing tag issue that prevented anyOf schemas from generating enums - Changed {{/composedSchemas.oneOf}} to {{/composedSchemas}} at line 262 - Put #[serde(untagged)] and pub enum on same line for test compatibility - Fixed TestUtils.linearize() method replacing spaces with literal '\s' string The Rust generator already converts anyOf to oneOf for processing, but the template wasn't correctly handling these converted schemas. Now anyOf schemas generate proper untagged enums, matching the expected behavior for oneOf schemas without discriminators. * fix(rust): maintain multi-line formatting for serde attributes in oneOf/anyOf enums - Keep #[serde(untagged)] on separate line from pub enum for better readability - Update test assertions to use two separate checks instead of linearize() - Ensures generated Rust code maintains consistent formatting with existing samples - Preserves the original multi-line attribute style preferred in Rust ecosystem