diff --git a/modules/openapi-generator/src/main/resources/rust-axum/Cargo.mustache b/modules/openapi-generator/src/main/resources/rust-axum/Cargo.mustache index 2dcdd5c9d7dd..56ad9103f575 100644 --- a/modules/openapi-generator/src/main/resources/rust-axum/Cargo.mustache +++ b/modules/openapi-generator/src/main/resources/rust-axum/Cargo.mustache @@ -62,7 +62,7 @@ tokio = { version = "1", default-features = false, features = [ ] } tracing = { version = "0.1", features = ["attributes"] } uuid = { version = "1", features = ["serde"] } -validator = { version = "0.19", features = ["derive"] } +validator = { version = "0.20", features = ["derive"] } [dev-dependencies] tracing-subscriber = "0.3" diff --git a/modules/openapi-generator/src/main/resources/rust-axum/README.mustache b/modules/openapi-generator/src/main/resources/rust-axum/README.mustache index 6a2ab5ce080f..592c97af2db5 100644 --- a/modules/openapi-generator/src/main/resources/rust-axum/README.mustache +++ b/modules/openapi-generator/src/main/resources/rust-axum/README.mustache @@ -48,16 +48,18 @@ struct ServerImpl { #[allow(unused_variables)] #[async_trait] -impl {{{packageName}}}::Api for ServerImpl { +impl {{{externCrateName}}}::apis::default::Api for ServerImpl { // API implementation goes here } +impl {{{externCrateName}}}::apis::ErrorHandler for ServerImpl {} + pub async fn start_server(addr: &str) { // initialize tracing tracing_subscriber::fmt::init(); // Init Axum router - let app = {{{packageName}}}::server::new(Arc::new(ServerImpl)); + let app = {{{externCrateName}}}::server::new(Arc::new(ServerImpl)); // Add layers to the router let app = app.layer(...); diff --git a/modules/openapi-generator/src/main/resources/rust-axum/apis-mod.mustache b/modules/openapi-generator/src/main/resources/rust-axum/apis-mod.mustache index 3aa19dbb7868..122aa90cb976 100644 --- a/modules/openapi-generator/src/main/resources/rust-axum/apis-mod.mustache +++ b/modules/openapi-generator/src/main/resources/rust-axum/apis-mod.mustache @@ -27,4 +27,24 @@ pub trait ApiKeyAuthHeader { } {{/isKeyInHeader}} {{/isApiKey}} -{{/authMethods}} \ No newline at end of file +{{/authMethods}} + +// Error handler for unhandled errors. +#[async_trait::async_trait] +pub trait ErrorHandler { + #[allow(unused_variables)] + #[tracing::instrument(skip_all)] + async fn handle_error( + &self, + method: &::http::Method, + host: &axum::extract::Host, + cookies: &axum_extra::extract::CookieJar, + error: E + ) -> Result { + tracing::error!("Unhandled error: {:?}", error); + axum::response::Response::builder() + .status(http::StatusCode::INTERNAL_SERVER_ERROR) + .body(axum::body::Body::empty()) + .map_err(|_| http::StatusCode::INTERNAL_SERVER_ERROR) + } +} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/rust-axum/apis.mustache b/modules/openapi-generator/src/main/resources/rust-axum/apis.mustache index aa25d52be55c..f6f69c1854a3 100644 --- a/modules/openapi-generator/src/main/resources/rust-axum/apis.mustache +++ b/modules/openapi-generator/src/main/resources/rust-axum/apis.mustache @@ -17,9 +17,9 @@ use crate::{models, types::*}; /// {{classnamePascalCase}} #[async_trait] #[allow(clippy::ptr_arg)] -pub trait {{classnamePascalCase}} { +pub trait {{classnamePascalCase}}: super::ErrorHandler { {{#havingAuthMethod}} - type Claims; + type Claims; {{/havingAuthMethod}} {{#operation}} @@ -31,36 +31,36 @@ pub trait {{classnamePascalCase}} { /// {{{operationId}}} - {{{httpMethod}}} {{{basePathWithoutHost}}}{{{path}}} async fn {{{x-operation-id}}}( &self, - method: Method, - host: Host, - cookies: CookieJar, + method: &Method, + host: &Host, + cookies: &CookieJar, {{#vendorExtensions}} {{#x-has-auth-methods}} - claims: Self::Claims, + claims: &Self::Claims, {{/x-has-auth-methods}} {{/vendorExtensions}} {{#headerParams.size}} - header_params: models::{{{operationIdCamelCase}}}HeaderParams, + header_params: &models::{{{operationIdCamelCase}}}HeaderParams, {{/headerParams.size}} {{#pathParams.size}} - path_params: models::{{{operationIdCamelCase}}}PathParams, + path_params: &models::{{{operationIdCamelCase}}}PathParams, {{/pathParams.size}} {{#queryParams.size}} - query_params: models::{{{operationIdCamelCase}}}QueryParams, + query_params: &models::{{{operationIdCamelCase}}}QueryParams, {{/queryParams.size}} {{^x-consumes-multipart-related}} {{^x-consumes-multipart}} {{#bodyParam}} {{#vendorExtensions}} {{^x-consumes-plain-text}} - body: {{^required}}Option<{{/required}}{{{dataType}}}{{^required}}>{{/required}}, + body: &{{^required}}Option<{{/required}}{{{dataType}}}{{^required}}>{{/required}}, {{/x-consumes-plain-text}} {{#x-consumes-plain-text}} {{#isString}} - body: String, + body: &String, {{/isString}} {{^isString}} - body: Bytes, + body: &Bytes, {{/isString}} {{/x-consumes-plain-text}} {{/vendorExtensions}} @@ -68,12 +68,12 @@ pub trait {{classnamePascalCase}} { {{/x-consumes-multipart}} {{/x-consumes-multipart-related}} {{#x-consumes-multipart}} - body: Multipart, + body: &Multipart, {{/x-consumes-multipart}} {{#x-consumes-multipart-related}} - body: axum::body::Body, + body: &axum::body::Body, {{/x-consumes-multipart-related}} - ) -> Result<{{{operationId}}}Response, ()>; + ) -> Result<{{{operationId}}}Response, E>; {{/vendorExtensions}} {{^-last}} diff --git a/modules/openapi-generator/src/main/resources/rust-axum/server-operation.mustache b/modules/openapi-generator/src/main/resources/rust-axum/server-operation.mustache index ceb477b11443..a3b08f9aacdc 100644 --- a/modules/openapi-generator/src/main/resources/rust-axum/server-operation.mustache +++ b/modules/openapi-generator/src/main/resources/rust-axum/server-operation.mustache @@ -1,6 +1,6 @@ /// {{{operationId}}} - {{{httpMethod}}} {{{basePathWithoutHost}}}{{{path}}} #[tracing::instrument(skip_all)] -async fn {{#vendorExtensions}}{{{x-operation-id}}}{{/vendorExtensions}}( +async fn {{#vendorExtensions}}{{{x-operation-id}}}{{/vendorExtensions}}( method: Method, host: Host, cookies: CookieJar, @@ -54,8 +54,9 @@ async fn {{#vendorExtensions}}{{{x-operation-id}}}{{/vendorExtensions}} Result where I: AsRef + Send + Sync, - A: apis::{{classFilename}}::{{classnamePascalCase}}{{#havingAuthMethod}}{{/havingAuthMethod}}{{#vendorExtensions}}{{#x-has-cookie-auth-methods}}+ apis::CookieAuthentication{{/x-has-cookie-auth-methods}}{{#x-has-header-auth-methods}}+ apis::ApiKeyAuthHeader{{/x-has-header-auth-methods}}{{/vendorExtensions}}, -{ + A: apis::{{classFilename}}::{{classnamePascalCase}}{{#vendorExtensions}}{{#x-has-cookie-auth-methods}}+ apis::CookieAuthentication{{/x-has-cookie-auth-methods}}{{#x-has-header-auth-methods}}+ apis::ApiKeyAuthHeader{{/x-has-header-auth-methods}}{{/vendorExtensions}} + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, + { {{#vendorExtensions}} {{#x-has-auth-methods}} // Authentication @@ -186,38 +187,38 @@ where {{/disableValidator}} let result = api_impl.as_ref().{{#vendorExtensions}}{{{x-operation-id}}}{{/vendorExtensions}}( - method, - host, - cookies, + &method, + &host, + &cookies, {{#vendorExtensions}} {{#x-has-auth-methods}} - claims, + &claims, {{/x-has-auth-methods}} {{/vendorExtensions}} {{#headerParams.size}} - header_params, + &header_params, {{/headerParams.size}} {{#pathParams.size}} - path_params, + &path_params, {{/pathParams.size}} {{#queryParams.size}} - query_params, + &query_params, {{/queryParams.size}} {{#vendorExtensions}} {{^x-consumes-multipart-related}} {{^x-consumes-multipart}} {{#bodyParams}} {{#-first}} - body, + &body, {{/-first}} {{/bodyParams}} {{/x-consumes-multipart}} {{/x-consumes-multipart-related}} {{#x-consumes-multipart}} - body, + &body, {{/x-consumes-multipart}} {{#x-consumes-multipart-related}} - body, + &body, {{/x-consumes-multipart-related}} {{/vendorExtensions}} ).await; @@ -342,10 +343,11 @@ where }, {{/responses}} }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl.as_ref().handle_error(&method, &host, &cookies, why).await; }, }; diff --git a/modules/openapi-generator/src/main/resources/rust-axum/server-route.mustache b/modules/openapi-generator/src/main/resources/rust-axum/server-route.mustache index 3f8fe8edbb3a..f75a627787a1 100644 --- a/modules/openapi-generator/src/main/resources/rust-axum/server-route.mustache +++ b/modules/openapi-generator/src/main/resources/rust-axum/server-route.mustache @@ -1,15 +1,16 @@ /// Setup API Server. -pub fn new(api_impl: I) -> Router +pub fn new(api_impl: I) -> Router where I: AsRef + Clone + Send + Sync + 'static, - A: {{#apiInfo}}{{#apis}}{{#operations}}apis::{{classFilename}}::{{classnamePascalCase}}{{#havingAuthMethod}}{{/havingAuthMethod}} + {{/operations}}{{/apis}}{{/apiInfo}}{{#authMethods}}{{#isApiKey}}{{#isKeyInCookie}}apis::CookieAuthentication + {{/isKeyInCookie}}{{#isKeyInHeader}}apis::ApiKeyAuthHeader + {{/isKeyInHeader}}{{/isApiKey}}{{/authMethods}}'static, + A: {{#apiInfo}}{{#apis}}{{#operations}}apis::{{classFilename}}::{{classnamePascalCase}} + {{/operations}}{{/apis}}{{/apiInfo}}{{#authMethods}}{{#isApiKey}}{{#isKeyInCookie}}apis::CookieAuthentication + {{/isKeyInCookie}}{{#isKeyInHeader}}apis::ApiKeyAuthHeader + {{/isKeyInHeader}}{{/isApiKey}}{{/authMethods}}Send + Sync + 'static, + E: std::fmt::Debug + Send + Sync + 'static, {{#havingAuthMethods}}C: Send + Sync + 'static,{{/havingAuthMethods}} { // build our application with a route Router::new() {{#pathMethodOps}} .route("{{{basePathWithoutHost}}}{{{path}}}", - {{#methodOperations}}{{{method}}}({{{operationID}}}::){{^-last}}.{{/-last}}{{/methodOperations}} + {{#methodOperations}}{{{method}}}({{{operationID}}}::){{^-last}}.{{/-last}}{{/methodOperations}} ) {{/pathMethodOps}} .with_state(api_impl) diff --git a/samples/server/petstore/rust-axum/output/apikey-auths/.openapi-generator/VERSION b/samples/server/petstore/rust-axum/output/apikey-auths/.openapi-generator/VERSION index 884119126398..de37f5c4cf59 100644 --- a/samples/server/petstore/rust-axum/output/apikey-auths/.openapi-generator/VERSION +++ b/samples/server/petstore/rust-axum/output/apikey-auths/.openapi-generator/VERSION @@ -1 +1 @@ -7.11.0-SNAPSHOT +7.12.0-SNAPSHOT diff --git a/samples/server/petstore/rust-axum/output/apikey-auths/Cargo.toml b/samples/server/petstore/rust-axum/output/apikey-auths/Cargo.toml index 1f44d1228ae4..9f5dc9ccc8eb 100644 --- a/samples/server/petstore/rust-axum/output/apikey-auths/Cargo.toml +++ b/samples/server/petstore/rust-axum/output/apikey-auths/Cargo.toml @@ -40,7 +40,7 @@ tokio = { version = "1", default-features = false, features = [ ] } tracing = { version = "0.1", features = ["attributes"] } uuid = { version = "1", features = ["serde"] } -validator = { version = "0.19", features = ["derive"] } +validator = { version = "0.20", features = ["derive"] } [dev-dependencies] tracing-subscriber = "0.3" diff --git a/samples/server/petstore/rust-axum/output/apikey-auths/README.md b/samples/server/petstore/rust-axum/output/apikey-auths/README.md index 143e1c1b27bb..9cf63a6d09de 100644 --- a/samples/server/petstore/rust-axum/output/apikey-auths/README.md +++ b/samples/server/petstore/rust-axum/output/apikey-auths/README.md @@ -12,7 +12,7 @@ server, you can easily generate a server stub. To see how to make this your own, look here: [README]((https://openapi-generator.tech)) - API version: 1.0.0 -- Generator version: 7.11.0-SNAPSHOT +- Generator version: 7.12.0-SNAPSHOT @@ -43,16 +43,18 @@ struct ServerImpl { #[allow(unused_variables)] #[async_trait] -impl apikey-auths::Api for ServerImpl { +impl apikey_auths::apis::default::Api for ServerImpl { // API implementation goes here } +impl apikey_auths::apis::ErrorHandler for ServerImpl {} + pub async fn start_server(addr: &str) { // initialize tracing tracing_subscriber::fmt::init(); // Init Axum router - let app = apikey-auths::server::new(Arc::new(ServerImpl)); + let app = apikey_auths::server::new(Arc::new(ServerImpl)); // Add layers to the router let app = app.layer(...); diff --git a/samples/server/petstore/rust-axum/output/apikey-auths/src/apis/mod.rs b/samples/server/petstore/rust-axum/output/apikey-auths/src/apis/mod.rs index 23e9675928fc..b411dafe544a 100644 --- a/samples/server/petstore/rust-axum/output/apikey-auths/src/apis/mod.rs +++ b/samples/server/petstore/rust-axum/output/apikey-auths/src/apis/mod.rs @@ -24,3 +24,23 @@ pub trait CookieAuthentication { key: &str, ) -> Option; } + +// Error handler for unhandled errors. +#[async_trait::async_trait] +pub trait ErrorHandler { + #[allow(unused_variables)] + #[tracing::instrument(skip_all)] + async fn handle_error( + &self, + method: &::http::Method, + host: &axum::extract::Host, + cookies: &axum_extra::extract::CookieJar, + error: E, + ) -> Result { + tracing::error!("Unhandled error: {:?}", error); + axum::response::Response::builder() + .status(http::StatusCode::INTERNAL_SERVER_ERROR) + .body(axum::body::Body::empty()) + .map_err(|_| http::StatusCode::INTERNAL_SERVER_ERROR) + } +} diff --git a/samples/server/petstore/rust-axum/output/apikey-auths/src/apis/payments.rs b/samples/server/petstore/rust-axum/output/apikey-auths/src/apis/payments.rs index 3dada59a82dd..01c97e2874c5 100644 --- a/samples/server/petstore/rust-axum/output/apikey-auths/src/apis/payments.rs +++ b/samples/server/petstore/rust-axum/output/apikey-auths/src/apis/payments.rs @@ -38,7 +38,9 @@ pub enum PostMakePaymentResponse { /// Payments #[async_trait] #[allow(clippy::ptr_arg)] -pub trait Payments { +pub trait Payments: + super::ErrorHandler +{ type Claims; /// Get payment method by id. @@ -46,31 +48,31 @@ pub trait Payments { /// GetPaymentMethodById - GET /v71/paymentMethods/{id} async fn get_payment_method_by_id( &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::GetPaymentMethodByIdPathParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + path_params: &models::GetPaymentMethodByIdPathParams, + ) -> Result; /// Get payment methods. /// /// GetPaymentMethods - GET /v71/paymentMethods async fn get_payment_methods( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Make a payment. /// /// PostMakePayment - POST /v71/payments async fn post_make_payment( &self, - method: Method, - host: Host, - cookies: CookieJar, - claims: Self::Claims, - body: Option, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + claims: &Self::Claims, + body: &Option, + ) -> Result; } diff --git a/samples/server/petstore/rust-axum/output/apikey-auths/src/server/mod.rs b/samples/server/petstore/rust-axum/output/apikey-auths/src/server/mod.rs index 7db56e8b151d..46899c5f2539 100644 --- a/samples/server/petstore/rust-axum/output/apikey-auths/src/server/mod.rs +++ b/samples/server/petstore/rust-axum/output/apikey-auths/src/server/mod.rs @@ -13,23 +13,29 @@ use crate::{header, types::*}; use crate::{apis, models}; /// Setup API Server. -pub fn new(api_impl: I) -> Router +pub fn new(api_impl: I) -> Router where I: AsRef + Clone + Send + Sync + 'static, - A: apis::payments::Payments + A: apis::payments::Payments + apis::ApiKeyAuthHeader + apis::CookieAuthentication + + Send + + Sync + 'static, + E: std::fmt::Debug + Send + Sync + 'static, C: Send + Sync + 'static, { // build our application with a route Router::new() - .route("/v71/paymentMethods", get(get_payment_methods::)) + .route( + "/v71/paymentMethods", + get(get_payment_methods::), + ) .route( "/v71/paymentMethods/:id", - get(get_payment_method_by_id::), + get(get_payment_method_by_id::), ) - .route("/v71/payments", post(post_make_payment::)) + .route("/v71/payments", post(post_make_payment::)) .with_state(api_impl) } @@ -43,7 +49,7 @@ fn get_payment_method_by_id_validation( } /// GetPaymentMethodById - GET /v71/paymentMethods/{id} #[tracing::instrument(skip_all)] -async fn get_payment_method_by_id( +async fn get_payment_method_by_id( method: Method, host: Host, cookies: CookieJar, @@ -52,7 +58,8 @@ async fn get_payment_method_by_id( ) -> Result where I: AsRef + Send + Sync, - A: apis::payments::Payments, + A: apis::payments::Payments + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = @@ -69,7 +76,7 @@ where let result = api_impl .as_ref() - .get_payment_method_by_id(method, host, cookies, path_params) + .get_payment_method_by_id(&method, &host, &cookies, &path_params) .await; let mut response = Response::builder(); @@ -123,10 +130,14 @@ where response.body(Body::from(body_content)) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -142,7 +153,7 @@ fn get_payment_methods_validation() -> std::result::Result<(), ValidationErrors> } /// GetPaymentMethods - GET /v71/paymentMethods #[tracing::instrument(skip_all)] -async fn get_payment_methods( +async fn get_payment_methods( method: Method, host: Host, cookies: CookieJar, @@ -150,7 +161,8 @@ async fn get_payment_methods( ) -> Result where I: AsRef + Send + Sync, - A: apis::payments::Payments, + A: apis::payments::Payments + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || get_payment_methods_validation()) @@ -166,7 +178,7 @@ where let result = api_impl .as_ref() - .get_payment_methods(method, host, cookies) + .get_payment_methods(&method, &host, &cookies) .await; let mut response = Response::builder(); @@ -197,10 +209,14 @@ where response.body(Body::from(body_content)) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -230,7 +246,7 @@ fn post_make_payment_validation( } /// PostMakePayment - POST /v71/payments #[tracing::instrument(skip_all)] -async fn post_make_payment( +async fn post_make_payment( method: Method, host: Host, cookies: CookieJar, @@ -239,7 +255,11 @@ async fn post_make_payment( ) -> Result where I: AsRef + Send + Sync, - A: apis::payments::Payments + apis::CookieAuthentication, + A: apis::payments::Payments + + apis::CookieAuthentication + + Send + + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { // Authentication let claims_in_cookie = api_impl @@ -268,7 +288,7 @@ where let result = api_impl .as_ref() - .post_make_payment(method, host, cookies, claims, body) + .post_make_payment(&method, &host, &cookies, &claims, &body) .await; let mut response = Response::builder(); @@ -322,10 +342,14 @@ where response.body(Body::from(body_content)) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; diff --git a/samples/server/petstore/rust-axum/output/multipart-v3/.openapi-generator/VERSION b/samples/server/petstore/rust-axum/output/multipart-v3/.openapi-generator/VERSION index 884119126398..de37f5c4cf59 100644 --- a/samples/server/petstore/rust-axum/output/multipart-v3/.openapi-generator/VERSION +++ b/samples/server/petstore/rust-axum/output/multipart-v3/.openapi-generator/VERSION @@ -1 +1 @@ -7.11.0-SNAPSHOT +7.12.0-SNAPSHOT diff --git a/samples/server/petstore/rust-axum/output/multipart-v3/Cargo.toml b/samples/server/petstore/rust-axum/output/multipart-v3/Cargo.toml index a9857fc6b6d6..14a77bf61a09 100644 --- a/samples/server/petstore/rust-axum/output/multipart-v3/Cargo.toml +++ b/samples/server/petstore/rust-axum/output/multipart-v3/Cargo.toml @@ -40,7 +40,7 @@ tokio = { version = "1", default-features = false, features = [ ] } tracing = { version = "0.1", features = ["attributes"] } uuid = { version = "1", features = ["serde"] } -validator = { version = "0.19", features = ["derive"] } +validator = { version = "0.20", features = ["derive"] } [dev-dependencies] tracing-subscriber = "0.3" diff --git a/samples/server/petstore/rust-axum/output/multipart-v3/README.md b/samples/server/petstore/rust-axum/output/multipart-v3/README.md index 4944ebb95cdf..0451497fd561 100644 --- a/samples/server/petstore/rust-axum/output/multipart-v3/README.md +++ b/samples/server/petstore/rust-axum/output/multipart-v3/README.md @@ -12,7 +12,7 @@ server, you can easily generate a server stub. To see how to make this your own, look here: [README]((https://openapi-generator.tech)) - API version: 1.0.7 -- Generator version: 7.11.0-SNAPSHOT +- Generator version: 7.12.0-SNAPSHOT @@ -43,16 +43,18 @@ struct ServerImpl { #[allow(unused_variables)] #[async_trait] -impl multipart-v3::Api for ServerImpl { +impl multipart_v3::apis::default::Api for ServerImpl { // API implementation goes here } +impl multipart_v3::apis::ErrorHandler for ServerImpl {} + pub async fn start_server(addr: &str) { // initialize tracing tracing_subscriber::fmt::init(); // Init Axum router - let app = multipart-v3::server::new(Arc::new(ServerImpl)); + let app = multipart_v3::server::new(Arc::new(ServerImpl)); // Add layers to the router let app = app.layer(...); diff --git a/samples/server/petstore/rust-axum/output/multipart-v3/src/apis/default.rs b/samples/server/petstore/rust-axum/output/multipart-v3/src/apis/default.rs index ad21c532ae7e..ff1e7b6353d7 100644 --- a/samples/server/petstore/rust-axum/output/multipart-v3/src/apis/default.rs +++ b/samples/server/petstore/rust-axum/output/multipart-v3/src/apis/default.rs @@ -34,31 +34,31 @@ pub enum MultipleIdenticalMimeTypesPostResponse { /// Default #[async_trait] #[allow(clippy::ptr_arg)] -pub trait Default { +pub trait Default: super::ErrorHandler { /// MultipartRelatedRequestPost - POST /multipart_related_request async fn multipart_related_request_post( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: axum::body::Body, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &axum::body::Body, + ) -> Result; /// MultipartRequestPost - POST /multipart_request async fn multipart_request_post( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Multipart, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &Multipart, + ) -> Result; /// MultipleIdenticalMimeTypesPost - POST /multiple-identical-mime-types async fn multiple_identical_mime_types_post( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: axum::body::Body, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &axum::body::Body, + ) -> Result; } diff --git a/samples/server/petstore/rust-axum/output/multipart-v3/src/apis/mod.rs b/samples/server/petstore/rust-axum/output/multipart-v3/src/apis/mod.rs index 1be8d340b8e0..189958193a59 100644 --- a/samples/server/petstore/rust-axum/output/multipart-v3/src/apis/mod.rs +++ b/samples/server/petstore/rust-axum/output/multipart-v3/src/apis/mod.rs @@ -1 +1,21 @@ pub mod default; + +// Error handler for unhandled errors. +#[async_trait::async_trait] +pub trait ErrorHandler { + #[allow(unused_variables)] + #[tracing::instrument(skip_all)] + async fn handle_error( + &self, + method: &::http::Method, + host: &axum::extract::Host, + cookies: &axum_extra::extract::CookieJar, + error: E, + ) -> Result { + tracing::error!("Unhandled error: {:?}", error); + axum::response::Response::builder() + .status(http::StatusCode::INTERNAL_SERVER_ERROR) + .body(axum::body::Body::empty()) + .map_err(|_| http::StatusCode::INTERNAL_SERVER_ERROR) + } +} diff --git a/samples/server/petstore/rust-axum/output/multipart-v3/src/server/mod.rs b/samples/server/petstore/rust-axum/output/multipart-v3/src/server/mod.rs index 89fd45ae4611..5deba8406f0c 100644 --- a/samples/server/petstore/rust-axum/output/multipart-v3/src/server/mod.rs +++ b/samples/server/petstore/rust-axum/output/multipart-v3/src/server/mod.rs @@ -13,21 +13,25 @@ use crate::{header, types::*}; use crate::{apis, models}; /// Setup API Server. -pub fn new(api_impl: I) -> Router +pub fn new(api_impl: I) -> Router where I: AsRef + Clone + Send + Sync + 'static, - A: apis::default::Default + 'static, + A: apis::default::Default + Send + Sync + 'static, + E: std::fmt::Debug + Send + Sync + 'static, { // build our application with a route Router::new() .route( "/multipart_related_request", - post(multipart_related_request_post::), + post(multipart_related_request_post::), + ) + .route( + "/multipart_request", + post(multipart_request_post::), ) - .route("/multipart_request", post(multipart_request_post::)) .route( "/multiple-identical-mime-types", - post(multiple_identical_mime_types_post::), + post(multiple_identical_mime_types_post::), ) .with_state(api_impl) } @@ -38,7 +42,7 @@ fn multipart_related_request_post_validation() -> std::result::Result<(), Valida } /// MultipartRelatedRequestPost - POST /multipart_related_request #[tracing::instrument(skip_all)] -async fn multipart_related_request_post( +async fn multipart_related_request_post( method: Method, host: Host, cookies: CookieJar, @@ -47,7 +51,8 @@ async fn multipart_related_request_post( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = @@ -64,7 +69,7 @@ where let result = api_impl .as_ref() - .multipart_related_request_post(method, host, cookies, body) + .multipart_related_request_post(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -76,10 +81,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -95,7 +104,7 @@ fn multipart_request_post_validation() -> std::result::Result<(), ValidationErro } /// MultipartRequestPost - POST /multipart_request #[tracing::instrument(skip_all)] -async fn multipart_request_post( +async fn multipart_request_post( method: Method, host: Host, cookies: CookieJar, @@ -104,7 +113,8 @@ async fn multipart_request_post( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || multipart_request_post_validation()) @@ -120,7 +130,7 @@ where let result = api_impl .as_ref() - .multipart_request_post(method, host, cookies, body) + .multipart_request_post(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -132,10 +142,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -151,7 +165,7 @@ fn multiple_identical_mime_types_post_validation() -> std::result::Result<(), Va } /// MultipleIdenticalMimeTypesPost - POST /multiple-identical-mime-types #[tracing::instrument(skip_all)] -async fn multiple_identical_mime_types_post( +async fn multiple_identical_mime_types_post( method: Method, host: Host, cookies: CookieJar, @@ -160,7 +174,8 @@ async fn multiple_identical_mime_types_post( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = @@ -177,7 +192,7 @@ where let result = api_impl .as_ref() - .multiple_identical_mime_types_post(method, host, cookies, body) + .multiple_identical_mime_types_post(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -189,10 +204,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; diff --git a/samples/server/petstore/rust-axum/output/openapi-v3/.openapi-generator/VERSION b/samples/server/petstore/rust-axum/output/openapi-v3/.openapi-generator/VERSION index 884119126398..de37f5c4cf59 100644 --- a/samples/server/petstore/rust-axum/output/openapi-v3/.openapi-generator/VERSION +++ b/samples/server/petstore/rust-axum/output/openapi-v3/.openapi-generator/VERSION @@ -1 +1 @@ -7.11.0-SNAPSHOT +7.12.0-SNAPSHOT diff --git a/samples/server/petstore/rust-axum/output/openapi-v3/Cargo.toml b/samples/server/petstore/rust-axum/output/openapi-v3/Cargo.toml index d53ab13dcb78..8ca134992a3b 100644 --- a/samples/server/petstore/rust-axum/output/openapi-v3/Cargo.toml +++ b/samples/server/petstore/rust-axum/output/openapi-v3/Cargo.toml @@ -40,7 +40,7 @@ tokio = { version = "1", default-features = false, features = [ ] } tracing = { version = "0.1", features = ["attributes"] } uuid = { version = "1", features = ["serde"] } -validator = { version = "0.19", features = ["derive"] } +validator = { version = "0.20", features = ["derive"] } [dev-dependencies] tracing-subscriber = "0.3" diff --git a/samples/server/petstore/rust-axum/output/openapi-v3/README.md b/samples/server/petstore/rust-axum/output/openapi-v3/README.md index 3054fe00af70..813a1753c314 100644 --- a/samples/server/petstore/rust-axum/output/openapi-v3/README.md +++ b/samples/server/petstore/rust-axum/output/openapi-v3/README.md @@ -12,7 +12,7 @@ server, you can easily generate a server stub. To see how to make this your own, look here: [README]((https://openapi-generator.tech)) - API version: 1.0.7 -- Generator version: 7.11.0-SNAPSHOT +- Generator version: 7.12.0-SNAPSHOT @@ -43,16 +43,18 @@ struct ServerImpl { #[allow(unused_variables)] #[async_trait] -impl openapi-v3::Api for ServerImpl { +impl openapi_v3::apis::default::Api for ServerImpl { // API implementation goes here } +impl openapi_v3::apis::ErrorHandler for ServerImpl {} + pub async fn start_server(addr: &str) { // initialize tracing tracing_subscriber::fmt::init(); // Init Axum router - let app = openapi-v3::server::new(Arc::new(ServerImpl)); + let app = openapi_v3::server::new(Arc::new(ServerImpl)); // Add layers to the router let app = app.layer(...); diff --git a/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/default.rs b/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/default.rs index 0e7b62722ca2..1e7c5186c981 100644 --- a/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/default.rs +++ b/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/default.rs @@ -274,255 +274,255 @@ pub enum XmlPutResponse { /// Default #[async_trait] #[allow(clippy::ptr_arg)] -pub trait Default { +pub trait Default: super::ErrorHandler { /// AnyOfGet - GET /any-of async fn any_of_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::AnyOfGetQueryParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + query_params: &models::AnyOfGetQueryParams, + ) -> Result; /// CallbackWithHeaderPost - POST /callback-with-header async fn callback_with_header_post( &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::CallbackWithHeaderPostQueryParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + query_params: &models::CallbackWithHeaderPostQueryParams, + ) -> Result; /// ComplexQueryParamGet - GET /complex-query-param async fn complex_query_param_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::ComplexQueryParamGetQueryParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + query_params: &models::ComplexQueryParamGetQueryParams, + ) -> Result; /// EnumInPathPathParamGet - GET /enum_in_path/{path_param} async fn enum_in_path_path_param_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::EnumInPathPathParamGetPathParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + path_params: &models::EnumInPathPathParamGetPathParams, + ) -> Result; /// Test a Form Post. /// /// FormTest - POST /form-test async fn form_test( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::FormTestRequest, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &models::FormTestRequest, + ) -> Result; /// GetWithBooleanParameter - GET /get-with-bool async fn get_with_boolean_parameter( &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::GetWithBooleanParameterQueryParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + query_params: &models::GetWithBooleanParameterQueryParams, + ) -> Result; /// JsonComplexQueryParamGet - GET /json-complex-query-param async fn json_complex_query_param_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::JsonComplexQueryParamGetQueryParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + query_params: &models::JsonComplexQueryParamGetQueryParams, + ) -> Result; /// MandatoryRequestHeaderGet - GET /mandatory-request-header async fn mandatory_request_header_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - header_params: models::MandatoryRequestHeaderGetHeaderParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + header_params: &models::MandatoryRequestHeaderGetHeaderParams, + ) -> Result; /// MergePatchJsonGet - GET /merge-patch-json async fn merge_patch_json_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Get some stuff.. /// /// MultigetGet - GET /multiget async fn multiget_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// MultipleAuthSchemeGet - GET /multiple_auth_scheme async fn multiple_auth_scheme_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// MultiplePathParamsWithVeryLongPathToTestFormattingPathParamAPathParamBGet - GET /multiple-path-params-with-very-long-path-to-test-formatting/{path_param_a}/{path_param_b} async fn multiple_path_params_with_very_long_path_to_test_formatting_path_param_a_path_param_b_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::MultiplePathParamsWithVeryLongPathToTestFormattingPathParamAPathParamBGetPathParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + path_params: &models::MultiplePathParamsWithVeryLongPathToTestFormattingPathParamAPathParamBGetPathParams, + ) -> Result; /// OneOfGet - GET /one-of async fn one_of_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// OverrideServerGet - GET /override-server async fn override_server_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Get some stuff with parameters.. /// /// ParamgetGet - GET /paramget async fn paramget_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::ParamgetGetQueryParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + query_params: &models::ParamgetGetQueryParams, + ) -> Result; /// ReadonlyAuthSchemeGet - GET /readonly_auth_scheme async fn readonly_auth_scheme_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// RegisterCallbackPost - POST /register-callback async fn register_callback_post( &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::RegisterCallbackPostQueryParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + query_params: &models::RegisterCallbackPostQueryParams, + ) -> Result; /// RequiredOctetStreamPut - PUT /required_octet_stream async fn required_octet_stream_put( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Bytes, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &Bytes, + ) -> Result; /// ResponsesWithHeadersGet - GET /responses_with_headers async fn responses_with_headers_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Rfc7807Get - GET /rfc7807 async fn rfc7807_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// TwoFirstLetterHeaders - POST /operation-two-first-letter-headers async fn two_first_letter_headers( &self, - method: Method, - host: Host, - cookies: CookieJar, - header_params: models::TwoFirstLetterHeadersHeaderParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + header_params: &models::TwoFirstLetterHeadersHeaderParams, + ) -> Result; /// UntypedPropertyGet - GET /untyped_property async fn untyped_property_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Option, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &Option, + ) -> Result; /// UuidGet - GET /uuid async fn uuid_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// XmlExtraPost - POST /xml_extra async fn xml_extra_post( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Bytes, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &Bytes, + ) -> Result; /// XmlOtherPost - POST /xml_other async fn xml_other_post( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Bytes, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &Bytes, + ) -> Result; /// XmlOtherPut - PUT /xml_other async fn xml_other_put( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Bytes, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &Bytes, + ) -> Result; /// Post an array. It's important we test apostrophes, so include one here.. /// /// XmlPost - POST /xml async fn xml_post( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Bytes, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &Bytes, + ) -> Result; /// XmlPut - PUT /xml async fn xml_put( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Bytes, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &Bytes, + ) -> Result; } diff --git a/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/info_repo.rs b/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/info_repo.rs index c73db4a16d43..116f1283534f 100644 --- a/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/info_repo.rs +++ b/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/info_repo.rs @@ -18,13 +18,15 @@ pub enum GetRepoInfoResponse { /// InfoRepo #[async_trait] #[allow(clippy::ptr_arg)] -pub trait InfoRepo { +pub trait InfoRepo: + super::ErrorHandler +{ /// GetRepoInfo - GET /repos/{repoId} async fn get_repo_info( &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::GetRepoInfoPathParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + path_params: &models::GetRepoInfoPathParams, + ) -> Result; } diff --git a/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/mod.rs b/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/mod.rs index 63ecd2990e89..8d27762fd6d9 100644 --- a/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/mod.rs +++ b/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/mod.rs @@ -1,3 +1,23 @@ pub mod default; pub mod info_repo; pub mod repo; + +// Error handler for unhandled errors. +#[async_trait::async_trait] +pub trait ErrorHandler { + #[allow(unused_variables)] + #[tracing::instrument(skip_all)] + async fn handle_error( + &self, + method: &::http::Method, + host: &axum::extract::Host, + cookies: &axum_extra::extract::CookieJar, + error: E, + ) -> Result { + tracing::error!("Unhandled error: {:?}", error); + axum::response::Response::builder() + .status(http::StatusCode::INTERNAL_SERVER_ERROR) + .body(axum::body::Body::empty()) + .map_err(|_| http::StatusCode::INTERNAL_SERVER_ERROR) + } +} diff --git a/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/repo.rs b/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/repo.rs index 90d9a774f6e1..d66414a5f9ef 100644 --- a/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/repo.rs +++ b/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/repo.rs @@ -18,13 +18,13 @@ pub enum CreateRepoResponse { /// Repo #[async_trait] #[allow(clippy::ptr_arg)] -pub trait Repo { +pub trait Repo: super::ErrorHandler { /// CreateRepo - POST /repos async fn create_repo( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::ObjectParam, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &models::ObjectParam, + ) -> Result; } diff --git a/samples/server/petstore/rust-axum/output/openapi-v3/src/server/mod.rs b/samples/server/petstore/rust-axum/output/openapi-v3/src/server/mod.rs index 666120206b69..3cf9e4a70bfa 100644 --- a/samples/server/petstore/rust-axum/output/openapi-v3/src/server/mod.rs +++ b/samples/server/petstore/rust-axum/output/openapi-v3/src/server/mod.rs @@ -13,96 +13,102 @@ use crate::{header, types::*}; use crate::{apis, models}; /// Setup API Server. -pub fn new(api_impl: I) -> Router +pub fn new(api_impl: I) -> Router where I: AsRef + Clone + Send + Sync + 'static, - A: apis::default::Default + apis::info_repo::InfoRepo + apis::repo::Repo + 'static, + A: apis::default::Default + + apis::info_repo::InfoRepo + + apis::repo::Repo + + Send + + Sync + + 'static, + E: std::fmt::Debug + Send + Sync + 'static, { // build our application with a route Router::new() .route("/any-of", - get(any_of_get::) + get(any_of_get::) ) .route("/callback-with-header", - post(callback_with_header_post::) + post(callback_with_header_post::) ) .route("/complex-query-param", - get(complex_query_param_get::) + get(complex_query_param_get::) ) .route("/enum_in_path/:path_param", - get(enum_in_path_path_param_get::) + get(enum_in_path_path_param_get::) ) .route("/form-test", - post(form_test::) + post(form_test::) ) .route("/get-with-bool", - get(get_with_boolean_parameter::) + get(get_with_boolean_parameter::) ) .route("/json-complex-query-param", - get(json_complex_query_param_get::) + get(json_complex_query_param_get::) ) .route("/mandatory-request-header", - get(mandatory_request_header_get::) + get(mandatory_request_header_get::) ) .route("/merge-patch-json", - get(merge_patch_json_get::) + get(merge_patch_json_get::) ) .route("/multiget", - get(multiget_get::) + get(multiget_get::) ) .route("/multiple-path-params-with-very-long-path-to-test-formatting/:path_param_a/:path_param_b", - get(multiple_path_params_with_very_long_path_to_test_formatting_path_param_a_path_param_b_get::) + get(multiple_path_params_with_very_long_path_to_test_formatting_path_param_a_path_param_b_get::) ) .route("/multiple_auth_scheme", - get(multiple_auth_scheme_get::) + get(multiple_auth_scheme_get::) ) .route("/one-of", - get(one_of_get::) + get(one_of_get::) ) .route("/operation-two-first-letter-headers", - post(two_first_letter_headers::) + post(two_first_letter_headers::) ) .route("/override-server", - get(override_server_get::) + get(override_server_get::) ) .route("/paramget", - get(paramget_get::) + get(paramget_get::) ) .route("/readonly_auth_scheme", - get(readonly_auth_scheme_get::) + get(readonly_auth_scheme_get::) ) .route("/register-callback", - post(register_callback_post::) + post(register_callback_post::) ) .route("/repos", - post(create_repo::) + post(create_repo::) ) .route("/repos/:repo_id", - get(get_repo_info::).get(get_repo_info::) + get(get_repo_info::).get(get_repo_info::) ) .route("/required_octet_stream", - put(required_octet_stream_put::) + put(required_octet_stream_put::) ) .route("/responses_with_headers", - get(responses_with_headers_get::) + get(responses_with_headers_get::) ) .route("/rfc7807", - get(rfc7807_get::) + get(rfc7807_get::) ) .route("/untyped_property", - get(untyped_property_get::) + get(untyped_property_get::) ) .route("/uuid", - get(uuid_get::) + get(uuid_get::) ) .route("/xml", - post(xml_post::).put(xml_put::) + post(xml_post::).put(xml_put::) ) .route("/xml_extra", - post(xml_extra_post::) + post(xml_extra_post::) ) .route("/xml_other", - post(xml_other_post::).put(xml_other_put::) + post(xml_other_post::).put(xml_other_put::) ) .with_state(api_impl) } @@ -117,7 +123,7 @@ fn any_of_get_validation( } /// AnyOfGet - GET /any-of #[tracing::instrument(skip_all)] -async fn any_of_get( +async fn any_of_get( method: Method, host: Host, cookies: CookieJar, @@ -126,7 +132,8 @@ async fn any_of_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { let validation = any_of_get_validation(query_params); @@ -139,7 +146,7 @@ where let result = api_impl .as_ref() - .any_of_get(method, host, cookies, query_params) + .any_of_get(&method, &host, &cookies, &query_params) .await; let mut response = Response::builder(); @@ -216,10 +223,14 @@ where response.body(Body::from(body_content)) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -239,7 +250,7 @@ fn callback_with_header_post_validation( } /// CallbackWithHeaderPost - POST /callback-with-header #[tracing::instrument(skip_all)] -async fn callback_with_header_post( +async fn callback_with_header_post( method: Method, host: Host, cookies: CookieJar, @@ -248,7 +259,8 @@ async fn callback_with_header_post( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { let validation = callback_with_header_post_validation(query_params); @@ -261,7 +273,7 @@ where let result = api_impl .as_ref() - .callback_with_header_post(method, host, cookies, query_params) + .callback_with_header_post(&method, &host, &cookies, &query_params) .await; let mut response = Response::builder(); @@ -273,10 +285,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -296,7 +312,7 @@ fn complex_query_param_get_validation( } /// ComplexQueryParamGet - GET /complex-query-param #[tracing::instrument(skip_all)] -async fn complex_query_param_get( +async fn complex_query_param_get( method: Method, host: Host, cookies: CookieJar, @@ -305,7 +321,8 @@ async fn complex_query_param_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { let validation = complex_query_param_get_validation(query_params); @@ -318,7 +335,7 @@ where let result = api_impl .as_ref() - .complex_query_param_get(method, host, cookies, query_params) + .complex_query_param_get(&method, &host, &cookies, &query_params) .await; let mut response = Response::builder(); @@ -330,10 +347,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -353,7 +374,7 @@ fn enum_in_path_path_param_get_validation( } /// EnumInPathPathParamGet - GET /enum_in_path/{path_param} #[tracing::instrument(skip_all)] -async fn enum_in_path_path_param_get( +async fn enum_in_path_path_param_get( method: Method, host: Host, cookies: CookieJar, @@ -362,7 +383,8 @@ async fn enum_in_path_path_param_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { let validation = enum_in_path_path_param_get_validation(path_params); @@ -375,7 +397,7 @@ where let result = api_impl .as_ref() - .enum_in_path_path_param_get(method, host, cookies, path_params) + .enum_in_path_path_param_get(&method, &host, &cookies, &path_params) .await; let mut response = Response::builder(); @@ -387,10 +409,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -418,7 +444,7 @@ fn form_test_validation( } /// FormTest - POST /form-test #[tracing::instrument(skip_all)] -async fn form_test( +async fn form_test( method: Method, host: Host, cookies: CookieJar, @@ -427,7 +453,8 @@ async fn form_test( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { let validation = form_test_validation(body); @@ -440,7 +467,7 @@ where let result = api_impl .as_ref() - .form_test(method, host, cookies, body) + .form_test(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -452,10 +479,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -475,7 +506,7 @@ fn get_with_boolean_parameter_validation( } /// GetWithBooleanParameter - GET /get-with-bool #[tracing::instrument(skip_all)] -async fn get_with_boolean_parameter( +async fn get_with_boolean_parameter( method: Method, host: Host, cookies: CookieJar, @@ -484,7 +515,8 @@ async fn get_with_boolean_parameter( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { let validation = get_with_boolean_parameter_validation(query_params); @@ -497,7 +529,7 @@ where let result = api_impl .as_ref() - .get_with_boolean_parameter(method, host, cookies, query_params) + .get_with_boolean_parameter(&method, &host, &cookies, &query_params) .await; let mut response = Response::builder(); @@ -509,10 +541,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -532,7 +568,7 @@ fn json_complex_query_param_get_validation( } /// JsonComplexQueryParamGet - GET /json-complex-query-param #[tracing::instrument(skip_all)] -async fn json_complex_query_param_get( +async fn json_complex_query_param_get( method: Method, host: Host, cookies: CookieJar, @@ -541,7 +577,8 @@ async fn json_complex_query_param_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { let validation = json_complex_query_param_get_validation(query_params); @@ -554,7 +591,7 @@ where let result = api_impl .as_ref() - .json_complex_query_param_get(method, host, cookies, query_params) + .json_complex_query_param_get(&method, &host, &cookies, &query_params) .await; let mut response = Response::builder(); @@ -566,10 +603,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -589,7 +630,7 @@ fn mandatory_request_header_get_validation( } /// MandatoryRequestHeaderGet - GET /mandatory-request-header #[tracing::instrument(skip_all)] -async fn mandatory_request_header_get( +async fn mandatory_request_header_get( method: Method, host: Host, cookies: CookieJar, @@ -598,7 +639,8 @@ async fn mandatory_request_header_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { // Header parameters let header_params = { @@ -644,7 +686,7 @@ where let result = api_impl .as_ref() - .mandatory_request_header_get(method, host, cookies, header_params) + .mandatory_request_header_get(&method, &host, &cookies, &header_params) .await; let mut response = Response::builder(); @@ -656,10 +698,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -675,7 +721,7 @@ fn merge_patch_json_get_validation() -> std::result::Result<(), ValidationErrors } /// MergePatchJsonGet - GET /merge-patch-json #[tracing::instrument(skip_all)] -async fn merge_patch_json_get( +async fn merge_patch_json_get( method: Method, host: Host, cookies: CookieJar, @@ -683,7 +729,8 @@ async fn merge_patch_json_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { let validation = merge_patch_json_get_validation(); @@ -696,7 +743,7 @@ where let result = api_impl .as_ref() - .merge_patch_json_get(method, host, cookies) + .merge_patch_json_get(&method, &host, &cookies) .await; let mut response = Response::builder(); @@ -727,10 +774,14 @@ where response.body(Body::from(body_content)) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -746,7 +797,7 @@ fn multiget_get_validation() -> std::result::Result<(), ValidationErrors> { } /// MultigetGet - GET /multiget #[tracing::instrument(skip_all)] -async fn multiget_get( +async fn multiget_get( method: Method, host: Host, cookies: CookieJar, @@ -754,7 +805,8 @@ async fn multiget_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { let validation = multiget_get_validation(); @@ -765,7 +817,10 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().multiget_get(method, host, cookies).await; + let result = api_impl + .as_ref() + .multiget_get(&method, &host, &cookies) + .await; let mut response = Response::builder(); @@ -912,10 +967,14 @@ where response.body(Body::from(body_content)) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -931,7 +990,7 @@ fn multiple_auth_scheme_get_validation() -> std::result::Result<(), ValidationEr } /// MultipleAuthSchemeGet - GET /multiple_auth_scheme #[tracing::instrument(skip_all)] -async fn multiple_auth_scheme_get( +async fn multiple_auth_scheme_get( method: Method, host: Host, cookies: CookieJar, @@ -939,7 +998,8 @@ async fn multiple_auth_scheme_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { let validation = multiple_auth_scheme_get_validation(); @@ -952,7 +1012,7 @@ where let result = api_impl .as_ref() - .multiple_auth_scheme_get(method, host, cookies) + .multiple_auth_scheme_get(&method, &host, &cookies) .await; let mut response = Response::builder(); @@ -965,10 +1025,11 @@ where response.body(Body::empty()) }, }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl.as_ref().handle_error(&method, &host, &cookies, why).await; }, }; @@ -994,6 +1055,7 @@ fn multiple_path_params_with_very_long_path_to_test_formatting_path_param_a_path async fn multiple_path_params_with_very_long_path_to_test_formatting_path_param_a_path_param_b_get< I, A, + E, >( method: Method, host: Host, @@ -1005,7 +1067,8 @@ async fn multiple_path_params_with_very_long_path_to_test_formatting_path_param_ ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { let validation = multiple_path_params_with_very_long_path_to_test_formatting_path_param_a_path_param_b_get_validation( @@ -1023,10 +1086,10 @@ where let result = api_impl .as_ref() .multiple_path_params_with_very_long_path_to_test_formatting_path_param_a_path_param_b_get( - method, - host, - cookies, - path_params, + &method, + &host, + &cookies, + &path_params, ) .await; @@ -1040,10 +1103,11 @@ where response.body(Body::empty()) }, }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl.as_ref().handle_error(&method, &host, &cookies, why).await; }, }; @@ -1059,7 +1123,7 @@ fn one_of_get_validation() -> std::result::Result<(), ValidationErrors> { } /// OneOfGet - GET /one-of #[tracing::instrument(skip_all)] -async fn one_of_get( +async fn one_of_get( method: Method, host: Host, cookies: CookieJar, @@ -1067,7 +1131,8 @@ async fn one_of_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { let validation = one_of_get_validation(); @@ -1078,7 +1143,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().one_of_get(method, host, cookies).await; + let result = api_impl.as_ref().one_of_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -1108,10 +1173,14 @@ where response.body(Body::from(body_content)) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1127,7 +1196,7 @@ fn override_server_get_validation() -> std::result::Result<(), ValidationErrors> } /// OverrideServerGet - GET /override-server #[tracing::instrument(skip_all)] -async fn override_server_get( +async fn override_server_get( method: Method, host: Host, cookies: CookieJar, @@ -1135,7 +1204,8 @@ async fn override_server_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { let validation = override_server_get_validation(); @@ -1148,7 +1218,7 @@ where let result = api_impl .as_ref() - .override_server_get(method, host, cookies) + .override_server_get(&method, &host, &cookies) .await; let mut response = Response::builder(); @@ -1160,10 +1230,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1183,7 +1257,7 @@ fn paramget_get_validation( } /// ParamgetGet - GET /paramget #[tracing::instrument(skip_all)] -async fn paramget_get( +async fn paramget_get( method: Method, host: Host, cookies: CookieJar, @@ -1192,7 +1266,8 @@ async fn paramget_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { let validation = paramget_get_validation(query_params); @@ -1205,7 +1280,7 @@ where let result = api_impl .as_ref() - .paramget_get(method, host, cookies, query_params) + .paramget_get(&method, &host, &cookies, &query_params) .await; let mut response = Response::builder(); @@ -1236,10 +1311,14 @@ where response.body(Body::from(body_content)) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1255,7 +1334,7 @@ fn readonly_auth_scheme_get_validation() -> std::result::Result<(), ValidationEr } /// ReadonlyAuthSchemeGet - GET /readonly_auth_scheme #[tracing::instrument(skip_all)] -async fn readonly_auth_scheme_get( +async fn readonly_auth_scheme_get( method: Method, host: Host, cookies: CookieJar, @@ -1263,7 +1342,8 @@ async fn readonly_auth_scheme_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { let validation = readonly_auth_scheme_get_validation(); @@ -1276,7 +1356,7 @@ where let result = api_impl .as_ref() - .readonly_auth_scheme_get(method, host, cookies) + .readonly_auth_scheme_get(&method, &host, &cookies) .await; let mut response = Response::builder(); @@ -1289,10 +1369,11 @@ where response.body(Body::empty()) }, }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl.as_ref().handle_error(&method, &host, &cookies, why).await; }, }; @@ -1312,7 +1393,7 @@ fn register_callback_post_validation( } /// RegisterCallbackPost - POST /register-callback #[tracing::instrument(skip_all)] -async fn register_callback_post( +async fn register_callback_post( method: Method, host: Host, cookies: CookieJar, @@ -1321,7 +1402,8 @@ async fn register_callback_post( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { let validation = register_callback_post_validation(query_params); @@ -1334,7 +1416,7 @@ where let result = api_impl .as_ref() - .register_callback_post(method, host, cookies, query_params) + .register_callback_post(&method, &host, &cookies, &query_params) .await; let mut response = Response::builder(); @@ -1346,10 +1428,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1373,7 +1459,7 @@ fn required_octet_stream_put_validation( } /// RequiredOctetStreamPut - PUT /required_octet_stream #[tracing::instrument(skip_all)] -async fn required_octet_stream_put( +async fn required_octet_stream_put( method: Method, host: Host, cookies: CookieJar, @@ -1382,7 +1468,8 @@ async fn required_octet_stream_put( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { let validation = required_octet_stream_put_validation(body); @@ -1395,7 +1482,7 @@ where let result = api_impl .as_ref() - .required_octet_stream_put(method, host, cookies, body) + .required_octet_stream_put(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -1407,10 +1494,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1426,7 +1517,7 @@ fn responses_with_headers_get_validation() -> std::result::Result<(), Validation } /// ResponsesWithHeadersGet - GET /responses_with_headers #[tracing::instrument(skip_all)] -async fn responses_with_headers_get( +async fn responses_with_headers_get( method: Method, host: Host, cookies: CookieJar, @@ -1434,7 +1525,8 @@ async fn responses_with_headers_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { let validation = responses_with_headers_get_validation(); @@ -1447,7 +1539,7 @@ where let result = api_impl .as_ref() - .responses_with_headers_get(method, host, cookies) + .responses_with_headers_get(&method, &host, &cookies) .await; let mut response = Response::builder(); @@ -1567,10 +1659,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1586,7 +1682,7 @@ fn rfc7807_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Rfc7807Get - GET /rfc7807 #[tracing::instrument(skip_all)] -async fn rfc7807_get( +async fn rfc7807_get( method: Method, host: Host, cookies: CookieJar, @@ -1594,7 +1690,8 @@ async fn rfc7807_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { let validation = rfc7807_get_validation(); @@ -1605,7 +1702,10 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().rfc7807_get(method, host, cookies).await; + let result = api_impl + .as_ref() + .rfc7807_get(&method, &host, &cookies) + .await; let mut response = Response::builder(); @@ -1674,10 +1774,14 @@ where response.body(Body::from(body_content)) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1697,7 +1801,7 @@ fn two_first_letter_headers_validation( } /// TwoFirstLetterHeaders - POST /operation-two-first-letter-headers #[tracing::instrument(skip_all)] -async fn two_first_letter_headers( +async fn two_first_letter_headers( method: Method, host: Host, cookies: CookieJar, @@ -1706,7 +1810,8 @@ async fn two_first_letter_headers( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { // Header parameters let header_params = { @@ -1762,7 +1867,7 @@ where let result = api_impl .as_ref() - .two_first_letter_headers(method, host, cookies, header_params) + .two_first_letter_headers(&method, &host, &cookies, &header_params) .await; let mut response = Response::builder(); @@ -1774,10 +1879,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1807,7 +1916,7 @@ fn untyped_property_get_validation( } /// UntypedPropertyGet - GET /untyped_property #[tracing::instrument(skip_all)] -async fn untyped_property_get( +async fn untyped_property_get( method: Method, host: Host, cookies: CookieJar, @@ -1816,7 +1925,8 @@ async fn untyped_property_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { let validation = untyped_property_get_validation(body); @@ -1829,7 +1939,7 @@ where let result = api_impl .as_ref() - .untyped_property_get(method, host, cookies, body) + .untyped_property_get(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -1842,10 +1952,11 @@ where response.body(Body::empty()) }, }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl.as_ref().handle_error(&method, &host, &cookies, why).await; }, }; @@ -1861,7 +1972,7 @@ fn uuid_get_validation() -> std::result::Result<(), ValidationErrors> { } /// UuidGet - GET /uuid #[tracing::instrument(skip_all)] -async fn uuid_get( +async fn uuid_get( method: Method, host: Host, cookies: CookieJar, @@ -1869,7 +1980,8 @@ async fn uuid_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { let validation = uuid_get_validation(); @@ -1880,7 +1992,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().uuid_get(method, host, cookies).await; + let result = api_impl.as_ref().uuid_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -1910,10 +2022,14 @@ where response.body(Body::from(body_content)) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1935,7 +2051,7 @@ fn xml_extra_post_validation(body: Bytes) -> std::result::Result<(Bytes,), Valid } /// XmlExtraPost - POST /xml_extra #[tracing::instrument(skip_all)] -async fn xml_extra_post( +async fn xml_extra_post( method: Method, host: Host, cookies: CookieJar, @@ -1944,7 +2060,8 @@ async fn xml_extra_post( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { let validation = xml_extra_post_validation(body); @@ -1957,7 +2074,7 @@ where let result = api_impl .as_ref() - .xml_extra_post(method, host, cookies, body) + .xml_extra_post(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -1973,10 +2090,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1998,7 +2119,7 @@ fn xml_other_post_validation(body: Bytes) -> std::result::Result<(Bytes,), Valid } /// XmlOtherPost - POST /xml_other #[tracing::instrument(skip_all)] -async fn xml_other_post( +async fn xml_other_post( method: Method, host: Host, cookies: CookieJar, @@ -2007,7 +2128,8 @@ async fn xml_other_post( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { let validation = xml_other_post_validation(body); @@ -2020,7 +2142,7 @@ where let result = api_impl .as_ref() - .xml_other_post(method, host, cookies, body) + .xml_other_post(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -2048,10 +2170,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -2073,7 +2199,7 @@ fn xml_other_put_validation(body: Bytes) -> std::result::Result<(Bytes,), Valida } /// XmlOtherPut - PUT /xml_other #[tracing::instrument(skip_all)] -async fn xml_other_put( +async fn xml_other_put( method: Method, host: Host, cookies: CookieJar, @@ -2082,7 +2208,8 @@ async fn xml_other_put( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { let validation = xml_other_put_validation(body); @@ -2095,7 +2222,7 @@ where let result = api_impl .as_ref() - .xml_other_put(method, host, cookies, body) + .xml_other_put(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -2111,10 +2238,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -2136,7 +2267,7 @@ fn xml_post_validation(body: Bytes) -> std::result::Result<(Bytes,), ValidationE } /// XmlPost - POST /xml #[tracing::instrument(skip_all)] -async fn xml_post( +async fn xml_post( method: Method, host: Host, cookies: CookieJar, @@ -2145,7 +2276,8 @@ async fn xml_post( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { let validation = xml_post_validation(body); @@ -2158,7 +2290,7 @@ where let result = api_impl .as_ref() - .xml_post(method, host, cookies, body) + .xml_post(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -2174,10 +2306,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -2199,7 +2335,7 @@ fn xml_put_validation(body: Bytes) -> std::result::Result<(Bytes,), ValidationEr } /// XmlPut - PUT /xml #[tracing::instrument(skip_all)] -async fn xml_put( +async fn xml_put( method: Method, host: Host, cookies: CookieJar, @@ -2208,7 +2344,8 @@ async fn xml_put( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { let validation = xml_put_validation(body); @@ -2219,7 +2356,10 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().xml_put(method, host, cookies, body).await; + let result = api_impl + .as_ref() + .xml_put(&method, &host, &cookies, &body) + .await; let mut response = Response::builder(); @@ -2234,10 +2374,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -2257,7 +2401,7 @@ fn get_repo_info_validation( } /// GetRepoInfo - GET /repos/{repoId} #[tracing::instrument(skip_all)] -async fn get_repo_info( +async fn get_repo_info( method: Method, host: Host, cookies: CookieJar, @@ -2266,7 +2410,8 @@ async fn get_repo_info( ) -> Result where I: AsRef + Send + Sync, - A: apis::info_repo::InfoRepo, + A: apis::info_repo::InfoRepo + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { let validation = get_repo_info_validation(path_params); @@ -2279,7 +2424,7 @@ where let result = api_impl .as_ref() - .get_repo_info(method, host, cookies, path_params) + .get_repo_info(&method, &host, &cookies, &path_params) .await; let mut response = Response::builder(); @@ -2310,10 +2455,14 @@ where response.body(Body::from(body_content)) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -2341,7 +2490,7 @@ fn create_repo_validation( } /// CreateRepo - POST /repos #[tracing::instrument(skip_all)] -async fn create_repo( +async fn create_repo( method: Method, host: Host, cookies: CookieJar, @@ -2350,7 +2499,8 @@ async fn create_repo( ) -> Result where I: AsRef + Send + Sync, - A: apis::repo::Repo, + A: apis::repo::Repo + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { let validation = create_repo_validation(body); @@ -2363,7 +2513,7 @@ where let result = api_impl .as_ref() - .create_repo(method, host, cookies, body) + .create_repo(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -2375,10 +2525,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; diff --git a/samples/server/petstore/rust-axum/output/ops-v3/.openapi-generator/VERSION b/samples/server/petstore/rust-axum/output/ops-v3/.openapi-generator/VERSION index 884119126398..de37f5c4cf59 100644 --- a/samples/server/petstore/rust-axum/output/ops-v3/.openapi-generator/VERSION +++ b/samples/server/petstore/rust-axum/output/ops-v3/.openapi-generator/VERSION @@ -1 +1 @@ -7.11.0-SNAPSHOT +7.12.0-SNAPSHOT diff --git a/samples/server/petstore/rust-axum/output/ops-v3/Cargo.toml b/samples/server/petstore/rust-axum/output/ops-v3/Cargo.toml index cf62658dc1f0..593a385ae810 100644 --- a/samples/server/petstore/rust-axum/output/ops-v3/Cargo.toml +++ b/samples/server/petstore/rust-axum/output/ops-v3/Cargo.toml @@ -40,7 +40,7 @@ tokio = { version = "1", default-features = false, features = [ ] } tracing = { version = "0.1", features = ["attributes"] } uuid = { version = "1", features = ["serde"] } -validator = { version = "0.19", features = ["derive"] } +validator = { version = "0.20", features = ["derive"] } [dev-dependencies] tracing-subscriber = "0.3" diff --git a/samples/server/petstore/rust-axum/output/ops-v3/README.md b/samples/server/petstore/rust-axum/output/ops-v3/README.md index dd0e372a0747..e22d2151321c 100644 --- a/samples/server/petstore/rust-axum/output/ops-v3/README.md +++ b/samples/server/petstore/rust-axum/output/ops-v3/README.md @@ -12,7 +12,7 @@ server, you can easily generate a server stub. To see how to make this your own, look here: [README]((https://openapi-generator.tech)) - API version: 0.0.1 -- Generator version: 7.11.0-SNAPSHOT +- Generator version: 7.12.0-SNAPSHOT @@ -43,16 +43,18 @@ struct ServerImpl { #[allow(unused_variables)] #[async_trait] -impl ops-v3::Api for ServerImpl { +impl ops_v3::apis::default::Api for ServerImpl { // API implementation goes here } +impl ops_v3::apis::ErrorHandler for ServerImpl {} + pub async fn start_server(addr: &str) { // initialize tracing tracing_subscriber::fmt::init(); // Init Axum router - let app = ops-v3::server::new(Arc::new(ServerImpl)); + let app = ops_v3::server::new(Arc::new(ServerImpl)); // Add layers to the router let app = app.layer(...); diff --git a/samples/server/petstore/rust-axum/output/ops-v3/src/apis/default.rs b/samples/server/petstore/rust-axum/output/ops-v3/src/apis/default.rs index 387f4b3fa792..300e1e48e8b5 100644 --- a/samples/server/petstore/rust-axum/output/ops-v3/src/apis/default.rs +++ b/samples/server/petstore/rust-axum/output/ops-v3/src/apis/default.rs @@ -306,300 +306,300 @@ pub enum Op9GetResponse { /// Default #[async_trait] #[allow(clippy::ptr_arg)] -pub trait Default { +pub trait Default: super::ErrorHandler { /// Op10Get - GET /op10 async fn op10_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op11Get - GET /op11 async fn op11_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op12Get - GET /op12 async fn op12_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op13Get - GET /op13 async fn op13_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op14Get - GET /op14 async fn op14_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op15Get - GET /op15 async fn op15_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op16Get - GET /op16 async fn op16_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op17Get - GET /op17 async fn op17_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op18Get - GET /op18 async fn op18_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op19Get - GET /op19 async fn op19_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op1Get - GET /op1 async fn op1_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op20Get - GET /op20 async fn op20_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op21Get - GET /op21 async fn op21_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op22Get - GET /op22 async fn op22_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op23Get - GET /op23 async fn op23_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op24Get - GET /op24 async fn op24_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op25Get - GET /op25 async fn op25_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op26Get - GET /op26 async fn op26_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op27Get - GET /op27 async fn op27_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op28Get - GET /op28 async fn op28_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op29Get - GET /op29 async fn op29_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op2Get - GET /op2 async fn op2_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op30Get - GET /op30 async fn op30_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op31Get - GET /op31 async fn op31_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op32Get - GET /op32 async fn op32_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op33Get - GET /op33 async fn op33_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op34Get - GET /op34 async fn op34_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op35Get - GET /op35 async fn op35_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op36Get - GET /op36 async fn op36_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op37Get - GET /op37 async fn op37_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op3Get - GET /op3 async fn op3_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op4Get - GET /op4 async fn op4_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op5Get - GET /op5 async fn op5_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op6Get - GET /op6 async fn op6_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op7Get - GET /op7 async fn op7_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op8Get - GET /op8 async fn op8_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Op9Get - GET /op9 async fn op9_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; } diff --git a/samples/server/petstore/rust-axum/output/ops-v3/src/apis/mod.rs b/samples/server/petstore/rust-axum/output/ops-v3/src/apis/mod.rs index 1be8d340b8e0..189958193a59 100644 --- a/samples/server/petstore/rust-axum/output/ops-v3/src/apis/mod.rs +++ b/samples/server/petstore/rust-axum/output/ops-v3/src/apis/mod.rs @@ -1 +1,21 @@ pub mod default; + +// Error handler for unhandled errors. +#[async_trait::async_trait] +pub trait ErrorHandler { + #[allow(unused_variables)] + #[tracing::instrument(skip_all)] + async fn handle_error( + &self, + method: &::http::Method, + host: &axum::extract::Host, + cookies: &axum_extra::extract::CookieJar, + error: E, + ) -> Result { + tracing::error!("Unhandled error: {:?}", error); + axum::response::Response::builder() + .status(http::StatusCode::INTERNAL_SERVER_ERROR) + .body(axum::body::Body::empty()) + .map_err(|_| http::StatusCode::INTERNAL_SERVER_ERROR) + } +} diff --git a/samples/server/petstore/rust-axum/output/ops-v3/src/server/mod.rs b/samples/server/petstore/rust-axum/output/ops-v3/src/server/mod.rs index a8b3ed89bc76..c27bd65a859b 100644 --- a/samples/server/petstore/rust-axum/output/ops-v3/src/server/mod.rs +++ b/samples/server/petstore/rust-axum/output/ops-v3/src/server/mod.rs @@ -13,50 +13,51 @@ use crate::{header, types::*}; use crate::{apis, models}; /// Setup API Server. -pub fn new(api_impl: I) -> Router +pub fn new(api_impl: I) -> Router where I: AsRef + Clone + Send + Sync + 'static, - A: apis::default::Default + 'static, + A: apis::default::Default + Send + Sync + 'static, + E: std::fmt::Debug + Send + Sync + 'static, { // build our application with a route Router::new() - .route("/op1", get(op1_get::)) - .route("/op10", get(op10_get::)) - .route("/op11", get(op11_get::)) - .route("/op12", get(op12_get::)) - .route("/op13", get(op13_get::)) - .route("/op14", get(op14_get::)) - .route("/op15", get(op15_get::)) - .route("/op16", get(op16_get::)) - .route("/op17", get(op17_get::)) - .route("/op18", get(op18_get::)) - .route("/op19", get(op19_get::)) - .route("/op2", get(op2_get::)) - .route("/op20", get(op20_get::)) - .route("/op21", get(op21_get::)) - .route("/op22", get(op22_get::)) - .route("/op23", get(op23_get::)) - .route("/op24", get(op24_get::)) - .route("/op25", get(op25_get::)) - .route("/op26", get(op26_get::)) - .route("/op27", get(op27_get::)) - .route("/op28", get(op28_get::)) - .route("/op29", get(op29_get::)) - .route("/op3", get(op3_get::)) - .route("/op30", get(op30_get::)) - .route("/op31", get(op31_get::)) - .route("/op32", get(op32_get::)) - .route("/op33", get(op33_get::)) - .route("/op34", get(op34_get::)) - .route("/op35", get(op35_get::)) - .route("/op36", get(op36_get::)) - .route("/op37", get(op37_get::)) - .route("/op4", get(op4_get::)) - .route("/op5", get(op5_get::)) - .route("/op6", get(op6_get::)) - .route("/op7", get(op7_get::)) - .route("/op8", get(op8_get::)) - .route("/op9", get(op9_get::)) + .route("/op1", get(op1_get::)) + .route("/op10", get(op10_get::)) + .route("/op11", get(op11_get::)) + .route("/op12", get(op12_get::)) + .route("/op13", get(op13_get::)) + .route("/op14", get(op14_get::)) + .route("/op15", get(op15_get::)) + .route("/op16", get(op16_get::)) + .route("/op17", get(op17_get::)) + .route("/op18", get(op18_get::)) + .route("/op19", get(op19_get::)) + .route("/op2", get(op2_get::)) + .route("/op20", get(op20_get::)) + .route("/op21", get(op21_get::)) + .route("/op22", get(op22_get::)) + .route("/op23", get(op23_get::)) + .route("/op24", get(op24_get::)) + .route("/op25", get(op25_get::)) + .route("/op26", get(op26_get::)) + .route("/op27", get(op27_get::)) + .route("/op28", get(op28_get::)) + .route("/op29", get(op29_get::)) + .route("/op3", get(op3_get::)) + .route("/op30", get(op30_get::)) + .route("/op31", get(op31_get::)) + .route("/op32", get(op32_get::)) + .route("/op33", get(op33_get::)) + .route("/op34", get(op34_get::)) + .route("/op35", get(op35_get::)) + .route("/op36", get(op36_get::)) + .route("/op37", get(op37_get::)) + .route("/op4", get(op4_get::)) + .route("/op5", get(op5_get::)) + .route("/op6", get(op6_get::)) + .route("/op7", get(op7_get::)) + .route("/op8", get(op8_get::)) + .route("/op9", get(op9_get::)) .with_state(api_impl) } @@ -66,7 +67,7 @@ fn op10_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op10Get - GET /op10 #[tracing::instrument(skip_all)] -async fn op10_get( +async fn op10_get( method: Method, host: Host, cookies: CookieJar, @@ -74,7 +75,8 @@ async fn op10_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op10_get_validation()) @@ -88,7 +90,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op10_get(method, host, cookies).await; + let result = api_impl.as_ref().op10_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -99,10 +101,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -118,7 +124,7 @@ fn op11_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op11Get - GET /op11 #[tracing::instrument(skip_all)] -async fn op11_get( +async fn op11_get( method: Method, host: Host, cookies: CookieJar, @@ -126,7 +132,8 @@ async fn op11_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op11_get_validation()) @@ -140,7 +147,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op11_get(method, host, cookies).await; + let result = api_impl.as_ref().op11_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -151,10 +158,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -170,7 +181,7 @@ fn op12_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op12Get - GET /op12 #[tracing::instrument(skip_all)] -async fn op12_get( +async fn op12_get( method: Method, host: Host, cookies: CookieJar, @@ -178,7 +189,8 @@ async fn op12_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op12_get_validation()) @@ -192,7 +204,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op12_get(method, host, cookies).await; + let result = api_impl.as_ref().op12_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -203,10 +215,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -222,7 +238,7 @@ fn op13_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op13Get - GET /op13 #[tracing::instrument(skip_all)] -async fn op13_get( +async fn op13_get( method: Method, host: Host, cookies: CookieJar, @@ -230,7 +246,8 @@ async fn op13_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op13_get_validation()) @@ -244,7 +261,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op13_get(method, host, cookies).await; + let result = api_impl.as_ref().op13_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -255,10 +272,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -274,7 +295,7 @@ fn op14_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op14Get - GET /op14 #[tracing::instrument(skip_all)] -async fn op14_get( +async fn op14_get( method: Method, host: Host, cookies: CookieJar, @@ -282,7 +303,8 @@ async fn op14_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op14_get_validation()) @@ -296,7 +318,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op14_get(method, host, cookies).await; + let result = api_impl.as_ref().op14_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -307,10 +329,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -326,7 +352,7 @@ fn op15_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op15Get - GET /op15 #[tracing::instrument(skip_all)] -async fn op15_get( +async fn op15_get( method: Method, host: Host, cookies: CookieJar, @@ -334,7 +360,8 @@ async fn op15_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op15_get_validation()) @@ -348,7 +375,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op15_get(method, host, cookies).await; + let result = api_impl.as_ref().op15_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -359,10 +386,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -378,7 +409,7 @@ fn op16_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op16Get - GET /op16 #[tracing::instrument(skip_all)] -async fn op16_get( +async fn op16_get( method: Method, host: Host, cookies: CookieJar, @@ -386,7 +417,8 @@ async fn op16_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op16_get_validation()) @@ -400,7 +432,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op16_get(method, host, cookies).await; + let result = api_impl.as_ref().op16_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -411,10 +443,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -430,7 +466,7 @@ fn op17_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op17Get - GET /op17 #[tracing::instrument(skip_all)] -async fn op17_get( +async fn op17_get( method: Method, host: Host, cookies: CookieJar, @@ -438,7 +474,8 @@ async fn op17_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op17_get_validation()) @@ -452,7 +489,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op17_get(method, host, cookies).await; + let result = api_impl.as_ref().op17_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -463,10 +500,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -482,7 +523,7 @@ fn op18_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op18Get - GET /op18 #[tracing::instrument(skip_all)] -async fn op18_get( +async fn op18_get( method: Method, host: Host, cookies: CookieJar, @@ -490,7 +531,8 @@ async fn op18_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op18_get_validation()) @@ -504,7 +546,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op18_get(method, host, cookies).await; + let result = api_impl.as_ref().op18_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -515,10 +557,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -534,7 +580,7 @@ fn op19_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op19Get - GET /op19 #[tracing::instrument(skip_all)] -async fn op19_get( +async fn op19_get( method: Method, host: Host, cookies: CookieJar, @@ -542,7 +588,8 @@ async fn op19_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op19_get_validation()) @@ -556,7 +603,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op19_get(method, host, cookies).await; + let result = api_impl.as_ref().op19_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -567,10 +614,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -586,7 +637,7 @@ fn op1_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op1Get - GET /op1 #[tracing::instrument(skip_all)] -async fn op1_get( +async fn op1_get( method: Method, host: Host, cookies: CookieJar, @@ -594,7 +645,8 @@ async fn op1_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op1_get_validation()) @@ -608,7 +660,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op1_get(method, host, cookies).await; + let result = api_impl.as_ref().op1_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -619,10 +671,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -638,7 +694,7 @@ fn op20_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op20Get - GET /op20 #[tracing::instrument(skip_all)] -async fn op20_get( +async fn op20_get( method: Method, host: Host, cookies: CookieJar, @@ -646,7 +702,8 @@ async fn op20_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op20_get_validation()) @@ -660,7 +717,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op20_get(method, host, cookies).await; + let result = api_impl.as_ref().op20_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -671,10 +728,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -690,7 +751,7 @@ fn op21_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op21Get - GET /op21 #[tracing::instrument(skip_all)] -async fn op21_get( +async fn op21_get( method: Method, host: Host, cookies: CookieJar, @@ -698,7 +759,8 @@ async fn op21_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op21_get_validation()) @@ -712,7 +774,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op21_get(method, host, cookies).await; + let result = api_impl.as_ref().op21_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -723,10 +785,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -742,7 +808,7 @@ fn op22_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op22Get - GET /op22 #[tracing::instrument(skip_all)] -async fn op22_get( +async fn op22_get( method: Method, host: Host, cookies: CookieJar, @@ -750,7 +816,8 @@ async fn op22_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op22_get_validation()) @@ -764,7 +831,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op22_get(method, host, cookies).await; + let result = api_impl.as_ref().op22_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -775,10 +842,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -794,7 +865,7 @@ fn op23_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op23Get - GET /op23 #[tracing::instrument(skip_all)] -async fn op23_get( +async fn op23_get( method: Method, host: Host, cookies: CookieJar, @@ -802,7 +873,8 @@ async fn op23_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op23_get_validation()) @@ -816,7 +888,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op23_get(method, host, cookies).await; + let result = api_impl.as_ref().op23_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -827,10 +899,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -846,7 +922,7 @@ fn op24_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op24Get - GET /op24 #[tracing::instrument(skip_all)] -async fn op24_get( +async fn op24_get( method: Method, host: Host, cookies: CookieJar, @@ -854,7 +930,8 @@ async fn op24_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op24_get_validation()) @@ -868,7 +945,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op24_get(method, host, cookies).await; + let result = api_impl.as_ref().op24_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -879,10 +956,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -898,7 +979,7 @@ fn op25_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op25Get - GET /op25 #[tracing::instrument(skip_all)] -async fn op25_get( +async fn op25_get( method: Method, host: Host, cookies: CookieJar, @@ -906,7 +987,8 @@ async fn op25_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op25_get_validation()) @@ -920,7 +1002,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op25_get(method, host, cookies).await; + let result = api_impl.as_ref().op25_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -931,10 +1013,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -950,7 +1036,7 @@ fn op26_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op26Get - GET /op26 #[tracing::instrument(skip_all)] -async fn op26_get( +async fn op26_get( method: Method, host: Host, cookies: CookieJar, @@ -958,7 +1044,8 @@ async fn op26_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op26_get_validation()) @@ -972,7 +1059,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op26_get(method, host, cookies).await; + let result = api_impl.as_ref().op26_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -983,10 +1070,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1002,7 +1093,7 @@ fn op27_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op27Get - GET /op27 #[tracing::instrument(skip_all)] -async fn op27_get( +async fn op27_get( method: Method, host: Host, cookies: CookieJar, @@ -1010,7 +1101,8 @@ async fn op27_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op27_get_validation()) @@ -1024,7 +1116,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op27_get(method, host, cookies).await; + let result = api_impl.as_ref().op27_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -1035,10 +1127,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1054,7 +1150,7 @@ fn op28_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op28Get - GET /op28 #[tracing::instrument(skip_all)] -async fn op28_get( +async fn op28_get( method: Method, host: Host, cookies: CookieJar, @@ -1062,7 +1158,8 @@ async fn op28_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op28_get_validation()) @@ -1076,7 +1173,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op28_get(method, host, cookies).await; + let result = api_impl.as_ref().op28_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -1087,10 +1184,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1106,7 +1207,7 @@ fn op29_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op29Get - GET /op29 #[tracing::instrument(skip_all)] -async fn op29_get( +async fn op29_get( method: Method, host: Host, cookies: CookieJar, @@ -1114,7 +1215,8 @@ async fn op29_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op29_get_validation()) @@ -1128,7 +1230,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op29_get(method, host, cookies).await; + let result = api_impl.as_ref().op29_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -1139,10 +1241,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1158,7 +1264,7 @@ fn op2_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op2Get - GET /op2 #[tracing::instrument(skip_all)] -async fn op2_get( +async fn op2_get( method: Method, host: Host, cookies: CookieJar, @@ -1166,7 +1272,8 @@ async fn op2_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op2_get_validation()) @@ -1180,7 +1287,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op2_get(method, host, cookies).await; + let result = api_impl.as_ref().op2_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -1191,10 +1298,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1210,7 +1321,7 @@ fn op30_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op30Get - GET /op30 #[tracing::instrument(skip_all)] -async fn op30_get( +async fn op30_get( method: Method, host: Host, cookies: CookieJar, @@ -1218,7 +1329,8 @@ async fn op30_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op30_get_validation()) @@ -1232,7 +1344,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op30_get(method, host, cookies).await; + let result = api_impl.as_ref().op30_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -1243,10 +1355,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1262,7 +1378,7 @@ fn op31_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op31Get - GET /op31 #[tracing::instrument(skip_all)] -async fn op31_get( +async fn op31_get( method: Method, host: Host, cookies: CookieJar, @@ -1270,7 +1386,8 @@ async fn op31_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op31_get_validation()) @@ -1284,7 +1401,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op31_get(method, host, cookies).await; + let result = api_impl.as_ref().op31_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -1295,10 +1412,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1314,7 +1435,7 @@ fn op32_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op32Get - GET /op32 #[tracing::instrument(skip_all)] -async fn op32_get( +async fn op32_get( method: Method, host: Host, cookies: CookieJar, @@ -1322,7 +1443,8 @@ async fn op32_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op32_get_validation()) @@ -1336,7 +1458,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op32_get(method, host, cookies).await; + let result = api_impl.as_ref().op32_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -1347,10 +1469,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1366,7 +1492,7 @@ fn op33_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op33Get - GET /op33 #[tracing::instrument(skip_all)] -async fn op33_get( +async fn op33_get( method: Method, host: Host, cookies: CookieJar, @@ -1374,7 +1500,8 @@ async fn op33_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op33_get_validation()) @@ -1388,7 +1515,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op33_get(method, host, cookies).await; + let result = api_impl.as_ref().op33_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -1399,10 +1526,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1418,7 +1549,7 @@ fn op34_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op34Get - GET /op34 #[tracing::instrument(skip_all)] -async fn op34_get( +async fn op34_get( method: Method, host: Host, cookies: CookieJar, @@ -1426,7 +1557,8 @@ async fn op34_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op34_get_validation()) @@ -1440,7 +1572,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op34_get(method, host, cookies).await; + let result = api_impl.as_ref().op34_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -1451,10 +1583,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1470,7 +1606,7 @@ fn op35_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op35Get - GET /op35 #[tracing::instrument(skip_all)] -async fn op35_get( +async fn op35_get( method: Method, host: Host, cookies: CookieJar, @@ -1478,7 +1614,8 @@ async fn op35_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op35_get_validation()) @@ -1492,7 +1629,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op35_get(method, host, cookies).await; + let result = api_impl.as_ref().op35_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -1503,10 +1640,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1522,7 +1663,7 @@ fn op36_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op36Get - GET /op36 #[tracing::instrument(skip_all)] -async fn op36_get( +async fn op36_get( method: Method, host: Host, cookies: CookieJar, @@ -1530,7 +1671,8 @@ async fn op36_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op36_get_validation()) @@ -1544,7 +1686,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op36_get(method, host, cookies).await; + let result = api_impl.as_ref().op36_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -1555,10 +1697,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1574,7 +1720,7 @@ fn op37_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op37Get - GET /op37 #[tracing::instrument(skip_all)] -async fn op37_get( +async fn op37_get( method: Method, host: Host, cookies: CookieJar, @@ -1582,7 +1728,8 @@ async fn op37_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op37_get_validation()) @@ -1596,7 +1743,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op37_get(method, host, cookies).await; + let result = api_impl.as_ref().op37_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -1607,10 +1754,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1626,7 +1777,7 @@ fn op3_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op3Get - GET /op3 #[tracing::instrument(skip_all)] -async fn op3_get( +async fn op3_get( method: Method, host: Host, cookies: CookieJar, @@ -1634,7 +1785,8 @@ async fn op3_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op3_get_validation()) @@ -1648,7 +1800,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op3_get(method, host, cookies).await; + let result = api_impl.as_ref().op3_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -1659,10 +1811,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1678,7 +1834,7 @@ fn op4_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op4Get - GET /op4 #[tracing::instrument(skip_all)] -async fn op4_get( +async fn op4_get( method: Method, host: Host, cookies: CookieJar, @@ -1686,7 +1842,8 @@ async fn op4_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op4_get_validation()) @@ -1700,7 +1857,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op4_get(method, host, cookies).await; + let result = api_impl.as_ref().op4_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -1711,10 +1868,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1730,7 +1891,7 @@ fn op5_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op5Get - GET /op5 #[tracing::instrument(skip_all)] -async fn op5_get( +async fn op5_get( method: Method, host: Host, cookies: CookieJar, @@ -1738,7 +1899,8 @@ async fn op5_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op5_get_validation()) @@ -1752,7 +1914,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op5_get(method, host, cookies).await; + let result = api_impl.as_ref().op5_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -1763,10 +1925,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1782,7 +1948,7 @@ fn op6_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op6Get - GET /op6 #[tracing::instrument(skip_all)] -async fn op6_get( +async fn op6_get( method: Method, host: Host, cookies: CookieJar, @@ -1790,7 +1956,8 @@ async fn op6_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op6_get_validation()) @@ -1804,7 +1971,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op6_get(method, host, cookies).await; + let result = api_impl.as_ref().op6_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -1815,10 +1982,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1834,7 +2005,7 @@ fn op7_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op7Get - GET /op7 #[tracing::instrument(skip_all)] -async fn op7_get( +async fn op7_get( method: Method, host: Host, cookies: CookieJar, @@ -1842,7 +2013,8 @@ async fn op7_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op7_get_validation()) @@ -1856,7 +2028,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op7_get(method, host, cookies).await; + let result = api_impl.as_ref().op7_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -1867,10 +2039,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1886,7 +2062,7 @@ fn op8_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op8Get - GET /op8 #[tracing::instrument(skip_all)] -async fn op8_get( +async fn op8_get( method: Method, host: Host, cookies: CookieJar, @@ -1894,7 +2070,8 @@ async fn op8_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op8_get_validation()) @@ -1908,7 +2085,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op8_get(method, host, cookies).await; + let result = api_impl.as_ref().op8_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -1919,10 +2096,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1938,7 +2119,7 @@ fn op9_get_validation() -> std::result::Result<(), ValidationErrors> { } /// Op9Get - GET /op9 #[tracing::instrument(skip_all)] -async fn op9_get( +async fn op9_get( method: Method, host: Host, cookies: CookieJar, @@ -1946,7 +2127,8 @@ async fn op9_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op9_get_validation()) @@ -1960,7 +2142,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().op9_get(method, host, cookies).await; + let result = api_impl.as_ref().op9_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -1971,10 +2153,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; diff --git a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/.openapi-generator/VERSION b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/.openapi-generator/VERSION index 884119126398..de37f5c4cf59 100644 --- a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/.openapi-generator/VERSION +++ b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/.openapi-generator/VERSION @@ -1 +1 @@ -7.11.0-SNAPSHOT +7.12.0-SNAPSHOT diff --git a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/Cargo.toml b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/Cargo.toml index 0b609777dec0..bb08b714ed11 100644 --- a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/Cargo.toml +++ b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/Cargo.toml @@ -42,7 +42,7 @@ tokio = { version = "1", default-features = false, features = [ ] } tracing = { version = "0.1", features = ["attributes"] } uuid = { version = "1", features = ["serde"] } -validator = { version = "0.19", features = ["derive"] } +validator = { version = "0.20", features = ["derive"] } [dev-dependencies] tracing-subscriber = "0.3" diff --git a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/README.md b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/README.md index abfcfff517be..32026c65f858 100644 --- a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/README.md +++ b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/README.md @@ -12,7 +12,7 @@ server, you can easily generate a server stub. To see how to make this your own, look here: [README]((https://openapi-generator.tech)) - API version: 1.0.0 -- Generator version: 7.11.0-SNAPSHOT +- Generator version: 7.12.0-SNAPSHOT @@ -43,16 +43,18 @@ struct ServerImpl { #[allow(unused_variables)] #[async_trait] -impl petstore-with-fake-endpoints-models-for-testing::Api for ServerImpl { +impl petstore_with_fake_endpoints_models_for_testing::apis::default::Api for ServerImpl { // API implementation goes here } +impl petstore_with_fake_endpoints_models_for_testing::apis::ErrorHandler for ServerImpl {} + pub async fn start_server(addr: &str) { // initialize tracing tracing_subscriber::fmt::init(); // Init Axum router - let app = petstore-with-fake-endpoints-models-for-testing::server::new(Arc::new(ServerImpl)); + let app = petstore_with_fake_endpoints_models_for_testing::server::new(Arc::new(ServerImpl)); // Add layers to the router let app = app.layer(...); diff --git a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/another_fake.rs b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/another_fake.rs index f64e2e451bb9..0594b1698397 100644 --- a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/another_fake.rs +++ b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/another_fake.rs @@ -18,15 +18,17 @@ pub enum TestSpecialTagsResponse { /// AnotherFake #[async_trait] #[allow(clippy::ptr_arg)] -pub trait AnotherFake { +pub trait AnotherFake: + super::ErrorHandler +{ /// To test special tags. /// /// TestSpecialTags - PATCH /v2/another-fake/dummy async fn test_special_tags( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::Client, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &models::Client, + ) -> Result; } diff --git a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/fake.rs b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/fake.rs index 22ad661101aa..86c3f00a5637 100644 --- a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/fake.rs +++ b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/fake.rs @@ -118,132 +118,132 @@ pub enum TestJsonFormDataResponse { /// Fake #[async_trait] #[allow(clippy::ptr_arg)] -pub trait Fake { +pub trait Fake: super::ErrorHandler { /// Call123example - GET /v2/fake/operation-with-numeric-id async fn call123example( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// FakeOuterBooleanSerialize - POST /v2/fake/outer/boolean async fn fake_outer_boolean_serialize( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Option, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &Option, + ) -> Result; /// FakeOuterCompositeSerialize - POST /v2/fake/outer/composite async fn fake_outer_composite_serialize( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Option, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &Option, + ) -> Result; /// FakeOuterNumberSerialize - POST /v2/fake/outer/number async fn fake_outer_number_serialize( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Option, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &Option, + ) -> Result; /// FakeOuterStringSerialize - POST /v2/fake/outer/string async fn fake_outer_string_serialize( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Option, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &Option, + ) -> Result; /// FakeResponseWithNumericalDescription - GET /v2/fake/response-with-numerical-description async fn fake_response_with_numerical_description( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// HyphenParam - GET /v2/fake/hyphenParam/{hyphen-param} async fn hyphen_param( &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::HyphenParamPathParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + path_params: &models::HyphenParamPathParams, + ) -> Result; /// TestBodyWithQueryParams - PUT /v2/fake/body-with-query-params async fn test_body_with_query_params( &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::TestBodyWithQueryParamsQueryParams, - body: models::User, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + query_params: &models::TestBodyWithQueryParamsQueryParams, + body: &models::User, + ) -> Result; /// To test \"client\" model. /// /// TestClientModel - PATCH /v2/fake async fn test_client_model( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::Client, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &models::Client, + ) -> Result; /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트. /// /// TestEndpointParameters - POST /v2/fake async fn test_endpoint_parameters( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::TestEndpointParametersRequest, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &models::TestEndpointParametersRequest, + ) -> Result; /// To test enum parameters. /// /// TestEnumParameters - GET /v2/fake async fn test_enum_parameters( &self, - method: Method, - host: Host, - cookies: CookieJar, - header_params: models::TestEnumParametersHeaderParams, - query_params: models::TestEnumParametersQueryParams, - body: Option, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + header_params: &models::TestEnumParametersHeaderParams, + query_params: &models::TestEnumParametersQueryParams, + body: &Option, + ) -> Result; /// test inline additionalProperties. /// /// TestInlineAdditionalProperties - POST /v2/fake/inline-additionalProperties async fn test_inline_additional_properties( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: std::collections::HashMap, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &std::collections::HashMap, + ) -> Result; /// test json serialization of form data. /// /// TestJsonFormData - GET /v2/fake/jsonFormData async fn test_json_form_data( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::TestJsonFormDataRequest, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &models::TestJsonFormDataRequest, + ) -> Result; } diff --git a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/fake_classname_tags123.rs b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/fake_classname_tags123.rs index 100f9dc7ad59..95b565f4203d 100644 --- a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/fake_classname_tags123.rs +++ b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/fake_classname_tags123.rs @@ -18,15 +18,17 @@ pub enum TestClassnameResponse { /// FakeClassnameTags123 #[async_trait] #[allow(clippy::ptr_arg)] -pub trait FakeClassnameTags123 { +pub trait FakeClassnameTags123: + super::ErrorHandler +{ /// To test class name in snake case. /// /// TestClassname - PATCH /v2/fake_classname_test async fn test_classname( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::Client, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &models::Client, + ) -> Result; } diff --git a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/mod.rs b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/mod.rs index 720eb77d2bfb..0b10eed0b611 100644 --- a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/mod.rs +++ b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/mod.rs @@ -17,3 +17,23 @@ pub trait ApiKeyAuthHeader { key: &str, ) -> Option; } + +// Error handler for unhandled errors. +#[async_trait::async_trait] +pub trait ErrorHandler { + #[allow(unused_variables)] + #[tracing::instrument(skip_all)] + async fn handle_error( + &self, + method: &::http::Method, + host: &axum::extract::Host, + cookies: &axum_extra::extract::CookieJar, + error: E, + ) -> Result { + tracing::error!("Unhandled error: {:?}", error); + axum::response::Response::builder() + .status(http::StatusCode::INTERNAL_SERVER_ERROR) + .body(axum::body::Body::empty()) + .map_err(|_| http::StatusCode::INTERNAL_SERVER_ERROR) + } +} diff --git a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/pet.rs b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/pet.rs index abac35a8571b..62f4fa27b493 100644 --- a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/pet.rs +++ b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/pet.rs @@ -86,7 +86,7 @@ pub enum UploadFileResponse { /// Pet #[async_trait] #[allow(clippy::ptr_arg)] -pub trait Pet { +pub trait Pet: super::ErrorHandler { type Claims; /// Add a new pet to the store. @@ -94,90 +94,90 @@ pub trait Pet { /// AddPet - POST /v2/pet async fn add_pet( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::Pet, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &models::Pet, + ) -> Result; /// Deletes a pet. /// /// DeletePet - DELETE /v2/pet/{petId} async fn delete_pet( &self, - method: Method, - host: Host, - cookies: CookieJar, - header_params: models::DeletePetHeaderParams, - path_params: models::DeletePetPathParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + header_params: &models::DeletePetHeaderParams, + path_params: &models::DeletePetPathParams, + ) -> Result; /// Finds Pets by status. /// /// FindPetsByStatus - GET /v2/pet/findByStatus async fn find_pets_by_status( &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::FindPetsByStatusQueryParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + query_params: &models::FindPetsByStatusQueryParams, + ) -> Result; /// Finds Pets by tags. /// /// FindPetsByTags - GET /v2/pet/findByTags async fn find_pets_by_tags( &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::FindPetsByTagsQueryParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + query_params: &models::FindPetsByTagsQueryParams, + ) -> Result; /// Find pet by ID. /// /// GetPetById - GET /v2/pet/{petId} async fn get_pet_by_id( &self, - method: Method, - host: Host, - cookies: CookieJar, - claims: Self::Claims, - path_params: models::GetPetByIdPathParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + claims: &Self::Claims, + path_params: &models::GetPetByIdPathParams, + ) -> Result; /// Update an existing pet. /// /// UpdatePet - PUT /v2/pet async fn update_pet( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::Pet, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &models::Pet, + ) -> Result; /// Updates a pet in the store with form data. /// /// UpdatePetWithForm - POST /v2/pet/{petId} async fn update_pet_with_form( &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::UpdatePetWithFormPathParams, - body: Option, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + path_params: &models::UpdatePetWithFormPathParams, + body: &Option, + ) -> Result; /// uploads an image. /// /// UploadFile - POST /v2/pet/{petId}/uploadImage async fn upload_file( &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::UploadFilePathParams, - body: Multipart, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + path_params: &models::UploadFilePathParams, + body: &Multipart, + ) -> Result; } diff --git a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/store.rs b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/store.rs index 56c33f935c7f..9ceedb0f32c7 100644 --- a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/store.rs +++ b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/store.rs @@ -50,7 +50,7 @@ pub enum PlaceOrderResponse { /// Store #[async_trait] #[allow(clippy::ptr_arg)] -pub trait Store { +pub trait Store: super::ErrorHandler { type Claims; /// Delete purchase order by ID. @@ -58,42 +58,42 @@ pub trait Store { /// DeleteOrder - DELETE /v2/store/order/{order_id} async fn delete_order( &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::DeleteOrderPathParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + path_params: &models::DeleteOrderPathParams, + ) -> Result; /// Returns pet inventories by status. /// /// GetInventory - GET /v2/store/inventory async fn get_inventory( &self, - method: Method, - host: Host, - cookies: CookieJar, - claims: Self::Claims, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + claims: &Self::Claims, + ) -> Result; /// Find purchase order by ID. /// /// GetOrderById - GET /v2/store/order/{order_id} async fn get_order_by_id( &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::GetOrderByIdPathParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + path_params: &models::GetOrderByIdPathParams, + ) -> Result; /// Place an order for a pet. /// /// PlaceOrder - POST /v2/store/order async fn place_order( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::Order, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &models::Order, + ) -> Result; } diff --git a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/user.rs b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/user.rs index 1aa623644320..bb42e89a031e 100644 --- a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/user.rs +++ b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/user.rs @@ -88,92 +88,92 @@ pub enum UpdateUserResponse { /// User #[async_trait] #[allow(clippy::ptr_arg)] -pub trait User { +pub trait User: super::ErrorHandler { /// Create user. /// /// CreateUser - POST /v2/user async fn create_user( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::User, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &models::User, + ) -> Result; /// Creates list of users with given input array. /// /// CreateUsersWithArrayInput - POST /v2/user/createWithArray async fn create_users_with_array_input( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Vec, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &Vec, + ) -> Result; /// Creates list of users with given input array. /// /// CreateUsersWithListInput - POST /v2/user/createWithList async fn create_users_with_list_input( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Vec, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &Vec, + ) -> Result; /// Delete user. /// /// DeleteUser - DELETE /v2/user/{username} async fn delete_user( &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::DeleteUserPathParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + path_params: &models::DeleteUserPathParams, + ) -> Result; /// Get user by user name. /// /// GetUserByName - GET /v2/user/{username} async fn get_user_by_name( &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::GetUserByNamePathParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + path_params: &models::GetUserByNamePathParams, + ) -> Result; /// Logs user into the system. /// /// LoginUser - GET /v2/user/login async fn login_user( &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::LoginUserQueryParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + query_params: &models::LoginUserQueryParams, + ) -> Result; /// Logs out current logged in user session. /// /// LogoutUser - GET /v2/user/logout async fn logout_user( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Updated user. /// /// UpdateUser - PUT /v2/user/{username} async fn update_user( &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::UpdateUserPathParams, - body: models::User, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + path_params: &models::UpdateUserPathParams, + body: &models::User, + ) -> Result; } diff --git a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/server/mod.rs b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/server/mod.rs index 33a54a8cc5da..9eedd8a6d0b2 100644 --- a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/server/mod.rs +++ b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/server/mod.rs @@ -13,102 +13,114 @@ use crate::{header, types::*}; use crate::{apis, models}; /// Setup API Server. -pub fn new(api_impl: I) -> Router +pub fn new(api_impl: I) -> Router where I: AsRef + Clone + Send + Sync + 'static, - A: apis::another_fake::AnotherFake - + apis::fake::Fake - + apis::fake_classname_tags123::FakeClassnameTags123 - + apis::pet::Pet - + apis::store::Store - + apis::user::User + A: apis::another_fake::AnotherFake + + apis::fake::Fake + + apis::fake_classname_tags123::FakeClassnameTags123 + + apis::pet::Pet + + apis::store::Store + + apis::user::User + apis::ApiKeyAuthHeader + + Send + + Sync + 'static, + E: std::fmt::Debug + Send + Sync + 'static, C: Send + Sync + 'static, { // build our application with a route Router::new() - .route("/v2/another-fake/dummy", patch(test_special_tags::)) + .route( + "/v2/another-fake/dummy", + patch(test_special_tags::), + ) .route( "/v2/fake", - get(test_enum_parameters::) - .patch(test_client_model::) - .post(test_endpoint_parameters::), + get(test_enum_parameters::) + .patch(test_client_model::) + .post(test_endpoint_parameters::), ) .route( "/v2/fake/body-with-query-params", - put(test_body_with_query_params::), + put(test_body_with_query_params::), ) .route( "/v2/fake/hyphenParam/:hyphen_param", - get(hyphen_param::), + get(hyphen_param::), ) .route( "/v2/fake/inline-additionalProperties", - post(test_inline_additional_properties::), + post(test_inline_additional_properties::), ) - .route("/v2/fake/jsonFormData", get(test_json_form_data::)) + .route("/v2/fake/jsonFormData", get(test_json_form_data::)) .route( "/v2/fake/operation-with-numeric-id", - get(call123example::), + get(call123example::), ) .route( "/v2/fake/outer/boolean", - post(fake_outer_boolean_serialize::), + post(fake_outer_boolean_serialize::), ) .route( "/v2/fake/outer/composite", - post(fake_outer_composite_serialize::), + post(fake_outer_composite_serialize::), ) .route( "/v2/fake/outer/number", - post(fake_outer_number_serialize::), + post(fake_outer_number_serialize::), ) .route( "/v2/fake/outer/string", - post(fake_outer_string_serialize::), + post(fake_outer_string_serialize::), ) .route( "/v2/fake/response-with-numerical-description", - get(fake_response_with_numerical_description::), + get(fake_response_with_numerical_description::), ) - .route("/v2/fake_classname_test", patch(test_classname::)) + .route("/v2/fake_classname_test", patch(test_classname::)) .route( "/v2/pet", - post(add_pet::).put(update_pet::), + post(add_pet::).put(update_pet::), ) .route( "/v2/pet/:pet_id", - delete(delete_pet::) - .get(get_pet_by_id::) - .post(update_pet_with_form::), + delete(delete_pet::) + .get(get_pet_by_id::) + .post(update_pet_with_form::), + ) + .route( + "/v2/pet/:pet_id/uploadImage", + post(upload_file::), + ) + .route( + "/v2/pet/findByStatus", + get(find_pets_by_status::), ) - .route("/v2/pet/:pet_id/uploadImage", post(upload_file::)) - .route("/v2/pet/findByStatus", get(find_pets_by_status::)) - .route("/v2/pet/findByTags", get(find_pets_by_tags::)) - .route("/v2/store/inventory", get(get_inventory::)) - .route("/v2/store/order", post(place_order::)) + .route("/v2/pet/findByTags", get(find_pets_by_tags::)) + .route("/v2/store/inventory", get(get_inventory::)) + .route("/v2/store/order", post(place_order::)) .route( "/v2/store/order/:order_id", - delete(delete_order::).get(get_order_by_id::), + delete(delete_order::).get(get_order_by_id::), ) - .route("/v2/user", post(create_user::)) + .route("/v2/user", post(create_user::)) .route( "/v2/user/:username", - delete(delete_user::) - .get(get_user_by_name::) - .put(update_user::), + delete(delete_user::) + .get(get_user_by_name::) + .put(update_user::), ) .route( "/v2/user/createWithArray", - post(create_users_with_array_input::), + post(create_users_with_array_input::), ) .route( "/v2/user/createWithList", - post(create_users_with_list_input::), + post(create_users_with_list_input::), ) - .route("/v2/user/login", get(login_user::)) - .route("/v2/user/logout", get(logout_user::)) + .route("/v2/user/login", get(login_user::)) + .route("/v2/user/logout", get(logout_user::)) .with_state(api_impl) } @@ -130,7 +142,7 @@ fn test_special_tags_validation( } /// TestSpecialTags - PATCH /v2/another-fake/dummy #[tracing::instrument(skip_all)] -async fn test_special_tags( +async fn test_special_tags( method: Method, host: Host, cookies: CookieJar, @@ -139,7 +151,8 @@ async fn test_special_tags( ) -> Result where I: AsRef + Send + Sync, - A: apis::another_fake::AnotherFake, + A: apis::another_fake::AnotherFake + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || test_special_tags_validation(body)) @@ -155,7 +168,7 @@ where let result = api_impl .as_ref() - .test_special_tags(method, host, cookies, body) + .test_special_tags(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -186,10 +199,14 @@ where response.body(Body::from(body_content)) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -205,7 +222,7 @@ fn call123example_validation() -> std::result::Result<(), ValidationErrors> { } /// Call123example - GET /v2/fake/operation-with-numeric-id #[tracing::instrument(skip_all)] -async fn call123example( +async fn call123example( method: Method, host: Host, cookies: CookieJar, @@ -213,7 +230,8 @@ async fn call123example( ) -> Result where I: AsRef + Send + Sync, - A: apis::fake::Fake, + A: apis::fake::Fake + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || call123example_validation()) @@ -229,7 +247,7 @@ where let result = api_impl .as_ref() - .call123example(method, host, cookies) + .call123example(&method, &host, &cookies) .await; let mut response = Response::builder(); @@ -241,10 +259,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -274,7 +296,7 @@ fn fake_outer_boolean_serialize_validation( } /// FakeOuterBooleanSerialize - POST /v2/fake/outer/boolean #[tracing::instrument(skip_all)] -async fn fake_outer_boolean_serialize( +async fn fake_outer_boolean_serialize( method: Method, host: Host, cookies: CookieJar, @@ -283,7 +305,8 @@ async fn fake_outer_boolean_serialize( ) -> Result where I: AsRef + Send + Sync, - A: apis::fake::Fake, + A: apis::fake::Fake + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = @@ -300,7 +323,7 @@ where let result = api_impl .as_ref() - .fake_outer_boolean_serialize(method, host, cookies, body) + .fake_outer_boolean_serialize(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -331,10 +354,14 @@ where response.body(Body::from(body_content)) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -364,7 +391,7 @@ fn fake_outer_composite_serialize_validation( } /// FakeOuterCompositeSerialize - POST /v2/fake/outer/composite #[tracing::instrument(skip_all)] -async fn fake_outer_composite_serialize( +async fn fake_outer_composite_serialize( method: Method, host: Host, cookies: CookieJar, @@ -373,7 +400,8 @@ async fn fake_outer_composite_serialize( ) -> Result where I: AsRef + Send + Sync, - A: apis::fake::Fake, + A: apis::fake::Fake + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = @@ -390,7 +418,7 @@ where let result = api_impl .as_ref() - .fake_outer_composite_serialize(method, host, cookies, body) + .fake_outer_composite_serialize(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -421,10 +449,14 @@ where response.body(Body::from(body_content)) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -454,7 +486,7 @@ fn fake_outer_number_serialize_validation( } /// FakeOuterNumberSerialize - POST /v2/fake/outer/number #[tracing::instrument(skip_all)] -async fn fake_outer_number_serialize( +async fn fake_outer_number_serialize( method: Method, host: Host, cookies: CookieJar, @@ -463,7 +495,8 @@ async fn fake_outer_number_serialize( ) -> Result where I: AsRef + Send + Sync, - A: apis::fake::Fake, + A: apis::fake::Fake + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = @@ -480,7 +513,7 @@ where let result = api_impl .as_ref() - .fake_outer_number_serialize(method, host, cookies, body) + .fake_outer_number_serialize(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -511,10 +544,14 @@ where response.body(Body::from(body_content)) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -544,7 +581,7 @@ fn fake_outer_string_serialize_validation( } /// FakeOuterStringSerialize - POST /v2/fake/outer/string #[tracing::instrument(skip_all)] -async fn fake_outer_string_serialize( +async fn fake_outer_string_serialize( method: Method, host: Host, cookies: CookieJar, @@ -553,7 +590,8 @@ async fn fake_outer_string_serialize( ) -> Result where I: AsRef + Send + Sync, - A: apis::fake::Fake, + A: apis::fake::Fake + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = @@ -570,7 +608,7 @@ where let result = api_impl .as_ref() - .fake_outer_string_serialize(method, host, cookies, body) + .fake_outer_string_serialize(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -601,10 +639,14 @@ where response.body(Body::from(body_content)) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -621,7 +663,7 @@ fn fake_response_with_numerical_description_validation() -> std::result::Result< } /// FakeResponseWithNumericalDescription - GET /v2/fake/response-with-numerical-description #[tracing::instrument(skip_all)] -async fn fake_response_with_numerical_description( +async fn fake_response_with_numerical_description( method: Method, host: Host, cookies: CookieJar, @@ -629,7 +671,8 @@ async fn fake_response_with_numerical_description( ) -> Result where I: AsRef + Send + Sync, - A: apis::fake::Fake, + A: apis::fake::Fake + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = @@ -646,7 +689,7 @@ where let result = api_impl .as_ref() - .fake_response_with_numerical_description(method, host, cookies) + .fake_response_with_numerical_description(&method, &host, &cookies) .await; let mut response = Response::builder(); @@ -658,10 +701,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -681,7 +728,7 @@ fn hyphen_param_validation( } /// HyphenParam - GET /v2/fake/hyphenParam/{hyphen-param} #[tracing::instrument(skip_all)] -async fn hyphen_param( +async fn hyphen_param( method: Method, host: Host, cookies: CookieJar, @@ -690,7 +737,8 @@ async fn hyphen_param( ) -> Result where I: AsRef + Send + Sync, - A: apis::fake::Fake, + A: apis::fake::Fake + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || hyphen_param_validation(path_params)) @@ -706,7 +754,7 @@ where let result = api_impl .as_ref() - .hyphen_param(method, host, cookies, path_params) + .hyphen_param(&method, &host, &cookies, &path_params) .await; let mut response = Response::builder(); @@ -718,10 +766,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -752,7 +804,7 @@ fn test_body_with_query_params_validation( } /// TestBodyWithQueryParams - PUT /v2/fake/body-with-query-params #[tracing::instrument(skip_all)] -async fn test_body_with_query_params( +async fn test_body_with_query_params( method: Method, host: Host, cookies: CookieJar, @@ -762,7 +814,8 @@ async fn test_body_with_query_params( ) -> Result where I: AsRef + Send + Sync, - A: apis::fake::Fake, + A: apis::fake::Fake + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || { @@ -780,7 +833,7 @@ where let result = api_impl .as_ref() - .test_body_with_query_params(method, host, cookies, query_params, body) + .test_body_with_query_params(&method, &host, &cookies, &query_params, &body) .await; let mut response = Response::builder(); @@ -792,10 +845,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -823,7 +880,7 @@ fn test_client_model_validation( } /// TestClientModel - PATCH /v2/fake #[tracing::instrument(skip_all)] -async fn test_client_model( +async fn test_client_model( method: Method, host: Host, cookies: CookieJar, @@ -832,7 +889,8 @@ async fn test_client_model( ) -> Result where I: AsRef + Send + Sync, - A: apis::fake::Fake, + A: apis::fake::Fake + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || test_client_model_validation(body)) @@ -848,7 +906,7 @@ where let result = api_impl .as_ref() - .test_client_model(method, host, cookies, body) + .test_client_model(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -879,10 +937,14 @@ where response.body(Body::from(body_content)) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -910,7 +972,7 @@ fn test_endpoint_parameters_validation( } /// TestEndpointParameters - POST /v2/fake #[tracing::instrument(skip_all)] -async fn test_endpoint_parameters( +async fn test_endpoint_parameters( method: Method, host: Host, cookies: CookieJar, @@ -919,7 +981,8 @@ async fn test_endpoint_parameters( ) -> Result where I: AsRef + Send + Sync, - A: apis::fake::Fake, + A: apis::fake::Fake + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || test_endpoint_parameters_validation(body)) @@ -935,7 +998,7 @@ where let result = api_impl .as_ref() - .test_endpoint_parameters(method, host, cookies, body) + .test_endpoint_parameters(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -951,10 +1014,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -995,7 +1062,7 @@ fn test_enum_parameters_validation( } /// TestEnumParameters - GET /v2/fake #[tracing::instrument(skip_all)] -async fn test_enum_parameters( +async fn test_enum_parameters( method: Method, host: Host, cookies: CookieJar, @@ -1006,7 +1073,8 @@ async fn test_enum_parameters( ) -> Result where I: AsRef + Send + Sync, - A: apis::fake::Fake, + A: apis::fake::Fake + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { // Header parameters let header_params = { @@ -1074,7 +1142,14 @@ where let result = api_impl .as_ref() - .test_enum_parameters(method, host, cookies, header_params, query_params, body) + .test_enum_parameters( + &method, + &host, + &cookies, + &header_params, + &query_params, + &body, + ) .await; let mut response = Response::builder(); @@ -1090,10 +1165,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1120,7 +1199,7 @@ fn test_inline_additional_properties_validation( } /// TestInlineAdditionalProperties - POST /v2/fake/inline-additionalProperties #[tracing::instrument(skip_all)] -async fn test_inline_additional_properties( +async fn test_inline_additional_properties( method: Method, host: Host, cookies: CookieJar, @@ -1129,7 +1208,8 @@ async fn test_inline_additional_properties( ) -> Result where I: AsRef + Send + Sync, - A: apis::fake::Fake, + A: apis::fake::Fake + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = @@ -1146,7 +1226,7 @@ where let result = api_impl .as_ref() - .test_inline_additional_properties(method, host, cookies, body) + .test_inline_additional_properties(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -1158,10 +1238,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1189,7 +1273,7 @@ fn test_json_form_data_validation( } /// TestJsonFormData - GET /v2/fake/jsonFormData #[tracing::instrument(skip_all)] -async fn test_json_form_data( +async fn test_json_form_data( method: Method, host: Host, cookies: CookieJar, @@ -1198,7 +1282,8 @@ async fn test_json_form_data( ) -> Result where I: AsRef + Send + Sync, - A: apis::fake::Fake, + A: apis::fake::Fake + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || test_json_form_data_validation(body)) @@ -1214,7 +1299,7 @@ where let result = api_impl .as_ref() - .test_json_form_data(method, host, cookies, body) + .test_json_form_data(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -1226,10 +1311,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1257,7 +1346,7 @@ fn test_classname_validation( } /// TestClassname - PATCH /v2/fake_classname_test #[tracing::instrument(skip_all)] -async fn test_classname( +async fn test_classname( method: Method, host: Host, cookies: CookieJar, @@ -1266,7 +1355,8 @@ async fn test_classname( ) -> Result where I: AsRef + Send + Sync, - A: apis::fake_classname_tags123::FakeClassnameTags123, + A: apis::fake_classname_tags123::FakeClassnameTags123 + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || test_classname_validation(body)) @@ -1282,7 +1372,7 @@ where let result = api_impl .as_ref() - .test_classname(method, host, cookies, body) + .test_classname(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -1315,10 +1405,14 @@ where response.body(Body::from(body_content)) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1344,7 +1438,7 @@ fn add_pet_validation(body: models::Pet) -> std::result::Result<(models::Pet,), } /// AddPet - POST /v2/pet #[tracing::instrument(skip_all)] -async fn add_pet( +async fn add_pet( method: Method, host: Host, cookies: CookieJar, @@ -1353,7 +1447,8 @@ async fn add_pet( ) -> Result where I: AsRef + Send + Sync, - A: apis::pet::Pet, + A: apis::pet::Pet + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || add_pet_validation(body)) @@ -1367,7 +1462,10 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().add_pet(method, host, cookies, body).await; + let result = api_impl + .as_ref() + .add_pet(&method, &host, &cookies, &body) + .await; let mut response = Response::builder(); @@ -1378,10 +1476,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1406,7 +1508,7 @@ fn delete_pet_validation( } /// DeletePet - DELETE /v2/pet/{petId} #[tracing::instrument(skip_all)] -async fn delete_pet( +async fn delete_pet( method: Method, host: Host, cookies: CookieJar, @@ -1416,7 +1518,8 @@ async fn delete_pet( ) -> Result where I: AsRef + Send + Sync, - A: apis::pet::Pet, + A: apis::pet::Pet + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { // Header parameters let header_params = { @@ -1458,7 +1561,7 @@ where let result = api_impl .as_ref() - .delete_pet(method, host, cookies, header_params, path_params) + .delete_pet(&method, &host, &cookies, &header_params, &path_params) .await; let mut response = Response::builder(); @@ -1470,10 +1573,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1493,7 +1600,7 @@ fn find_pets_by_status_validation( } /// FindPetsByStatus - GET /v2/pet/findByStatus #[tracing::instrument(skip_all)] -async fn find_pets_by_status( +async fn find_pets_by_status( method: Method, host: Host, cookies: CookieJar, @@ -1502,7 +1609,8 @@ async fn find_pets_by_status( ) -> Result where I: AsRef + Send + Sync, - A: apis::pet::Pet, + A: apis::pet::Pet + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = @@ -1519,7 +1627,7 @@ where let result = api_impl .as_ref() - .find_pets_by_status(method, host, cookies, query_params) + .find_pets_by_status(&method, &host, &cookies, &query_params) .await; let mut response = Response::builder(); @@ -1547,10 +1655,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1570,7 +1682,7 @@ fn find_pets_by_tags_validation( } /// FindPetsByTags - GET /v2/pet/findByTags #[tracing::instrument(skip_all)] -async fn find_pets_by_tags( +async fn find_pets_by_tags( method: Method, host: Host, cookies: CookieJar, @@ -1579,7 +1691,8 @@ async fn find_pets_by_tags( ) -> Result where I: AsRef + Send + Sync, - A: apis::pet::Pet, + A: apis::pet::Pet + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = @@ -1596,7 +1709,7 @@ where let result = api_impl .as_ref() - .find_pets_by_tags(method, host, cookies, query_params) + .find_pets_by_tags(&method, &host, &cookies, &query_params) .await; let mut response = Response::builder(); @@ -1624,10 +1737,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1647,7 +1764,7 @@ fn get_pet_by_id_validation( } /// GetPetById - GET /v2/pet/{petId} #[tracing::instrument(skip_all)] -async fn get_pet_by_id( +async fn get_pet_by_id( method: Method, host: Host, cookies: CookieJar, @@ -1657,7 +1774,8 @@ async fn get_pet_by_id( ) -> Result where I: AsRef + Send + Sync, - A: apis::pet::Pet + apis::ApiKeyAuthHeader, + A: apis::pet::Pet + apis::ApiKeyAuthHeader + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { // Authentication let claims_in_header = api_impl @@ -1686,7 +1804,7 @@ where let result = api_impl .as_ref() - .get_pet_by_id(method, host, cookies, claims, path_params) + .get_pet_by_id(&method, &host, &cookies, &claims, &path_params) .await; let mut response = Response::builder(); @@ -1718,10 +1836,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1749,7 +1871,7 @@ fn update_pet_validation( } /// UpdatePet - PUT /v2/pet #[tracing::instrument(skip_all)] -async fn update_pet( +async fn update_pet( method: Method, host: Host, cookies: CookieJar, @@ -1758,7 +1880,8 @@ async fn update_pet( ) -> Result where I: AsRef + Send + Sync, - A: apis::pet::Pet, + A: apis::pet::Pet + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || update_pet_validation(body)) @@ -1774,7 +1897,7 @@ where let result = api_impl .as_ref() - .update_pet(method, host, cookies, body) + .update_pet(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -1794,10 +1917,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1835,7 +1962,7 @@ fn update_pet_with_form_validation( } /// UpdatePetWithForm - POST /v2/pet/{petId} #[tracing::instrument(skip_all)] -async fn update_pet_with_form( +async fn update_pet_with_form( method: Method, host: Host, cookies: CookieJar, @@ -1845,7 +1972,8 @@ async fn update_pet_with_form( ) -> Result where I: AsRef + Send + Sync, - A: apis::pet::Pet, + A: apis::pet::Pet + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = @@ -1862,7 +1990,7 @@ where let result = api_impl .as_ref() - .update_pet_with_form(method, host, cookies, path_params, body) + .update_pet_with_form(&method, &host, &cookies, &path_params, &body) .await; let mut response = Response::builder(); @@ -1874,10 +2002,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1897,7 +2029,7 @@ fn upload_file_validation( } /// UploadFile - POST /v2/pet/{petId}/uploadImage #[tracing::instrument(skip_all)] -async fn upload_file( +async fn upload_file( method: Method, host: Host, cookies: CookieJar, @@ -1907,7 +2039,8 @@ async fn upload_file( ) -> Result where I: AsRef + Send + Sync, - A: apis::pet::Pet, + A: apis::pet::Pet + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || upload_file_validation(path_params)) @@ -1923,7 +2056,7 @@ where let result = api_impl .as_ref() - .upload_file(method, host, cookies, path_params, body) + .upload_file(&method, &host, &cookies, &path_params, &body) .await; let mut response = Response::builder(); @@ -1954,10 +2087,14 @@ where response.body(Body::from(body_content)) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1977,7 +2114,7 @@ fn delete_order_validation( } /// DeleteOrder - DELETE /v2/store/order/{order_id} #[tracing::instrument(skip_all)] -async fn delete_order( +async fn delete_order( method: Method, host: Host, cookies: CookieJar, @@ -1986,7 +2123,8 @@ async fn delete_order( ) -> Result where I: AsRef + Send + Sync, - A: apis::store::Store, + A: apis::store::Store + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || delete_order_validation(path_params)) @@ -2002,7 +2140,7 @@ where let result = api_impl .as_ref() - .delete_order(method, host, cookies, path_params) + .delete_order(&method, &host, &cookies, &path_params) .await; let mut response = Response::builder(); @@ -2018,10 +2156,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -2037,7 +2179,7 @@ fn get_inventory_validation() -> std::result::Result<(), ValidationErrors> { } /// GetInventory - GET /v2/store/inventory #[tracing::instrument(skip_all)] -async fn get_inventory( +async fn get_inventory( method: Method, host: Host, cookies: CookieJar, @@ -2046,7 +2188,8 @@ async fn get_inventory( ) -> Result where I: AsRef + Send + Sync, - A: apis::store::Store + apis::ApiKeyAuthHeader, + A: apis::store::Store + apis::ApiKeyAuthHeader + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { // Authentication let claims_in_header = api_impl @@ -2075,7 +2218,7 @@ where let result = api_impl .as_ref() - .get_inventory(method, host, cookies, claims) + .get_inventory(&method, &host, &cookies, &claims) .await; let mut response = Response::builder(); @@ -2106,10 +2249,14 @@ where response.body(Body::from(body_content)) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -2129,7 +2276,7 @@ fn get_order_by_id_validation( } /// GetOrderById - GET /v2/store/order/{order_id} #[tracing::instrument(skip_all)] -async fn get_order_by_id( +async fn get_order_by_id( method: Method, host: Host, cookies: CookieJar, @@ -2138,7 +2285,8 @@ async fn get_order_by_id( ) -> Result where I: AsRef + Send + Sync, - A: apis::store::Store, + A: apis::store::Store + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || get_order_by_id_validation(path_params)) @@ -2154,7 +2302,7 @@ where let result = api_impl .as_ref() - .get_order_by_id(method, host, cookies, path_params) + .get_order_by_id(&method, &host, &cookies, &path_params) .await; let mut response = Response::builder(); @@ -2186,10 +2334,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -2217,7 +2369,7 @@ fn place_order_validation( } /// PlaceOrder - POST /v2/store/order #[tracing::instrument(skip_all)] -async fn place_order( +async fn place_order( method: Method, host: Host, cookies: CookieJar, @@ -2226,7 +2378,8 @@ async fn place_order( ) -> Result where I: AsRef + Send + Sync, - A: apis::store::Store, + A: apis::store::Store + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || place_order_validation(body)) @@ -2242,7 +2395,7 @@ where let result = api_impl .as_ref() - .place_order(method, host, cookies, body) + .place_order(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -2270,10 +2423,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -2301,7 +2458,7 @@ fn create_user_validation( } /// CreateUser - POST /v2/user #[tracing::instrument(skip_all)] -async fn create_user( +async fn create_user( method: Method, host: Host, cookies: CookieJar, @@ -2310,7 +2467,8 @@ async fn create_user( ) -> Result where I: AsRef + Send + Sync, - A: apis::user::User, + A: apis::user::User + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || create_user_validation(body)) @@ -2326,7 +2484,7 @@ where let result = api_impl .as_ref() - .create_user(method, host, cookies, body) + .create_user(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -2338,10 +2496,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -2369,7 +2531,7 @@ fn create_users_with_array_input_validation( } /// CreateUsersWithArrayInput - POST /v2/user/createWithArray #[tracing::instrument(skip_all)] -async fn create_users_with_array_input( +async fn create_users_with_array_input( method: Method, host: Host, cookies: CookieJar, @@ -2378,7 +2540,8 @@ async fn create_users_with_array_input( ) -> Result where I: AsRef + Send + Sync, - A: apis::user::User, + A: apis::user::User + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = @@ -2395,7 +2558,7 @@ where let result = api_impl .as_ref() - .create_users_with_array_input(method, host, cookies, body) + .create_users_with_array_input(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -2407,10 +2570,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -2438,7 +2605,7 @@ fn create_users_with_list_input_validation( } /// CreateUsersWithListInput - POST /v2/user/createWithList #[tracing::instrument(skip_all)] -async fn create_users_with_list_input( +async fn create_users_with_list_input( method: Method, host: Host, cookies: CookieJar, @@ -2447,7 +2614,8 @@ async fn create_users_with_list_input( ) -> Result where I: AsRef + Send + Sync, - A: apis::user::User, + A: apis::user::User + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = @@ -2464,7 +2632,7 @@ where let result = api_impl .as_ref() - .create_users_with_list_input(method, host, cookies, body) + .create_users_with_list_input(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -2476,10 +2644,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -2499,7 +2671,7 @@ fn delete_user_validation( } /// DeleteUser - DELETE /v2/user/{username} #[tracing::instrument(skip_all)] -async fn delete_user( +async fn delete_user( method: Method, host: Host, cookies: CookieJar, @@ -2508,7 +2680,8 @@ async fn delete_user( ) -> Result where I: AsRef + Send + Sync, - A: apis::user::User, + A: apis::user::User + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || delete_user_validation(path_params)) @@ -2524,7 +2697,7 @@ where let result = api_impl .as_ref() - .delete_user(method, host, cookies, path_params) + .delete_user(&method, &host, &cookies, &path_params) .await; let mut response = Response::builder(); @@ -2540,10 +2713,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -2563,7 +2740,7 @@ fn get_user_by_name_validation( } /// GetUserByName - GET /v2/user/{username} #[tracing::instrument(skip_all)] -async fn get_user_by_name( +async fn get_user_by_name( method: Method, host: Host, cookies: CookieJar, @@ -2572,7 +2749,8 @@ async fn get_user_by_name( ) -> Result where I: AsRef + Send + Sync, - A: apis::user::User, + A: apis::user::User + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || get_user_by_name_validation(path_params)) @@ -2588,7 +2766,7 @@ where let result = api_impl .as_ref() - .get_user_by_name(method, host, cookies, path_params) + .get_user_by_name(&method, &host, &cookies, &path_params) .await; let mut response = Response::builder(); @@ -2620,10 +2798,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -2643,7 +2825,7 @@ fn login_user_validation( } /// LoginUser - GET /v2/user/login #[tracing::instrument(skip_all)] -async fn login_user( +async fn login_user( method: Method, host: Host, cookies: CookieJar, @@ -2652,7 +2834,8 @@ async fn login_user( ) -> Result where I: AsRef + Send + Sync, - A: apis::user::User, + A: apis::user::User + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || login_user_validation(query_params)) @@ -2668,7 +2851,7 @@ where let result = api_impl .as_ref() - .login_user(method, host, cookies, query_params) + .login_user(&method, &host, &cookies, &query_params) .await; let mut response = Response::builder(); @@ -2733,10 +2916,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -2752,7 +2939,7 @@ fn logout_user_validation() -> std::result::Result<(), ValidationErrors> { } /// LogoutUser - GET /v2/user/logout #[tracing::instrument(skip_all)] -async fn logout_user( +async fn logout_user( method: Method, host: Host, cookies: CookieJar, @@ -2760,7 +2947,8 @@ async fn logout_user( ) -> Result where I: AsRef + Send + Sync, - A: apis::user::User, + A: apis::user::User + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || logout_user_validation()) @@ -2774,7 +2962,10 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().logout_user(method, host, cookies).await; + let result = api_impl + .as_ref() + .logout_user(&method, &host, &cookies) + .await; let mut response = Response::builder(); @@ -2785,10 +2976,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -2818,7 +3013,7 @@ fn update_user_validation( } /// UpdateUser - PUT /v2/user/{username} #[tracing::instrument(skip_all)] -async fn update_user( +async fn update_user( method: Method, host: Host, cookies: CookieJar, @@ -2828,7 +3023,8 @@ async fn update_user( ) -> Result where I: AsRef + Send + Sync, - A: apis::user::User, + A: apis::user::User + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || update_user_validation(path_params, body)) @@ -2844,7 +3040,7 @@ where let result = api_impl .as_ref() - .update_user(method, host, cookies, path_params, body) + .update_user(&method, &host, &cookies, &path_params, &body) .await; let mut response = Response::builder(); @@ -2860,10 +3056,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; diff --git a/samples/server/petstore/rust-axum/output/petstore/.openapi-generator/VERSION b/samples/server/petstore/rust-axum/output/petstore/.openapi-generator/VERSION index 884119126398..de37f5c4cf59 100644 --- a/samples/server/petstore/rust-axum/output/petstore/.openapi-generator/VERSION +++ b/samples/server/petstore/rust-axum/output/petstore/.openapi-generator/VERSION @@ -1 +1 @@ -7.11.0-SNAPSHOT +7.12.0-SNAPSHOT diff --git a/samples/server/petstore/rust-axum/output/petstore/Cargo.toml b/samples/server/petstore/rust-axum/output/petstore/Cargo.toml index 49676ee40c94..e2f53672a539 100644 --- a/samples/server/petstore/rust-axum/output/petstore/Cargo.toml +++ b/samples/server/petstore/rust-axum/output/petstore/Cargo.toml @@ -41,7 +41,7 @@ tokio = { version = "1", default-features = false, features = [ ] } tracing = { version = "0.1", features = ["attributes"] } uuid = { version = "1", features = ["serde"] } -validator = { version = "0.19", features = ["derive"] } +validator = { version = "0.20", features = ["derive"] } [dev-dependencies] tracing-subscriber = "0.3" diff --git a/samples/server/petstore/rust-axum/output/petstore/README.md b/samples/server/petstore/rust-axum/output/petstore/README.md index e2f49a93712b..9949db12c305 100644 --- a/samples/server/petstore/rust-axum/output/petstore/README.md +++ b/samples/server/petstore/rust-axum/output/petstore/README.md @@ -12,7 +12,7 @@ server, you can easily generate a server stub. To see how to make this your own, look here: [README]((https://openapi-generator.tech)) - API version: 1.0.0 -- Generator version: 7.11.0-SNAPSHOT +- Generator version: 7.12.0-SNAPSHOT @@ -43,10 +43,12 @@ struct ServerImpl { #[allow(unused_variables)] #[async_trait] -impl petstore::Api for ServerImpl { +impl petstore::apis::default::Api for ServerImpl { // API implementation goes here } +impl petstore::apis::ErrorHandler for ServerImpl {} + pub async fn start_server(addr: &str) { // initialize tracing tracing_subscriber::fmt::init(); diff --git a/samples/server/petstore/rust-axum/output/petstore/src/apis/mod.rs b/samples/server/petstore/rust-axum/output/petstore/src/apis/mod.rs index f6b0a17ddd57..b3bea180cfde 100644 --- a/samples/server/petstore/rust-axum/output/petstore/src/apis/mod.rs +++ b/samples/server/petstore/rust-axum/output/petstore/src/apis/mod.rs @@ -14,3 +14,23 @@ pub trait ApiKeyAuthHeader { key: &str, ) -> Option; } + +// Error handler for unhandled errors. +#[async_trait::async_trait] +pub trait ErrorHandler { + #[allow(unused_variables)] + #[tracing::instrument(skip_all)] + async fn handle_error( + &self, + method: &::http::Method, + host: &axum::extract::Host, + cookies: &axum_extra::extract::CookieJar, + error: E, + ) -> Result { + tracing::error!("Unhandled error: {:?}", error); + axum::response::Response::builder() + .status(http::StatusCode::INTERNAL_SERVER_ERROR) + .body(axum::body::Body::empty()) + .map_err(|_| http::StatusCode::INTERNAL_SERVER_ERROR) + } +} diff --git a/samples/server/petstore/rust-axum/output/petstore/src/apis/pet.rs b/samples/server/petstore/rust-axum/output/petstore/src/apis/pet.rs index 3cf7805ba541..a3cf82acb948 100644 --- a/samples/server/petstore/rust-axum/output/petstore/src/apis/pet.rs +++ b/samples/server/petstore/rust-axum/output/petstore/src/apis/pet.rs @@ -90,7 +90,7 @@ pub enum UploadFileResponse { /// Pet #[async_trait] #[allow(clippy::ptr_arg)] -pub trait Pet { +pub trait Pet: super::ErrorHandler { type Claims; /// Add a new pet to the store. @@ -98,90 +98,90 @@ pub trait Pet { /// AddPet - POST /v2/pet async fn add_pet( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::Pet, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &models::Pet, + ) -> Result; /// Deletes a pet. /// /// DeletePet - DELETE /v2/pet/{petId} async fn delete_pet( &self, - method: Method, - host: Host, - cookies: CookieJar, - header_params: models::DeletePetHeaderParams, - path_params: models::DeletePetPathParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + header_params: &models::DeletePetHeaderParams, + path_params: &models::DeletePetPathParams, + ) -> Result; /// Finds Pets by status. /// /// FindPetsByStatus - GET /v2/pet/findByStatus async fn find_pets_by_status( &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::FindPetsByStatusQueryParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + query_params: &models::FindPetsByStatusQueryParams, + ) -> Result; /// Finds Pets by tags. /// /// FindPetsByTags - GET /v2/pet/findByTags async fn find_pets_by_tags( &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::FindPetsByTagsQueryParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + query_params: &models::FindPetsByTagsQueryParams, + ) -> Result; /// Find pet by ID. /// /// GetPetById - GET /v2/pet/{petId} async fn get_pet_by_id( &self, - method: Method, - host: Host, - cookies: CookieJar, - claims: Self::Claims, - path_params: models::GetPetByIdPathParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + claims: &Self::Claims, + path_params: &models::GetPetByIdPathParams, + ) -> Result; /// Update an existing pet. /// /// UpdatePet - PUT /v2/pet async fn update_pet( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::Pet, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &models::Pet, + ) -> Result; /// Updates a pet in the store with form data. /// /// UpdatePetWithForm - POST /v2/pet/{petId} async fn update_pet_with_form( &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::UpdatePetWithFormPathParams, - body: Option, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + path_params: &models::UpdatePetWithFormPathParams, + body: &Option, + ) -> Result; /// uploads an image. /// /// UploadFile - POST /v2/pet/{petId}/uploadImage async fn upload_file( &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::UploadFilePathParams, - body: Multipart, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + path_params: &models::UploadFilePathParams, + body: &Multipart, + ) -> Result; } diff --git a/samples/server/petstore/rust-axum/output/petstore/src/apis/store.rs b/samples/server/petstore/rust-axum/output/petstore/src/apis/store.rs index eb592d88aa83..bc8b22fcddc3 100644 --- a/samples/server/petstore/rust-axum/output/petstore/src/apis/store.rs +++ b/samples/server/petstore/rust-axum/output/petstore/src/apis/store.rs @@ -50,7 +50,7 @@ pub enum PlaceOrderResponse { /// Store #[async_trait] #[allow(clippy::ptr_arg)] -pub trait Store { +pub trait Store: super::ErrorHandler { type Claims; /// Delete purchase order by ID. @@ -58,42 +58,42 @@ pub trait Store { /// DeleteOrder - DELETE /v2/store/order/{orderId} async fn delete_order( &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::DeleteOrderPathParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + path_params: &models::DeleteOrderPathParams, + ) -> Result; /// Returns pet inventories by status. /// /// GetInventory - GET /v2/store/inventory async fn get_inventory( &self, - method: Method, - host: Host, - cookies: CookieJar, - claims: Self::Claims, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + claims: &Self::Claims, + ) -> Result; /// Find purchase order by ID. /// /// GetOrderById - GET /v2/store/order/{orderId} async fn get_order_by_id( &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::GetOrderByIdPathParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + path_params: &models::GetOrderByIdPathParams, + ) -> Result; /// Place an order for a pet. /// /// PlaceOrder - POST /v2/store/order async fn place_order( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::Order, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &models::Order, + ) -> Result; } diff --git a/samples/server/petstore/rust-axum/output/petstore/src/apis/user.rs b/samples/server/petstore/rust-axum/output/petstore/src/apis/user.rs index cfec1d4f84e8..91e30ee7637c 100644 --- a/samples/server/petstore/rust-axum/output/petstore/src/apis/user.rs +++ b/samples/server/petstore/rust-axum/output/petstore/src/apis/user.rs @@ -89,7 +89,7 @@ pub enum UpdateUserResponse { /// User #[async_trait] #[allow(clippy::ptr_arg)] -pub trait User { +pub trait User: super::ErrorHandler { type Claims; /// Create user. @@ -97,92 +97,92 @@ pub trait User { /// CreateUser - POST /v2/user async fn create_user( &self, - method: Method, - host: Host, - cookies: CookieJar, - claims: Self::Claims, - body: models::User, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + claims: &Self::Claims, + body: &models::User, + ) -> Result; /// Creates list of users with given input array. /// /// CreateUsersWithArrayInput - POST /v2/user/createWithArray async fn create_users_with_array_input( &self, - method: Method, - host: Host, - cookies: CookieJar, - claims: Self::Claims, - body: Vec, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + claims: &Self::Claims, + body: &Vec, + ) -> Result; /// Creates list of users with given input array. /// /// CreateUsersWithListInput - POST /v2/user/createWithList async fn create_users_with_list_input( &self, - method: Method, - host: Host, - cookies: CookieJar, - claims: Self::Claims, - body: Vec, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + claims: &Self::Claims, + body: &Vec, + ) -> Result; /// Delete user. /// /// DeleteUser - DELETE /v2/user/{username} async fn delete_user( &self, - method: Method, - host: Host, - cookies: CookieJar, - claims: Self::Claims, - path_params: models::DeleteUserPathParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + claims: &Self::Claims, + path_params: &models::DeleteUserPathParams, + ) -> Result; /// Get user by user name. /// /// GetUserByName - GET /v2/user/{username} async fn get_user_by_name( &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::GetUserByNamePathParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + path_params: &models::GetUserByNamePathParams, + ) -> Result; /// Logs user into the system. /// /// LoginUser - GET /v2/user/login async fn login_user( &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::LoginUserQueryParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + query_params: &models::LoginUserQueryParams, + ) -> Result; /// Logs out current logged in user session. /// /// LogoutUser - GET /v2/user/logout async fn logout_user( &self, - method: Method, - host: Host, - cookies: CookieJar, - claims: Self::Claims, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + claims: &Self::Claims, + ) -> Result; /// Updated user. /// /// UpdateUser - PUT /v2/user/{username} async fn update_user( &self, - method: Method, - host: Host, - cookies: CookieJar, - claims: Self::Claims, - path_params: models::UpdateUserPathParams, - body: models::User, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + claims: &Self::Claims, + path_params: &models::UpdateUserPathParams, + body: &models::User, + ) -> Result; } diff --git a/samples/server/petstore/rust-axum/output/petstore/src/server/mod.rs b/samples/server/petstore/rust-axum/output/petstore/src/server/mod.rs index edb1b82fc442..e143adb5f88c 100644 --- a/samples/server/petstore/rust-axum/output/petstore/src/server/mod.rs +++ b/samples/server/petstore/rust-axum/output/petstore/src/server/mod.rs @@ -13,54 +13,63 @@ use crate::{header, types::*}; use crate::{apis, models}; /// Setup API Server. -pub fn new(api_impl: I) -> Router +pub fn new(api_impl: I) -> Router where I: AsRef + Clone + Send + Sync + 'static, - A: apis::pet::Pet - + apis::store::Store - + apis::user::User + A: apis::pet::Pet + + apis::store::Store + + apis::user::User + apis::ApiKeyAuthHeader + + Send + + Sync + 'static, + E: std::fmt::Debug + Send + Sync + 'static, C: Send + Sync + 'static, { // build our application with a route Router::new() .route( "/v2/pet", - post(add_pet::).put(update_pet::), + post(add_pet::).put(update_pet::), ) .route( "/v2/pet/:pet_id", - delete(delete_pet::) - .get(get_pet_by_id::) - .post(update_pet_with_form::), + delete(delete_pet::) + .get(get_pet_by_id::) + .post(update_pet_with_form::), ) - .route("/v2/pet/:pet_id/uploadImage", post(upload_file::)) - .route("/v2/pet/findByStatus", get(find_pets_by_status::)) - .route("/v2/pet/findByTags", get(find_pets_by_tags::)) - .route("/v2/store/inventory", get(get_inventory::)) - .route("/v2/store/order", post(place_order::)) + .route( + "/v2/pet/:pet_id/uploadImage", + post(upload_file::), + ) + .route( + "/v2/pet/findByStatus", + get(find_pets_by_status::), + ) + .route("/v2/pet/findByTags", get(find_pets_by_tags::)) + .route("/v2/store/inventory", get(get_inventory::)) + .route("/v2/store/order", post(place_order::)) .route( "/v2/store/order/:order_id", - delete(delete_order::).get(get_order_by_id::), + delete(delete_order::).get(get_order_by_id::), ) - .route("/v2/user", post(create_user::)) + .route("/v2/user", post(create_user::)) .route( "/v2/user/:username", - delete(delete_user::) - .get(get_user_by_name::) - .put(update_user::), + delete(delete_user::) + .get(get_user_by_name::) + .put(update_user::), ) .route( "/v2/user/createWithArray", - post(create_users_with_array_input::), + post(create_users_with_array_input::), ) .route( "/v2/user/createWithList", - post(create_users_with_list_input::), + post(create_users_with_list_input::), ) - .route("/v2/user/login", get(login_user::)) - .route("/v2/user/logout", get(logout_user::)) + .route("/v2/user/login", get(login_user::)) + .route("/v2/user/logout", get(logout_user::)) .with_state(api_impl) } @@ -80,7 +89,7 @@ fn add_pet_validation(body: models::Pet) -> std::result::Result<(models::Pet,), } /// AddPet - POST /v2/pet #[tracing::instrument(skip_all)] -async fn add_pet( +async fn add_pet( method: Method, host: Host, cookies: CookieJar, @@ -89,7 +98,8 @@ async fn add_pet( ) -> Result where I: AsRef + Send + Sync, - A: apis::pet::Pet, + A: apis::pet::Pet + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || add_pet_validation(body)) @@ -103,7 +113,10 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().add_pet(method, host, cookies, body).await; + let result = api_impl + .as_ref() + .add_pet(&method, &host, &cookies, &body) + .await; let mut response = Response::builder(); @@ -130,10 +143,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -158,7 +175,7 @@ fn delete_pet_validation( } /// DeletePet - DELETE /v2/pet/{petId} #[tracing::instrument(skip_all)] -async fn delete_pet( +async fn delete_pet( method: Method, host: Host, cookies: CookieJar, @@ -168,7 +185,8 @@ async fn delete_pet( ) -> Result where I: AsRef + Send + Sync, - A: apis::pet::Pet, + A: apis::pet::Pet + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { // Header parameters let header_params = { @@ -210,7 +228,7 @@ where let result = api_impl .as_ref() - .delete_pet(method, host, cookies, header_params, path_params) + .delete_pet(&method, &host, &cookies, &header_params, &path_params) .await; let mut response = Response::builder(); @@ -222,10 +240,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -245,7 +267,7 @@ fn find_pets_by_status_validation( } /// FindPetsByStatus - GET /v2/pet/findByStatus #[tracing::instrument(skip_all)] -async fn find_pets_by_status( +async fn find_pets_by_status( method: Method, host: Host, cookies: CookieJar, @@ -254,7 +276,8 @@ async fn find_pets_by_status( ) -> Result where I: AsRef + Send + Sync, - A: apis::pet::Pet, + A: apis::pet::Pet + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = @@ -271,7 +294,7 @@ where let result = api_impl .as_ref() - .find_pets_by_status(method, host, cookies, query_params) + .find_pets_by_status(&method, &host, &cookies, &query_params) .await; let mut response = Response::builder(); @@ -299,10 +322,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -322,7 +349,7 @@ fn find_pets_by_tags_validation( } /// FindPetsByTags - GET /v2/pet/findByTags #[tracing::instrument(skip_all)] -async fn find_pets_by_tags( +async fn find_pets_by_tags( method: Method, host: Host, cookies: CookieJar, @@ -331,7 +358,8 @@ async fn find_pets_by_tags( ) -> Result where I: AsRef + Send + Sync, - A: apis::pet::Pet, + A: apis::pet::Pet + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = @@ -348,7 +376,7 @@ where let result = api_impl .as_ref() - .find_pets_by_tags(method, host, cookies, query_params) + .find_pets_by_tags(&method, &host, &cookies, &query_params) .await; let mut response = Response::builder(); @@ -376,10 +404,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -399,7 +431,7 @@ fn get_pet_by_id_validation( } /// GetPetById - GET /v2/pet/{petId} #[tracing::instrument(skip_all)] -async fn get_pet_by_id( +async fn get_pet_by_id( method: Method, host: Host, cookies: CookieJar, @@ -409,7 +441,8 @@ async fn get_pet_by_id( ) -> Result where I: AsRef + Send + Sync, - A: apis::pet::Pet + apis::ApiKeyAuthHeader, + A: apis::pet::Pet + apis::ApiKeyAuthHeader + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { // Authentication let claims_in_header = api_impl @@ -438,7 +471,7 @@ where let result = api_impl .as_ref() - .get_pet_by_id(method, host, cookies, claims, path_params) + .get_pet_by_id(&method, &host, &cookies, &claims, &path_params) .await; let mut response = Response::builder(); @@ -470,10 +503,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -501,7 +538,7 @@ fn update_pet_validation( } /// UpdatePet - PUT /v2/pet #[tracing::instrument(skip_all)] -async fn update_pet( +async fn update_pet( method: Method, host: Host, cookies: CookieJar, @@ -510,7 +547,8 @@ async fn update_pet( ) -> Result where I: AsRef + Send + Sync, - A: apis::pet::Pet, + A: apis::pet::Pet + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || update_pet_validation(body)) @@ -526,7 +564,7 @@ where let result = api_impl .as_ref() - .update_pet(method, host, cookies, body) + .update_pet(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -562,10 +600,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -603,7 +645,7 @@ fn update_pet_with_form_validation( } /// UpdatePetWithForm - POST /v2/pet/{petId} #[tracing::instrument(skip_all)] -async fn update_pet_with_form( +async fn update_pet_with_form( method: Method, host: Host, cookies: CookieJar, @@ -613,7 +655,8 @@ async fn update_pet_with_form( ) -> Result where I: AsRef + Send + Sync, - A: apis::pet::Pet, + A: apis::pet::Pet + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = @@ -630,7 +673,7 @@ where let result = api_impl .as_ref() - .update_pet_with_form(method, host, cookies, path_params, body) + .update_pet_with_form(&method, &host, &cookies, &path_params, &body) .await; let mut response = Response::builder(); @@ -642,10 +685,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -665,7 +712,7 @@ fn upload_file_validation( } /// UploadFile - POST /v2/pet/{petId}/uploadImage #[tracing::instrument(skip_all)] -async fn upload_file( +async fn upload_file( method: Method, host: Host, cookies: CookieJar, @@ -675,7 +722,8 @@ async fn upload_file( ) -> Result where I: AsRef + Send + Sync, - A: apis::pet::Pet, + A: apis::pet::Pet + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || upload_file_validation(path_params)) @@ -691,7 +739,7 @@ where let result = api_impl .as_ref() - .upload_file(method, host, cookies, path_params, body) + .upload_file(&method, &host, &cookies, &path_params, &body) .await; let mut response = Response::builder(); @@ -722,10 +770,14 @@ where response.body(Body::from(body_content)) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -745,7 +797,7 @@ fn delete_order_validation( } /// DeleteOrder - DELETE /v2/store/order/{orderId} #[tracing::instrument(skip_all)] -async fn delete_order( +async fn delete_order( method: Method, host: Host, cookies: CookieJar, @@ -754,7 +806,8 @@ async fn delete_order( ) -> Result where I: AsRef + Send + Sync, - A: apis::store::Store, + A: apis::store::Store + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || delete_order_validation(path_params)) @@ -770,7 +823,7 @@ where let result = api_impl .as_ref() - .delete_order(method, host, cookies, path_params) + .delete_order(&method, &host, &cookies, &path_params) .await; let mut response = Response::builder(); @@ -786,10 +839,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -805,7 +862,7 @@ fn get_inventory_validation() -> std::result::Result<(), ValidationErrors> { } /// GetInventory - GET /v2/store/inventory #[tracing::instrument(skip_all)] -async fn get_inventory( +async fn get_inventory( method: Method, host: Host, cookies: CookieJar, @@ -814,7 +871,8 @@ async fn get_inventory( ) -> Result where I: AsRef + Send + Sync, - A: apis::store::Store + apis::ApiKeyAuthHeader, + A: apis::store::Store + apis::ApiKeyAuthHeader + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { // Authentication let claims_in_header = api_impl @@ -843,7 +901,7 @@ where let result = api_impl .as_ref() - .get_inventory(method, host, cookies, claims) + .get_inventory(&method, &host, &cookies, &claims) .await; let mut response = Response::builder(); @@ -874,10 +932,14 @@ where response.body(Body::from(body_content)) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -897,7 +959,7 @@ fn get_order_by_id_validation( } /// GetOrderById - GET /v2/store/order/{orderId} #[tracing::instrument(skip_all)] -async fn get_order_by_id( +async fn get_order_by_id( method: Method, host: Host, cookies: CookieJar, @@ -906,7 +968,8 @@ async fn get_order_by_id( ) -> Result where I: AsRef + Send + Sync, - A: apis::store::Store, + A: apis::store::Store + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || get_order_by_id_validation(path_params)) @@ -922,7 +985,7 @@ where let result = api_impl .as_ref() - .get_order_by_id(method, host, cookies, path_params) + .get_order_by_id(&method, &host, &cookies, &path_params) .await; let mut response = Response::builder(); @@ -954,10 +1017,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -985,7 +1052,7 @@ fn place_order_validation( } /// PlaceOrder - POST /v2/store/order #[tracing::instrument(skip_all)] -async fn place_order( +async fn place_order( method: Method, host: Host, cookies: CookieJar, @@ -994,7 +1061,8 @@ async fn place_order( ) -> Result where I: AsRef + Send + Sync, - A: apis::store::Store, + A: apis::store::Store + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || place_order_validation(body)) @@ -1010,7 +1078,7 @@ where let result = api_impl .as_ref() - .place_order(method, host, cookies, body) + .place_order(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -1038,10 +1106,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1069,7 +1141,7 @@ fn create_user_validation( } /// CreateUser - POST /v2/user #[tracing::instrument(skip_all)] -async fn create_user( +async fn create_user( method: Method, host: Host, cookies: CookieJar, @@ -1079,7 +1151,8 @@ async fn create_user( ) -> Result where I: AsRef + Send + Sync, - A: apis::user::User + apis::ApiKeyAuthHeader, + A: apis::user::User + apis::ApiKeyAuthHeader + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { // Authentication let claims_in_header = api_impl @@ -1108,7 +1181,7 @@ where let result = api_impl .as_ref() - .create_user(method, host, cookies, claims, body) + .create_user(&method, &host, &cookies, &claims, &body) .await; let mut response = Response::builder(); @@ -1120,10 +1193,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1151,7 +1228,7 @@ fn create_users_with_array_input_validation( } /// CreateUsersWithArrayInput - POST /v2/user/createWithArray #[tracing::instrument(skip_all)] -async fn create_users_with_array_input( +async fn create_users_with_array_input( method: Method, host: Host, cookies: CookieJar, @@ -1161,7 +1238,8 @@ async fn create_users_with_array_input( ) -> Result where I: AsRef + Send + Sync, - A: apis::user::User + apis::ApiKeyAuthHeader, + A: apis::user::User + apis::ApiKeyAuthHeader + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { // Authentication let claims_in_header = api_impl @@ -1191,7 +1269,7 @@ where let result = api_impl .as_ref() - .create_users_with_array_input(method, host, cookies, claims, body) + .create_users_with_array_input(&method, &host, &cookies, &claims, &body) .await; let mut response = Response::builder(); @@ -1203,10 +1281,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1234,7 +1316,7 @@ fn create_users_with_list_input_validation( } /// CreateUsersWithListInput - POST /v2/user/createWithList #[tracing::instrument(skip_all)] -async fn create_users_with_list_input( +async fn create_users_with_list_input( method: Method, host: Host, cookies: CookieJar, @@ -1244,7 +1326,8 @@ async fn create_users_with_list_input( ) -> Result where I: AsRef + Send + Sync, - A: apis::user::User + apis::ApiKeyAuthHeader, + A: apis::user::User + apis::ApiKeyAuthHeader + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { // Authentication let claims_in_header = api_impl @@ -1274,7 +1357,7 @@ where let result = api_impl .as_ref() - .create_users_with_list_input(method, host, cookies, claims, body) + .create_users_with_list_input(&method, &host, &cookies, &claims, &body) .await; let mut response = Response::builder(); @@ -1286,10 +1369,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1309,7 +1396,7 @@ fn delete_user_validation( } /// DeleteUser - DELETE /v2/user/{username} #[tracing::instrument(skip_all)] -async fn delete_user( +async fn delete_user( method: Method, host: Host, cookies: CookieJar, @@ -1319,7 +1406,8 @@ async fn delete_user( ) -> Result where I: AsRef + Send + Sync, - A: apis::user::User + apis::ApiKeyAuthHeader, + A: apis::user::User + apis::ApiKeyAuthHeader + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { // Authentication let claims_in_header = api_impl @@ -1348,7 +1436,7 @@ where let result = api_impl .as_ref() - .delete_user(method, host, cookies, claims, path_params) + .delete_user(&method, &host, &cookies, &claims, &path_params) .await; let mut response = Response::builder(); @@ -1364,10 +1452,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1387,7 +1479,7 @@ fn get_user_by_name_validation( } /// GetUserByName - GET /v2/user/{username} #[tracing::instrument(skip_all)] -async fn get_user_by_name( +async fn get_user_by_name( method: Method, host: Host, cookies: CookieJar, @@ -1396,7 +1488,8 @@ async fn get_user_by_name( ) -> Result where I: AsRef + Send + Sync, - A: apis::user::User, + A: apis::user::User + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || get_user_by_name_validation(path_params)) @@ -1412,7 +1505,7 @@ where let result = api_impl .as_ref() - .get_user_by_name(method, host, cookies, path_params) + .get_user_by_name(&method, &host, &cookies, &path_params) .await; let mut response = Response::builder(); @@ -1444,10 +1537,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1467,7 +1564,7 @@ fn login_user_validation( } /// LoginUser - GET /v2/user/login #[tracing::instrument(skip_all)] -async fn login_user( +async fn login_user( method: Method, host: Host, cookies: CookieJar, @@ -1476,7 +1573,8 @@ async fn login_user( ) -> Result where I: AsRef + Send + Sync, - A: apis::user::User, + A: apis::user::User + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || login_user_validation(query_params)) @@ -1492,7 +1590,7 @@ where let result = api_impl .as_ref() - .login_user(method, host, cookies, query_params) + .login_user(&method, &host, &cookies, &query_params) .await; let mut response = Response::builder(); @@ -1573,10 +1671,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1592,7 +1694,7 @@ fn logout_user_validation() -> std::result::Result<(), ValidationErrors> { } /// LogoutUser - GET /v2/user/logout #[tracing::instrument(skip_all)] -async fn logout_user( +async fn logout_user( method: Method, host: Host, cookies: CookieJar, @@ -1601,7 +1703,8 @@ async fn logout_user( ) -> Result where I: AsRef + Send + Sync, - A: apis::user::User + apis::ApiKeyAuthHeader, + A: apis::user::User + apis::ApiKeyAuthHeader + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { // Authentication let claims_in_header = api_impl @@ -1630,7 +1733,7 @@ where let result = api_impl .as_ref() - .logout_user(method, host, cookies, claims) + .logout_user(&method, &host, &cookies, &claims) .await; let mut response = Response::builder(); @@ -1642,10 +1745,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -1675,7 +1782,7 @@ fn update_user_validation( } /// UpdateUser - PUT /v2/user/{username} #[tracing::instrument(skip_all)] -async fn update_user( +async fn update_user( method: Method, host: Host, cookies: CookieJar, @@ -1686,7 +1793,8 @@ async fn update_user( ) -> Result where I: AsRef + Send + Sync, - A: apis::user::User + apis::ApiKeyAuthHeader, + A: apis::user::User + apis::ApiKeyAuthHeader + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { // Authentication let claims_in_header = api_impl @@ -1715,7 +1823,7 @@ where let result = api_impl .as_ref() - .update_user(method, host, cookies, claims, path_params, body) + .update_user(&method, &host, &cookies, &claims, &path_params, &body) .await; let mut response = Response::builder(); @@ -1731,10 +1839,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; diff --git a/samples/server/petstore/rust-axum/output/ping-bearer-auth/.openapi-generator/VERSION b/samples/server/petstore/rust-axum/output/ping-bearer-auth/.openapi-generator/VERSION index 884119126398..de37f5c4cf59 100644 --- a/samples/server/petstore/rust-axum/output/ping-bearer-auth/.openapi-generator/VERSION +++ b/samples/server/petstore/rust-axum/output/ping-bearer-auth/.openapi-generator/VERSION @@ -1 +1 @@ -7.11.0-SNAPSHOT +7.12.0-SNAPSHOT diff --git a/samples/server/petstore/rust-axum/output/ping-bearer-auth/Cargo.toml b/samples/server/petstore/rust-axum/output/ping-bearer-auth/Cargo.toml index ff8b87cc4ed7..0ef3a0b7a976 100644 --- a/samples/server/petstore/rust-axum/output/ping-bearer-auth/Cargo.toml +++ b/samples/server/petstore/rust-axum/output/ping-bearer-auth/Cargo.toml @@ -40,7 +40,7 @@ tokio = { version = "1", default-features = false, features = [ ] } tracing = { version = "0.1", features = ["attributes"] } uuid = { version = "1", features = ["serde"] } -validator = { version = "0.19", features = ["derive"] } +validator = { version = "0.20", features = ["derive"] } [dev-dependencies] tracing-subscriber = "0.3" diff --git a/samples/server/petstore/rust-axum/output/ping-bearer-auth/README.md b/samples/server/petstore/rust-axum/output/ping-bearer-auth/README.md index 5b152c6a4fb2..580ec9920643 100644 --- a/samples/server/petstore/rust-axum/output/ping-bearer-auth/README.md +++ b/samples/server/petstore/rust-axum/output/ping-bearer-auth/README.md @@ -12,7 +12,7 @@ server, you can easily generate a server stub. To see how to make this your own, look here: [README]((https://openapi-generator.tech)) - API version: 1.0 -- Generator version: 7.11.0-SNAPSHOT +- Generator version: 7.12.0-SNAPSHOT @@ -43,16 +43,18 @@ struct ServerImpl { #[allow(unused_variables)] #[async_trait] -impl ping-bearer-auth::Api for ServerImpl { +impl ping_bearer_auth::apis::default::Api for ServerImpl { // API implementation goes here } +impl ping_bearer_auth::apis::ErrorHandler for ServerImpl {} + pub async fn start_server(addr: &str) { // initialize tracing tracing_subscriber::fmt::init(); // Init Axum router - let app = ping-bearer-auth::server::new(Arc::new(ServerImpl)); + let app = ping_bearer_auth::server::new(Arc::new(ServerImpl)); // Add layers to the router let app = app.layer(...); diff --git a/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/apis/default.rs b/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/apis/default.rs index cfb12ef7fd4d..7e86a4c6713c 100644 --- a/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/apis/default.rs +++ b/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/apis/default.rs @@ -18,12 +18,12 @@ pub enum PingGetResponse { /// Default #[async_trait] #[allow(clippy::ptr_arg)] -pub trait Default { +pub trait Default: super::ErrorHandler { /// PingGet - GET /ping async fn ping_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; } diff --git a/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/apis/mod.rs b/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/apis/mod.rs index 1be8d340b8e0..189958193a59 100644 --- a/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/apis/mod.rs +++ b/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/apis/mod.rs @@ -1 +1,21 @@ pub mod default; + +// Error handler for unhandled errors. +#[async_trait::async_trait] +pub trait ErrorHandler { + #[allow(unused_variables)] + #[tracing::instrument(skip_all)] + async fn handle_error( + &self, + method: &::http::Method, + host: &axum::extract::Host, + cookies: &axum_extra::extract::CookieJar, + error: E, + ) -> Result { + tracing::error!("Unhandled error: {:?}", error); + axum::response::Response::builder() + .status(http::StatusCode::INTERNAL_SERVER_ERROR) + .body(axum::body::Body::empty()) + .map_err(|_| http::StatusCode::INTERNAL_SERVER_ERROR) + } +} diff --git a/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/server/mod.rs b/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/server/mod.rs index 2d1e7ca10116..6cc123686069 100644 --- a/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/server/mod.rs +++ b/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/server/mod.rs @@ -13,14 +13,15 @@ use crate::{header, types::*}; use crate::{apis, models}; /// Setup API Server. -pub fn new(api_impl: I) -> Router +pub fn new(api_impl: I) -> Router where I: AsRef + Clone + Send + Sync + 'static, - A: apis::default::Default + 'static, + A: apis::default::Default + Send + Sync + 'static, + E: std::fmt::Debug + Send + Sync + 'static, { // build our application with a route Router::new() - .route("/ping", get(ping_get::)) + .route("/ping", get(ping_get::)) .with_state(api_impl) } @@ -30,7 +31,7 @@ fn ping_get_validation() -> std::result::Result<(), ValidationErrors> { } /// PingGet - GET /ping #[tracing::instrument(skip_all)] -async fn ping_get( +async fn ping_get( method: Method, host: Host, cookies: CookieJar, @@ -38,7 +39,8 @@ async fn ping_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || ping_get_validation()) @@ -52,7 +54,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().ping_get(method, host, cookies).await; + let result = api_impl.as_ref().ping_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -63,10 +65,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; diff --git a/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/.openapi-generator/VERSION b/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/.openapi-generator/VERSION index 884119126398..de37f5c4cf59 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/.openapi-generator/VERSION +++ b/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/.openapi-generator/VERSION @@ -1 +1 @@ -7.11.0-SNAPSHOT +7.12.0-SNAPSHOT diff --git a/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/Cargo.toml b/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/Cargo.toml index ecfbde9106a7..61a1be517f9b 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/Cargo.toml +++ b/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/Cargo.toml @@ -40,7 +40,7 @@ tokio = { version = "1", default-features = false, features = [ ] } tracing = { version = "0.1", features = ["attributes"] } uuid = { version = "1", features = ["serde"] } -validator = { version = "0.19", features = ["derive"] } +validator = { version = "0.20", features = ["derive"] } [dev-dependencies] tracing-subscriber = "0.3" diff --git a/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/README.md b/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/README.md index 56220aaf10fd..880ec2323a16 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/README.md +++ b/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/README.md @@ -12,7 +12,7 @@ server, you can easily generate a server stub. To see how to make this your own, look here: [README]((https://openapi-generator.tech)) - API version: 0.1.9 -- Generator version: 7.11.0-SNAPSHOT +- Generator version: 7.12.0-SNAPSHOT @@ -43,16 +43,18 @@ struct ServerImpl { #[allow(unused_variables)] #[async_trait] -impl rust-axum-header-uui::Api for ServerImpl { +impl rust_axum_header_uui::apis::default::Api for ServerImpl { // API implementation goes here } +impl rust_axum_header_uui::apis::ErrorHandler for ServerImpl {} + pub async fn start_server(addr: &str) { // initialize tracing tracing_subscriber::fmt::init(); // Init Axum router - let app = rust-axum-header-uui::server::new(Arc::new(ServerImpl)); + let app = rust_axum_header_uui::server::new(Arc::new(ServerImpl)); // Add layers to the router let app = app.layer(...); diff --git a/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/src/apis/default.rs b/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/src/apis/default.rs index 2c6c51c0d2c3..c2d71af1d828 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/src/apis/default.rs +++ b/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/src/apis/default.rs @@ -18,13 +18,13 @@ pub enum UsersPostResponse { /// Default #[async_trait] #[allow(clippy::ptr_arg)] -pub trait Default { +pub trait Default: super::ErrorHandler { /// UsersPost - POST /users async fn users_post( &self, - method: Method, - host: Host, - cookies: CookieJar, - header_params: models::UsersPostHeaderParams, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + header_params: &models::UsersPostHeaderParams, + ) -> Result; } diff --git a/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/src/apis/mod.rs b/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/src/apis/mod.rs index 1be8d340b8e0..189958193a59 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/src/apis/mod.rs +++ b/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/src/apis/mod.rs @@ -1 +1,21 @@ pub mod default; + +// Error handler for unhandled errors. +#[async_trait::async_trait] +pub trait ErrorHandler { + #[allow(unused_variables)] + #[tracing::instrument(skip_all)] + async fn handle_error( + &self, + method: &::http::Method, + host: &axum::extract::Host, + cookies: &axum_extra::extract::CookieJar, + error: E, + ) -> Result { + tracing::error!("Unhandled error: {:?}", error); + axum::response::Response::builder() + .status(http::StatusCode::INTERNAL_SERVER_ERROR) + .body(axum::body::Body::empty()) + .map_err(|_| http::StatusCode::INTERNAL_SERVER_ERROR) + } +} diff --git a/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/src/server/mod.rs b/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/src/server/mod.rs index e0deda59d9c9..4c13730cf906 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/src/server/mod.rs +++ b/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/src/server/mod.rs @@ -13,14 +13,15 @@ use crate::{header, types::*}; use crate::{apis, models}; /// Setup API Server. -pub fn new(api_impl: I) -> Router +pub fn new(api_impl: I) -> Router where I: AsRef + Clone + Send + Sync + 'static, - A: apis::default::Default + 'static, + A: apis::default::Default + Send + Sync + 'static, + E: std::fmt::Debug + Send + Sync + 'static, { // build our application with a route Router::new() - .route("/users", post(users_post::)) + .route("/users", post(users_post::)) .with_state(api_impl) } @@ -34,7 +35,7 @@ fn users_post_validation( } /// UsersPost - POST /users #[tracing::instrument(skip_all)] -async fn users_post( +async fn users_post( method: Method, host: Host, cookies: CookieJar, @@ -43,7 +44,8 @@ async fn users_post( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { // Header parameters let header_params = { @@ -92,7 +94,7 @@ where let result = api_impl .as_ref() - .users_post(method, host, cookies, header_params) + .users_post(&method, &host, &cookies, &header_params) .await; let mut response = Response::builder(); @@ -123,10 +125,14 @@ where response.body(Body::from(body_content)) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; diff --git a/samples/server/petstore/rust-axum/output/rust-axum-oneof/.openapi-generator/VERSION b/samples/server/petstore/rust-axum/output/rust-axum-oneof/.openapi-generator/VERSION index 884119126398..de37f5c4cf59 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-oneof/.openapi-generator/VERSION +++ b/samples/server/petstore/rust-axum/output/rust-axum-oneof/.openapi-generator/VERSION @@ -1 +1 @@ -7.11.0-SNAPSHOT +7.12.0-SNAPSHOT diff --git a/samples/server/petstore/rust-axum/output/rust-axum-oneof/Cargo.toml b/samples/server/petstore/rust-axum/output/rust-axum-oneof/Cargo.toml index 849859898918..6f1c1537e730 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-oneof/Cargo.toml +++ b/samples/server/petstore/rust-axum/output/rust-axum-oneof/Cargo.toml @@ -40,7 +40,7 @@ tokio = { version = "1", default-features = false, features = [ ] } tracing = { version = "0.1", features = ["attributes"] } uuid = { version = "1", features = ["serde"] } -validator = { version = "0.19", features = ["derive"] } +validator = { version = "0.20", features = ["derive"] } [dev-dependencies] tracing-subscriber = "0.3" diff --git a/samples/server/petstore/rust-axum/output/rust-axum-oneof/README.md b/samples/server/petstore/rust-axum/output/rust-axum-oneof/README.md index 6c4665e80ba0..6c8dfa29b8f5 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-oneof/README.md +++ b/samples/server/petstore/rust-axum/output/rust-axum-oneof/README.md @@ -12,7 +12,7 @@ server, you can easily generate a server stub. To see how to make this your own, look here: [README]((https://openapi-generator.tech)) - API version: 0.0.1 -- Generator version: 7.11.0-SNAPSHOT +- Generator version: 7.12.0-SNAPSHOT @@ -43,16 +43,18 @@ struct ServerImpl { #[allow(unused_variables)] #[async_trait] -impl rust-axum-oneof::Api for ServerImpl { +impl rust_axum_oneof::apis::default::Api for ServerImpl { // API implementation goes here } +impl rust_axum_oneof::apis::ErrorHandler for ServerImpl {} + pub async fn start_server(addr: &str) { // initialize tracing tracing_subscriber::fmt::init(); // Init Axum router - let app = rust-axum-oneof::server::new(Arc::new(ServerImpl)); + let app = rust_axum_oneof::server::new(Arc::new(ServerImpl)); // Add layers to the router let app = app.layer(...); diff --git a/samples/server/petstore/rust-axum/output/rust-axum-oneof/src/apis/default.rs b/samples/server/petstore/rust-axum/output/rust-axum-oneof/src/apis/default.rs index 1873aebd9db8..dd9fae3277fb 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-oneof/src/apis/default.rs +++ b/samples/server/petstore/rust-axum/output/rust-axum-oneof/src/apis/default.rs @@ -18,13 +18,13 @@ pub enum FooResponse { /// Default #[async_trait] #[allow(clippy::ptr_arg)] -pub trait Default { +pub trait Default: super::ErrorHandler { /// Foo - POST / async fn foo( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::Message, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &models::Message, + ) -> Result; } diff --git a/samples/server/petstore/rust-axum/output/rust-axum-oneof/src/apis/mod.rs b/samples/server/petstore/rust-axum/output/rust-axum-oneof/src/apis/mod.rs index 1be8d340b8e0..189958193a59 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-oneof/src/apis/mod.rs +++ b/samples/server/petstore/rust-axum/output/rust-axum-oneof/src/apis/mod.rs @@ -1 +1,21 @@ pub mod default; + +// Error handler for unhandled errors. +#[async_trait::async_trait] +pub trait ErrorHandler { + #[allow(unused_variables)] + #[tracing::instrument(skip_all)] + async fn handle_error( + &self, + method: &::http::Method, + host: &axum::extract::Host, + cookies: &axum_extra::extract::CookieJar, + error: E, + ) -> Result { + tracing::error!("Unhandled error: {:?}", error); + axum::response::Response::builder() + .status(http::StatusCode::INTERNAL_SERVER_ERROR) + .body(axum::body::Body::empty()) + .map_err(|_| http::StatusCode::INTERNAL_SERVER_ERROR) + } +} diff --git a/samples/server/petstore/rust-axum/output/rust-axum-oneof/src/server/mod.rs b/samples/server/petstore/rust-axum/output/rust-axum-oneof/src/server/mod.rs index 8db98b873f15..31e7d18306f7 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-oneof/src/server/mod.rs +++ b/samples/server/petstore/rust-axum/output/rust-axum-oneof/src/server/mod.rs @@ -13,14 +13,15 @@ use crate::{header, types::*}; use crate::{apis, models}; /// Setup API Server. -pub fn new(api_impl: I) -> Router +pub fn new(api_impl: I) -> Router where I: AsRef + Clone + Send + Sync + 'static, - A: apis::default::Default + 'static, + A: apis::default::Default + Send + Sync + 'static, + E: std::fmt::Debug + Send + Sync + 'static, { // build our application with a route Router::new() - .route("/", post(foo::)) + .route("/", post(foo::)) .with_state(api_impl) } @@ -42,7 +43,7 @@ fn foo_validation( } /// Foo - POST / #[tracing::instrument(skip_all)] -async fn foo( +async fn foo( method: Method, host: Host, cookies: CookieJar, @@ -51,7 +52,8 @@ async fn foo( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || foo_validation(body)) @@ -65,7 +67,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().foo(method, host, cookies, body).await; + let result = api_impl.as_ref().foo(&method, &host, &cookies, &body).await; let mut response = Response::builder(); @@ -95,10 +97,14 @@ where response.body(Body::from(body_content)) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; diff --git a/samples/server/petstore/rust-axum/output/rust-axum-test/.openapi-generator/VERSION b/samples/server/petstore/rust-axum/output/rust-axum-test/.openapi-generator/VERSION index 884119126398..de37f5c4cf59 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-test/.openapi-generator/VERSION +++ b/samples/server/petstore/rust-axum/output/rust-axum-test/.openapi-generator/VERSION @@ -1 +1 @@ -7.11.0-SNAPSHOT +7.12.0-SNAPSHOT diff --git a/samples/server/petstore/rust-axum/output/rust-axum-test/Cargo.toml b/samples/server/petstore/rust-axum/output/rust-axum-test/Cargo.toml index 9803ea83268c..e5673ab75676 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-test/Cargo.toml +++ b/samples/server/petstore/rust-axum/output/rust-axum-test/Cargo.toml @@ -40,7 +40,7 @@ tokio = { version = "1", default-features = false, features = [ ] } tracing = { version = "0.1", features = ["attributes"] } uuid = { version = "1", features = ["serde"] } -validator = { version = "0.19", features = ["derive"] } +validator = { version = "0.20", features = ["derive"] } [dev-dependencies] tracing-subscriber = "0.3" diff --git a/samples/server/petstore/rust-axum/output/rust-axum-test/README.md b/samples/server/petstore/rust-axum/output/rust-axum-test/README.md index 17add5a653eb..d6a8781dfe38 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-test/README.md +++ b/samples/server/petstore/rust-axum/output/rust-axum-test/README.md @@ -12,7 +12,7 @@ server, you can easily generate a server stub. To see how to make this your own, look here: [README]((https://openapi-generator.tech)) - API version: 2.3.4 -- Generator version: 7.11.0-SNAPSHOT +- Generator version: 7.12.0-SNAPSHOT @@ -43,16 +43,18 @@ struct ServerImpl { #[allow(unused_variables)] #[async_trait] -impl rust-server-test::Api for ServerImpl { +impl rust_server_test::apis::default::Api for ServerImpl { // API implementation goes here } +impl rust_server_test::apis::ErrorHandler for ServerImpl {} + pub async fn start_server(addr: &str) { // initialize tracing tracing_subscriber::fmt::init(); // Init Axum router - let app = rust-server-test::server::new(Arc::new(ServerImpl)); + let app = rust_server_test::server::new(Arc::new(ServerImpl)); // Add layers to the router let app = app.layer(...); diff --git a/samples/server/petstore/rust-axum/output/rust-axum-test/src/apis/default.rs b/samples/server/petstore/rust-axum/output/rust-axum-test/src/apis/default.rs index ba643a1d2f82..914ccacd9708 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-test/src/apis/default.rs +++ b/samples/server/petstore/rust-axum/output/rust-axum-test/src/apis/default.rs @@ -82,90 +82,90 @@ pub enum SoloObjectPostResponse { /// Default #[async_trait] #[allow(clippy::ptr_arg)] -pub trait Default { +pub trait Default: super::ErrorHandler { /// AllOfGet - GET /allOf async fn all_of_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// A dummy endpoint to make the spec valid.. /// /// DummyGet - GET /dummy async fn dummy_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// DummyPut - PUT /dummy async fn dummy_put( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::FooDummyPutRequest, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &models::FooDummyPutRequest, + ) -> Result; /// Get a file. /// /// FileResponseGet - GET /file_response async fn file_response_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// GetStructuredYaml - GET /get-structured-yaml async fn get_structured_yaml( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Test HTML handling. /// /// HtmlPost - POST /html async fn html_post( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: String, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &String, + ) -> Result; /// PostYaml - POST /post-yaml async fn post_yaml( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: String, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &String, + ) -> Result; /// Get an arbitrary JSON blob.. /// /// RawJsonGet - GET /raw_json async fn raw_json_get( &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + ) -> Result; /// Send an arbitrary JSON blob. /// /// SoloObjectPost - POST /solo-object async fn solo_object_post( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: crate::types::Object, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &crate::types::Object, + ) -> Result; } diff --git a/samples/server/petstore/rust-axum/output/rust-axum-test/src/apis/mod.rs b/samples/server/petstore/rust-axum/output/rust-axum-test/src/apis/mod.rs index 1be8d340b8e0..189958193a59 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-test/src/apis/mod.rs +++ b/samples/server/petstore/rust-axum/output/rust-axum-test/src/apis/mod.rs @@ -1 +1,21 @@ pub mod default; + +// Error handler for unhandled errors. +#[async_trait::async_trait] +pub trait ErrorHandler { + #[allow(unused_variables)] + #[tracing::instrument(skip_all)] + async fn handle_error( + &self, + method: &::http::Method, + host: &axum::extract::Host, + cookies: &axum_extra::extract::CookieJar, + error: E, + ) -> Result { + tracing::error!("Unhandled error: {:?}", error); + axum::response::Response::builder() + .status(http::StatusCode::INTERNAL_SERVER_ERROR) + .body(axum::body::Body::empty()) + .map_err(|_| http::StatusCode::INTERNAL_SERVER_ERROR) + } +} diff --git a/samples/server/petstore/rust-axum/output/rust-axum-test/src/server/mod.rs b/samples/server/petstore/rust-axum/output/rust-axum-test/src/server/mod.rs index c8205254790a..344af2c02581 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-test/src/server/mod.rs +++ b/samples/server/petstore/rust-axum/output/rust-axum-test/src/server/mod.rs @@ -13,21 +13,25 @@ use crate::{header, types::*}; use crate::{apis, models}; /// Setup API Server. -pub fn new(api_impl: I) -> Router +pub fn new(api_impl: I) -> Router where I: AsRef + Clone + Send + Sync + 'static, - A: apis::default::Default + 'static, + A: apis::default::Default + Send + Sync + 'static, + E: std::fmt::Debug + Send + Sync + 'static, { // build our application with a route Router::new() - .route("/allOf", get(all_of_get::)) - .route("/dummy", get(dummy_get::).put(dummy_put::)) - .route("/file_response", get(file_response_get::)) - .route("/get-structured-yaml", get(get_structured_yaml::)) - .route("/html", post(html_post::)) - .route("/post-yaml", post(post_yaml::)) - .route("/raw_json", get(raw_json_get::)) - .route("/solo-object", post(solo_object_post::)) + .route("/allOf", get(all_of_get::)) + .route( + "/dummy", + get(dummy_get::).put(dummy_put::), + ) + .route("/file_response", get(file_response_get::)) + .route("/get-structured-yaml", get(get_structured_yaml::)) + .route("/html", post(html_post::)) + .route("/post-yaml", post(post_yaml::)) + .route("/raw_json", get(raw_json_get::)) + .route("/solo-object", post(solo_object_post::)) .with_state(api_impl) } @@ -37,7 +41,7 @@ fn all_of_get_validation() -> std::result::Result<(), ValidationErrors> { } /// AllOfGet - GET /allOf #[tracing::instrument(skip_all)] -async fn all_of_get( +async fn all_of_get( method: Method, host: Host, cookies: CookieJar, @@ -45,7 +49,8 @@ async fn all_of_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || all_of_get_validation()) @@ -59,7 +64,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().all_of_get(method, host, cookies).await; + let result = api_impl.as_ref().all_of_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -89,10 +94,14 @@ where response.body(Body::from(body_content)) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -108,7 +117,7 @@ fn dummy_get_validation() -> std::result::Result<(), ValidationErrors> { } /// DummyGet - GET /dummy #[tracing::instrument(skip_all)] -async fn dummy_get( +async fn dummy_get( method: Method, host: Host, cookies: CookieJar, @@ -116,7 +125,8 @@ async fn dummy_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || dummy_get_validation()) @@ -130,7 +140,7 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().dummy_get(method, host, cookies).await; + let result = api_impl.as_ref().dummy_get(&method, &host, &cookies).await; let mut response = Response::builder(); @@ -141,10 +151,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -172,7 +186,7 @@ fn dummy_put_validation( } /// DummyPut - PUT /dummy #[tracing::instrument(skip_all)] -async fn dummy_put( +async fn dummy_put( method: Method, host: Host, cookies: CookieJar, @@ -181,7 +195,8 @@ async fn dummy_put( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || dummy_put_validation(body)) @@ -197,7 +212,7 @@ where let result = api_impl .as_ref() - .dummy_put(method, host, cookies, body) + .dummy_put(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -209,10 +224,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -228,7 +247,7 @@ fn file_response_get_validation() -> std::result::Result<(), ValidationErrors> { } /// FileResponseGet - GET /file_response #[tracing::instrument(skip_all)] -async fn file_response_get( +async fn file_response_get( method: Method, host: Host, cookies: CookieJar, @@ -236,7 +255,8 @@ async fn file_response_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || file_response_get_validation()) @@ -252,7 +272,7 @@ where let result = api_impl .as_ref() - .file_response_get(method, host, cookies) + .file_response_get(&method, &host, &cookies) .await; let mut response = Response::builder(); @@ -283,10 +303,14 @@ where response.body(Body::from(body_content)) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -302,7 +326,7 @@ fn get_structured_yaml_validation() -> std::result::Result<(), ValidationErrors> } /// GetStructuredYaml - GET /get-structured-yaml #[tracing::instrument(skip_all)] -async fn get_structured_yaml( +async fn get_structured_yaml( method: Method, host: Host, cookies: CookieJar, @@ -310,7 +334,8 @@ async fn get_structured_yaml( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || get_structured_yaml_validation()) @@ -326,7 +351,7 @@ where let result = api_impl .as_ref() - .get_structured_yaml(method, host, cookies) + .get_structured_yaml(&method, &host, &cookies) .await; let mut response = Response::builder(); @@ -350,10 +375,14 @@ where response.body(Body::from(body_content)) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -375,7 +404,7 @@ fn html_post_validation(body: String) -> std::result::Result<(String,), Validati } /// HtmlPost - POST /html #[tracing::instrument(skip_all)] -async fn html_post( +async fn html_post( method: Method, host: Host, cookies: CookieJar, @@ -384,7 +413,8 @@ async fn html_post( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || html_post_validation(body)) @@ -400,7 +430,7 @@ where let result = api_impl .as_ref() - .html_post(method, host, cookies, body) + .html_post(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -424,10 +454,14 @@ where response.body(Body::from(body_content)) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -449,7 +483,7 @@ fn post_yaml_validation(body: String) -> std::result::Result<(String,), Validati } /// PostYaml - POST /post-yaml #[tracing::instrument(skip_all)] -async fn post_yaml( +async fn post_yaml( method: Method, host: Host, cookies: CookieJar, @@ -458,7 +492,8 @@ async fn post_yaml( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || post_yaml_validation(body)) @@ -474,7 +509,7 @@ where let result = api_impl .as_ref() - .post_yaml(method, host, cookies, body) + .post_yaml(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -486,10 +521,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -505,7 +544,7 @@ fn raw_json_get_validation() -> std::result::Result<(), ValidationErrors> { } /// RawJsonGet - GET /raw_json #[tracing::instrument(skip_all)] -async fn raw_json_get( +async fn raw_json_get( method: Method, host: Host, cookies: CookieJar, @@ -513,7 +552,8 @@ async fn raw_json_get( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || raw_json_get_validation()) @@ -527,7 +567,10 @@ where .map_err(|_| StatusCode::BAD_REQUEST); }; - let result = api_impl.as_ref().raw_json_get(method, host, cookies).await; + let result = api_impl + .as_ref() + .raw_json_get(&method, &host, &cookies) + .await; let mut response = Response::builder(); @@ -557,10 +600,14 @@ where response.body(Body::from(body_content)) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; @@ -587,7 +634,7 @@ fn solo_object_post_validation( } /// SoloObjectPost - POST /solo-object #[tracing::instrument(skip_all)] -async fn solo_object_post( +async fn solo_object_post( method: Method, host: Host, cookies: CookieJar, @@ -596,7 +643,8 @@ async fn solo_object_post( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || solo_object_post_validation(body)) @@ -612,7 +660,7 @@ where let result = api_impl .as_ref() - .solo_object_post(method, host, cookies, body) + .solo_object_post(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -624,10 +672,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } }; diff --git a/samples/server/petstore/rust-axum/output/rust-axum-validation-test/.openapi-generator/VERSION b/samples/server/petstore/rust-axum/output/rust-axum-validation-test/.openapi-generator/VERSION index 884119126398..de37f5c4cf59 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-validation-test/.openapi-generator/VERSION +++ b/samples/server/petstore/rust-axum/output/rust-axum-validation-test/.openapi-generator/VERSION @@ -1 +1 @@ -7.11.0-SNAPSHOT +7.12.0-SNAPSHOT diff --git a/samples/server/petstore/rust-axum/output/rust-axum-validation-test/Cargo.toml b/samples/server/petstore/rust-axum/output/rust-axum-validation-test/Cargo.toml index 7d8fd93b600d..f4a38c11157a 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-validation-test/Cargo.toml +++ b/samples/server/petstore/rust-axum/output/rust-axum-validation-test/Cargo.toml @@ -40,7 +40,7 @@ tokio = { version = "1", default-features = false, features = [ ] } tracing = { version = "0.1", features = ["attributes"] } uuid = { version = "1", features = ["serde"] } -validator = { version = "0.19", features = ["derive"] } +validator = { version = "0.20", features = ["derive"] } [dev-dependencies] tracing-subscriber = "0.3" diff --git a/samples/server/petstore/rust-axum/output/rust-axum-validation-test/README.md b/samples/server/petstore/rust-axum/output/rust-axum-validation-test/README.md index fbff4455f06b..1699a54f8b45 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-validation-test/README.md +++ b/samples/server/petstore/rust-axum/output/rust-axum-validation-test/README.md @@ -12,7 +12,7 @@ server, you can easily generate a server stub. To see how to make this your own, look here: [README]((https://openapi-generator.tech)) - API version: 0.0.1 -- Generator version: 7.11.0-SNAPSHOT +- Generator version: 7.12.0-SNAPSHOT @@ -43,16 +43,18 @@ struct ServerImpl { #[allow(unused_variables)] #[async_trait] -impl rust-axum-validation-test::Api for ServerImpl { +impl rust_axum_validation_test::apis::default::Api for ServerImpl { // API implementation goes here } +impl rust_axum_validation_test::apis::ErrorHandler for ServerImpl {} + pub async fn start_server(addr: &str) { // initialize tracing tracing_subscriber::fmt::init(); // Init Axum router - let app = rust-axum-validation-test::server::new(Arc::new(ServerImpl)); + let app = rust_axum_validation_test::server::new(Arc::new(ServerImpl)); // Add layers to the router let app = app.layer(...); diff --git a/samples/server/petstore/rust-axum/output/rust-axum-validation-test/src/apis/default.rs b/samples/server/petstore/rust-axum/output/rust-axum-validation-test/src/apis/default.rs index d9ef3904a0ca..99614283bc48 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-validation-test/src/apis/default.rs +++ b/samples/server/petstore/rust-axum/output/rust-axum-validation-test/src/apis/default.rs @@ -18,13 +18,13 @@ pub enum MailPutResponse { /// Default #[async_trait] #[allow(clippy::ptr_arg)] -pub trait Default { +pub trait Default: super::ErrorHandler { /// MailPut - PUT /mail async fn mail_put( &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::Email, - ) -> Result; + method: &Method, + host: &Host, + cookies: &CookieJar, + body: &models::Email, + ) -> Result; } diff --git a/samples/server/petstore/rust-axum/output/rust-axum-validation-test/src/apis/mod.rs b/samples/server/petstore/rust-axum/output/rust-axum-validation-test/src/apis/mod.rs index 1be8d340b8e0..189958193a59 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-validation-test/src/apis/mod.rs +++ b/samples/server/petstore/rust-axum/output/rust-axum-validation-test/src/apis/mod.rs @@ -1 +1,21 @@ pub mod default; + +// Error handler for unhandled errors. +#[async_trait::async_trait] +pub trait ErrorHandler { + #[allow(unused_variables)] + #[tracing::instrument(skip_all)] + async fn handle_error( + &self, + method: &::http::Method, + host: &axum::extract::Host, + cookies: &axum_extra::extract::CookieJar, + error: E, + ) -> Result { + tracing::error!("Unhandled error: {:?}", error); + axum::response::Response::builder() + .status(http::StatusCode::INTERNAL_SERVER_ERROR) + .body(axum::body::Body::empty()) + .map_err(|_| http::StatusCode::INTERNAL_SERVER_ERROR) + } +} diff --git a/samples/server/petstore/rust-axum/output/rust-axum-validation-test/src/server/mod.rs b/samples/server/petstore/rust-axum/output/rust-axum-validation-test/src/server/mod.rs index 822b74a61f60..55d30ae25f9b 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-validation-test/src/server/mod.rs +++ b/samples/server/petstore/rust-axum/output/rust-axum-validation-test/src/server/mod.rs @@ -13,20 +13,21 @@ use crate::{header, types::*}; use crate::{apis, models}; /// Setup API Server. -pub fn new(api_impl: I) -> Router +pub fn new(api_impl: I) -> Router where I: AsRef + Clone + Send + Sync + 'static, - A: apis::default::Default + 'static, + A: apis::default::Default + Send + Sync + 'static, + E: std::fmt::Debug + Send + Sync + 'static, { // build our application with a route Router::new() - .route("/mail", put(mail_put::)) + .route("/mail", put(mail_put::)) .with_state(api_impl) } /// MailPut - PUT /mail #[tracing::instrument(skip_all)] -async fn mail_put( +async fn mail_put( method: Method, host: Host, cookies: CookieJar, @@ -35,11 +36,12 @@ async fn mail_put( ) -> Result where I: AsRef + Send + Sync, - A: apis::default::Default, + A: apis::default::Default + Send + Sync, + E: std::fmt::Debug + Send + Sync + 'static, { let result = api_impl .as_ref() - .mail_put(method, host, cookies, body) + .mail_put(&method, &host, &cookies, &body) .await; let mut response = Response::builder(); @@ -51,10 +53,14 @@ where response.body(Body::empty()) } }, - Err(_) => { + Err(why) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - response.status(500).body(Body::empty()) + + return api_impl + .as_ref() + .handle_error(&method, &host, &cookies, why) + .await; } };