Skip to content

Commit 453997b

Browse files
authored
Ensure rust-server compiles with no-default-features (#22445)
1 parent e9bc44b commit 453997b

File tree

51 files changed

+148
-131
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+148
-131
lines changed

.github/workflows/samples-rust-server.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ jobs:
3939
4040
- name: Build
4141
working-directory: ${{ matrix.sample }}
42-
run: cargo build --all-targets --all-features
42+
run: |
43+
set -e
44+
cargo build --all-targets --all-features
45+
cargo build --all-targets --no-default-features
4346
- name: Tests
4447
working-directory: ${{ matrix.sample }}
4548
run: |

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,10 @@ public CodegenModel fromModel(String name, Schema model) {
12331233
additionalProperties.put("apiUsesUuid", true);
12341234
}
12351235

1236+
if (prop.isByteArray) {
1237+
additionalProperties.put("apiUsesByteArray", true);
1238+
}
1239+
12361240
String xmlName = modelXmlNames.get(prop.dataType);
12371241
if (xmlName != null) {
12381242
prop.vendorExtensions.put("x-item-xml-name", xmlName);
@@ -1535,6 +1539,11 @@ private void processParam(CodegenParameter param, CodegenOperation op) {
15351539
additionalProperties.put("apiUsesUuid", true);
15361540
}
15371541

1542+
// If a parameter uses byte arrays, we need to set a flag.
1543+
if (param.isByteArray) {
1544+
additionalProperties.put("apiUsesByteArray", true);
1545+
}
1546+
15381547
if (Boolean.TRUE.equals(param.isFreeFormObject)) {
15391548
param.vendorExtensions.put("x-format-string", "{:?}");
15401549
example = null;

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegenDeprecated.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,10 @@ public CodegenModel fromModel(String name, Schema model) {
12131213
additionalProperties.put("apiUsesUuid", true);
12141214
}
12151215

1216+
if (prop.isByteArray) {
1217+
additionalProperties.put("apiUsesByteArray", true);
1218+
}
1219+
12161220
String xmlName = modelXmlNames.get(prop.dataType);
12171221
if (xmlName != null) {
12181222
prop.vendorExtensions.put("x-item-xml-name", xmlName);
@@ -1515,6 +1519,11 @@ private void processParam(CodegenParameter param, CodegenOperation op) {
15151519
additionalProperties.put("apiUsesUuid", true);
15161520
}
15171521

1522+
// If a parameter uses byte arrays, we need to set a flag.
1523+
if (param.isByteArray) {
1524+
additionalProperties.put("apiUsesByteArray", true);
1525+
}
1526+
15181527
if (Boolean.TRUE.equals(param.isFreeFormObject)) {
15191528
param.vendorExtensions.put("x-format-string", "{:?}");
15201529
example = null;

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ client = [
4747
"serde_urlencoded",
4848
{{/usesUrlEncodedForm}}
4949
{{#hasCallbacks}}
50-
"serde_ignored", "regex", "percent-encoding", "lazy_static",
50+
"serde_ignored", "percent-encoding", {{^apiUsesByteArray}}"lazy_static", "regex",{{/apiUsesByteArray}}
5151
{{/hasCallbacks}}
5252
{{! Anything added to the list below, should probably be added to the callbacks list below }}
5353
"hyper", "hyper-openssl", "hyper-tls", "native-tls", "openssl", "url"
@@ -66,7 +66,7 @@ server = [
6666
"native-tls", "hyper-openssl", "hyper-tls", "openssl",
6767
{{/hasCallbacks}}
6868
{{! Anything added to the list below, should probably be added to the callbacks list above }}
69-
"serde_ignored", "hyper", "regex", "percent-encoding", "url", "lazy_static"
69+
"serde_ignored", "hyper", "percent-encoding", "url" {{^apiUsesByteArray}},"lazy_static", "regex"{{/apiUsesByteArray}}
7070
]
7171
cli = [
7272
{{#apiHasDeleteMethods}}
@@ -96,6 +96,10 @@ mime = "0.3"
9696
serde = { version = "1.0", features = ["derive"] }
9797
serde_json = "1.0"
9898
validator = { version = "0.16", features = ["derive"] }
99+
{{#apiUsesByteArray}}
100+
lazy_static = "1.5"
101+
regex = "1.12"
102+
{{/apiUsesByteArray}}
99103

100104
# Crates included if required by the API definition
101105
{{#usesXml}}
@@ -126,9 +130,11 @@ serde_urlencoded = {version = "0.6.1", optional = true}
126130
{{/usesUrlEncodedForm}}
127131

128132
# Server, and client callback-specific
133+
{{^apiUsesByteArray}}
129134
lazy_static = { version = "1.4", optional = true }
130-
percent-encoding = {version = "2.1.0", optional = true}
131135
regex = {version = "1.3", optional = true}
136+
{{/apiUsesByteArray}}
137+
percent-encoding = {version = "2.1.0", optional = true}
132138

133139
# CLI-specific
134140
anyhow = { version = "1", optional = true }

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::collections::BTreeSet;
2-
use crate::server::Authorization;
32
use serde::{Deserialize, Serialize};
4-
use swagger::{ApiError, auth::{Basic, Bearer}};
3+
use swagger::{ApiError, auth::{Basic, Bearer, Authorization}};
54

65
#[derive(Debug, Serialize, Deserialize)]
76
pub struct Claims {
@@ -24,7 +23,7 @@ pub trait AuthenticationApi {
2423
2524
/// Method should be implemented (see example-code) to map Basic (Username:password) to an Authorization
2625
fn basic_authorization(&self, basic: &Basic) -> Result<Authorization, ApiError>;
27-
}
26+
}
2827

2928
// Implement it for AllowAllAuthenticator (dummy is needed, but should not used as we have Bearer authorization)
3029
use swagger::auth::{AllowAllAuthenticator, RcBound, Scopes};

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ use futures::Stream;
66
use std::error::Error;
77
use std::collections::BTreeSet;
88
use std::task::{Poll, Context};
9-
use swagger::{ApiError, ContextWrapper};
9+
use swagger::{ApiError, ContextWrapper, auth::Authorization};
1010
use serde::{Serialize, Deserialize};
11-
use crate::server::Authorization;
12-
1311

1412
type ServiceError = Box<dyn Error + Send + Sync + 'static>;
1513

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ client = [
4444
"serde_urlencoded",
4545
{{/usesUrlEncodedForm}}
4646
{{#hasCallbacks}}
47-
"serde_ignored", "regex", "percent-encoding", "lazy_static",
47+
"serde_ignored", "percent-encoding", {{^apiUsesByteArray}}"lazy_static", "regex"{{/apiUsesByteArray}}
4848
{{/hasCallbacks}}
4949
{{! Anything added to the list below, should probably be added to the callbacks list below }}
5050
"hyper", "hyper-util/http1", "hyper-util/http2", "hyper-openssl", "hyper-tls", "native-tls", "openssl", "url"
@@ -60,7 +60,8 @@ server = [
6060
"native-tls", "hyper-openssl", "hyper-tls", "openssl",
6161
{{/hasCallbacks}}
6262
{{! Anything added to the list below, should probably be added to the callbacks list above }}
63-
"serde_ignored", "hyper", "regex", "percent-encoding", "url", "lazy_static"
63+
"serde_ignored", "hyper", "percent-encoding", "url",
64+
{{^apiUsesByteArray}}"lazy_static", "regex"{{/apiUsesByteArray}}
6465
]
6566
cli = [
6667
{{#apiHasDeleteMethods}}
@@ -88,8 +89,14 @@ futures = "0.3"
8889
swagger = { version = "7.0.0", features = ["serdejson", "server", "client", "tls"] }
8990
headers = "0.4.0"
9091
log = "0.4.27"
92+
9193
mime = "0.3"
9294
mockall = { version = "0.13.1", optional = true }
95+
{{#apiUsesByteArray}}
96+
lazy_static = "1.5"
97+
regex = "1.12"
98+
{{/apiUsesByteArray}}
99+
93100

94101
serde = { version = "1.0", features = ["derive"] }
95102
serde_json = "1.0"
@@ -124,9 +131,11 @@ serde_urlencoded = { version = "0.7.1", optional = true }
124131
tower-service = "0.3.3"
125132

126133
# Server, and client callback-specific
134+
{{^apiUsesByteArray}}
127135
lazy_static = { version = "1.5", optional = true }
128-
percent-encoding = { version = "2.3.1", optional = true }
129136
regex = { version = "1.12", optional = true }
137+
{{/apiUsesByteArray}}
138+
percent-encoding = { version = "2.3.1", optional = true }
130139

131140
# CLI-specific
132141
anyhow = { version = "1", optional = true }

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::collections::BTreeSet;
2-
use crate::server::Authorization;
32
use serde::{Deserialize, Serialize};
4-
use swagger::ApiError;
3+
use swagger::{ApiError, auth::Authorization};
54
use headers::authorization::{Basic, Bearer};
65
#[derive(Debug, Serialize, Deserialize)]
76
pub struct Claims {

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ use mockall::automock;
88
use std::error::Error;
99
use std::collections::BTreeSet;
1010
use std::task::{Poll, Context};
11-
use swagger::{ApiError, ContextWrapper};
11+
use swagger::{ApiError, ContextWrapper, auth::Authorization};
1212
use serde::{Serialize, Deserialize};
13-
use crate::server::Authorization;
14-
1513

14+
#[cfg(any(feature = "client", feature = "server"))]
1615
type ServiceError = Box<dyn Error + Send + Sync + 'static>;
1716
1817
pub const BASE_PATH: &str = "{{{basePathWithoutHost}}}";

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ server = [
1919
"mime_0_2",
2020
"multipart", "multipart/server", "swagger/multipart_form",
2121
"hyper_0_10", "mime_multipart", "swagger/multipart_related",
22-
"serde_ignored", "hyper", "regex", "percent-encoding", "url", "lazy_static"
22+
"serde_ignored", "hyper", "percent-encoding", "url"
2323
]
2424
cli = [
2525
"anyhow", "clap-verbosity-flag", "simple_logger", "structopt", "tokio"
@@ -46,6 +46,8 @@ mime = "0.3"
4646
serde = { version = "1.0", features = ["derive"] }
4747
serde_json = "1.0"
4848
validator = { version = "0.16", features = ["derive"] }
49+
lazy_static = "1.5"
50+
regex = "1.12"
4951

5052
# Crates included if required by the API definition
5153
mime_0_2 = { package = "mime", version = "0.2.6", optional = true }
@@ -61,9 +63,7 @@ url = {version = "2.1", optional = true}
6163
# Client-specific
6264

6365
# Server, and client callback-specific
64-
lazy_static = { version = "1.4", optional = true }
6566
percent-encoding = {version = "2.1.0", optional = true}
66-
regex = {version = "1.3", optional = true}
6767

6868
# CLI-specific
6969
anyhow = { version = "1", optional = true }

0 commit comments

Comments
 (0)