Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@ use crate::{{{operationId}}}Response;
{{/callbacks}}
{{>server-service-footer}}

{{! Per-operation handler functions — extracted from the match arms in run() to
reduce per-function compilation-unit size and avoid rustc OOM on large APIs. }}
{{#apiInfo}}
{{#apis}}
{{#operations}}
{{#operation}}
{{#callbacks}}
{{#urls}}
{{#requests}}
{{>server-operation-handler}}

{{/requests}}
{{/urls}}
{{/callbacks}}
{{/operation}}
{{/operations}}
{{/apis}}
{{/apiInfo}}
/// Request parser for `Api`.
pub struct ApiRequestParser;
impl<T> RequestParser<T> for ApiRequestParser {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ pub mod callbacks;
{{/pathSet}}
{{>server-service-footer}}

{{! Per-operation handler functions — extracted from the match arms in run() to
reduce per-function compilation-unit size and avoid rustc OOM on large APIs. }}
{{#apiInfo}}
{{#apis}}
{{#operations}}
{{#operation}}
{{>server-operation-handler}}

{{/operation}}
{{/operations}}
{{/apis}}
{{/apiInfo}}
/// Request parser for `Api`.
pub struct ApiRequestParser;
impl<T> RequestParser<T> for ApiRequestParser {
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,53 @@ impl<T, C, ReqBody> hyper::service::Service<(Request<ReqBody>, C)> for Service<T

// MultipartRelatedRequestPost - POST /multipart_related_request
hyper::Method::POST if path.matched(paths::ID_MULTIPART_RELATED_REQUEST) => {
handle_multipart_related_request_post(api_impl, uri, headers, body, context, validation, multipart_form_size_limit).await
},

// MultipartRequestPost - POST /multipart_request
hyper::Method::POST if path.matched(paths::ID_MULTIPART_REQUEST) => {
handle_multipart_request_post(api_impl, uri, headers, body, context, validation, multipart_form_size_limit).await
},

// MultipleIdenticalMimeTypesPost - POST /multiple-identical-mime-types
hyper::Method::POST if path.matched(paths::ID_MULTIPLE_IDENTICAL_MIME_TYPES) => {
handle_multiple_identical_mime_types_post(api_impl, uri, headers, body, context, validation, multipart_form_size_limit).await
},

_ if path.matched(paths::ID_MULTIPART_RELATED_REQUEST) => method_not_allowed(),
_ if path.matched(paths::ID_MULTIPART_REQUEST) => method_not_allowed(),
_ if path.matched(paths::ID_MULTIPLE_IDENTICAL_MIME_TYPES) => method_not_allowed(),
_ => Ok(Response::builder().status(StatusCode::NOT_FOUND)
.body(BoxBody::new(http_body_util::Empty::new()))
.expect("Unable to create Not Found response"))
}
}
Box::pin(run(
self.api_impl.clone(),
req,
self.validation,
self.multipart_form_size_limit
))
}
}

#[allow(unused_variables)]
async fn handle_multipart_related_request_post<T, C, ReqBody>(
mut api_impl: T,
uri: hyper::Uri,
headers: HeaderMap,
body: ReqBody,
context: C,
validation: bool,
multipart_form_size_limit: Option<u64>,
) -> Result<Response<BoxBody<Bytes, Infallible>>, crate::ServiceError>
where
T: Api<C> + Clone + Send + 'static,
C: Has<XSpanIdString> + Send + Sync + 'static,
ReqBody: Body + Send + 'static,
ReqBody::Error: Into<Box<dyn Error + Send + Sync>> + 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.
Expand Down Expand Up @@ -383,10 +430,25 @@ impl<T, C, ReqBody> hyper::service::Service<(Request<ReqBody>, C)> for Service<T
.body(body_from_string(format!("Unable to read body: {}", e.into())))
.expect("Unable to create Bad Request response due to unable to read body")),
}
},
}

// MultipartRequestPost - POST /multipart_request
hyper::Method::POST if path.matched(paths::ID_MULTIPART_REQUEST) => {
#[allow(unused_variables)]
async fn handle_multipart_request_post<T, C, ReqBody>(
mut api_impl: T,
uri: hyper::Uri,
headers: HeaderMap,
body: ReqBody,
context: C,
validation: bool,
multipart_form_size_limit: Option<u64>,
) -> Result<Response<BoxBody<Bytes, Infallible>>, crate::ServiceError>
where
T: Api<C> + Clone + Send + 'static,
C: Has<XSpanIdString> + Send + Sync + 'static,
ReqBody: Body + Send + 'static,
ReqBody::Error: Into<Box<dyn Error + Send + Sync>> + 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.
Expand Down Expand Up @@ -571,10 +633,25 @@ impl<T, C, ReqBody> hyper::service::Service<(Request<ReqBody>, C)> for Service<T
.body(body_from_string(format!("Unable to read body: {}", e.into())))
.expect("Unable to create Bad Request response due to unable to read body")),
}
},
}

// MultipleIdenticalMimeTypesPost - POST /multiple-identical-mime-types
hyper::Method::POST if path.matched(paths::ID_MULTIPLE_IDENTICAL_MIME_TYPES) => {
#[allow(unused_variables)]
async fn handle_multiple_identical_mime_types_post<T, C, ReqBody>(
mut api_impl: T,
uri: hyper::Uri,
headers: HeaderMap,
body: ReqBody,
context: C,
validation: bool,
multipart_form_size_limit: Option<u64>,
) -> Result<Response<BoxBody<Bytes, Infallible>>, crate::ServiceError>
where
T: Api<C> + Clone + Send + 'static,
C: Has<XSpanIdString> + Send + Sync + 'static,
ReqBody: Body + Send + 'static,
ReqBody::Error: Into<Box<dyn Error + Send + Sync>> + 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.
Expand Down Expand Up @@ -677,23 +754,6 @@ impl<T, C, ReqBody> hyper::service::Service<(Request<ReqBody>, C)> for Service<T
.body(body_from_string(format!("Unable to read body: {}", e.into())))
.expect("Unable to create Bad Request response due to unable to read body")),
}
},

_ if path.matched(paths::ID_MULTIPART_RELATED_REQUEST) => method_not_allowed(),
_ if path.matched(paths::ID_MULTIPART_REQUEST) => method_not_allowed(),
_ if path.matched(paths::ID_MULTIPLE_IDENTICAL_MIME_TYPES) => method_not_allowed(),
_ => Ok(Response::builder().status(StatusCode::NOT_FOUND)
.body(BoxBody::new(http_body_util::Empty::new()))
.expect("Unable to create Not Found response"))
}
}
Box::pin(run(
self.api_impl.clone(),
req,
self.validation,
self.multipart_form_size_limit
))
}
}

/// Request parser for `Api`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,39 @@ impl<T, C, ReqBody> hyper::service::Service<(Request<ReqBody>, C)> for Service<T

// OpGet - GET /op
hyper::Method::GET if path.matched(paths::ID_OP) => {
handle_op_get(api_impl, uri, headers, body, context, validation).await
},

_ if path.matched(paths::ID_OP) => method_not_allowed(),
_ => Ok(Response::builder().status(StatusCode::NOT_FOUND)
.body(BoxBody::new(http_body_util::Empty::new()))
.expect("Unable to create Not Found response"))
}
}
Box::pin(run(
self.api_impl.clone(),
req,
self.validation
))
}
}

#[allow(unused_variables)]
async fn handle_op_get<T, C, ReqBody>(
mut api_impl: T,
uri: hyper::Uri,
headers: HeaderMap,
body: ReqBody,
context: C,
validation: bool,
) -> Result<Response<BoxBody<Bytes, Infallible>>, crate::ServiceError>
where
T: Api<C> + Clone + Send + 'static,
C: Has<XSpanIdString> + Send + Sync + 'static,
ReqBody: Body + Send + 'static,
ReqBody::Error: Into<Box<dyn Error + Send + Sync>> + 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.
Expand Down Expand Up @@ -292,20 +325,6 @@ impl<T, C, ReqBody> hyper::service::Service<(Request<ReqBody>, C)> for Service<T
.body(body_from_string(format!("Unable to read body: {}", e.into())))
.expect("Unable to create Bad Request response due to unable to read body")),
}
},

_ if path.matched(paths::ID_OP) => method_not_allowed(),
_ => Ok(Response::builder().status(StatusCode::NOT_FOUND)
.body(BoxBody::new(http_body_util::Empty::new()))
.expect("Unable to create Not Found response"))
}
}
Box::pin(run(
self.api_impl.clone(),
req,
self.validation
))
}
}

/// Request parser for `Api`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,45 @@ impl<T, C, ReqBody> hyper::service::Service<(Request<ReqBody>, C)> for Service<T

// CallbackCallbackWithHeaderPost - POST /{$request.query.url}/callback-with-header
hyper::Method::POST if path.matched(paths::ID_REQUEST_QUERY_URL_CALLBACK_WITH_HEADER) => {
handle_callback_callback_with_header_post(api_impl, uri, headers, body, context, validation).await
},

// CallbackCallbackPost - POST /{$request.query.url}/callback
hyper::Method::POST if path.matched(paths::ID_REQUEST_QUERY_URL_CALLBACK) => {
handle_callback_callback_post(api_impl, uri, headers, body, context, validation).await
},

_ if path.matched(paths::ID_REQUEST_QUERY_URL_CALLBACK) => method_not_allowed(),
_ if path.matched(paths::ID_REQUEST_QUERY_URL_CALLBACK_WITH_HEADER) => method_not_allowed(),
_ => Ok(Response::builder().status(StatusCode::NOT_FOUND)
.body(BoxBody::new(http_body_util::Empty::new()))
.expect("Unable to create Not Found response"))
}
}
Box::pin(run(
self.api_impl.clone(),
req,
self.validation
))
}
}

#[allow(unused_variables)]
async fn handle_callback_callback_with_header_post<T, C, ReqBody>(
mut api_impl: T,
uri: hyper::Uri,
headers: HeaderMap,
body: ReqBody,
context: C,
validation: bool,
) -> Result<Response<BoxBody<Bytes, Infallible>>, crate::ServiceError>
where
T: Api<C> + Clone + Send + 'static,
C: Has<XSpanIdString> + Send + Sync + 'static,
ReqBody: Body + Send + 'static,
ReqBody::Error: Into<Box<dyn Error + Send + Sync>> + Send,
ReqBody::Data: Send,
{
// Path parameters
let path: &str = uri.path();
let path_params =
Expand Down Expand Up @@ -291,10 +330,24 @@ impl<T, C, ReqBody> hyper::service::Service<(Request<ReqBody>, C)> for Service<T
}

Ok(response)
},
}

// CallbackCallbackPost - POST /{$request.query.url}/callback
hyper::Method::POST if path.matched(paths::ID_REQUEST_QUERY_URL_CALLBACK) => {
#[allow(unused_variables)]
async fn handle_callback_callback_post<T, C, ReqBody>(
mut api_impl: T,
uri: hyper::Uri,
headers: HeaderMap,
body: ReqBody,
context: C,
validation: bool,
) -> Result<Response<BoxBody<Bytes, Infallible>>, crate::ServiceError>
where
T: Api<C> + Clone + Send + 'static,
C: Has<XSpanIdString> + Send + Sync + 'static,
ReqBody: Body + Send + 'static,
ReqBody::Error: Into<Box<dyn Error + Send + Sync>> + Send,
ReqBody::Data: Send,
{
// Path parameters
let path: &str = uri.path();
let path_params =
Expand Down Expand Up @@ -332,21 +385,6 @@ impl<T, C, ReqBody> hyper::service::Service<(Request<ReqBody>, C)> for Service<T
}

Ok(response)
},

_ if path.matched(paths::ID_REQUEST_QUERY_URL_CALLBACK) => method_not_allowed(),
_ if path.matched(paths::ID_REQUEST_QUERY_URL_CALLBACK_WITH_HEADER) => method_not_allowed(),
_ => Ok(Response::builder().status(StatusCode::NOT_FOUND)
.body(BoxBody::new(http_body_util::Empty::new()))
.expect("Unable to create Not Found response"))
}
}
Box::pin(run(
self.api_impl.clone(),
req,
self.validation
))
}
}

/// Request parser for `Api`.
Expand Down
Loading
Loading