Skip to content

Conversation

JMLX42
Copy link
Contributor

@JMLX42 JMLX42 commented Sep 28, 2025

PR checklist

Description

This PR removes the default features (specifically native-tls) from the reqwest dependency in the Rust client generator. This allows users to explicitly choose their TLS backend without automatically including openssl-sys as a transitive dependency.

Problem

As described in #21933, the current implementation sets default = ["native-tls"], which:

  • Always pulls in openssl-sys as a transitive dependency
  • Can cause build issues for certain targets like Android
  • May include an "unsafe SSL implementation" that users don't need

Solution

  • Modified Cargo.mustache template to set default = [] instead of default = ["native-tls"]
  • Users can now explicitly enable their preferred TLS backend using feature flags

Available TLS Backends

After this change, users can explicitly select:

  • native-tls: Uses platform-native TLS (OpenSSL on Linux, SChannel on Windows, Security Framework on macOS)
  • rustls-tls: Uses rustls, a pure Rust TLS implementation
  • default-tls: Uses reqwest's default choice

Breaking Change Notice

⚠️ This is a breaking change. Users will need to explicitly enable a TLS backend feature in their Cargo.toml:

This is not a breaking change (cf #22041 (comment))

Testing

  • Built the project successfully with Maven
  • Regenerated all Rust samples
  • Verified that generated Cargo.toml files have empty default features list
  • Exported documentation

Fixes #21933

This change removes the default features (specifically native-tls) from the reqwest
dependency in the Rust client generator. This allows users to explicitly choose
their TLS backend without automatically including openssl-sys as a transitive dependency.

Users can now explicitly enable TLS backends using feature flags:
- native-tls
- rustls-tls
- default-tls

Fixes OpenAPITools#21933
@JMLX42 JMLX42 force-pushed the fix/21933-rust-reqwest-no-default-features branch from f019545 to 137a660 Compare September 28, 2025 17:06
@JMLX42
Copy link
Contributor Author

JMLX42 commented Sep 28, 2025

@dsteeley
Copy link
Contributor

LGTM, thanks for raising as a follow-up to the previous PR.

@wing328
Copy link
Member

wing328 commented Sep 30, 2025

⚠️ This is a breaking change. Users will need to explicitly enable a TLS backend feature in their Cargo.toml:

what about adding an option to let users choose?

@JMLX42
Copy link
Contributor Author

JMLX42 commented Sep 30, 2025

what about adding an option to let users choose?

An option to set a Cargo feature? Sounds a bit complicated to me.

But if that's a show stopper for 7.16 then yes, I'll do it.

@wing328
Copy link
Member

wing328 commented Sep 30, 2025

the next release v7.17.0 allows breaking changes with fallback so if you can add an option with native-tls (or empty) as the default, then we can include this enhancement in the upcoming release

@wing328
Copy link
Member

wing328 commented Sep 30, 2025

thanks again for putting together the following to highlight it's a breaking change:

Breaking Change Notice

⚠️ This is a breaking change. Users will need to explicitly enable a TLS backend feature in their Cargo.toml:

[dependencies]
my_api_client = { version = "1.0", features = ["native-tls"] }
# or
my_api_client = { version = "1.0", features = ["rustls-tls"] }

is it correct to say that users need to manually update the auto-generated Cargo.toml in order to consume the API client?

@JMLX42
Copy link
Contributor Author

JMLX42 commented Sep 30, 2025

This is a breaking change. Users will need to explicitly enable a TLS backend feature in their Cargo.toml:

There was a typo in the codeblock so I fixed it.

is it correct to say that users need to manually update the auto-generated Cargo.toml in order to consume the API client?

No. There will be 0 required modification of the generated Cargo.toml.

What the codeblock shows is that the feature is enabled by the user's crate that will use the generated SDK.

the next release v7.17.0 allows breaking changes with fallback so if you can add an option with native-tls (or empty) as the default, then we can include this enhancement in the upcoming release

OK so IMHO to be backward compatible the default value for this option will have to be the current default feature, so "native-tls".

…e default

This change adds a new generator option `reqwestDefaultFeatures` that allows
users to configure the default Cargo features for the reqwest dependency.

The option accepts:
- An array of strings in YAML config: reqwestDefaultFeatures: ["native-tls"]
- A comma-separated string via CLI: --additional-properties=reqwestDefaultFeatures=native-tls
- An empty value for no defaults: reqwestDefaultFeatures: []

Default value: ["native-tls"] (maintains backward compatibility)

This addresses the feedback in OpenAPITools#21933 to make the change opt-in rather than
breaking existing users.

Users can now:
- Keep the current behavior (default)
- Opt-out: reqwestDefaultFeatures: []
- Use alternative TLS: reqwestDefaultFeatures: ["rustls-tls"]
- Combine features: reqwestDefaultFeatures: ["native-tls", "cookies"]

Fixes OpenAPITools#21933
@JMLX42
Copy link
Contributor Author

JMLX42 commented Sep 30, 2025

I've updated the PR to address the feedback. Here's what changed:

Changes Made

Added a new generator option reqwestDefaultFeatures that allows users to configure the default Cargo features for the reqwest dependency.

Key Points

Backward Compatible: Default value is ["native-tls"] - maintains existing behavior
Flexible: Supports array of strings for forward compatibility
Meets v7.17.0 criteria: Breaking change with fallback

Usage

YAML configuration:

additionalProperties:
  reqwestDefaultFeatures: []  # No default features
  # or
  reqwestDefaultFeatures: ["rustls-tls"]  # Use rustls
  # or  
  reqwestDefaultFeatures: ["native-tls", "cookies"]  # Multiple features

CLI:

--additional-properties=reqwestDefaultFeatures=  # Empty for no defaults
--additional-properties=reqwestDefaultFeatures=rustls-tls  # Single feature
--additional-properties=reqwestDefaultFeatures=rustls-tls,cookies  # Multiple (comma-separated)

Implementation Details

  • Added REQWEST_DEFAULT_FEATURES constant and field to RustClientCodegen
  • Default value: Arrays.asList("native-tls")
  • Processes both List<String> (from YAML) and comma-separated strings (from CLI)
  • Updated Cargo.mustache template to use array iteration with proper comma handling
  • Applied to both reqwest and reqwest-trait library sections

All builds, samples, and documentation have been regenerated successfully.

@JMLX42 JMLX42 changed the title [Rust] Remove default features from reqwest dependency [Rust] Configurable default features from reqwest dependency Oct 1, 2025
@wing328
Copy link
Member

wing328 commented Oct 1, 2025

nice 👍

thanks for the contribution

@wing328 wing328 merged commit 7ab9364 into OpenAPITools:master Oct 1, 2025
14 checks passed
@wing328 wing328 added this to the 7.16.0 milestone Oct 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Rust] The reqwest(-trait) library must not enable any default feature

3 participants