diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ad1cc9b..56b9a64e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Store the private representation of generated Rust `ApiCallError` values behind + a `Box`, making the common erased error pointer-sized. Derived `Debug` output now + reflects the private inner wrapper. + ## [0.2.1] ### Breaking Changes diff --git a/src/generators/rust/common/runtime.rs b/src/generators/rust/common/runtime.rs index 49b53fd7..d3eee933 100644 --- a/src/generators/rust/common/runtime.rs +++ b/src/generators/rust/common/runtime.rs @@ -20,6 +20,7 @@ pub(crate) fn render_api_call_error( FileSpec::builder("error.rs") .add_type(api_call_http_error(response_headers_type.clone())?) .add_type(api_call_error_kind()?) + .add_type(api_call_error_inner()?) .add_type(api_call_error(response_headers_type)?) .add_code(api_call_error_display()?) .add_code(api_call_error_source()?) @@ -83,6 +84,56 @@ fn api_call_error_kind() -> Result { .build() } +fn api_call_error_inner() -> Result { + let api_error_of_t = TypeName::generic( + TypeName::primitive("ApiError"), + vec![TypeName::primitive("T")], + ); + let from_api_error = FunSpec::builder("from_api_error") + .add_type_param(TypeParamSpec::new("T")) + .add_param(ParameterSpec::of("operation_id", operation_id_type())) + .add_param(ParameterSpec::of("error", api_error_of_t)) + .returns(TypeName::primitive("Self")) + .body( + sigil_quote!(RustLang { + Self { + operation_id, + kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), + } + }) + .map_err(|error| SigilStitchError::Render { + context: "ApiCallErrorInner::from_api_error body".into(), + message: error.to_string(), + })?, + ) + .build()?; + let from_runtime_error = FunSpec::builder("from_runtime_error") + .add_param(ParameterSpec::of("operation_id", operation_id_type())) + .add_param(ParameterSpec::of("error", TypeName::primitive("Error"))) + .returns(TypeName::primitive("Self")) + .body( + sigil_quote!(RustLang { + Self { + operation_id, + kind: ApiCallErrorKind::Runtime(error), + } + }) + .map_err(|error| SigilStitchError::Render { + context: "ApiCallErrorInner::from_runtime_error body".into(), + message: error.to_string(), + })?, + ) + .build()?; + + TypeSpec::builder("ApiCallErrorInner", TypeKind::Struct) + .annotate(AnnotationSpec::new("derive").args(["Debug"])) + .add_field(FieldSpec::builder("operation_id", operation_id_type()).build()?) + .add_field(FieldSpec::builder("kind", TypeName::primitive("ApiCallErrorKind")).build()?) + .add_method(from_api_error) + .add_method(from_runtime_error) + .build() +} + fn api_call_error(response_headers_type: TypeName) -> Result { let static_str = operation_id_type(); let api_error_of_t = TypeName::generic( @@ -99,24 +150,34 @@ fn api_call_error(response_headers_type: TypeName) -> Result Result Result Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -147,7 +208,7 @@ fn api_call_error(response_headers_type: TypeName) -> Result Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -159,7 +220,7 @@ fn api_call_error(response_headers_type: TypeName) -> Result Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -170,8 +231,7 @@ fn api_call_error(response_headers_type: TypeName) -> Result TypeName { TypeName::reference_with_lifetime(TypeName::primitive("str"), "'static") } +fn api_call_error_inner_type() -> TypeName { + TypeName::generic( + TypeName::primitive("Box"), + vec![TypeName::primitive("ApiCallErrorInner")], + ) +} + fn api_call_headers_type(response_headers_type: TypeName) -> TypeName { TypeName::optional(TypeName::reference(response_headers_type)) } @@ -197,12 +264,12 @@ fn api_call_error_display() -> Result { sigil_quote!(RustLang { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -214,12 +281,12 @@ fn api_call_error_source() -> Result { sigil_quote!(RustLang { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None @@ -256,6 +323,27 @@ mod tests { r#"fn inspect(operation_id: &'static str) -> (Option<&reqwest::header::HeaderMap>, Option<&[u8]>) { todo!() } +"#, + ); + } + + #[test] + fn api_call_error_owned_type_renders_exactly() { + let inner = api_call_error_inner_type(); + let block = sigil_quote!(RustLang { + struct ApiCallError { + inner: $T(inner), + } + }) + .expect("ApiCallError owned type probe builds"); + + assert_rendered!( + Rust::new(), + width = 100, + block, + r#"struct ApiCallError { + inner: Box, +} "#, ); } diff --git a/tests/golden/rust/rust-aioduct/additional-properties/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/additional-properties/src/runtime/error.rs.golden index 2efbdf51..b79124a5 100644 --- a/tests/golden/rust/rust-aioduct/additional-properties/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/additional-properties/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/binary-transfer-media-types/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/binary-transfer-media-types/src/runtime/error.rs.golden index 9db23476..1256a1e0 100644 --- a/tests/golden/rust/rust-aioduct/binary-transfer-media-types/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/binary-transfer-media-types/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/comprehensive-schemas/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/comprehensive-schemas/src/runtime/error.rs.golden index 24133ff0..c9db5226 100644 --- a/tests/golden/rust/rust-aioduct/comprehensive-schemas/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/comprehensive-schemas/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/delete-with-response-schema/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/delete-with-response-schema/src/runtime/error.rs.golden index d34013bc..17a12f2f 100644 --- a/tests/golden/rust/rust-aioduct/delete-with-response-schema/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/delete-with-response-schema/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/duplicate-param-names/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/duplicate-param-names/src/runtime/error.rs.golden index 9d75448e..eebfce44 100644 --- a/tests/golden/rust/rust-aioduct/duplicate-param-names/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/duplicate-param-names/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/enum-repr/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/enum-repr/src/runtime/error.rs.golden index c3f68c65..ebd85f66 100644 --- a/tests/golden/rust/rust-aioduct/enum-repr/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/enum-repr/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/media-type-selection/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/media-type-selection/src/runtime/error.rs.golden index 9e412f08..9b6a9f68 100644 --- a/tests/golden/rust/rust-aioduct/media-type-selection/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/media-type-selection/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/minimal/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/minimal/src/runtime/error.rs.golden index 28fea5aa..c4cc4b4a 100644 --- a/tests/golden/rust/rust-aioduct/minimal/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/minimal/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/multiline-docs-and-primitive-alias/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/multiline-docs-and-primitive-alias/src/runtime/error.rs.golden index 052a83b9..c82fbd25 100644 --- a/tests/golden/rust/rust-aioduct/multiline-docs-and-primitive-alias/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/multiline-docs-and-primitive-alias/src/runtime/error.rs.golden @@ -132,36 +132,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -169,7 +188,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -177,7 +196,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -186,12 +205,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -199,12 +218,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/multipart-edge-cases/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/multipart-edge-cases/src/runtime/error.rs.golden index da0d971c..1d86bb98 100644 --- a/tests/golden/rust/rust-aioduct/multipart-edge-cases/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/multipart-edge-cases/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/multipart-explicit-encoding/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/multipart-explicit-encoding/src/runtime/error.rs.golden index b5b14ff3..928a1a7b 100644 --- a/tests/golden/rust/rust-aioduct/multipart-explicit-encoding/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/multipart-explicit-encoding/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/multipart-nested-object-parts/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/multipart-nested-object-parts/src/runtime/error.rs.golden index 6240d343..9340399b 100644 --- a/tests/golden/rust/rust-aioduct/multipart-nested-object-parts/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/multipart-nested-object-parts/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/multipart-unsupported-schema/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/multipart-unsupported-schema/src/runtime/error.rs.golden index f582a28c..6440de20 100644 --- a/tests/golden/rust/rust-aioduct/multipart-unsupported-schema/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/multipart-unsupported-schema/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/multiple-similar-request-schemas/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/multiple-similar-request-schemas/src/runtime/error.rs.golden index e4a7b4a3..078b1c9a 100644 --- a/tests/golden/rust/rust-aioduct/multiple-similar-request-schemas/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/multiple-similar-request-schemas/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/naming-conventions/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/naming-conventions/src/runtime/error.rs.golden index 4d4616f4..427a78f9 100644 --- a/tests/golden/rust/rust-aioduct/naming-conventions/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/naming-conventions/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/optional-request-bodies/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/optional-request-bodies/src/runtime/error.rs.golden index 79bc5e46..57d8a122 100644 --- a/tests/golden/rust/rust-aioduct/optional-request-bodies/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/optional-request-bodies/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/petstore/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/petstore/src/runtime/error.rs.golden index d7de47a1..e027d78f 100644 --- a/tests/golden/rust/rust-aioduct/petstore/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/petstore/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/query-param-enum/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/query-param-enum/src/runtime/error.rs.golden index 243cef68..cf3db403 100644 --- a/tests/golden/rust/rust-aioduct/query-param-enum/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/query-param-enum/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/recursive-json-all-optional-properties/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/recursive-json-all-optional-properties/src/runtime/error.rs.golden index ef9d914d..3f1d1f32 100644 --- a/tests/golden/rust/rust-aioduct/recursive-json-all-optional-properties/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/recursive-json-all-optional-properties/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/recursive-json-array-of-inline-objects/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/recursive-json-array-of-inline-objects/src/runtime/error.rs.golden index 3c6effae..531ba402 100644 --- a/tests/golden/rust/rust-aioduct/recursive-json-array-of-inline-objects/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/recursive-json-array-of-inline-objects/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/recursive-json-array-of-referenced-types/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/recursive-json-array-of-referenced-types/src/runtime/error.rs.golden index 515477ab..aa2e5125 100644 --- a/tests/golden/rust/rust-aioduct/recursive-json-array-of-referenced-types/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/recursive-json-array-of-referenced-types/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/recursive-json-array-with-reference-property/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/recursive-json-array-with-reference-property/src/runtime/error.rs.golden index 10b22d04..a5d290f6 100644 --- a/tests/golden/rust/rust-aioduct/recursive-json-array-with-reference-property/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/recursive-json-array-with-reference-property/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/recursive-json-complex-array-structure/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/recursive-json-complex-array-structure/src/runtime/error.rs.golden index 7ceb584e..576a8d5d 100644 --- a/tests/golden/rust/rust-aioduct/recursive-json-complex-array-structure/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/recursive-json-complex-array-structure/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/recursive-json-deeply-nested-inline/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/recursive-json-deeply-nested-inline/src/runtime/error.rs.golden index b8220126..63412d74 100644 --- a/tests/golden/rust/rust-aioduct/recursive-json-deeply-nested-inline/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/recursive-json-deeply-nested-inline/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/recursive-json-empty-array/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/recursive-json-empty-array/src/runtime/error.rs.golden index 5221954a..62e165ca 100644 --- a/tests/golden/rust/rust-aioduct/recursive-json-empty-array/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/recursive-json-empty-array/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/recursive-json-inline-object-with-array/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/recursive-json-inline-object-with-array/src/runtime/error.rs.golden index 337006c1..6e3b0f4c 100644 --- a/tests/golden/rust/rust-aioduct/recursive-json-inline-object-with-array/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/recursive-json-inline-object-with-array/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/recursive-json-inline-object/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/recursive-json-inline-object/src/runtime/error.rs.golden index d7995c73..61f4f07c 100644 --- a/tests/golden/rust/rust-aioduct/recursive-json-inline-object/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/recursive-json-inline-object/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/recursive-json-mixed-property-types/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/recursive-json-mixed-property-types/src/runtime/error.rs.golden index d7a8b747..079a08e0 100644 --- a/tests/golden/rust/rust-aioduct/recursive-json-mixed-property-types/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/recursive-json-mixed-property-types/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/recursive-json-nested-object-reference/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/recursive-json-nested-object-reference/src/runtime/error.rs.golden index b5f8dd3e..2b55828c 100644 --- a/tests/golden/rust/rust-aioduct/recursive-json-nested-object-reference/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/recursive-json-nested-object-reference/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/recursive-json-optional-array-of-inline-objects/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/recursive-json-optional-array-of-inline-objects/src/runtime/error.rs.golden index e2b493cb..12eea57f 100644 --- a/tests/golden/rust/rust-aioduct/recursive-json-optional-array-of-inline-objects/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/recursive-json-optional-array-of-inline-objects/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/recursive-json-optional-array-of-referenced-types/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/recursive-json-optional-array-of-referenced-types/src/runtime/error.rs.golden index 8d677597..fa1b29e9 100644 --- a/tests/golden/rust/rust-aioduct/recursive-json-optional-array-of-referenced-types/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/recursive-json-optional-array-of-referenced-types/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/recursive-json-optional-inline-object/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/recursive-json-optional-inline-object/src/runtime/error.rs.golden index 1d857ca3..d3f314bd 100644 --- a/tests/golden/rust/rust-aioduct/recursive-json-optional-inline-object/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/recursive-json-optional-inline-object/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/recursive-json-optional-nested-object-reference/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/recursive-json-optional-nested-object-reference/src/runtime/error.rs.golden index c9a66bc7..b1f904d5 100644 --- a/tests/golden/rust/rust-aioduct/recursive-json-optional-nested-object-reference/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/recursive-json-optional-nested-object-reference/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/recursive-json-primitive-array/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/recursive-json-primitive-array/src/runtime/error.rs.golden index fc4135a5..5ab0ff67 100644 --- a/tests/golden/rust/rust-aioduct/recursive-json-primitive-array/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/recursive-json-primitive-array/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/recursive-json-self-referential-object/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/recursive-json-self-referential-object/src/runtime/error.rs.golden index 4c06534c..6cc64738 100644 --- a/tests/golden/rust/rust-aioduct/recursive-json-self-referential-object/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/recursive-json-self-referential-object/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/request-body-content-types/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/request-body-content-types/src/runtime/error.rs.golden index 2432ce0c..2637fcd8 100644 --- a/tests/golden/rust/rust-aioduct/request-body-content-types/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/request-body-content-types/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/response-body-default-and-exact/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/response-body-default-and-exact/src/runtime/error.rs.golden index e3b6ab36..13125d6d 100644 --- a/tests/golden/rust/rust-aioduct/response-body-default-and-exact/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/response-body-default-and-exact/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/response-body-fallback/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/response-body-fallback/src/runtime/error.rs.golden index 10606ed7..c1e06132 100644 --- a/tests/golden/rust/rust-aioduct/response-body-fallback/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/response-body-fallback/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/response-body-multi-status-responses/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/response-body-multi-status-responses/src/runtime/error.rs.golden index d4a035ce..a8b948ac 100644 --- a/tests/golden/rust/rust-aioduct/response-body-multi-status-responses/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/response-body-multi-status-responses/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/response-body-no-response-body/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/response-body-no-response-body/src/runtime/error.rs.golden index 3984752c..8920b3f5 100644 --- a/tests/golden/rust/rust-aioduct/response-body-no-response-body/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/response-body-no-response-body/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/server-object/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/server-object/src/runtime/error.rs.golden index c40c1926..7e021b96 100644 --- a/tests/golden/rust/rust-aioduct/server-object/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/server-object/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/server-path-prefix/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/server-path-prefix/src/runtime/error.rs.golden index c5d77284..d1b18777 100644 --- a/tests/golden/rust/rust-aioduct/server-path-prefix/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/server-path-prefix/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/type-aliases-complex-union/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/type-aliases-complex-union/src/runtime/error.rs.golden index e9d91613..b8e53d0e 100644 --- a/tests/golden/rust/rust-aioduct/type-aliases-complex-union/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/type-aliases-complex-union/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/type-aliases-discriminated-union-inline-discriminator-only/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/type-aliases-discriminated-union-inline-discriminator-only/src/runtime/error.rs.golden index edba25ba..c0f9e0dc 100644 --- a/tests/golden/rust/rust-aioduct/type-aliases-discriminated-union-inline-discriminator-only/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/type-aliases-discriminated-union-inline-discriminator-only/src/runtime/error.rs.golden @@ -140,36 +140,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -177,7 +196,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -185,7 +204,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -194,12 +213,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -207,12 +226,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/type-aliases-discriminated-union-internally-tagged/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/type-aliases-discriminated-union-internally-tagged/src/runtime/error.rs.golden index 27246ea2..836f7f3b 100644 --- a/tests/golden/rust/rust-aioduct/type-aliases-discriminated-union-internally-tagged/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/type-aliases-discriminated-union-internally-tagged/src/runtime/error.rs.golden @@ -133,36 +133,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -170,7 +189,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -178,7 +197,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -187,12 +206,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -200,12 +219,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/type-aliases-discriminated-union-long-names/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/type-aliases-discriminated-union-long-names/src/runtime/error.rs.golden index 21bdd8ed..a4e8a27e 100644 --- a/tests/golden/rust/rust-aioduct/type-aliases-discriminated-union-long-names/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/type-aliases-discriminated-union-long-names/src/runtime/error.rs.golden @@ -133,36 +133,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -170,7 +189,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -178,7 +197,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -187,12 +206,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -200,12 +219,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/type-aliases-discriminated-union-mixed-unit-and-allof/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/type-aliases-discriminated-union-mixed-unit-and-allof/src/runtime/error.rs.golden index 7fa31493..95c1cdf1 100644 --- a/tests/golden/rust/rust-aioduct/type-aliases-discriminated-union-mixed-unit-and-allof/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/type-aliases-discriminated-union-mixed-unit-and-allof/src/runtime/error.rs.golden @@ -136,36 +136,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -173,7 +192,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -181,7 +200,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -190,12 +209,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -203,12 +222,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/type-aliases-discriminated-union-multiple/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/type-aliases-discriminated-union-multiple/src/runtime/error.rs.golden index e960dbfe..d08faaf6 100644 --- a/tests/golden/rust/rust-aioduct/type-aliases-discriminated-union-multiple/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/type-aliases-discriminated-union-multiple/src/runtime/error.rs.golden @@ -134,36 +134,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -171,7 +190,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -179,7 +198,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -188,12 +207,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -201,12 +220,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/type-aliases-discriminated-union-with-refs/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/type-aliases-discriminated-union-with-refs/src/runtime/error.rs.golden index 224e1a36..45ab1003 100644 --- a/tests/golden/rust/rust-aioduct/type-aliases-discriminated-union-with-refs/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/type-aliases-discriminated-union-with-refs/src/runtime/error.rs.golden @@ -132,36 +132,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -169,7 +188,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -177,7 +196,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -186,12 +205,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -199,12 +218,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/type-aliases-intersection-allof/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/type-aliases-intersection-allof/src/runtime/error.rs.golden index e548ae5c..d247688b 100644 --- a/tests/golden/rust/rust-aioduct/type-aliases-intersection-allof/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/type-aliases-intersection-allof/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/type-aliases-intersection-with-nullable-reference/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/type-aliases-intersection-with-nullable-reference/src/runtime/error.rs.golden index 463cb166..f7f93c8b 100644 --- a/tests/golden/rust/rust-aioduct/type-aliases-intersection-with-nullable-reference/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/type-aliases-intersection-with-nullable-reference/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/type-aliases-nested-union/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/type-aliases-nested-union/src/runtime/error.rs.golden index 23e49df7..cc076f01 100644 --- a/tests/golden/rust/rust-aioduct/type-aliases-nested-union/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/type-aliases-nested-union/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/type-aliases-simple-type-alias/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/type-aliases-simple-type-alias/src/runtime/error.rs.golden index f2cc74d6..abf72f86 100644 --- a/tests/golden/rust/rust-aioduct/type-aliases-simple-type-alias/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/type-aliases-simple-type-alias/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/type-aliases-union-mixed/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/type-aliases-union-mixed/src/runtime/error.rs.golden index 8c1b2f31..d512d169 100644 --- a/tests/golden/rust/rust-aioduct/type-aliases-union-mixed/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/type-aliases-union-mixed/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/type-aliases-union-with-any/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/type-aliases-union-with-any/src/runtime/error.rs.golden index 0cc9fe1a..76131499 100644 --- a/tests/golden/rust/rust-aioduct/type-aliases-union-with-any/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/type-aliases-union-with-any/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/type-aliases-union-with-inline-objects/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/type-aliases-union-with-inline-objects/src/runtime/error.rs.golden index 69e8f6fa..9c6b0f24 100644 --- a/tests/golden/rust/rust-aioduct/type-aliases-union-with-inline-objects/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/type-aliases-union-with-inline-objects/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/type-aliases-union-with-interfaces/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/type-aliases-union-with-interfaces/src/runtime/error.rs.golden index 029e4427..3295af14 100644 --- a/tests/golden/rust/rust-aioduct/type-aliases-union-with-interfaces/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/type-aliases-union-with-interfaces/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/type-aliases-union-with-primitives/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/type-aliases-union-with-primitives/src/runtime/error.rs.golden index 5de3faea..39987b51 100644 --- a/tests/golden/rust/rust-aioduct/type-aliases-union-with-primitives/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/type-aliases-union-with-primitives/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/typed-error-responses/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/typed-error-responses/src/runtime/error.rs.golden index 0ec53e7f..a996faa8 100644 --- a/tests/golden/rust/rust-aioduct/typed-error-responses/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/typed-error-responses/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/utoipa-mixed/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/utoipa-mixed/src/runtime/error.rs.golden index 61b4d322..7ac286f2 100644 --- a/tests/golden/rust/rust-aioduct/utoipa-mixed/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/utoipa-mixed/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/utoipa-untagged-union/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/utoipa-untagged-union/src/runtime/error.rs.golden index 3d43a9c0..f7604622 100644 --- a/tests/golden/rust/rust-aioduct/utoipa-untagged-union/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/utoipa-untagged-union/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-aioduct/utoipa-with-extra-derives/src/runtime/error.rs.golden b/tests/golden/rust/rust-aioduct/utoipa-with-extra-derives/src/runtime/error.rs.golden index cc375efb..1601d691 100644 --- a/tests/golden/rust/rust-aioduct/utoipa-with-extra-derives/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-aioduct/utoipa-with-extra-derives/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&aioduct::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/additional-properties/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/additional-properties/src/runtime/error.rs.golden index fd33cedc..fe97221b 100644 --- a/tests/golden/rust/rust-reqwest/additional-properties/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/additional-properties/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/binary-transfer-media-types/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/binary-transfer-media-types/src/runtime/error.rs.golden index 00dda373..a4512bd1 100644 --- a/tests/golden/rust/rust-reqwest/binary-transfer-media-types/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/binary-transfer-media-types/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/comprehensive-schemas/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/comprehensive-schemas/src/runtime/error.rs.golden index 6c087459..bc730c86 100644 --- a/tests/golden/rust/rust-reqwest/comprehensive-schemas/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/comprehensive-schemas/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/delete-with-response-schema/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/delete-with-response-schema/src/runtime/error.rs.golden index 64bd2e28..9126bf79 100644 --- a/tests/golden/rust/rust-reqwest/delete-with-response-schema/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/delete-with-response-schema/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/duplicate-param-names/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/duplicate-param-names/src/runtime/error.rs.golden index 3fcf4ce7..87596608 100644 --- a/tests/golden/rust/rust-reqwest/duplicate-param-names/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/duplicate-param-names/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/enum-repr/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/enum-repr/src/runtime/error.rs.golden index 810cf9e1..fa1ec16d 100644 --- a/tests/golden/rust/rust-reqwest/enum-repr/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/enum-repr/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/media-type-selection/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/media-type-selection/src/runtime/error.rs.golden index df2d6eef..862b23c6 100644 --- a/tests/golden/rust/rust-reqwest/media-type-selection/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/media-type-selection/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/minimal/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/minimal/src/runtime/error.rs.golden index 390f7113..f75d4938 100644 --- a/tests/golden/rust/rust-reqwest/minimal/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/minimal/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/multiline-docs-and-primitive-alias/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/multiline-docs-and-primitive-alias/src/runtime/error.rs.golden index b3779e86..91306a45 100644 --- a/tests/golden/rust/rust-reqwest/multiline-docs-and-primitive-alias/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/multiline-docs-and-primitive-alias/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/multipart-edge-cases/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/multipart-edge-cases/src/runtime/error.rs.golden index ddcac1bb..50a1b166 100644 --- a/tests/golden/rust/rust-reqwest/multipart-edge-cases/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/multipart-edge-cases/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/multipart-explicit-encoding/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/multipart-explicit-encoding/src/runtime/error.rs.golden index 6a5b31ad..a7dd3a5b 100644 --- a/tests/golden/rust/rust-reqwest/multipart-explicit-encoding/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/multipart-explicit-encoding/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/multipart-nested-object-parts/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/multipart-nested-object-parts/src/runtime/error.rs.golden index 9132a7e8..70c232ef 100644 --- a/tests/golden/rust/rust-reqwest/multipart-nested-object-parts/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/multipart-nested-object-parts/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/multipart-unsupported-schema/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/multipart-unsupported-schema/src/runtime/error.rs.golden index f47b4e3a..0b9cde17 100644 --- a/tests/golden/rust/rust-reqwest/multipart-unsupported-schema/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/multipart-unsupported-schema/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/multiple-similar-request-schemas/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/multiple-similar-request-schemas/src/runtime/error.rs.golden index dd673104..1b596daf 100644 --- a/tests/golden/rust/rust-reqwest/multiple-similar-request-schemas/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/multiple-similar-request-schemas/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/naming-conventions/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/naming-conventions/src/runtime/error.rs.golden index 8b302361..2d6427b0 100644 --- a/tests/golden/rust/rust-reqwest/naming-conventions/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/naming-conventions/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/optional-request-bodies/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/optional-request-bodies/src/runtime/error.rs.golden index 17a4f0c8..92a5b19c 100644 --- a/tests/golden/rust/rust-reqwest/optional-request-bodies/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/optional-request-bodies/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/petstore/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/petstore/src/runtime/error.rs.golden index a6e693e2..5bcb8b99 100644 --- a/tests/golden/rust/rust-reqwest/petstore/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/petstore/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/query-param-enum/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/query-param-enum/src/runtime/error.rs.golden index a45ac4a0..377ad9c9 100644 --- a/tests/golden/rust/rust-reqwest/query-param-enum/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/query-param-enum/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/recursive-json-all-optional-properties/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/recursive-json-all-optional-properties/src/runtime/error.rs.golden index 05f6b518..821b6f98 100644 --- a/tests/golden/rust/rust-reqwest/recursive-json-all-optional-properties/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/recursive-json-all-optional-properties/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/recursive-json-array-of-inline-objects/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/recursive-json-array-of-inline-objects/src/runtime/error.rs.golden index e57e34e1..f6e0594c 100644 --- a/tests/golden/rust/rust-reqwest/recursive-json-array-of-inline-objects/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/recursive-json-array-of-inline-objects/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/recursive-json-array-of-referenced-types/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/recursive-json-array-of-referenced-types/src/runtime/error.rs.golden index 79b0dae0..45d5d3c0 100644 --- a/tests/golden/rust/rust-reqwest/recursive-json-array-of-referenced-types/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/recursive-json-array-of-referenced-types/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/recursive-json-array-with-reference-property/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/recursive-json-array-with-reference-property/src/runtime/error.rs.golden index f60b49c5..740cc0b5 100644 --- a/tests/golden/rust/rust-reqwest/recursive-json-array-with-reference-property/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/recursive-json-array-with-reference-property/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/recursive-json-complex-array-structure/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/recursive-json-complex-array-structure/src/runtime/error.rs.golden index f8b65523..a720ce64 100644 --- a/tests/golden/rust/rust-reqwest/recursive-json-complex-array-structure/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/recursive-json-complex-array-structure/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/recursive-json-deeply-nested-inline/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/recursive-json-deeply-nested-inline/src/runtime/error.rs.golden index d581a45a..5720b4ca 100644 --- a/tests/golden/rust/rust-reqwest/recursive-json-deeply-nested-inline/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/recursive-json-deeply-nested-inline/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/recursive-json-empty-array/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/recursive-json-empty-array/src/runtime/error.rs.golden index 9bc97b4a..515d74f7 100644 --- a/tests/golden/rust/rust-reqwest/recursive-json-empty-array/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/recursive-json-empty-array/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/recursive-json-inline-object-with-array/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/recursive-json-inline-object-with-array/src/runtime/error.rs.golden index 034a34b2..05a34a5e 100644 --- a/tests/golden/rust/rust-reqwest/recursive-json-inline-object-with-array/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/recursive-json-inline-object-with-array/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/recursive-json-inline-object/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/recursive-json-inline-object/src/runtime/error.rs.golden index 31ae4028..999facef 100644 --- a/tests/golden/rust/rust-reqwest/recursive-json-inline-object/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/recursive-json-inline-object/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/recursive-json-mixed-property-types/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/recursive-json-mixed-property-types/src/runtime/error.rs.golden index 4072f32f..111ca585 100644 --- a/tests/golden/rust/rust-reqwest/recursive-json-mixed-property-types/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/recursive-json-mixed-property-types/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/recursive-json-nested-object-reference/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/recursive-json-nested-object-reference/src/runtime/error.rs.golden index d95141c4..66e8e315 100644 --- a/tests/golden/rust/rust-reqwest/recursive-json-nested-object-reference/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/recursive-json-nested-object-reference/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/recursive-json-optional-array-of-inline-objects/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/recursive-json-optional-array-of-inline-objects/src/runtime/error.rs.golden index 96ecd07c..c7a24235 100644 --- a/tests/golden/rust/rust-reqwest/recursive-json-optional-array-of-inline-objects/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/recursive-json-optional-array-of-inline-objects/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/recursive-json-optional-array-of-referenced-types/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/recursive-json-optional-array-of-referenced-types/src/runtime/error.rs.golden index 4fc5c7d1..7e450284 100644 --- a/tests/golden/rust/rust-reqwest/recursive-json-optional-array-of-referenced-types/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/recursive-json-optional-array-of-referenced-types/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/recursive-json-optional-inline-object/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/recursive-json-optional-inline-object/src/runtime/error.rs.golden index 110c58ec..83b4589d 100644 --- a/tests/golden/rust/rust-reqwest/recursive-json-optional-inline-object/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/recursive-json-optional-inline-object/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/recursive-json-optional-nested-object-reference/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/recursive-json-optional-nested-object-reference/src/runtime/error.rs.golden index 71e97afa..96e03e75 100644 --- a/tests/golden/rust/rust-reqwest/recursive-json-optional-nested-object-reference/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/recursive-json-optional-nested-object-reference/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/recursive-json-primitive-array/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/recursive-json-primitive-array/src/runtime/error.rs.golden index 267893b4..f701e11e 100644 --- a/tests/golden/rust/rust-reqwest/recursive-json-primitive-array/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/recursive-json-primitive-array/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/recursive-json-self-referential-object/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/recursive-json-self-referential-object/src/runtime/error.rs.golden index d28199a1..50bbfe4a 100644 --- a/tests/golden/rust/rust-reqwest/recursive-json-self-referential-object/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/recursive-json-self-referential-object/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/request-body-content-types/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/request-body-content-types/src/runtime/error.rs.golden index 41474c3b..08d25e0e 100644 --- a/tests/golden/rust/rust-reqwest/request-body-content-types/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/request-body-content-types/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/response-body-default-and-exact/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/response-body-default-and-exact/src/runtime/error.rs.golden index d9edaa35..f66ef1d5 100644 --- a/tests/golden/rust/rust-reqwest/response-body-default-and-exact/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/response-body-default-and-exact/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/response-body-fallback/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/response-body-fallback/src/runtime/error.rs.golden index 38d5d509..0655de87 100644 --- a/tests/golden/rust/rust-reqwest/response-body-fallback/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/response-body-fallback/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/response-body-multi-status-responses/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/response-body-multi-status-responses/src/runtime/error.rs.golden index ae1afe52..4f675a8f 100644 --- a/tests/golden/rust/rust-reqwest/response-body-multi-status-responses/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/response-body-multi-status-responses/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/response-body-no-response-body/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/response-body-no-response-body/src/runtime/error.rs.golden index 093578f2..3baaedf2 100644 --- a/tests/golden/rust/rust-reqwest/response-body-no-response-body/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/response-body-no-response-body/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/server-object/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/server-object/src/runtime/error.rs.golden index 3a61c25c..ed2c78d6 100644 --- a/tests/golden/rust/rust-reqwest/server-object/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/server-object/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/server-path-prefix/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/server-path-prefix/src/runtime/error.rs.golden index 7b3e8d93..088d28e0 100644 --- a/tests/golden/rust/rust-reqwest/server-path-prefix/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/server-path-prefix/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/type-aliases-complex-union/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/type-aliases-complex-union/src/runtime/error.rs.golden index 88de117a..84342f38 100644 --- a/tests/golden/rust/rust-reqwest/type-aliases-complex-union/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/type-aliases-complex-union/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/type-aliases-discriminated-union-inline-discriminator-only/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/type-aliases-discriminated-union-inline-discriminator-only/src/runtime/error.rs.golden index 21a9c332..2a1ddc14 100644 --- a/tests/golden/rust/rust-reqwest/type-aliases-discriminated-union-inline-discriminator-only/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/type-aliases-discriminated-union-inline-discriminator-only/src/runtime/error.rs.golden @@ -139,36 +139,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -184,7 +203,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -193,12 +212,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -206,12 +225,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/type-aliases-discriminated-union-internally-tagged/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/type-aliases-discriminated-union-internally-tagged/src/runtime/error.rs.golden index 2e5cc67e..dff2d3dc 100644 --- a/tests/golden/rust/rust-reqwest/type-aliases-discriminated-union-internally-tagged/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/type-aliases-discriminated-union-internally-tagged/src/runtime/error.rs.golden @@ -132,36 +132,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -169,7 +188,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -177,7 +196,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -186,12 +205,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -199,12 +218,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/type-aliases-discriminated-union-long-names/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/type-aliases-discriminated-union-long-names/src/runtime/error.rs.golden index 8a3ede0e..506d79b3 100644 --- a/tests/golden/rust/rust-reqwest/type-aliases-discriminated-union-long-names/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/type-aliases-discriminated-union-long-names/src/runtime/error.rs.golden @@ -132,36 +132,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -169,7 +188,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -177,7 +196,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -186,12 +205,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -199,12 +218,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/type-aliases-discriminated-union-mixed-unit-and-allof/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/type-aliases-discriminated-union-mixed-unit-and-allof/src/runtime/error.rs.golden index 726e5b04..c026c06d 100644 --- a/tests/golden/rust/rust-reqwest/type-aliases-discriminated-union-mixed-unit-and-allof/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/type-aliases-discriminated-union-mixed-unit-and-allof/src/runtime/error.rs.golden @@ -135,36 +135,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -172,7 +191,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -180,7 +199,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -189,12 +208,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -202,12 +221,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/type-aliases-discriminated-union-multiple/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/type-aliases-discriminated-union-multiple/src/runtime/error.rs.golden index 84a4f596..9a2281b1 100644 --- a/tests/golden/rust/rust-reqwest/type-aliases-discriminated-union-multiple/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/type-aliases-discriminated-union-multiple/src/runtime/error.rs.golden @@ -133,36 +133,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -170,7 +189,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -178,7 +197,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -187,12 +206,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -200,12 +219,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/type-aliases-discriminated-union-with-refs/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/type-aliases-discriminated-union-with-refs/src/runtime/error.rs.golden index 08916819..aa83d1fb 100644 --- a/tests/golden/rust/rust-reqwest/type-aliases-discriminated-union-with-refs/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/type-aliases-discriminated-union-with-refs/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/type-aliases-intersection-allof/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/type-aliases-intersection-allof/src/runtime/error.rs.golden index 45f8a087..a582e056 100644 --- a/tests/golden/rust/rust-reqwest/type-aliases-intersection-allof/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/type-aliases-intersection-allof/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/type-aliases-intersection-with-nullable-reference/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/type-aliases-intersection-with-nullable-reference/src/runtime/error.rs.golden index e66f0af4..45f4771a 100644 --- a/tests/golden/rust/rust-reqwest/type-aliases-intersection-with-nullable-reference/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/type-aliases-intersection-with-nullable-reference/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/type-aliases-nested-union/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/type-aliases-nested-union/src/runtime/error.rs.golden index 6eee8ad3..dcadd7d4 100644 --- a/tests/golden/rust/rust-reqwest/type-aliases-nested-union/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/type-aliases-nested-union/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/type-aliases-simple-type-alias/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/type-aliases-simple-type-alias/src/runtime/error.rs.golden index f516f829..652b9ab1 100644 --- a/tests/golden/rust/rust-reqwest/type-aliases-simple-type-alias/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/type-aliases-simple-type-alias/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/type-aliases-union-mixed/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/type-aliases-union-mixed/src/runtime/error.rs.golden index e288378e..2b1a6bd2 100644 --- a/tests/golden/rust/rust-reqwest/type-aliases-union-mixed/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/type-aliases-union-mixed/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/type-aliases-union-with-any/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/type-aliases-union-with-any/src/runtime/error.rs.golden index 45c71e1c..513f3a4b 100644 --- a/tests/golden/rust/rust-reqwest/type-aliases-union-with-any/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/type-aliases-union-with-any/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/type-aliases-union-with-inline-objects/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/type-aliases-union-with-inline-objects/src/runtime/error.rs.golden index 32ad3d14..fc150f3d 100644 --- a/tests/golden/rust/rust-reqwest/type-aliases-union-with-inline-objects/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/type-aliases-union-with-inline-objects/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/type-aliases-union-with-interfaces/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/type-aliases-union-with-interfaces/src/runtime/error.rs.golden index 11902526..e04c2abd 100644 --- a/tests/golden/rust/rust-reqwest/type-aliases-union-with-interfaces/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/type-aliases-union-with-interfaces/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/type-aliases-union-with-primitives/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/type-aliases-union-with-primitives/src/runtime/error.rs.golden index f0fb1614..a10daa9f 100644 --- a/tests/golden/rust/rust-reqwest/type-aliases-union-with-primitives/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/type-aliases-union-with-primitives/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/typed-error-responses/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/typed-error-responses/src/runtime/error.rs.golden index bcd50b31..2c05e8ed 100644 --- a/tests/golden/rust/rust-reqwest/typed-error-responses/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/typed-error-responses/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/utoipa-mixed/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/utoipa-mixed/src/runtime/error.rs.golden index 1120d985..342bcdee 100644 --- a/tests/golden/rust/rust-reqwest/utoipa-mixed/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/utoipa-mixed/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/utoipa-untagged-union/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/utoipa-untagged-union/src/runtime/error.rs.golden index 02afd684..460d422e 100644 --- a/tests/golden/rust/rust-reqwest/utoipa-untagged-union/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/utoipa-untagged-union/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-reqwest/utoipa-with-extra-derives/src/runtime/error.rs.golden b/tests/golden/rust/rust-reqwest/utoipa-with-extra-derives/src/runtime/error.rs.golden index 8f5fc1e5..c009b857 100644 --- a/tests/golden/rust/rust-reqwest/utoipa-with-extra-derives/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-reqwest/utoipa-with-extra-derives/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&reqwest::header::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/additional-properties/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/additional-properties/src/runtime/error.rs.golden index 47f6fbc3..d6f7b587 100644 --- a/tests/golden/rust/rust-ureq/additional-properties/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/additional-properties/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/binary-transfer-media-types/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/binary-transfer-media-types/src/runtime/error.rs.golden index 3935b1f0..203346c8 100644 --- a/tests/golden/rust/rust-ureq/binary-transfer-media-types/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/binary-transfer-media-types/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/comprehensive-schemas/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/comprehensive-schemas/src/runtime/error.rs.golden index 9a4f74b0..06340427 100644 --- a/tests/golden/rust/rust-ureq/comprehensive-schemas/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/comprehensive-schemas/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/delete-with-response-schema/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/delete-with-response-schema/src/runtime/error.rs.golden index 54495d83..da0cb264 100644 --- a/tests/golden/rust/rust-ureq/delete-with-response-schema/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/delete-with-response-schema/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/duplicate-param-names/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/duplicate-param-names/src/runtime/error.rs.golden index a902529b..d2ba3301 100644 --- a/tests/golden/rust/rust-ureq/duplicate-param-names/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/duplicate-param-names/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/enum-repr/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/enum-repr/src/runtime/error.rs.golden index b46f815d..db06bf84 100644 --- a/tests/golden/rust/rust-ureq/enum-repr/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/enum-repr/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/media-type-selection/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/media-type-selection/src/runtime/error.rs.golden index 168d4829..332154ce 100644 --- a/tests/golden/rust/rust-ureq/media-type-selection/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/media-type-selection/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/minimal/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/minimal/src/runtime/error.rs.golden index 79141951..6532102f 100644 --- a/tests/golden/rust/rust-ureq/minimal/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/minimal/src/runtime/error.rs.golden @@ -128,36 +128,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -165,7 +184,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -173,7 +192,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -182,12 +201,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -195,12 +214,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/multiline-docs-and-primitive-alias/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/multiline-docs-and-primitive-alias/src/runtime/error.rs.golden index 1137d9df..93c2dc9a 100644 --- a/tests/golden/rust/rust-ureq/multiline-docs-and-primitive-alias/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/multiline-docs-and-primitive-alias/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/multipart-edge-cases/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/multipart-edge-cases/src/runtime/error.rs.golden index a5dac92c..4591c694 100644 --- a/tests/golden/rust/rust-ureq/multipart-edge-cases/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/multipart-edge-cases/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/multipart-explicit-encoding/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/multipart-explicit-encoding/src/runtime/error.rs.golden index 66ebce8b..f93065b4 100644 --- a/tests/golden/rust/rust-ureq/multipart-explicit-encoding/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/multipart-explicit-encoding/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/multipart-nested-object-parts/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/multipart-nested-object-parts/src/runtime/error.rs.golden index de770deb..44e98965 100644 --- a/tests/golden/rust/rust-ureq/multipart-nested-object-parts/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/multipart-nested-object-parts/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/multipart-unsupported-schema/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/multipart-unsupported-schema/src/runtime/error.rs.golden index e3fd84bb..57224058 100644 --- a/tests/golden/rust/rust-ureq/multipart-unsupported-schema/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/multipart-unsupported-schema/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/multiple-similar-request-schemas/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/multiple-similar-request-schemas/src/runtime/error.rs.golden index c48b093d..061e79cc 100644 --- a/tests/golden/rust/rust-ureq/multiple-similar-request-schemas/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/multiple-similar-request-schemas/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/naming-conventions/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/naming-conventions/src/runtime/error.rs.golden index 047fc825..d7df6cac 100644 --- a/tests/golden/rust/rust-ureq/naming-conventions/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/naming-conventions/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/optional-request-bodies/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/optional-request-bodies/src/runtime/error.rs.golden index 2cf88c0e..09c6a6c9 100644 --- a/tests/golden/rust/rust-ureq/optional-request-bodies/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/optional-request-bodies/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/petstore/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/petstore/src/runtime/error.rs.golden index e4908923..9bcc099c 100644 --- a/tests/golden/rust/rust-ureq/petstore/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/petstore/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/query-param-enum/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/query-param-enum/src/runtime/error.rs.golden index a18cd399..de3efd75 100644 --- a/tests/golden/rust/rust-ureq/query-param-enum/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/query-param-enum/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/recursive-json-all-optional-properties/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/recursive-json-all-optional-properties/src/runtime/error.rs.golden index 8e8b5f05..58001e86 100644 --- a/tests/golden/rust/rust-ureq/recursive-json-all-optional-properties/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/recursive-json-all-optional-properties/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/recursive-json-array-of-inline-objects/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/recursive-json-array-of-inline-objects/src/runtime/error.rs.golden index f15cf5ec..fbf238fd 100644 --- a/tests/golden/rust/rust-ureq/recursive-json-array-of-inline-objects/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/recursive-json-array-of-inline-objects/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/recursive-json-array-of-referenced-types/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/recursive-json-array-of-referenced-types/src/runtime/error.rs.golden index cc890db0..8bc2068d 100644 --- a/tests/golden/rust/rust-ureq/recursive-json-array-of-referenced-types/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/recursive-json-array-of-referenced-types/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/recursive-json-array-with-reference-property/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/recursive-json-array-with-reference-property/src/runtime/error.rs.golden index db6e0ad0..d17dd8d3 100644 --- a/tests/golden/rust/rust-ureq/recursive-json-array-with-reference-property/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/recursive-json-array-with-reference-property/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/recursive-json-complex-array-structure/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/recursive-json-complex-array-structure/src/runtime/error.rs.golden index 50bb3886..72bacb15 100644 --- a/tests/golden/rust/rust-ureq/recursive-json-complex-array-structure/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/recursive-json-complex-array-structure/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/recursive-json-deeply-nested-inline/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/recursive-json-deeply-nested-inline/src/runtime/error.rs.golden index 88ed7382..a79e5df9 100644 --- a/tests/golden/rust/rust-ureq/recursive-json-deeply-nested-inline/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/recursive-json-deeply-nested-inline/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/recursive-json-empty-array/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/recursive-json-empty-array/src/runtime/error.rs.golden index d329d525..3eed2596 100644 --- a/tests/golden/rust/rust-ureq/recursive-json-empty-array/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/recursive-json-empty-array/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/recursive-json-inline-object-with-array/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/recursive-json-inline-object-with-array/src/runtime/error.rs.golden index 84c99914..f9d60616 100644 --- a/tests/golden/rust/rust-ureq/recursive-json-inline-object-with-array/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/recursive-json-inline-object-with-array/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/recursive-json-inline-object/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/recursive-json-inline-object/src/runtime/error.rs.golden index a5236a03..02240020 100644 --- a/tests/golden/rust/rust-ureq/recursive-json-inline-object/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/recursive-json-inline-object/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/recursive-json-mixed-property-types/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/recursive-json-mixed-property-types/src/runtime/error.rs.golden index 6402ebce..f522cac9 100644 --- a/tests/golden/rust/rust-ureq/recursive-json-mixed-property-types/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/recursive-json-mixed-property-types/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/recursive-json-nested-object-reference/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/recursive-json-nested-object-reference/src/runtime/error.rs.golden index 995d5c98..2e2f7f0f 100644 --- a/tests/golden/rust/rust-ureq/recursive-json-nested-object-reference/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/recursive-json-nested-object-reference/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/recursive-json-optional-array-of-inline-objects/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/recursive-json-optional-array-of-inline-objects/src/runtime/error.rs.golden index bac4cf41..a3d4b402 100644 --- a/tests/golden/rust/rust-ureq/recursive-json-optional-array-of-inline-objects/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/recursive-json-optional-array-of-inline-objects/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/recursive-json-optional-array-of-referenced-types/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/recursive-json-optional-array-of-referenced-types/src/runtime/error.rs.golden index 10fe8402..a6ae8cca 100644 --- a/tests/golden/rust/rust-ureq/recursive-json-optional-array-of-referenced-types/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/recursive-json-optional-array-of-referenced-types/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/recursive-json-optional-inline-object/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/recursive-json-optional-inline-object/src/runtime/error.rs.golden index d1660d02..6e368f7d 100644 --- a/tests/golden/rust/rust-ureq/recursive-json-optional-inline-object/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/recursive-json-optional-inline-object/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/recursive-json-optional-nested-object-reference/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/recursive-json-optional-nested-object-reference/src/runtime/error.rs.golden index 4eccf364..89df71db 100644 --- a/tests/golden/rust/rust-ureq/recursive-json-optional-nested-object-reference/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/recursive-json-optional-nested-object-reference/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/recursive-json-primitive-array/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/recursive-json-primitive-array/src/runtime/error.rs.golden index e3dcef48..b2f7e500 100644 --- a/tests/golden/rust/rust-ureq/recursive-json-primitive-array/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/recursive-json-primitive-array/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/recursive-json-self-referential-object/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/recursive-json-self-referential-object/src/runtime/error.rs.golden index 88e9812a..66a39066 100644 --- a/tests/golden/rust/rust-ureq/recursive-json-self-referential-object/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/recursive-json-self-referential-object/src/runtime/error.rs.golden @@ -128,36 +128,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -165,7 +184,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -173,7 +192,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -182,12 +201,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -195,12 +214,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/request-body-content-types/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/request-body-content-types/src/runtime/error.rs.golden index 19e3d623..6a58446b 100644 --- a/tests/golden/rust/rust-ureq/request-body-content-types/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/request-body-content-types/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/response-body-default-and-exact/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/response-body-default-and-exact/src/runtime/error.rs.golden index 103cdaea..6c1cfa9b 100644 --- a/tests/golden/rust/rust-ureq/response-body-default-and-exact/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/response-body-default-and-exact/src/runtime/error.rs.golden @@ -128,36 +128,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -165,7 +184,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -173,7 +192,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -182,12 +201,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -195,12 +214,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/response-body-fallback/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/response-body-fallback/src/runtime/error.rs.golden index fd68e337..8b27c94a 100644 --- a/tests/golden/rust/rust-ureq/response-body-fallback/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/response-body-fallback/src/runtime/error.rs.golden @@ -128,36 +128,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -165,7 +184,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -173,7 +192,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -182,12 +201,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -195,12 +214,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/response-body-multi-status-responses/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/response-body-multi-status-responses/src/runtime/error.rs.golden index e2910e74..d3751480 100644 --- a/tests/golden/rust/rust-ureq/response-body-multi-status-responses/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/response-body-multi-status-responses/src/runtime/error.rs.golden @@ -128,36 +128,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -165,7 +184,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -173,7 +192,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -182,12 +201,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -195,12 +214,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/response-body-no-response-body/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/response-body-no-response-body/src/runtime/error.rs.golden index 3d93df07..6c6bfc20 100644 --- a/tests/golden/rust/rust-ureq/response-body-no-response-body/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/response-body-no-response-body/src/runtime/error.rs.golden @@ -128,36 +128,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -165,7 +184,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -173,7 +192,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -182,12 +201,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -195,12 +214,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/server-object/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/server-object/src/runtime/error.rs.golden index 5d50e45d..053c6a62 100644 --- a/tests/golden/rust/rust-ureq/server-object/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/server-object/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/server-path-prefix/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/server-path-prefix/src/runtime/error.rs.golden index 441239fa..ceac4d8d 100644 --- a/tests/golden/rust/rust-ureq/server-path-prefix/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/server-path-prefix/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/type-aliases-complex-union/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/type-aliases-complex-union/src/runtime/error.rs.golden index bec62b70..41ec9f63 100644 --- a/tests/golden/rust/rust-ureq/type-aliases-complex-union/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/type-aliases-complex-union/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/type-aliases-discriminated-union-inline-discriminator-only/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/type-aliases-discriminated-union-inline-discriminator-only/src/runtime/error.rs.golden index f879ff35..7672116a 100644 --- a/tests/golden/rust/rust-ureq/type-aliases-discriminated-union-inline-discriminator-only/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/type-aliases-discriminated-union-inline-discriminator-only/src/runtime/error.rs.golden @@ -138,36 +138,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -183,7 +202,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -192,12 +211,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -205,12 +224,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/type-aliases-discriminated-union-internally-tagged/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/type-aliases-discriminated-union-internally-tagged/src/runtime/error.rs.golden index e7dd6b70..1f4283a6 100644 --- a/tests/golden/rust/rust-ureq/type-aliases-discriminated-union-internally-tagged/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/type-aliases-discriminated-union-internally-tagged/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/type-aliases-discriminated-union-long-names/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/type-aliases-discriminated-union-long-names/src/runtime/error.rs.golden index 2f43830a..a7cf988e 100644 --- a/tests/golden/rust/rust-ureq/type-aliases-discriminated-union-long-names/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/type-aliases-discriminated-union-long-names/src/runtime/error.rs.golden @@ -131,36 +131,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -168,7 +187,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -176,7 +195,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -185,12 +204,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -198,12 +217,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/type-aliases-discriminated-union-mixed-unit-and-allof/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/type-aliases-discriminated-union-mixed-unit-and-allof/src/runtime/error.rs.golden index f4c75f54..f2534a2f 100644 --- a/tests/golden/rust/rust-ureq/type-aliases-discriminated-union-mixed-unit-and-allof/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/type-aliases-discriminated-union-mixed-unit-and-allof/src/runtime/error.rs.golden @@ -134,36 +134,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -171,7 +190,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -179,7 +198,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -188,12 +207,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -201,12 +220,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/type-aliases-discriminated-union-multiple/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/type-aliases-discriminated-union-multiple/src/runtime/error.rs.golden index 5f88df30..054adca9 100644 --- a/tests/golden/rust/rust-ureq/type-aliases-discriminated-union-multiple/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/type-aliases-discriminated-union-multiple/src/runtime/error.rs.golden @@ -132,36 +132,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -169,7 +188,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -177,7 +196,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -186,12 +205,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -199,12 +218,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/type-aliases-discriminated-union-with-refs/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/type-aliases-discriminated-union-with-refs/src/runtime/error.rs.golden index 6efe3886..39782a15 100644 --- a/tests/golden/rust/rust-ureq/type-aliases-discriminated-union-with-refs/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/type-aliases-discriminated-union-with-refs/src/runtime/error.rs.golden @@ -130,36 +130,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -167,7 +186,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -175,7 +194,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -184,12 +203,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -197,12 +216,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/type-aliases-intersection-allof/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/type-aliases-intersection-allof/src/runtime/error.rs.golden index 04c7e970..6b6df311 100644 --- a/tests/golden/rust/rust-ureq/type-aliases-intersection-allof/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/type-aliases-intersection-allof/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/type-aliases-intersection-with-nullable-reference/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/type-aliases-intersection-with-nullable-reference/src/runtime/error.rs.golden index 78e8ca6f..5ccf1351 100644 --- a/tests/golden/rust/rust-ureq/type-aliases-intersection-with-nullable-reference/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/type-aliases-intersection-with-nullable-reference/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/type-aliases-nested-union/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/type-aliases-nested-union/src/runtime/error.rs.golden index 98c89bb0..e5242a83 100644 --- a/tests/golden/rust/rust-ureq/type-aliases-nested-union/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/type-aliases-nested-union/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/type-aliases-simple-type-alias/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/type-aliases-simple-type-alias/src/runtime/error.rs.golden index a15992cb..99a4e688 100644 --- a/tests/golden/rust/rust-ureq/type-aliases-simple-type-alias/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/type-aliases-simple-type-alias/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/type-aliases-union-mixed/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/type-aliases-union-mixed/src/runtime/error.rs.golden index 6763d440..64a38b55 100644 --- a/tests/golden/rust/rust-ureq/type-aliases-union-mixed/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/type-aliases-union-mixed/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/type-aliases-union-with-any/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/type-aliases-union-with-any/src/runtime/error.rs.golden index d24a3400..a186a4f6 100644 --- a/tests/golden/rust/rust-ureq/type-aliases-union-with-any/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/type-aliases-union-with-any/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/type-aliases-union-with-inline-objects/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/type-aliases-union-with-inline-objects/src/runtime/error.rs.golden index d5105951..f9a9739a 100644 --- a/tests/golden/rust/rust-ureq/type-aliases-union-with-inline-objects/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/type-aliases-union-with-inline-objects/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/type-aliases-union-with-interfaces/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/type-aliases-union-with-interfaces/src/runtime/error.rs.golden index ba2a8041..97c6381f 100644 --- a/tests/golden/rust/rust-ureq/type-aliases-union-with-interfaces/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/type-aliases-union-with-interfaces/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/type-aliases-union-with-primitives/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/type-aliases-union-with-primitives/src/runtime/error.rs.golden index ea4a0ae3..b80e3ee6 100644 --- a/tests/golden/rust/rust-ureq/type-aliases-union-with-primitives/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/type-aliases-union-with-primitives/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/typed-error-responses/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/typed-error-responses/src/runtime/error.rs.golden index 4fe52936..86bcdf9c 100644 --- a/tests/golden/rust/rust-ureq/typed-error-responses/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/typed-error-responses/src/runtime/error.rs.golden @@ -128,36 +128,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -165,7 +184,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -173,7 +192,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -182,12 +201,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -195,12 +214,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/utoipa-mixed/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/utoipa-mixed/src/runtime/error.rs.golden index 028a4a75..e1e5f43d 100644 --- a/tests/golden/rust/rust-ureq/utoipa-mixed/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/utoipa-mixed/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/utoipa-untagged-union/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/utoipa-untagged-union/src/runtime/error.rs.golden index e7186ea7..fca75b34 100644 --- a/tests/golden/rust/rust-ureq/utoipa-untagged-union/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/utoipa-untagged-union/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/golden/rust/rust-ureq/utoipa-with-extra-derives/src/runtime/error.rs.golden b/tests/golden/rust/rust-ureq/utoipa-with-extra-derives/src/runtime/error.rs.golden index 13222063..7acfa092 100644 --- a/tests/golden/rust/rust-ureq/utoipa-with-extra-derives/src/runtime/error.rs.golden +++ b/tests/golden/rust/rust-ureq/utoipa-with-extra-derives/src/runtime/error.rs.golden @@ -129,36 +129,55 @@ enum ApiCallErrorKind { Runtime(Error), } -/// Type-erased error from any generated API operation. #[derive(Debug)] -pub struct ApiCallError { +struct ApiCallErrorInner { operation_id: &'static str, kind: ApiCallErrorKind, } -impl ApiCallError { - pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { +impl ApiCallErrorInner { + fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { Self { operation_id, kind: ApiCallErrorKind::Http(ApiCallHttpError::from_api_error(error)), } } - pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { Self { operation_id, kind: ApiCallErrorKind::Runtime(error), } } +} + +/// Type-erased error from any generated API operation. +#[derive(Debug)] +pub struct ApiCallError { + inner: Box, +} + +impl ApiCallError { + pub(crate) fn from_api_error(operation_id: &'static str, error: ApiError) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_api_error(operation_id, error)), + } + } + + pub(crate) fn from_runtime_error(operation_id: &'static str, error: Error) -> Self { + Self { + inner: Box::new(ApiCallErrorInner::from_runtime_error(operation_id, error)), + } + } /// Operation identifier, generated from the HTTP method and path when OpenAPI omits one. pub fn operation_id(&self) -> &'static str { - self.operation_id + self.inner.operation_id } /// HTTP response status, if the operation reached the server and received an error response. pub fn status_code(&self) -> Option { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(error.status_code), ApiCallErrorKind::Runtime(_) => None, } @@ -166,7 +185,7 @@ impl ApiCallError { /// Native HTTP response headers, if an error response was received. pub fn headers(&self) -> Option<&ureq::http::HeaderMap> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.headers), ApiCallErrorKind::Runtime(_) => None, } @@ -174,7 +193,7 @@ impl ApiCallError { /// Raw HTTP response body, if an error response was received. pub fn raw_body(&self) -> Option<&[u8]> { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => Some(&error.raw_body), ApiCallErrorKind::Runtime(_) => None, } @@ -183,12 +202,12 @@ impl ApiCallError { impl std::fmt::Display for ApiCallError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self.inner.kind { ApiCallErrorKind::Http(error) => { - write!(f, "operation {} failed with HTTP status {}", self.operation_id, error.status_code) + write!(f, "operation {} failed with HTTP status {}", self.inner.operation_id, error.status_code) } ApiCallErrorKind::Runtime(error) => { - write!(f, "operation {} failed: {error}", self.operation_id) + write!(f, "operation {} failed: {error}", self.inner.operation_id) } } } @@ -196,12 +215,12 @@ impl std::fmt::Display for ApiCallError { impl std::error::Error for ApiCallError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - if let ApiCallErrorKind::Http(error) = &self.kind { + if let ApiCallErrorKind::Http(error) = &self.inner.kind { if let Some(error) = &error.body_error { return Some(error); } } - if let ApiCallErrorKind::Runtime(error) = &self.kind { + if let ApiCallErrorKind::Runtime(error) = &self.inner.kind { return Some(error); } None diff --git a/tests/typed_http_error_runtime.rs b/tests/typed_http_error_runtime.rs index ba49b0f8..0024b74e 100644 --- a/tests/typed_http_error_runtime.rs +++ b/tests/typed_http_error_runtime.rs @@ -4,6 +4,7 @@ use std::path::{Path, PathBuf}; use std::process::Command; use std::time::{SystemTime, UNIX_EPOCH}; +use openapi_nexus::generators::rust::aioduct::RustAioductCodeGenerator; use openapi_nexus::generators::rust::reqwest::RustReqwestCodeGenerator; use openapi_nexus::generators::rust::ureq::RustUreqCodeGenerator; use openapi_nexus::test_utils::{generate_files, read_fixture}; @@ -116,6 +117,14 @@ use typed_error_responses_api::models::CreateResourceRequest; use typed_error_responses_api::runtime::client::Client; use typed_error_responses_api::runtime::error::{ApiCallError, Error}; +#[test] +fn api_call_error_is_pointer_sized() { + assert_eq!( + std::mem::size_of::(), + std::mem::size_of::>() + ); +} + #[allow(dead_code)] async fn propagate_uniformly( api: &ResourcesApi<'_>, @@ -391,6 +400,14 @@ use typed_error_responses_api::models::CreateResourceRequest; use typed_error_responses_api::runtime::client::Client; use typed_error_responses_api::runtime::error::ApiCallError; +#[test] +fn api_call_error_is_pointer_sized() { + assert_eq!( + std::mem::size_of::(), + std::mem::size_of::>() + ); +} + #[allow(dead_code)] fn propagate_uniformly( api: &ResourcesApi<'_>, @@ -498,6 +515,25 @@ fn success_without_documented_body_does_not_drain_body() { .expect("generated runtime test should be written"); } +fn add_aioduct_layout_test(root: &Path) { + let tests_dir = root.join("tests"); + fs::create_dir_all(&tests_dir).expect("generated tests directory should be created"); + fs::write( + tests_dir.join("api_call_error_layout.rs"), + r#"use typed_error_responses_api::runtime::error::ApiCallError; + +#[test] +fn api_call_error_is_pointer_sized() { + assert_eq!( + std::mem::size_of::(), + std::mem::size_of::>() + ); +} +"#, + ) + .expect("generated layout test should be written"); +} + #[test] fn reqwest_http_503_is_not_success_and_preserves_error_detail() { let fixture = read_fixture("valid/typed-error-responses.yaml"); @@ -547,3 +583,28 @@ fn ureq_http_503_is_not_transport_and_preserves_error_detail() { String::from_utf8_lossy(&output.stderr) ); } + +#[test] +fn aioduct_api_call_error_is_pointer_sized() { + let fixture = read_fixture("valid/typed-error-responses.yaml"); + let files = generate_files(&RustAioductCodeGenerator::new(empty_config()), &fixture) + .expect("typed error fixture should generate"); + let temp = TempDir::new("api-call-error-layout-aioduct"); + write_generated_crate(&files, &temp.path); + add_aioduct_layout_test(&temp.path); + + let output = Command::new("cargo") + .arg("test") + .arg("--quiet") + .current_dir(&temp.path) + .output() + .expect("generated crate cargo test should run"); + + assert!( + output.status.success(), + "generated aioduct layout test failed\nstatus: {}\nstdout:\n{}\nstderr:\n{}", + output.status, + String::from_utf8_lossy(&output.stdout), + String::from_utf8_lossy(&output.stderr) + ); +}