Skip to content

Commit b571442

Browse files
committed
Further tweaks to rust-server HTTPS feature flagging
1 parent 2d9a24a commit b571442

24 files changed

Lines changed: 186 additions & 152 deletions

File tree

modules/openapi-generator/src/main/resources/rust-server/Cargo.mustache

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ homepage = "{{.}}"
3232
{{/homePageUrl}}
3333

3434
[features]
35-
default = ["client", "server"]
35+
default = ["client", "server", "client-tls"]
3636
client = [
3737
{{#apiUsesMultipartFormData}}
3838
"multipart", "multipart/client", "swagger/multipart_form",
@@ -69,6 +69,7 @@ server = [
6969
"mime_multipart", "swagger/multipart_related",
7070
{{/apiUsesMultipartRelated}}
7171
{{#hasCallbacks}}
72+
"hyper-util/http1", "hyper-util/http2",
7273
{{/hasCallbacks}}
7374
{{! Anything added to the list below, should probably be added to the callbacks list above }}
7475
"serde_ignored", "hyper", "percent-encoding", "url",
@@ -136,12 +137,6 @@ serde_urlencoded = { version = "0.7.1", optional = true }
136137
{{/usesUrlEncodedForm}}
137138
tower-service = "0.3.3"
138139

139-
# TLS support - all listed here, actual usage determined by cfg attributes in code
140-
native-tls = { version = "0.2", optional = true }
141-
hyper-tls = { version = "0.6", optional = true }
142-
openssl = { version = "0.10", optional = true }
143-
hyper-openssl = { version = "0.10", optional = true }
144-
145140
# Server, and client callback-specific
146141
{{^apiUsesByteArray}}
147142
lazy_static = { version = "1.5", optional = true }
@@ -166,19 +161,32 @@ frunk_core = { version = "0.4.3", optional = true }
166161
frunk-enum-derive = { version = "0.3.0", optional = true }
167162
frunk-enum-core = { version = "0.3.0", optional = true }
168163

164+
# TLS dependencies - platform-specific backends
165+
# On macOS/Windows/iOS, use native-tls via hyper-tls
166+
[target.'cfg(any(target_os = "macos", target_os = "windows", target_os = "ios"))'.dependencies]
167+
native-tls = { version = "0.2", optional = true }
168+
hyper-tls = { version = "0.6", optional = true }
169+
170+
# On other platforms (Linux, etc.), use OpenSSL via hyper-openssl
171+
[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dependencies]
172+
openssl = { version = "0.10", optional = true }
173+
hyper-openssl = { version = "0.10", optional = true }
174+
169175
[dev-dependencies]
170176
always_send = "0.1.1"
171177
clap = "4.5"
172178
env_logger = "0.11"
173179
tokio = { version = "1.49", features = ["full"] }
174180
native-tls = "0.2"
175-
openssl = "0.10"
176-
tokio-openssl = "0.6"
177181
pin-project = "1.1.10"
178182

179183
# Bearer authentication, used in examples
180184
jsonwebtoken = {version = "10.0.0", features = ["rust_crypto"]}
181185

186+
[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dev-dependencies]
187+
openssl = "0.10"
188+
tokio-openssl = "0.6"
189+
182190
[[example]]
183191
name = "client"
184192
required-features = ["client"]

modules/openapi-generator/src/main/resources/rust-server/README.mustache

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,9 @@ The generated library has a few optional features that can be activated through
127127
* This defaults to enabled and creates the basic skeleton of a client implementation based on hyper
128128
* The constructed client implements the API trait by making remote API call.
129129
* `client-tls`
130-
* Optional feature that provides HTTPS support with automatic TLS backend selection:
130+
* This default to enabled and provides HTTPS support with automatic TLS backend selection:
131131
- macOS/Windows/iOS: native-tls + hyper-tls
132132
- Linux/Unix/others: OpenSSL + hyper-openssl
133-
* Not enabled by default to minimize dependencies.
134133
* `conversions`
135134
* This defaults to disabled and creates extra derives on models to allow "transmogrification" between objects of structurally similar types.
136135
* `cli`
@@ -139,13 +138,13 @@ The generated library has a few optional features that can be activated through
139138
* This defaults to disabled and allows JSON Schema validation of received data using `MakeService::set_validation` or `Service::set_validation`.
140139
* Note, enabling validation will have a performance penalty, especially if the API heavily uses regex based checks.
141140

142-
### Enabling HTTPS/TLS Support
141+
### HTTPS/TLS Support
143142

144-
By default, only HTTP support is included. To enable HTTPS, add the `client-tls` feature:
143+
HTTPS support is included by default. To disable it (for example, to reduce dependencies), you can:
145144

146145
```toml
147146
[dependencies]
148-
{{{packageName}}} = { version = "{{{packageVersion}}}", features = ["client-tls"] }
147+
{{{packageName}}} = { version = "{{{packageVersion}}}", default-features = false, features = ["client", "server"] }
149148
```
150149

151150
**For server with callbacks that need HTTPS:**
@@ -158,8 +157,6 @@ The TLS backend is automatically selected based on your target platform:
158157
- **macOS, Windows, iOS**: Uses `native-tls` (system TLS libraries)
159158
- **Linux, Unix, other platforms**: Uses `openssl`
160159

161-
This ensures the best compatibility and native integration on each platform.
162-
163160
See https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section for how to use features in your `Cargo.toml`.
164161

165162
## Documentation for API Endpoints

modules/openapi-generator/src/main/resources/rust-server/client-mod.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ impl<C> Client<
241241
> where
242242
C: Clone + Send + Sync + 'static
243243
{
244-
/// Create a client with a TLS connection to the server using native-tls.
244+
/// Create a client with a TLS connection to the server.
245245
///
246246
/// # Arguments
247247
/// * `base_path` - base path of the client API, i.e. "<https://www.my-api-implementation.com>"
@@ -255,7 +255,7 @@ impl<C> Client<
255255
Self::try_new_with_connector(base_path, Some("https"), https_connector)
256256
}
257257

258-
/// Create a client with a TLS connection to the server using OpenSSL.
258+
/// Create a client with a TLS connection to the server using OpenSSL via swagger.
259259
///
260260
/// # Arguments
261261
/// * `base_path` - base path of the client API, i.e. "<https://www.my-api-implementation.com>"
@@ -269,7 +269,7 @@ impl<C> Client<
269269
Self::try_new_with_connector(base_path, Some("https"), https_connector)
270270
}
271271

272-
/// Create a client with a TLS connection to the server using a pinned certificate
272+
/// Create a client with a TLS connection to the server using a pinned certificate.
273273
///
274274
/// # Arguments
275275
/// * `base_path` - base path of the client API, i.e. "<https://www.my-api-implementation.com>"

samples/server/petstore/rust-server/output/multipart-v3/Cargo.toml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ license = "Unlicense"
88
edition = "2018"
99

1010
[features]
11-
default = ["client", "server"]
11+
default = ["client", "server", "client-tls"]
1212
client = [
1313
"multipart", "multipart/client", "swagger/multipart_form",
1414
"mime_multipart", "swagger/multipart_related",
@@ -76,12 +76,6 @@ url = { version = "2.5", optional = true }
7676
# Client-specific
7777
tower-service = "0.3.3"
7878

79-
# TLS support - all listed here, actual usage determined by cfg attributes in code
80-
native-tls = { version = "0.2", optional = true }
81-
hyper-tls = { version = "0.6", optional = true }
82-
openssl = { version = "0.10", optional = true }
83-
hyper-openssl = { version = "0.10", optional = true }
84-
8579
# Server, and client callback-specific
8680
percent-encoding = { version = "2.3.2", optional = true }
8781

@@ -99,19 +93,32 @@ frunk_core = { version = "0.4.3", optional = true }
9993
frunk-enum-derive = { version = "0.3.0", optional = true }
10094
frunk-enum-core = { version = "0.3.0", optional = true }
10195

96+
# TLS dependencies - platform-specific backends
97+
# On macOS/Windows/iOS, use native-tls via hyper-tls
98+
[target.'cfg(any(target_os = "macos", target_os = "windows", target_os = "ios"))'.dependencies]
99+
native-tls = { version = "0.2", optional = true }
100+
hyper-tls = { version = "0.6", optional = true }
101+
102+
# On other platforms (Linux, etc.), use OpenSSL via hyper-openssl
103+
[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dependencies]
104+
openssl = { version = "0.10", optional = true }
105+
hyper-openssl = { version = "0.10", optional = true }
106+
102107
[dev-dependencies]
103108
always_send = "0.1.1"
104109
clap = "4.5"
105110
env_logger = "0.11"
106111
tokio = { version = "1.49", features = ["full"] }
107112
native-tls = "0.2"
108-
openssl = "0.10"
109-
tokio-openssl = "0.6"
110113
pin-project = "1.1.10"
111114

112115
# Bearer authentication, used in examples
113116
jsonwebtoken = {version = "10.0.0", features = ["rust_crypto"]}
114117

118+
[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dev-dependencies]
119+
openssl = "0.10"
120+
tokio-openssl = "0.6"
121+
115122
[[example]]
116123
name = "client"
117124
required-features = ["client"]

samples/server/petstore/rust-server/output/multipart-v3/README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,9 @@ The generated library has a few optional features that can be activated through
112112
* This defaults to enabled and creates the basic skeleton of a client implementation based on hyper
113113
* The constructed client implements the API trait by making remote API call.
114114
* `client-tls`
115-
* Optional feature that provides HTTPS support with automatic TLS backend selection:
115+
* This default to enabled and provides HTTPS support with automatic TLS backend selection:
116116
- macOS/Windows/iOS: native-tls + hyper-tls
117117
- Linux/Unix/others: OpenSSL + hyper-openssl
118-
* Not enabled by default to minimize dependencies.
119118
* `conversions`
120119
* This defaults to disabled and creates extra derives on models to allow "transmogrification" between objects of structurally similar types.
121120
* `cli`
@@ -124,13 +123,13 @@ The generated library has a few optional features that can be activated through
124123
* This defaults to disabled and allows JSON Schema validation of received data using `MakeService::set_validation` or `Service::set_validation`.
125124
* Note, enabling validation will have a performance penalty, especially if the API heavily uses regex based checks.
126125

127-
### Enabling HTTPS/TLS Support
126+
### HTTPS/TLS Support
128127

129-
By default, only HTTP support is included. To enable HTTPS, add the `client-tls` feature:
128+
HTTPS support is included by default. To disable it (for example, to reduce dependencies), you can:
130129

131130
```toml
132131
[dependencies]
133-
multipart-v3 = { version = "1.0.7", features = ["client-tls"] }
132+
multipart-v3 = { version = "1.0.7", default-features = false, features = ["client", "server"] }
134133
```
135134

136135
**For server with callbacks that need HTTPS:**
@@ -143,8 +142,6 @@ The TLS backend is automatically selected based on your target platform:
143142
- **macOS, Windows, iOS**: Uses `native-tls` (system TLS libraries)
144143
- **Linux, Unix, other platforms**: Uses `openssl`
145144

146-
This ensures the best compatibility and native integration on each platform.
147-
148145
See https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section for how to use features in your `Cargo.toml`.
149146

150147
## Documentation for API Endpoints

samples/server/petstore/rust-server/output/multipart-v3/src/client/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ impl<C> Client<
283283
> where
284284
C: Clone + Send + Sync + 'static
285285
{
286-
/// Create a client with a TLS connection to the server using native-tls.
286+
/// Create a client with a TLS connection to the server.
287287
///
288288
/// # Arguments
289289
/// * `base_path` - base path of the client API, i.e. "<https://www.my-api-implementation.com>"
@@ -297,7 +297,7 @@ impl<C> Client<
297297
Self::try_new_with_connector(base_path, Some("https"), https_connector)
298298
}
299299

300-
/// Create a client with a TLS connection to the server using OpenSSL.
300+
/// Create a client with a TLS connection to the server using OpenSSL via swagger.
301301
///
302302
/// # Arguments
303303
/// * `base_path` - base path of the client API, i.e. "<https://www.my-api-implementation.com>"
@@ -311,7 +311,7 @@ impl<C> Client<
311311
Self::try_new_with_connector(base_path, Some("https"), https_connector)
312312
}
313313

314-
/// Create a client with a TLS connection to the server using a pinned certificate
314+
/// Create a client with a TLS connection to the server using a pinned certificate.
315315
///
316316
/// # Arguments
317317
/// * `base_path` - base path of the client API, i.e. "<https://www.my-api-implementation.com>"

samples/server/petstore/rust-server/output/no-example-v3/Cargo.toml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ license = "Unlicense"
88
edition = "2018"
99

1010
[features]
11-
default = ["client", "server"]
11+
default = ["client", "server", "client-tls"]
1212
client = [
1313
"hyper", "percent-encoding", "hyper-util/http1", "hyper-util/http2", "url"
1414
]
@@ -68,12 +68,6 @@ url = { version = "2.5", optional = true }
6868
# Client-specific
6969
tower-service = "0.3.3"
7070

71-
# TLS support - all listed here, actual usage determined by cfg attributes in code
72-
native-tls = { version = "0.2", optional = true }
73-
hyper-tls = { version = "0.6", optional = true }
74-
openssl = { version = "0.10", optional = true }
75-
hyper-openssl = { version = "0.10", optional = true }
76-
7771
# Server, and client callback-specific
7872
lazy_static = { version = "1.5", optional = true }
7973
regex = { version = "1.12", optional = true }
@@ -93,19 +87,32 @@ frunk_core = { version = "0.4.3", optional = true }
9387
frunk-enum-derive = { version = "0.3.0", optional = true }
9488
frunk-enum-core = { version = "0.3.0", optional = true }
9589

90+
# TLS dependencies - platform-specific backends
91+
# On macOS/Windows/iOS, use native-tls via hyper-tls
92+
[target.'cfg(any(target_os = "macos", target_os = "windows", target_os = "ios"))'.dependencies]
93+
native-tls = { version = "0.2", optional = true }
94+
hyper-tls = { version = "0.6", optional = true }
95+
96+
# On other platforms (Linux, etc.), use OpenSSL via hyper-openssl
97+
[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dependencies]
98+
openssl = { version = "0.10", optional = true }
99+
hyper-openssl = { version = "0.10", optional = true }
100+
96101
[dev-dependencies]
97102
always_send = "0.1.1"
98103
clap = "4.5"
99104
env_logger = "0.11"
100105
tokio = { version = "1.49", features = ["full"] }
101106
native-tls = "0.2"
102-
openssl = "0.10"
103-
tokio-openssl = "0.6"
104107
pin-project = "1.1.10"
105108

106109
# Bearer authentication, used in examples
107110
jsonwebtoken = {version = "10.0.0", features = ["rust_crypto"]}
108111

112+
[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dev-dependencies]
113+
openssl = "0.10"
114+
tokio-openssl = "0.6"
115+
109116
[[example]]
110117
name = "client"
111118
required-features = ["client"]

samples/server/petstore/rust-server/output/no-example-v3/README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,9 @@ The generated library has a few optional features that can be activated through
109109
* This defaults to enabled and creates the basic skeleton of a client implementation based on hyper
110110
* The constructed client implements the API trait by making remote API call.
111111
* `client-tls`
112-
* Optional feature that provides HTTPS support with automatic TLS backend selection:
112+
* This default to enabled and provides HTTPS support with automatic TLS backend selection:
113113
- macOS/Windows/iOS: native-tls + hyper-tls
114114
- Linux/Unix/others: OpenSSL + hyper-openssl
115-
* Not enabled by default to minimize dependencies.
116115
* `conversions`
117116
* This defaults to disabled and creates extra derives on models to allow "transmogrification" between objects of structurally similar types.
118117
* `cli`
@@ -121,13 +120,13 @@ The generated library has a few optional features that can be activated through
121120
* This defaults to disabled and allows JSON Schema validation of received data using `MakeService::set_validation` or `Service::set_validation`.
122121
* Note, enabling validation will have a performance penalty, especially if the API heavily uses regex based checks.
123122

124-
### Enabling HTTPS/TLS Support
123+
### HTTPS/TLS Support
125124

126-
By default, only HTTP support is included. To enable HTTPS, add the `client-tls` feature:
125+
HTTPS support is included by default. To disable it (for example, to reduce dependencies), you can:
127126

128127
```toml
129128
[dependencies]
130-
no-example-v3 = { version = "0.0.1", features = ["client-tls"] }
129+
no-example-v3 = { version = "0.0.1", default-features = false, features = ["client", "server"] }
131130
```
132131

133132
**For server with callbacks that need HTTPS:**
@@ -140,8 +139,6 @@ The TLS backend is automatically selected based on your target platform:
140139
- **macOS, Windows, iOS**: Uses `native-tls` (system TLS libraries)
141140
- **Linux, Unix, other platforms**: Uses `openssl`
142141

143-
This ensures the best compatibility and native integration on each platform.
144-
145142
See https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section for how to use features in your `Cargo.toml`.
146143

147144
## Documentation for API Endpoints

samples/server/petstore/rust-server/output/no-example-v3/src/client/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ impl<C> Client<
276276
> where
277277
C: Clone + Send + Sync + 'static
278278
{
279-
/// Create a client with a TLS connection to the server using native-tls.
279+
/// Create a client with a TLS connection to the server.
280280
///
281281
/// # Arguments
282282
/// * `base_path` - base path of the client API, i.e. "<https://www.my-api-implementation.com>"
@@ -290,7 +290,7 @@ impl<C> Client<
290290
Self::try_new_with_connector(base_path, Some("https"), https_connector)
291291
}
292292

293-
/// Create a client with a TLS connection to the server using OpenSSL.
293+
/// Create a client with a TLS connection to the server using OpenSSL via swagger.
294294
///
295295
/// # Arguments
296296
/// * `base_path` - base path of the client API, i.e. "<https://www.my-api-implementation.com>"
@@ -304,7 +304,7 @@ impl<C> Client<
304304
Self::try_new_with_connector(base_path, Some("https"), https_connector)
305305
}
306306

307-
/// Create a client with a TLS connection to the server using a pinned certificate
307+
/// Create a client with a TLS connection to the server using a pinned certificate.
308308
///
309309
/// # Arguments
310310
/// * `base_path` - base path of the client API, i.e. "<https://www.my-api-implementation.com>"

0 commit comments

Comments
 (0)