Skip to content

Conversation

@awwyushh
Copy link

@awwyushh awwyushh commented Oct 3, 2025

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 anyOf fields 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 anyOf fields with multiple variants, the generator produces the expected Rust enum variant types.

This resolves the issue reported in [#22042](#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

  1. Run mvn clean install -DskipTests -pl modules/openapi-generator-cli -am to build the CLI module after applying the patch.
  2. Generate Rust client code using the minimal repro OpenAPI spec provided in the issue.
  3. Confirm that the generated Rust code for the anyOf field no longer produces empty structs but the appropriate primitive type or enum.
  4. Verify that existing tests pass and no regressions occur.

Related issue

Fixes #22042


PR checklist

return mdl;
}

private void processComposedSchemas(Schema model, CodegenModel mdl, String type) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the PR

what about adding some comments (e.g. docstring, inline comments) for this function?

}
{{/anyOf.isEmpty}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the same fix for oneOf block below (around line 220) ?

@wing328
Copy link
Member

wing328 commented Oct 20, 2025

thanks for the PR

can you please merge #21911 contains some tests for anyOf) into your branch?

@wing328 wing328 modified the milestones: 7.17.0, 7.18.0 Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment