Skip to content

Commit 1dd6734

Browse files
[Rust Server] Update more Body instantiations.
1 parent 2552fc4 commit 1dd6734

6 files changed

Lines changed: 27 additions & 27 deletions

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use crate::{{{operationId}}}Response;
1919
/// A client that implements the API by making HTTP calls out to a server.
2020
pub struct Client<S, C> where
2121
S: Service<
22-
(Request<Body>, C),
23-
Response=Response<Body>,
22+
(Request<Incoming>, C),
23+
Response=Response<BoxBody<Bytes, Infallible>>,
2424
Error=hyper::Error> + Clone + Send + Sync,
2525
S::Future: Send + 'static,
2626
C: Clone + Send + Sync + 'static
@@ -34,8 +34,8 @@ pub struct Client<S, C> where
3434

3535
impl<S, C> fmt::Debug for Client<S, C> where
3636
S: Service<
37-
(Request<Body>, C),
38-
Response=Response<Body>,
37+
(Request<Incoming>, C),
38+
Response=Response<BoxBody<Bytes, Infallible>>,
3939
Error=hyper::Error> + Clone + Send + Sync,
4040
S::Future: Send + 'static,
4141
C: Clone + Send + Sync + 'static
@@ -47,8 +47,8 @@ impl<S, C> fmt::Debug for Client<S, C> where
4747
4848
impl<S, C> Clone for Client<S, C> where
4949
S: Service<
50-
(Request<Body>, C),
51-
Response=Response<Body>,
50+
(Request<Incoming>, C),
51+
Response=Response<BoxBody<Bytes, Infallible>>,
5252
Error=hyper::Error> + Clone + Send + Sync,
5353
S::Future: Send + 'static,
5454
C: Clone + Send + Sync + 'static
@@ -169,8 +169,8 @@ impl<C> Client<DropContextService<hyper::client::Client<HttpsConnector, Body>, C
169169

170170
impl<S, C> Client<S, C> where
171171
S: Service<
172-
(Request<Body>, C),
173-
Response=Response<Body>,
172+
(Request<Incoming>, C),
173+
Response=Response<BoxBody<Bytes, Infallible>>,
174174
Error=hyper::Error> + Clone + Send + Sync,
175175
S::Future: Send + 'static,
176176
C: Clone + Send + Sync + 'static
@@ -191,8 +191,8 @@ impl<S, C> Client<S, C> where
191191
#[async_trait]
192192
impl<S, C> CallbackApi<C> for Client<S, C> where
193193
S: Service<
194-
(Request<Body>, C),
195-
Response=Response<Body>,
194+
(Request<Incoming>, C),
195+
Response=Response<BoxBody<Bytes, Infallible>>,
196196
Error=hyper::Error> + Clone + Send + Sync,
197197
S::Future: Send + 'static,
198198
S::Error: Into<crate::ServiceError> + fmt::Display,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
let missing_scopes = required_scopes.difference(scopes);
2525
return Ok(Response::builder()
2626
.status(StatusCode::FORBIDDEN)
27-
.body(Body::from(missing_scopes.fold(
27+
.body(body_from_string(missing_scopes.fold(
2828
"Insufficient authorization, missing scopes".to_string(),
2929
|s, scope| format!("{} {}", s, scope))
3030
))

modules/openapi-generator/src/main/resources/rust-server/server-request-body-basic.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
{{#required}}
1616
Err(e) => return Ok(Response::builder()
1717
.status(StatusCode::BAD_REQUEST)
18-
.body(Body::from(format!("Couldn't parse body parameter {{{baseName}}} - doesn't match schema: {}", e)))
18+
.body(body_from_string(format!("Couldn't parse body parameter {{{baseName}}} - doesn't match schema: {}", e)))
1919
.expect("Unable to create Bad Request response for invalid body parameter {{{baseName}}} due to schema")),
2020
{{/required}}
2121
{{^required}}
@@ -32,7 +32,7 @@
3232
Ok(param_{{{paramName}}}) => Some(param_{{{paramName}}}),
3333
Err(e) => return Ok(Response::builder()
3434
.status(StatusCode::BAD_REQUEST)
35-
.body(Body::from(format!("Couldn't parse body parameter {{{baseName}}} - not valid UTF-8: {}", e)))
35+
.body(body_from_string(format!("Couldn't parse body parameter {{{baseName}}} - not valid UTF-8: {}", e)))
3636
.expect("Unable to create Bad Request response for invalid body parameter {{{baseName}}} due to UTF-8")),
3737
}
3838
{{/isString}}
@@ -46,7 +46,7 @@
4646
Some(param_{{{paramName}}}) => param_{{{paramName}}},
4747
None => return Ok(Response::builder()
4848
.status(StatusCode::BAD_REQUEST)
49-
.body(Body::from("Missing required body parameter {{{baseName}}}"))
49+
.body(body_from_str("Missing required body parameter {{{baseName}}}"))
5050
.expect("Unable to create Bad Request response for missing body parameter {{{baseName}}}")),
5151
};
5252
{{/required}}

modules/openapi-generator/src/main/resources/rust-server/server-request-body-multipart-form.mustache

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Some(boundary) => boundary.to_string(),
33
None => return Ok(Response::builder()
44
.status(StatusCode::BAD_REQUEST)
5-
.body(Body::from("Couldn't find valid multipart body".to_string()))
5+
.body(body_from_str("Couldn't find valid multipart body".to_string()))
66
.expect("Unable to create Bad Request response for incorrect boundary")),
77
};
88

@@ -20,31 +20,31 @@
2020
SaveResult::Partial(_, PartialReason::CountLimit) => {
2121
return Ok(Response::builder()
2222
.status(StatusCode::BAD_REQUEST)
23-
.body(Body::from("Unable to process message part due to excessive parts".to_string()))
23+
.body(body_from_str("Unable to process message part due to excessive parts".to_string()))
2424
.expect("Unable to create Bad Request response due to excessive parts"))
2525
},
2626
SaveResult::Partial(_, PartialReason::SizeLimit) => {
2727
return Ok(Response::builder()
2828
.status(StatusCode::BAD_REQUEST)
29-
.body(Body::from("Unable to process message part due to excessive data".to_string()))
29+
.body(body_from_str("Unable to process message part due to excessive data".to_string()))
3030
.expect("Unable to create Bad Request response due to excessive data"))
3131
},
3232
SaveResult::Partial(_, PartialReason::Utf8Error(_)) => {
3333
return Ok(Response::builder()
3434
.status(StatusCode::BAD_REQUEST)
35-
.body(Body::from("Unable to process message part due to invalid data".to_string()))
35+
.body(body_from_str("Unable to process message part due to invalid data".to_string()))
3636
.expect("Unable to create Bad Request response due to invalid data"))
3737
},
3838
SaveResult::Partial(_, PartialReason::IoError(_)) => {
3939
return Ok(Response::builder()
4040
.status(StatusCode::INTERNAL_SERVER_ERROR)
41-
.body(Body::from("Failed to process message part due an internal error".to_string()))
41+
.body(body_from_str("Failed to process message part due an internal error".to_string()))
4242
.expect("Unable to create Internal Server Error response due to an internal error"))
4343
},
4444
SaveResult::Error(e) => {
4545
return Ok(Response::builder()
4646
.status(StatusCode::INTERNAL_SERVER_ERROR)
47-
.body(Body::from("Failed to process all message parts due to an internal error".to_string()))
47+
.body(body_from_str("Failed to process all message parts due to an internal error".to_string()))
4848
.expect("Unable to create Internal Server Error response due to an internal error"))
4949
},
5050
};
@@ -71,7 +71,7 @@
7171
return Ok(
7272
Response::builder()
7373
.status(StatusCode::BAD_REQUEST)
74-
.body(Body::from(format!("{{{paramName}}} data does not match API definition : {}", e)))
74+
.body(body_from_string(format!("{{{paramName}}} data does not match API definition : {}", e)))
7575
.expect("Unable to create Bad Request due to missing required form parameter {{{paramName}}}"))
7676
}
7777
};
@@ -87,7 +87,7 @@
8787
return Ok(
8888
Response::builder()
8989
.status(StatusCode::BAD_REQUEST)
90-
.body(Body::from("Missing required form parameter {{{paramName}}}".to_string()))
90+
.body(body_from_str("Missing required form parameter {{{paramName}}}".to_string()))
9191
.expect("Unable to create Bad Request due to missing required form parameter {{{paramName}}}"))
9292
{{/required}}
9393
{{^required}}

modules/openapi-generator/src/main/resources/rust-server/server-request-body-multipart-related.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Err(e) => {
77
return Ok(Response::builder()
88
.status(StatusCode::BAD_REQUEST)
9-
.body(Body::from(e))
9+
.body(body_from_string(e.to_string()))
1010
.expect("Unable to create Bad Request response due to unable to read content-type header for {{operationId}}"));
1111
}
1212
};
@@ -18,7 +18,7 @@
1818
Err(e) => {
1919
return Ok(Response::builder()
2020
.status(StatusCode::BAD_REQUEST)
21-
.body(Body::from(format!("Could not read multipart body for {{operationId}}: {}", e)))
21+
.body(body_from_string(format!("Could not read multipart body for {{operationId}}: {}", e)))
2222
.expect("Unable to create Bad Request response due to unable to read multipart body for {{operationId}}"));
2323
}
2424
};
@@ -43,7 +43,7 @@
4343
Ok(json_data) => json_data,
4444
Err(e) => return Ok(Response::builder()
4545
.status(StatusCode::BAD_REQUEST)
46-
.body(Body::from(format!("Couldn't parse body parameter {{dataType}} - doesn't match schema: {}", e)))
46+
.body(body_from_string(format!("Couldn't parse body parameter {{dataType}} - doesn't match schema: {}", e)))
4747
.expect("Unable to create Bad Request response for invalid body parameter {{dataType}} due to schema"))
4848
};
4949
// Push JSON part to return object.
@@ -79,7 +79,7 @@
7979
Some(x) => x,
8080
None => return Ok(Response::builder()
8181
.status(StatusCode::BAD_REQUEST)
82-
.body(Body::from("Missing required multipart/related parameter {{{paramName}}}".to_string()))
82+
.body(body_from_str("Missing required multipart/related parameter {{{paramName}}}".to_string()))
8383
.expect("Unable to create Bad Request response for missing multipart/related parameter {{{paramName}}} due to schema"))
8484
};
8585
{{/required}}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@
4646
{{/formParams}}
4747
{{/x-produces-multipart-related}}
4848
{{/vendorExtensions}}
49-
*response.body_mut() = body_from_string(body);
49+
*response.body_mut() = BoxBody::new(Full::new(Bytes::from(body)));
5050
{{/dataType}}

0 commit comments

Comments
 (0)