fix(rust): correctly handle anyOf with inline primitives
Pull Request: Fix Rust generator issue with anyOf field naming conflicts
Description
This PR fixes a bug in the Rust client generator where an anyOf field in a response body that has the same name as a request parameter generates an empty struct instead of the expected type or enum. This issue occurs whether the anyOf contains a single variant or multiple variants.
The fix ensures that:
- For
anyOffields with a single primitive type variant, the generated Rust struct uses the expected primitive type (e.g.,Option<String>), instead of generating an empty struct wrapper. - For
anyOffields with multiple variants, the generator produces the expected Rust enum variant types.
This resolves the issue reported in [#22042](https://github.com/OpenAPITools/openapi-generator/issues/22042) and was validated by running the generator against the minimal repro spec from the issue. The output matches the expected Rust struct and enum definitions.
How to verify
- Run
mvn clean install -DskipTests -pl modules/openapi-generator-cli -amto build the CLI module after applying the patch. - Generate Rust client code using the minimal repro OpenAPI spec provided in the issue.
- Confirm that the generated Rust code for the
anyOffield no longer produces empty structs but the appropriate primitive type or enum. - Verify that existing tests pass and no regressions occur.
Related issue
Fixes #22042
PR checklist
-
[x] Read the [contribution guidelines](https://github.com/openapitools/openapi-generator/blob/master/CONTRIBUTING.md).
-
[x] Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work.
-
[x] Ran the following to build the project and update samples:
./mvnw clean package || exit ./bin/generate-samples.sh ./bin/configs/*.yaml || exit ./bin/utils/export_docs_generators.sh || exit -
[x] Committed all changed files, including regenerated samples.
-
[x] Targeted the
masterbranch. -
[x] Linked the PR to the issue using “Fixes #22042 ”.
-
[x] Mentioned relevant technical committee members for Rust generator review: @frol (2017/07) @farcaller (2017/08) @richardwhiuk (2019/07) @paladinzh (2020/05) @jacob-pro (2022/10) @dsteeley (2025/07)
thanks for the PR
can you please merge https://github.com/OpenAPITools/openapi-generator/pull/21911(which contains some tests for anyOf) into your branch?