Skip to content

Commit 074daaf

Browse files
committed
fix: Rust-server bytes response fixed to not attempt string conversion
1 parent c0d9886 commit 074daaf

5 files changed

Lines changed: 15 additions & 19 deletions

File tree

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,10 +1233,6 @@ 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-
12401236
String xmlName = modelXmlNames.get(prop.dataType);
12411237
if (xmlName != null) {
12421238
prop.vendorExtensions.put("x-item-xml-name", xmlName);
@@ -1539,11 +1535,6 @@ private void processParam(CodegenParameter param, CodegenOperation op) {
15391535
additionalProperties.put("apiUsesUuid", true);
15401536
}
15411537

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

modules/openapi-generator/src/main/resources/rust-server/server-response-body-instance.mustache

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,10 @@
4444
{{/formParams}}
4545
{{/x-produces-multipart-related}}
4646
{{/exts}}
47+
{{#x-produces-bytes}}
48+
*response.body_mut() = BoxBody::new(Full::new(Bytes::from(body.0)));
49+
{{/x-produces-bytes}}
50+
{{^x-produces-bytes}}
4751
*response.body_mut() = body_from_string(body);
52+
{{/x-produces-bytes}}
4853
{{/dataType}}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ server = [
1818
"multipart", "multipart/server", "swagger/multipart_form",
1919
"mime_multipart", "swagger/multipart_related",
2020
"serde_ignored", "hyper", "percent-encoding", "url",
21-
21+
"lazy_static", "regex"
2222
]
2323
cli = [
2424
"anyhow", "clap", "clap-verbosity-flag", "simple_logger", "tokio"
@@ -46,8 +46,6 @@ log = "0.4.27"
4646

4747
mime = "0.3"
4848
mockall = { version = "0.13.1", optional = true }
49-
lazy_static = "1.5"
50-
regex = "1.12"
5149

5250

5351
serde = { version = "1.0", features = ["derive"] }
@@ -70,6 +68,8 @@ url = { version = "2.5", optional = true }
7068
tower-service = "0.3.3"
7169

7270
# Server, and client callback-specific
71+
lazy_static = { version = "1.5", optional = true }
72+
regex = { version = "1.12", optional = true }
7373
percent-encoding = { version = "2.3.1", optional = true }
7474

7575
# CLI-specific

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ edition = "2018"
1111
default = ["client", "server"]
1212
client = [
1313
"serde_urlencoded",
14-
"serde_ignored", "percent-encoding",
14+
"serde_ignored", "percent-encoding", "lazy_static", "regex"
1515
"hyper", "hyper-util/http1", "hyper-util/http2", "hyper-openssl", "hyper-tls", "native-tls", "openssl", "url"
1616
]
1717
server = [
1818
"native-tls", "hyper-openssl", "hyper-tls", "openssl",
1919
"serde_ignored", "hyper", "percent-encoding", "url",
20-
20+
"lazy_static", "regex"
2121
]
2222
cli = [
2323
"anyhow", "clap", "clap-verbosity-flag", "simple_logger", "tokio"
@@ -45,8 +45,6 @@ log = "0.4.27"
4545

4646
mime = "0.3"
4747
mockall = { version = "0.13.1", optional = true }
48-
lazy_static = "1.5"
49-
regex = "1.12"
5048

5149

5250
serde = { version = "1.0", features = ["derive"] }
@@ -70,6 +68,8 @@ serde_urlencoded = { version = "0.7.1", optional = true }
7068
tower-service = "0.3.3"
7169

7270
# Server, and client callback-specific
71+
lazy_static = { version = "1.5", optional = true }
72+
regex = { version = "1.12", optional = true }
7373
percent-encoding = { version = "2.3.1", optional = true }
7474

7575
# CLI-specific

samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ client = [
1717
server = [
1818
"multipart", "multipart/server", "swagger/multipart_form",
1919
"serde_ignored", "hyper", "percent-encoding", "url",
20-
20+
"lazy_static", "regex"
2121
]
2222
cli = [
2323
"dialoguer",
@@ -46,8 +46,6 @@ log = "0.4.27"
4646

4747
mime = "0.3"
4848
mockall = { version = "0.13.1", optional = true }
49-
lazy_static = "1.5"
50-
regex = "1.12"
5149

5250

5351
serde = { version = "1.0", features = ["derive"] }
@@ -72,6 +70,8 @@ serde_urlencoded = { version = "0.7.1", optional = true }
7270
tower-service = "0.3.3"
7371

7472
# Server, and client callback-specific
73+
lazy_static = { version = "1.5", optional = true }
74+
regex = { version = "1.12", optional = true }
7575
percent-encoding = { version = "2.3.1", optional = true }
7676

7777
# CLI-specific

0 commit comments

Comments
 (0)