From 2faffc6f110509bca396cddc1b22c0b10e2311f0 Mon Sep 17 00:00:00 2001 From: Alice Twist Date: Wed, 24 Jun 2026 09:29:03 +0100 Subject: [PATCH] [rust-server] Fix panic on binary request bodies coerced to UTF-8 --- .../resources/rust-server/client-mod.mustache | 5 + .../client-request-body-instance.mustache | 10 +- .../codegen/rust/RustServerCodegenTest.java | 29 ++++++ .../resources/3_0/rust-server/openapi-v3.yaml | 12 +++ .../output/openapi-v3/README.md | 2 + .../output/openapi-v3/api/openapi.yaml | 12 +++ .../output/openapi-v3/bin/cli.rs | 21 ++++ .../output/openapi-v3/docs/default_api.md | 26 +++++ .../output/openapi-v3/examples/client/main.rs | 8 ++ .../openapi-v3/examples/server/server.rs | 9 ++ .../output/openapi-v3/src/client/mod.rs | 75 ++++++++++++++ .../output/openapi-v3/src/lib.rs | 24 +++++ .../output/openapi-v3/src/server/mod.rs | 74 ++++++++++++-- .../output/multipart-v3/src/client/mod.rs | 5 + .../output/no-example-v3/src/client/mod.rs | 5 + .../rust-server/output/openapi-v3/README.md | 2 + .../output/openapi-v3/api/openapi.yaml | 12 +++ .../rust-server/output/openapi-v3/bin/cli.rs | 21 ++++ .../output/openapi-v3/docs/default_api.md | 26 +++++ .../output/openapi-v3/examples/client/main.rs | 8 ++ .../openapi-v3/examples/server/server.rs | 10 ++ .../output/openapi-v3/src/client/mod.rs | 87 +++++++++++++++- .../rust-server/output/openapi-v3/src/lib.rs | 25 +++++ .../output/openapi-v3/src/server/mod.rs | 98 +++++++++++++++++-- .../output/ops-v3/src/client/mod.rs | 5 + .../src/client/mod.rs | 5 + .../output/ping-bearer-auth/src/client/mod.rs | 5 + .../output/rust-server-test/src/client/mod.rs | 5 + 28 files changed, 605 insertions(+), 21 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/rust-server/client-mod.mustache b/modules/openapi-generator/src/main/resources/rust-server/client-mod.mustache index cc9569c92b78..47723dc4d95c 100644 --- a/modules/openapi-generator/src/main/resources/rust-server/client-mod.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server/client-mod.mustache @@ -391,6 +391,11 @@ fn body_from_string(s: String) -> BoxBody { BoxBody::new(Full::new(Bytes::from(s))) } +#[allow(dead_code)] +fn body_from_bytes(b: Vec) -> BoxBody { + BoxBody::new(Full::new(Bytes::from(b))) +} + #[async_trait] impl Api for Client where S: Service< diff --git a/modules/openapi-generator/src/main/resources/rust-server/client-request-body-instance.mustache b/modules/openapi-generator/src/main/resources/rust-server/client-request-body-instance.mustache index 55806f12df72..5a1c0d162fff 100644 --- a/modules/openapi-generator/src/main/resources/rust-server/client-request-body-instance.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server/client-request-body-instance.mustache @@ -83,23 +83,27 @@ {{^isByteArray}} {{^isBinary}} let body = param_{{{paramName}}}; + *request.body_mut() = body_from_string(body); {{/isBinary}} {{/isByteArray}} {{#isByteArray}} - let body = String::from_utf8(param_{{{paramName}}}.0).expect("Body was not valid UTF8"); + // Raw binary body - pass the bytes through without coercing to UTF-8. + *request.body_mut() = body_from_bytes(param_{{{paramName}}}.0); {{/isByteArray}} {{#isBinary}} - let body = String::from_utf8(param_{{{paramName}}}.0).expect("Body was not valid UTF8"); + // Raw binary body - pass the bytes through without coercing to UTF-8. + *request.body_mut() = body_from_bytes(param_{{{paramName}}}.0); {{/isBinary}} {{/x-consumes-plain-text}} {{#x-consumes-xml}} let body = param_{{{paramName}}}.as_xml(); + *request.body_mut() = body_from_string(body); {{/x-consumes-xml}} {{#x-consumes-json}} let body = serde_json::to_string(¶m_{{{paramName}}}).expect("impossible to fail to serialize"); + *request.body_mut() = body_from_string(body); {{/x-consumes-json}} {{/exts}} - *request.body_mut() = body_from_string(body); {{^required}} } {{/required}} diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/rust/RustServerCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/rust/RustServerCodegenTest.java index e6d664e26762..ab515ec7eebb 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/rust/RustServerCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/rust/RustServerCodegenTest.java @@ -112,4 +112,33 @@ public void testRequiredQueryParamWithoutExampleDisablesClientExample() throws I // Clean up target.toFile().deleteOnExit(); } + + /** + * Test that binary/byte request bodies are passed through as raw bytes rather than being + * coerced to UTF-8, which panics on any non-UTF-8 payload (see issue #24094). + */ + @Test + public void testBinaryRequestBodyNotCoercedToUtf8() throws IOException { + Path target = Files.createTempDirectory("test"); + final CodegenConfigurator configurator = new CodegenConfigurator() + .setGeneratorName("rust-server") + .setInputSpec("src/test/resources/3_0/rust-server/openapi-v3.yaml") + .setSkipOverwrite(false) + .setOutputDir(target.toAbsolutePath().toString().replace("\\", "/")); + List files = new DefaultGenerator().opts(configurator.toClientOptInput()).generate(); + files.forEach(File::deleteOnExit); + + Path clientModPath = Path.of(target.toString(), "/src/client/mod.rs"); + TestUtils.assertFileExists(clientModPath); + + // format: binary request body should pass raw bytes through. + TestUtils.assertFileContains(clientModPath, "*request.body_mut() = body_from_bytes(param_body.0);"); + // The bytes helper must be generated. + TestUtils.assertFileContains(clientModPath, "fn body_from_bytes(b: Vec) -> BoxBody {"); + // The request body must no longer be coerced to UTF-8 (would panic on non-UTF-8 payloads). + TestUtils.assertFileNotContains(clientModPath, "let body = String::from_utf8(param_body.0).expect(\"Body was not valid UTF8\");"); + + // Clean up + target.toFile().deleteOnExit(); + } } diff --git a/modules/openapi-generator/src/test/resources/3_0/rust-server/openapi-v3.yaml b/modules/openapi-generator/src/test/resources/3_0/rust-server/openapi-v3.yaml index 69ae83c5bd64..31ddec7303bf 100644 --- a/modules/openapi-generator/src/test/resources/3_0/rust-server/openapi-v3.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/rust-server/openapi-v3.yaml @@ -210,6 +210,18 @@ paths: responses: '200': description: 'OK' + /required_binary_stream: + put: + requestBody: + required: true + content: + application/octet-stream: + schema: + type: string + format: binary + responses: + '200': + description: 'OK' /readonly_auth_scheme: get: security: diff --git a/samples/server/petstore/rust-server-deprecated/output/openapi-v3/README.md b/samples/server/petstore/rust-server-deprecated/output/openapi-v3/README.md index 89f9743223f1..9a09a5849b95 100644 --- a/samples/server/petstore/rust-server-deprecated/output/openapi-v3/README.md +++ b/samples/server/petstore/rust-server-deprecated/output/openapi-v3/README.md @@ -103,6 +103,7 @@ cargo run --example openapi-v3-client ParamgetGet cargo run --example openapi-v3-client QueryExampleGet cargo run --example openapi-v3-client ReadonlyAuthSchemeGet cargo run --example openapi-v3-client RegisterCallbackPost +cargo run --example openapi-v3-client RequiredBinaryStreamPut cargo run --example openapi-v3-client RequiredOctetStreamPut cargo run --example openapi-v3-client ResponsesWithHeadersGet cargo run --example openapi-v3-client Rfc7807Get @@ -170,6 +171,7 @@ Method | HTTP request | Description [**queryExampleGet**](docs/default_api.md#queryExampleGet) | **GET** /query-example | Test required query params with and without examples [****](docs/default_api.md#) | **GET** /readonly_auth_scheme | [****](docs/default_api.md#) | **POST** /register-callback | +[****](docs/default_api.md#) | **PUT** /required_binary_stream | [****](docs/default_api.md#) | **PUT** /required_octet_stream | [****](docs/default_api.md#) | **GET** /responses_with_headers | [****](docs/default_api.md#) | **GET** /rfc7807 | diff --git a/samples/server/petstore/rust-server-deprecated/output/openapi-v3/api/openapi.yaml b/samples/server/petstore/rust-server-deprecated/output/openapi-v3/api/openapi.yaml index 9e1e521879f3..e05db02b4ad4 100644 --- a/samples/server/petstore/rust-server-deprecated/output/openapi-v3/api/openapi.yaml +++ b/samples/server/petstore/rust-server-deprecated/output/openapi-v3/api/openapi.yaml @@ -198,6 +198,18 @@ paths: responses: "200": description: OK + /required_binary_stream: + put: + requestBody: + content: + application/octet-stream: + schema: + format: binary + type: string + required: true + responses: + "200": + description: OK /readonly_auth_scheme: get: responses: diff --git a/samples/server/petstore/rust-server-deprecated/output/openapi-v3/bin/cli.rs b/samples/server/petstore/rust-server-deprecated/output/openapi-v3/bin/cli.rs index d2c022bdc3ad..0fab15ac198b 100644 --- a/samples/server/petstore/rust-server-deprecated/output/openapi-v3/bin/cli.rs +++ b/samples/server/petstore/rust-server-deprecated/output/openapi-v3/bin/cli.rs @@ -22,6 +22,7 @@ use openapi_v3::{ QueryExampleGetResponse, ReadonlyAuthSchemeGetResponse, RegisterCallbackPostResponse, + RequiredBinaryStreamPutResponse, RequiredOctetStreamPutResponse, ResponsesWithHeadersGetResponse, Rfc7807GetResponse, @@ -162,6 +163,10 @@ enum Operation { RegisterCallbackPost { url: String, }, + RequiredBinaryStreamPut { + #[structopt(parse(try_from_str = parse_json))] + body: swagger::ByteArray, + }, RequiredOctetStreamPut { #[structopt(parse(try_from_str = parse_json))] body: swagger::ByteArray, @@ -600,6 +605,22 @@ async fn main() -> Result<()> { , } } + Operation::RequiredBinaryStreamPut { + body, + } => { + info!("Performing a RequiredBinaryStreamPut request"); + + let result = client.required_binary_stream_put( + body, + ).await?; + debug!("Result: {:?}", result); + + match result { + RequiredBinaryStreamPutResponse::OK + => "OK\n".to_string() + , + } + } Operation::RequiredOctetStreamPut { body, } => { diff --git a/samples/server/petstore/rust-server-deprecated/output/openapi-v3/docs/default_api.md b/samples/server/petstore/rust-server-deprecated/output/openapi-v3/docs/default_api.md index 0fec99e704d2..ae6efb8add9e 100644 --- a/samples/server/petstore/rust-server-deprecated/output/openapi-v3/docs/default_api.md +++ b/samples/server/petstore/rust-server-deprecated/output/openapi-v3/docs/default_api.md @@ -21,6 +21,7 @@ Method | HTTP request | Description **queryExampleGet**](default_api.md#queryExampleGet) | **GET** /query-example | Test required query params with and without examples ****](default_api.md#) | **GET** /readonly_auth_scheme | ****](default_api.md#) | **POST** /register-callback | +****](default_api.md#) | **PUT** /required_binary_stream | ****](default_api.md#) | **PUT** /required_octet_stream | ****](default_api.md#) | **GET** /responses_with_headers | ****](default_api.md#) | **GET** /rfc7807 | @@ -490,6 +491,31 @@ No authorization required > (body) +### Required Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **body** | **swagger::ByteArray**| | + +### Return type + + (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: application/octet-stream + - **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + +# **** +> (body) + + ### Required Parameters Name | Type | Description | Notes diff --git a/samples/server/petstore/rust-server-deprecated/output/openapi-v3/examples/client/main.rs b/samples/server/petstore/rust-server-deprecated/output/openapi-v3/examples/client/main.rs index b728a07075ac..29e8b8945ff6 100644 --- a/samples/server/petstore/rust-server-deprecated/output/openapi-v3/examples/client/main.rs +++ b/samples/server/petstore/rust-server-deprecated/output/openapi-v3/examples/client/main.rs @@ -23,6 +23,7 @@ use openapi_v3::{Api, ApiNoContext, Claims, Client, ContextWrapperExt, models, QueryExampleGetResponse, ReadonlyAuthSchemeGetResponse, RegisterCallbackPostResponse, + RequiredBinaryStreamPutResponse, RequiredOctetStreamPutResponse, ResponsesWithHeadersGetResponse, Rfc7807GetResponse, @@ -83,6 +84,7 @@ fn main() { "QueryExampleGet", "ReadonlyAuthSchemeGet", "RegisterCallbackPost", + "RequiredBinaryStreamPut", "RequiredOctetStreamPut", "ResponsesWithHeadersGet", "Rfc7807Get", @@ -274,6 +276,12 @@ fn main() { )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, + Some("RequiredBinaryStreamPut") => { + let result = rt.block_on(client.required_binary_stream_put( + swagger::ByteArray(Vec::from("BINARY_DATA_HERE")) + )); + info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); + }, Some("RequiredOctetStreamPut") => { let result = rt.block_on(client.required_octet_stream_put( swagger::ByteArray(Vec::from("BYTE_ARRAY_DATA_HERE")) diff --git a/samples/server/petstore/rust-server-deprecated/output/openapi-v3/examples/server/server.rs b/samples/server/petstore/rust-server-deprecated/output/openapi-v3/examples/server/server.rs index 1bcc542e1177..49dbe7086a0b 100644 --- a/samples/server/petstore/rust-server-deprecated/output/openapi-v3/examples/server/server.rs +++ b/samples/server/petstore/rust-server-deprecated/output/openapi-v3/examples/server/server.rs @@ -119,6 +119,7 @@ use openapi_v3::{ QueryExampleGetResponse, ReadonlyAuthSchemeGetResponse, RegisterCallbackPostResponse, + RequiredBinaryStreamPutResponse, RequiredOctetStreamPutResponse, ResponsesWithHeadersGetResponse, Rfc7807GetResponse, @@ -281,6 +282,14 @@ impl Api for Server where C: Has + Send + Sync info!("register_callback_post(\"{}\") - X-Span-ID: {:?}", url, context.get().0.clone()); Err(ApiError("Api-Error: Operation is NOT implemented".into())) } + async fn required_binary_stream_put( + &self, + body: swagger::ByteArray, + context: &C) -> Result + { + info!("required_binary_stream_put({:?}) - X-Span-ID: {:?}", body, context.get().0.clone()); + Err(ApiError("Api-Error: Operation is NOT implemented".into())) + } async fn required_octet_stream_put( &self, body: swagger::ByteArray, diff --git a/samples/server/petstore/rust-server-deprecated/output/openapi-v3/src/client/mod.rs b/samples/server/petstore/rust-server-deprecated/output/openapi-v3/src/client/mod.rs index d8fc3bac71b5..2b4f6646b551 100644 --- a/samples/server/petstore/rust-server-deprecated/output/openapi-v3/src/client/mod.rs +++ b/samples/server/petstore/rust-server-deprecated/output/openapi-v3/src/client/mod.rs @@ -55,6 +55,7 @@ use crate::{Api, QueryExampleGetResponse, ReadonlyAuthSchemeGetResponse, RegisterCallbackPostResponse, + RequiredBinaryStreamPutResponse, RequiredOctetStreamPutResponse, ResponsesWithHeadersGetResponse, Rfc7807GetResponse, @@ -1823,6 +1824,80 @@ impl Api for Client where } } } + async fn required_binary_stream_put( + &self, + param_body: swagger::ByteArray, + context: &C) -> Result + { + let mut client_service = self.client_service.clone(); + #[allow(clippy::uninlined_format_args)] + let mut uri = format!( + "{}/required_binary_stream", + self.base_path + ); + + // Query parameters + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { + uri += "?"; + uri += &query_string; + } + + let uri = match Uri::from_str(&uri) { + Ok(uri) => uri, + Err(err) => return Err(ApiError(format!("Unable to build URI: {err}"))), + }; + + let mut request = match Request::builder() + .method("PUT") + .uri(uri) + .body(Body::empty()) { + Ok(req) => req, + Err(e) => return Err(ApiError(format!("Unable to create request: {e}"))) + }; + + // Consumes basic body + // Body parameter + let body = param_body; + *request.body_mut() = Body::from(body); + + let header = "application/octet-stream"; + request.headers_mut().insert(CONTENT_TYPE, HeaderValue::from_static(header)); + let header = HeaderValue::from_str(Has::::get(context).0.as_str()); + request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { + Ok(h) => h, + Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {e}"))) + }); + + let response = client_service.call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {e}"))).await?; + + match response.status().as_u16() { + 200 => { + Ok( + RequiredBinaryStreamPutResponse::OK + ) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body() + .take(100) + .into_raw().await; + Err(ApiError(format!("Unexpected response code {code}:\n{headers:?}\n\n{}", + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!(""), + }, + Err(e) => format!(""), + } + ))) + } + } + } async fn required_octet_stream_put( &self, param_body: swagger::ByteArray, diff --git a/samples/server/petstore/rust-server-deprecated/output/openapi-v3/src/lib.rs b/samples/server/petstore/rust-server-deprecated/output/openapi-v3/src/lib.rs index 177f2b7bd156..60d8bf529bd7 100644 --- a/samples/server/petstore/rust-server-deprecated/output/openapi-v3/src/lib.rs +++ b/samples/server/petstore/rust-server-deprecated/output/openapi-v3/src/lib.rs @@ -144,6 +144,11 @@ pub enum RegisterCallbackPostResponse { OK } #[derive(Debug, PartialEq, Serialize, Deserialize)] +pub enum RequiredBinaryStreamPutResponse { + /// OK + OK +} +#[derive(Debug, PartialEq, Serialize, Deserialize)] pub enum RequiredOctetStreamPutResponse { /// OK OK @@ -377,6 +382,11 @@ pub trait Api { url: String, context: &C) -> Result; + async fn required_binary_stream_put( + &self, + body: swagger::ByteArray, + context: &C) -> Result; + async fn required_octet_stream_put( &self, body: swagger::ByteArray, @@ -551,6 +561,11 @@ pub trait ApiNoContext { url: String, ) -> Result; + async fn required_binary_stream_put( + &self, + body: swagger::ByteArray, + ) -> Result; + async fn required_octet_stream_put( &self, body: swagger::ByteArray, @@ -807,6 +822,15 @@ impl + Send + Sync, C: Clone + Send + Sync> ApiNoContext for Contex self.api().register_callback_post(url, &context).await } + async fn required_binary_stream_put( + &self, + body: swagger::ByteArray, + ) -> Result + { + let context = self.context().clone(); + self.api().required_binary_stream_put(body, &context).await + } + async fn required_octet_stream_put( &self, body: swagger::ByteArray, diff --git a/samples/server/petstore/rust-server-deprecated/output/openapi-v3/src/server/mod.rs b/samples/server/petstore/rust-server-deprecated/output/openapi-v3/src/server/mod.rs index 692f1e2b2d37..a7954cb838b6 100644 --- a/samples/server/petstore/rust-server-deprecated/output/openapi-v3/src/server/mod.rs +++ b/samples/server/petstore/rust-server-deprecated/output/openapi-v3/src/server/mod.rs @@ -41,6 +41,7 @@ use crate::{Api, QueryExampleGetResponse, ReadonlyAuthSchemeGetResponse, RegisterCallbackPostResponse, + RequiredBinaryStreamPutResponse, RequiredOctetStreamPutResponse, ResponsesWithHeadersGetResponse, Rfc7807GetResponse, @@ -89,6 +90,7 @@ mod paths { r"^/register-callback$", r"^/repos$", r"^/repos/(?P[^/?#]*)$", + r"^/required_binary_stream$", r"^/required_octet_stream$", r"^/responses_with_headers$", r"^/rfc7807$", @@ -140,14 +142,15 @@ mod paths { regex::Regex::new(r"^/repos/(?P[^/?#]*)$") .expect("Unable to create regex for REPOS_REPOID"); } - pub(crate) static ID_REQUIRED_OCTET_STREAM: usize = 22; - pub(crate) static ID_RESPONSES_WITH_HEADERS: usize = 23; - pub(crate) static ID_RFC7807: usize = 24; - pub(crate) static ID_UNTYPED_PROPERTY: usize = 25; - pub(crate) static ID_UUID: usize = 26; - pub(crate) static ID_XML: usize = 27; - pub(crate) static ID_XML_EXTRA: usize = 28; - pub(crate) static ID_XML_OTHER: usize = 29; + pub(crate) static ID_REQUIRED_BINARY_STREAM: usize = 22; + pub(crate) static ID_REQUIRED_OCTET_STREAM: usize = 23; + pub(crate) static ID_RESPONSES_WITH_HEADERS: usize = 24; + pub(crate) static ID_RFC7807: usize = 25; + pub(crate) static ID_UNTYPED_PROPERTY: usize = 26; + pub(crate) static ID_UUID: usize = 27; + pub(crate) static ID_XML: usize = 28; + pub(crate) static ID_XML_EXTRA: usize = 29; + pub(crate) static ID_XML_OTHER: usize = 30; } pub struct MakeService where @@ -1204,6 +1207,58 @@ impl hyper::service::Service<(Request, C)> for Service where Ok(response) }, + // RequiredBinaryStreamPut - PUT /required_binary_stream + hyper::Method::PUT if path.matched(paths::ID_REQUIRED_BINARY_STREAM) => { + // Handle body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + let result = body.into_raw().await; + match result { + Ok(body) => { + let param_body: Option = if !body.is_empty() { + } else { + None + }; + let param_body = match param_body { + Some(param_body) => param_body, + None => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from("Missing required body parameter body")) + .expect("Unable to create Bad Request response for missing body parameter body")), + }; + let result = api_impl.required_binary_stream_put( + param_body, + &context + ).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) + .expect("Unable to create X-Span-ID header value")); + + match result { + Ok(rsp) => match rsp { + RequiredBinaryStreamPutResponse::OK + => { + *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); + }, + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); + }, + } + + Ok(response) + }, + Err(e) => Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Unable to read body: {e}"))) + .expect("Unable to create Bad Request response due to unable to read body")), + } + }, // RequiredOctetStreamPut - PUT /required_octet_stream hyper::Method::PUT if path.matched(paths::ID_REQUIRED_OCTET_STREAM) => { // Handle body parameters (note that non-required body parameters will ignore garbage @@ -2208,6 +2263,7 @@ impl hyper::service::Service<(Request, C)> for Service where _ if path.matched(paths::ID_REGISTER_CALLBACK) => method_not_allowed(), _ if path.matched(paths::ID_REPOS) => method_not_allowed(), _ if path.matched(paths::ID_REPOS_REPOID) => method_not_allowed(), + _ if path.matched(paths::ID_REQUIRED_BINARY_STREAM) => method_not_allowed(), _ if path.matched(paths::ID_REQUIRED_OCTET_STREAM) => method_not_allowed(), _ if path.matched(paths::ID_RESPONSES_WITH_HEADERS) => method_not_allowed(), _ if path.matched(paths::ID_RFC7807) => method_not_allowed(), @@ -2267,6 +2323,8 @@ impl RequestParser for ApiRequestParser { hyper::Method::GET if path.matched(paths::ID_READONLY_AUTH_SCHEME) => Some("ReadonlyAuthSchemeGet"), // RegisterCallbackPost - POST /register-callback hyper::Method::POST if path.matched(paths::ID_REGISTER_CALLBACK) => Some("RegisterCallbackPost"), + // RequiredBinaryStreamPut - PUT /required_binary_stream + hyper::Method::PUT if path.matched(paths::ID_REQUIRED_BINARY_STREAM) => Some("RequiredBinaryStreamPut"), // RequiredOctetStreamPut - PUT /required_octet_stream hyper::Method::PUT if path.matched(paths::ID_REQUIRED_OCTET_STREAM) => Some("RequiredOctetStreamPut"), // ResponsesWithHeadersGet - GET /responses_with_headers diff --git a/samples/server/petstore/rust-server/output/multipart-v3/src/client/mod.rs b/samples/server/petstore/rust-server/output/multipart-v3/src/client/mod.rs index 7d7dffb7ab88..65c4b38f8434 100644 --- a/samples/server/petstore/rust-server/output/multipart-v3/src/client/mod.rs +++ b/samples/server/petstore/rust-server/output/multipart-v3/src/client/mod.rs @@ -433,6 +433,11 @@ fn body_from_string(s: String) -> BoxBody { BoxBody::new(Full::new(Bytes::from(s))) } +#[allow(dead_code)] +fn body_from_bytes(b: Vec) -> BoxBody { + BoxBody::new(Full::new(Bytes::from(b))) +} + #[async_trait] impl Api for Client where S: Service< diff --git a/samples/server/petstore/rust-server/output/no-example-v3/src/client/mod.rs b/samples/server/petstore/rust-server/output/no-example-v3/src/client/mod.rs index de9fcd4e3f48..34d1724b31e7 100644 --- a/samples/server/petstore/rust-server/output/no-example-v3/src/client/mod.rs +++ b/samples/server/petstore/rust-server/output/no-example-v3/src/client/mod.rs @@ -426,6 +426,11 @@ fn body_from_string(s: String) -> BoxBody { BoxBody::new(Full::new(Bytes::from(s))) } +#[allow(dead_code)] +fn body_from_bytes(b: Vec) -> BoxBody { + BoxBody::new(Full::new(Bytes::from(b))) +} + #[async_trait] impl Api for Client where S: Service< diff --git a/samples/server/petstore/rust-server/output/openapi-v3/README.md b/samples/server/petstore/rust-server/output/openapi-v3/README.md index 397acf19868f..565a125781ea 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/README.md +++ b/samples/server/petstore/rust-server/output/openapi-v3/README.md @@ -99,6 +99,7 @@ cargo run --example openapi-v3-client OneOfGet cargo run --example openapi-v3-client OverrideServerGet cargo run --example openapi-v3-client ParamgetGet cargo run --example openapi-v3-client ReadonlyAuthSchemeGet +cargo run --example openapi-v3-client RequiredBinaryStreamPut cargo run --example openapi-v3-client RequiredOctetStreamPut cargo run --example openapi-v3-client ResponsesWithHeadersGet cargo run --example openapi-v3-client Rfc7807Get @@ -190,6 +191,7 @@ Method | HTTP request | Description [**queryExampleGet**](docs/default_api.md#queryExampleGet) | **GET** /query-example | Test required query params with and without examples [****](docs/default_api.md#) | **GET** /readonly_auth_scheme | [****](docs/default_api.md#) | **POST** /register-callback | +[****](docs/default_api.md#) | **PUT** /required_binary_stream | [****](docs/default_api.md#) | **PUT** /required_octet_stream | [****](docs/default_api.md#) | **GET** /responses_with_headers | [****](docs/default_api.md#) | **GET** /rfc7807 | diff --git a/samples/server/petstore/rust-server/output/openapi-v3/api/openapi.yaml b/samples/server/petstore/rust-server/output/openapi-v3/api/openapi.yaml index 9e1e521879f3..e05db02b4ad4 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/api/openapi.yaml +++ b/samples/server/petstore/rust-server/output/openapi-v3/api/openapi.yaml @@ -198,6 +198,18 @@ paths: responses: "200": description: OK + /required_binary_stream: + put: + requestBody: + content: + application/octet-stream: + schema: + format: binary + type: string + required: true + responses: + "200": + description: OK /readonly_auth_scheme: get: responses: diff --git a/samples/server/petstore/rust-server/output/openapi-v3/bin/cli.rs b/samples/server/petstore/rust-server/output/openapi-v3/bin/cli.rs index 8e7ab7a96cb6..fab73ef75def 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/bin/cli.rs +++ b/samples/server/petstore/rust-server/output/openapi-v3/bin/cli.rs @@ -23,6 +23,7 @@ use openapi_v3::{ QueryExampleGetResponse, ReadonlyAuthSchemeGetResponse, RegisterCallbackPostResponse, + RequiredBinaryStreamPutResponse, RequiredOctetStreamPutResponse, ResponsesWithHeadersGetResponse, Rfc7807GetResponse, @@ -162,6 +163,10 @@ enum Operation { RegisterCallbackPost { url: String, }, + RequiredBinaryStreamPut { + #[clap(value_parser = parse_json::)] + body: swagger::ByteArray, + }, RequiredOctetStreamPut { #[clap(value_parser = parse_json::)] body: swagger::ByteArray, @@ -608,6 +613,22 @@ async fn main() -> Result<()> { , } } + Operation::RequiredBinaryStreamPut { + body, + } => { + info!("Performing a RequiredBinaryStreamPut request"); + + let result = client.required_binary_stream_put( + body, + ).await?; + debug!("Result: {:?}", result); + + match result { + RequiredBinaryStreamPutResponse::OK + => "OK\n".to_string() + , + } + } Operation::RequiredOctetStreamPut { body, } => { diff --git a/samples/server/petstore/rust-server/output/openapi-v3/docs/default_api.md b/samples/server/petstore/rust-server/output/openapi-v3/docs/default_api.md index 2e0108f7f2e5..4c5b2c173a68 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/docs/default_api.md +++ b/samples/server/petstore/rust-server/output/openapi-v3/docs/default_api.md @@ -21,6 +21,7 @@ Method | HTTP request | Description **queryExampleGet**](default_api.md#queryExampleGet) | **GET** /query-example | Test required query params with and without examples ****](default_api.md#) | **GET** /readonly_auth_scheme | ****](default_api.md#) | **POST** /register-callback | +****](default_api.md#) | **PUT** /required_binary_stream | ****](default_api.md#) | **PUT** /required_octet_stream | ****](default_api.md#) | **GET** /responses_with_headers | ****](default_api.md#) | **GET** /rfc7807 | @@ -490,6 +491,31 @@ No authorization required > (body) +### Required Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **body** | **swagger::ByteArray**| | + +### Return type + + (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: application/octet-stream + - **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + +# **** +> (body) + + ### Required Parameters Name | Type | Description | Notes diff --git a/samples/server/petstore/rust-server/output/openapi-v3/examples/client/main.rs b/samples/server/petstore/rust-server/output/openapi-v3/examples/client/main.rs index 0ee7292ba787..32655c7bb120 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/examples/client/main.rs +++ b/samples/server/petstore/rust-server/output/openapi-v3/examples/client/main.rs @@ -23,6 +23,7 @@ use openapi_v3::{Api, ApiNoContext, Claims, Client, ContextWrapperExt, models, QueryExampleGetResponse, ReadonlyAuthSchemeGetResponse, RegisterCallbackPostResponse, + RequiredBinaryStreamPutResponse, RequiredOctetStreamPutResponse, ResponsesWithHeadersGetResponse, Rfc7807GetResponse, @@ -79,6 +80,7 @@ fn main() { "OverrideServerGet", "ParamgetGet", "ReadonlyAuthSchemeGet", + "RequiredBinaryStreamPut", "RequiredOctetStreamPut", "ResponsesWithHeadersGet", "Rfc7807Get", @@ -290,6 +292,12 @@ fn main() { info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, */ + Some("RequiredBinaryStreamPut") => { + let result = rt.block_on(client.required_binary_stream_put( + swagger::ByteArray(Vec::from("BINARY_DATA_HERE")) + )); + info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); + }, Some("RequiredOctetStreamPut") => { let result = rt.block_on(client.required_octet_stream_put( swagger::ByteArray(Vec::from("BYTE_ARRAY_DATA_HERE")) diff --git a/samples/server/petstore/rust-server/output/openapi-v3/examples/server/server.rs b/samples/server/petstore/rust-server/output/openapi-v3/examples/server/server.rs index 6e4b73c6adc3..70eeb81eb3a4 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/examples/server/server.rs +++ b/samples/server/petstore/rust-server/output/openapi-v3/examples/server/server.rs @@ -154,6 +154,7 @@ use openapi_v3::{ QueryExampleGetResponse, ReadonlyAuthSchemeGetResponse, RegisterCallbackPostResponse, + RequiredBinaryStreamPutResponse, RequiredOctetStreamPutResponse, ResponsesWithHeadersGetResponse, Rfc7807GetResponse, @@ -333,6 +334,15 @@ impl Api for Server where C: Has + Send + Sync Err(ApiError("Api-Error: Operation is NOT implemented".into())) } + async fn required_binary_stream_put( + &self, + body: swagger::ByteArray, + context: &C) -> Result + { + info!("required_binary_stream_put({:?}) - X-Span-ID: {:?}", body, context.get().0.clone()); + Err(ApiError("Api-Error: Operation is NOT implemented".into())) + } + async fn required_octet_stream_put( &self, body: swagger::ByteArray, diff --git a/samples/server/petstore/rust-server/output/openapi-v3/src/client/mod.rs b/samples/server/petstore/rust-server/output/openapi-v3/src/client/mod.rs index c85c3207b1f3..770ee3fb05f2 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/src/client/mod.rs +++ b/samples/server/petstore/rust-server/output/openapi-v3/src/client/mod.rs @@ -56,6 +56,7 @@ use crate::{Api, QueryExampleGetResponse, ReadonlyAuthSchemeGetResponse, RegisterCallbackPostResponse, + RequiredBinaryStreamPutResponse, RequiredOctetStreamPutResponse, ResponsesWithHeadersGetResponse, Rfc7807GetResponse, @@ -459,6 +460,11 @@ fn body_from_string(s: String) -> BoxBody { BoxBody::new(Full::new(Bytes::from(s))) } +#[allow(dead_code)] +fn body_from_bytes(b: Vec) -> BoxBody { + BoxBody::new(Full::new(Bytes::from(b))) +} + #[async_trait] impl Api for Client where S: Service< @@ -1959,6 +1965,83 @@ impl Api for Client where } } + #[allow(clippy::vec_init_then_push)] + async fn required_binary_stream_put( + &self, + param_body: swagger::ByteArray, + context: &C) -> Result + { + let mut client_service = self.client_service.clone(); + #[allow(clippy::uninlined_format_args)] + let mut uri = format!( + "{}/required_binary_stream", + self.base_path + ); + + // Query parameters + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { + uri += "?"; + uri += &query_string; + } + + let uri = match Uri::from_str(&uri) { + Ok(uri) => uri, + Err(err) => return Err(ApiError(format!("Unable to build URI: {err}"))), + }; + + let mut request = match Request::builder() + .method("PUT") + .uri(uri) + .body(BoxBody::new(http_body_util::Empty::new())) { + Ok(req) => req, + Err(e) => return Err(ApiError(format!("Unable to create request: {e}"))) + }; + + // Consumes basic body + // Body parameter + // Raw binary body - pass the bytes through without coercing to UTF-8. + *request.body_mut() = body_from_bytes(param_body.0); + + let header = "application/octet-stream"; + request.headers_mut().insert(CONTENT_TYPE, HeaderValue::from_static(header)); + + let header = HeaderValue::from_str(Has::::get(context).0.as_str()); + request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header { + Ok(h) => h, + Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {e}"))) + }); + + let response = client_service.call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {e}"))).await?; + + match response.status().as_u16() { + 200 => { + Ok( + RequiredBinaryStreamPutResponse::OK + ) + } + code => { + let headers = response.headers().clone(); + let body = http_body_util::BodyExt::collect(response.into_body()) + .await + .map(|f| f.to_bytes().to_vec()); + Err(ApiError(format!("Unexpected response code {code}:\n{headers:?}\n\n{}", + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!(""), + }, + Err(e) => format!("", Into::::into(e)), + } + ))) + } + } + } + #[allow(clippy::vec_init_then_push)] async fn required_octet_stream_put( &self, @@ -1997,8 +2080,8 @@ impl Api for Client where // Consumes basic body // Body parameter - let body = String::from_utf8(param_body.0).expect("Body was not valid UTF8"); - *request.body_mut() = body_from_string(body); + // Raw binary body - pass the bytes through without coercing to UTF-8. + *request.body_mut() = body_from_bytes(param_body.0); let header = "application/octet-stream"; request.headers_mut().insert(CONTENT_TYPE, HeaderValue::from_static(header)); diff --git a/samples/server/petstore/rust-server/output/openapi-v3/src/lib.rs b/samples/server/petstore/rust-server/output/openapi-v3/src/lib.rs index 1e9f566f5616..4c8e7b9d8fa1 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/src/lib.rs +++ b/samples/server/petstore/rust-server/output/openapi-v3/src/lib.rs @@ -163,6 +163,12 @@ pub enum RegisterCallbackPostResponse { OK } +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub enum RequiredBinaryStreamPutResponse { + /// OK + OK +} + #[derive(Debug, PartialEq, Serialize, Deserialize)] pub enum RequiredOctetStreamPutResponse { /// OK @@ -409,6 +415,11 @@ pub trait Api { url: String, context: &C) -> Result; + async fn required_binary_stream_put( + &self, + body: swagger::ByteArray, + context: &C) -> Result; + async fn required_octet_stream_put( &self, body: swagger::ByteArray, @@ -586,6 +597,11 @@ pub trait ApiNoContext { url: String, ) -> Result; + async fn required_binary_stream_put( + &self, + body: swagger::ByteArray, + ) -> Result; + async fn required_octet_stream_put( &self, body: swagger::ByteArray, @@ -838,6 +854,15 @@ impl + Send + Sync, C: Clone + Send + Sync> ApiNoContext for Contex self.api().register_callback_post(url, &context).await } + async fn required_binary_stream_put( + &self, + body: swagger::ByteArray, + ) -> Result + { + let context = self.context().clone(); + self.api().required_binary_stream_put(body, &context).await + } + async fn required_octet_stream_put( &self, body: swagger::ByteArray, diff --git a/samples/server/petstore/rust-server/output/openapi-v3/src/server/mod.rs b/samples/server/petstore/rust-server/output/openapi-v3/src/server/mod.rs index eed0dc8578a1..31e7bdee6ce9 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/src/server/mod.rs +++ b/samples/server/petstore/rust-server/output/openapi-v3/src/server/mod.rs @@ -42,6 +42,7 @@ use crate::{Api, QueryExampleGetResponse, ReadonlyAuthSchemeGetResponse, RegisterCallbackPostResponse, + RequiredBinaryStreamPutResponse, RequiredOctetStreamPutResponse, ResponsesWithHeadersGetResponse, Rfc7807GetResponse, @@ -90,6 +91,7 @@ mod paths { r"^/register-callback$", r"^/repos$", r"^/repos/(?P[^/?#]*)$", + r"^/required_binary_stream$", r"^/required_octet_stream$", r"^/responses_with_headers$", r"^/rfc7807$", @@ -141,14 +143,15 @@ mod paths { regex::Regex::new(r"^/repos/(?P[^/?#]*)$") .expect("Unable to create regex for REPOS_REPOID"); } - pub(crate) static ID_REQUIRED_OCTET_STREAM: usize = 22; - pub(crate) static ID_RESPONSES_WITH_HEADERS: usize = 23; - pub(crate) static ID_RFC7807: usize = 24; - pub(crate) static ID_UNTYPED_PROPERTY: usize = 25; - pub(crate) static ID_UUID: usize = 26; - pub(crate) static ID_XML: usize = 27; - pub(crate) static ID_XML_EXTRA: usize = 28; - pub(crate) static ID_XML_OTHER: usize = 29; + pub(crate) static ID_REQUIRED_BINARY_STREAM: usize = 22; + pub(crate) static ID_REQUIRED_OCTET_STREAM: usize = 23; + pub(crate) static ID_RESPONSES_WITH_HEADERS: usize = 24; + pub(crate) static ID_RFC7807: usize = 25; + pub(crate) static ID_UNTYPED_PROPERTY: usize = 26; + pub(crate) static ID_UUID: usize = 27; + pub(crate) static ID_XML: usize = 28; + pub(crate) static ID_XML_EXTRA: usize = 29; + pub(crate) static ID_XML_OTHER: usize = 30; } @@ -411,6 +414,11 @@ impl hyper::service::Service<(Request, C)> for Service { + handle_required_binary_stream_put(api_impl, uri, headers, body, context, validation).await + }, + // RequiredOctetStreamPut - PUT /required_octet_stream hyper::Method::PUT if path.matched(paths::ID_REQUIRED_OCTET_STREAM) => { handle_required_octet_stream_put(api_impl, uri, headers, body, context, validation).await @@ -508,6 +516,7 @@ impl hyper::service::Service<(Request, C)> for Service method_not_allowed(), _ if path.matched(paths::ID_REPOS) => method_not_allowed(), _ if path.matched(paths::ID_REPOS_REPOID) => method_not_allowed(), + _ if path.matched(paths::ID_REQUIRED_BINARY_STREAM) => method_not_allowed(), _ if path.matched(paths::ID_REQUIRED_OCTET_STREAM) => method_not_allowed(), _ if path.matched(paths::ID_RESPONSES_WITH_HEADERS) => method_not_allowed(), _ if path.matched(paths::ID_RFC7807) => method_not_allowed(), @@ -1772,6 +1781,77 @@ where Ok(response) } +#[allow(unused_variables)] +async fn handle_required_binary_stream_put( + mut api_impl: T, + uri: hyper::Uri, + headers: HeaderMap, + body: ReqBody, + context: C, + validation: bool, +) -> Result>, crate::ServiceError> +where + T: Api + Clone + Send + 'static, + C: Has + Send + Sync + 'static, + ReqBody: Body + Send + 'static, + ReqBody::Error: Into> + Send, + ReqBody::Data: Send, +{ + // Handle body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + let result = http_body_util::BodyExt::collect(body).await.map(|f| f.to_bytes().to_vec()); + match result { + Ok(body) => { + let param_body: Option = if !body.is_empty() { + Some(swagger::ByteArray(body.to_vec())) + } else { + None + }; + let param_body = match param_body { + Some(param_body) => param_body, + None => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(BoxBody::new("Missing required body parameter body".to_string())) + .expect("Unable to create Bad Request response for missing body parameter body")), + }; + + + let result = api_impl.required_binary_stream_put( + param_body, + &context + ).await; + let mut response = Response::new(BoxBody::new(http_body_util::Empty::new())); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str((&context as &dyn Has).get().0.clone().as_str()) + .expect("Unable to create X-Span-ID header value")); + + match result { + Ok(rsp) => match rsp { + RequiredBinaryStreamPutResponse::OK + => { + *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); + + }, + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = body_from_str("An internal error occurred"); + }, + } + + Ok(response) + }, + Err(e) => Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(body_from_string(format!("Unable to read body: {}", e.into()))) + .expect("Unable to create Bad Request response due to unable to read body")), + } +} + #[allow(unused_variables)] async fn handle_required_octet_stream_put( mut api_impl: T, @@ -3061,6 +3141,8 @@ impl RequestParser for ApiRequestParser { hyper::Method::GET if path.matched(paths::ID_READONLY_AUTH_SCHEME) => Some("ReadonlyAuthSchemeGet"), // RegisterCallbackPost - POST /register-callback hyper::Method::POST if path.matched(paths::ID_REGISTER_CALLBACK) => Some("RegisterCallbackPost"), + // RequiredBinaryStreamPut - PUT /required_binary_stream + hyper::Method::PUT if path.matched(paths::ID_REQUIRED_BINARY_STREAM) => Some("RequiredBinaryStreamPut"), // RequiredOctetStreamPut - PUT /required_octet_stream hyper::Method::PUT if path.matched(paths::ID_REQUIRED_OCTET_STREAM) => Some("RequiredOctetStreamPut"), // ResponsesWithHeadersGet - GET /responses_with_headers diff --git a/samples/server/petstore/rust-server/output/ops-v3/src/client/mod.rs b/samples/server/petstore/rust-server/output/ops-v3/src/client/mod.rs index b9035f6e45b0..ae007b288424 100644 --- a/samples/server/petstore/rust-server/output/ops-v3/src/client/mod.rs +++ b/samples/server/petstore/rust-server/output/ops-v3/src/client/mod.rs @@ -462,6 +462,11 @@ fn body_from_string(s: String) -> BoxBody { BoxBody::new(Full::new(Bytes::from(s))) } +#[allow(dead_code)] +fn body_from_bytes(b: Vec) -> BoxBody { + BoxBody::new(Full::new(Bytes::from(b))) +} + #[async_trait] impl Api for Client where S: Service< diff --git a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/client/mod.rs b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/client/mod.rs index 8aa1102e56ff..0a9fecefd823 100644 --- a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/client/mod.rs +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/client/mod.rs @@ -463,6 +463,11 @@ fn body_from_string(s: String) -> BoxBody { BoxBody::new(Full::new(Bytes::from(s))) } +#[allow(dead_code)] +fn body_from_bytes(b: Vec) -> BoxBody { + BoxBody::new(Full::new(Bytes::from(b))) +} + #[async_trait] impl Api for Client where S: Service< diff --git a/samples/server/petstore/rust-server/output/ping-bearer-auth/src/client/mod.rs b/samples/server/petstore/rust-server/output/ping-bearer-auth/src/client/mod.rs index 49ead2648b88..811e54285120 100644 --- a/samples/server/petstore/rust-server/output/ping-bearer-auth/src/client/mod.rs +++ b/samples/server/petstore/rust-server/output/ping-bearer-auth/src/client/mod.rs @@ -426,6 +426,11 @@ fn body_from_string(s: String) -> BoxBody { BoxBody::new(Full::new(Bytes::from(s))) } +#[allow(dead_code)] +fn body_from_bytes(b: Vec) -> BoxBody { + BoxBody::new(Full::new(Bytes::from(b))) +} + #[async_trait] impl Api for Client where S: Service< diff --git a/samples/server/petstore/rust-server/output/rust-server-test/src/client/mod.rs b/samples/server/petstore/rust-server/output/rust-server-test/src/client/mod.rs index 98b1550118b0..1a6a5e36ffb8 100644 --- a/samples/server/petstore/rust-server/output/rust-server-test/src/client/mod.rs +++ b/samples/server/petstore/rust-server/output/rust-server-test/src/client/mod.rs @@ -434,6 +434,11 @@ fn body_from_string(s: String) -> BoxBody { BoxBody::new(Full::new(Bytes::from(s))) } +#[allow(dead_code)] +fn body_from_bytes(b: Vec) -> BoxBody { + BoxBody::new(Full::new(Bytes::from(b))) +} + #[async_trait] impl Api for Client where S: Service<