Skip to content

Commit 02ef6ed

Browse files
committed
Ensure rust-server compiles with no-default-features
1 parent 578bdbe commit 02ef6ed

File tree

26 files changed

+88
-62
lines changed

26 files changed

+88
-62
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/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/output/multipart-v3/Cargo.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ client = [
1717
server = [
1818
"multipart", "multipart/server", "swagger/multipart_form",
1919
"mime_multipart", "swagger/multipart_related",
20-
"serde_ignored", "hyper", "regex", "percent-encoding", "url", "lazy_static"
20+
"serde_ignored", "hyper", "percent-encoding", "url",
21+
2122
]
2223
cli = [
2324
"anyhow", "clap", "clap-verbosity-flag", "simple_logger", "tokio"
@@ -42,8 +43,12 @@ futures = "0.3"
4243
swagger = { version = "7.0.0", features = ["serdejson", "server", "client", "tls"] }
4344
headers = "0.4.0"
4445
log = "0.4.27"
46+
4547
mime = "0.3"
4648
mockall = { version = "0.13.1", optional = true }
49+
lazy_static = "1.5"
50+
regex = "1.12"
51+
4752

4853
serde = { version = "1.0", features = ["derive"] }
4954
serde_json = "1.0"
@@ -65,9 +70,7 @@ url = { version = "2.5", optional = true }
6570
tower-service = "0.3.3"
6671

6772
# Server, and client callback-specific
68-
lazy_static = { version = "1.5", optional = true }
6973
percent-encoding = { version = "2.3.1", optional = true }
70-
regex = { version = "1.12", optional = true }
7174

7275
# CLI-specific
7376
anyhow = { version = "1", optional = true }

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

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 {

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

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 = "";

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ client = [
1313
"hyper", "hyper-util/http1", "hyper-util/http2", "hyper-openssl", "hyper-tls", "native-tls", "openssl", "url"
1414
]
1515
server = [
16-
"serde_ignored", "hyper", "regex", "percent-encoding", "url", "lazy_static"
16+
"serde_ignored", "hyper", "percent-encoding", "url",
17+
"lazy_static", "regex"
1718
]
1819
cli = [
1920
"anyhow", "clap", "clap-verbosity-flag", "simple_logger", "tokio"
@@ -38,9 +39,11 @@ futures = "0.3"
3839
swagger = { version = "7.0.0", features = ["serdejson", "server", "client", "tls"] }
3940
headers = "0.4.0"
4041
log = "0.4.27"
42+
4143
mime = "0.3"
4244
mockall = { version = "0.13.1", optional = true }
4345

46+
4447
serde = { version = "1.0", features = ["derive"] }
4548
serde_json = "1.0"
4649
validator = { version = "0.20", features = ["derive"] }
@@ -60,8 +63,8 @@ tower-service = "0.3.3"
6063

6164
# Server, and client callback-specific
6265
lazy_static = { version = "1.5", optional = true }
63-
percent-encoding = { version = "2.3.1", optional = true }
6466
regex = { version = "1.12", optional = true }
67+
percent-encoding = { version = "2.3.1", optional = true }
6568

6669
# CLI-specific
6770
anyhow = { version = "1", optional = true }

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

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 {

0 commit comments

Comments
 (0)