From e129d23f4e3aafdcc51d268d343d0b05b8fc8e73 Mon Sep 17 00:00:00 2001 From: Ross Sullivan Date: Tue, 11 Feb 2025 21:50:09 +0900 Subject: [PATCH 1/8] [rust] Added support for text/plain to reqwest-trait client --- .../codegen/languages/RustClientCodegen.java | 4 ++++ .../resources/rust/reqwest-trait/api.mustache | 20 +++++++++++++++++-- .../rust/reqwest-trait/api_mod.mustache | 20 +++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java index 18c6e48a636a..c523ddf9f825 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java @@ -677,6 +677,10 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List serde_json::from_str(&local_var_content).map_err(Error::from), + {{#vendorExtensions.x-supports-plain-text}} + ContentType::Text => return Ok(local_var_content), + {{/vendorExtensions.x-supports-plain-text}} + {{^vendorExtensions.x-supports-plain-text}} + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `{{returnType}}`"))), + {{/vendorExtensions.x-supports-plain-text}} + ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `{{returnType}}`")))), + } {{/returnType}} {{/supportMultipleResponses}} {{#supportMultipleResponses}} diff --git a/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api_mod.mustache b/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api_mod.mustache index c693585870fb..9b3e6d714046 100644 --- a/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api_mod.mustache +++ b/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api_mod.mustache @@ -128,6 +128,26 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String unimplemented!("Only objects are supported with style=deepObject") } +/// Internal use only +/// A content type supported by this client. +enum ContentType { + Json, + Text, + Unsupported(String) +} + +impl From<&str> for ContentType { + fn from(content_type: &str) -> Self { + if content_type.starts_with("application") && content_type.contains("json") { + return Self::Json; + } else if content_type == "text/plain" { + return Self::Text; + } else { + return Self::Unsupported(content_type.to_string()); + } + } +} + {{#apiInfo}} {{#apis}} pub mod {{{classFilename}}}; From c7e87fa1ce878a5d32e80c6c22fa34881edb5440 Mon Sep 17 00:00:00 2001 From: Ross Sullivan Date: Tue, 11 Feb 2025 21:50:34 +0900 Subject: [PATCH 2/8] Updated samples --- .../petstore/src/apis/fake_api.rs | 9 +- .../reqwest-trait/petstore/src/apis/mod.rs | 20 +++++ .../petstore/src/apis/pet_api.rs | 87 +++++++++++++++++-- .../petstore/src/apis/store_api.rs | 45 +++++++++- .../petstore/src/apis/testing_api.rs | 27 +++++- .../petstore/src/apis/user_api.rs | 63 +++++++++++++- 6 files changed, 233 insertions(+), 18 deletions(-) diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/fake_api.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/fake_api.rs index 7368946bb46f..d16294784ce4 100644 --- a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/fake_api.rs +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/fake_api.rs @@ -14,9 +14,10 @@ use async_trait::async_trait; use mockall::automock; use reqwest; use std::sync::Arc; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; use super::{Error, configuration}; +use crate::apis::ContentType; #[cfg_attr(feature = "mockall", automock)] #[async_trait] @@ -68,6 +69,12 @@ impl FakeApi for FakeApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/mod.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/mod.rs index ba670264380c..86a9f0597206 100644 --- a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/mod.rs @@ -90,6 +90,26 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String unimplemented!("Only objects are supported with style=deepObject") } +/// Internal use only +/// A content type supported by this client. +enum ContentType { + Json, + Text, + Unsupported(String) +} + +impl From<&str> for ContentType { + fn from(content_type: &str) -> Self { + if content_type.starts_with("application") && content_type.contains("json") { + return Self::Json; + } else if content_type == "text/plain" { + return Self::Text; + } else { + return Self::Unsupported(content_type.to_string()); + } + } +} + pub mod fake_api; pub mod pet_api; pub mod store_api; diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/pet_api.rs index 2ac8dff7ec8f..951e4d5d08a4 100644 --- a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/pet_api.rs @@ -14,9 +14,10 @@ use async_trait::async_trait; use mockall::automock; use reqwest; use std::sync::Arc; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; use super::{Error, configuration}; +use crate::apis::ContentType; #[cfg_attr(feature = "mockall", automock)] #[async_trait] @@ -90,10 +91,20 @@ impl PetApi for PetApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { - serde_json::from_str(&local_var_content).map_err(Error::from) + match local_var_content_type { + ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Pet`"))), + ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::Pet`")))), + } } else { let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; @@ -124,6 +135,12 @@ impl PetApi for PetApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { @@ -165,10 +182,20 @@ impl PetApi for PetApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { - serde_json::from_str(&local_var_content).map_err(Error::from) + match local_var_content_type { + ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::Pet>`"))), + ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `Vec<models::Pet>`")))), + } } else { let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; @@ -200,10 +227,20 @@ impl PetApi for PetApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { - serde_json::from_str(&local_var_content).map_err(Error::from) + match local_var_content_type { + ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::Pet>`"))), + ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `Vec<models::Pet>`")))), + } } else { let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; @@ -236,10 +273,20 @@ impl PetApi for PetApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { - serde_json::from_str(&local_var_content).map_err(Error::from) + match local_var_content_type { + ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Pet`"))), + ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::Pet`")))), + } } else { let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; @@ -268,10 +315,20 @@ impl PetApi for PetApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { - serde_json::from_str(&local_var_content).map_err(Error::from) + match local_var_content_type { + ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Pet`"))), + ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::Pet`")))), + } } else { let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; @@ -307,6 +364,12 @@ impl PetApi for PetApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { @@ -344,10 +407,20 @@ impl PetApi for PetApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { - serde_json::from_str(&local_var_content).map_err(Error::from) + match local_var_content_type { + ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ApiResponse`"))), + ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::ApiResponse`")))), + } } else { let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/store_api.rs index 16ca71786d04..2e0f8f4a3c76 100644 --- a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/store_api.rs @@ -14,9 +14,10 @@ use async_trait::async_trait; use mockall::automock; use reqwest; use std::sync::Arc; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; use super::{Error, configuration}; +use crate::apis::ContentType; #[cfg_attr(feature = "mockall", automock)] #[async_trait] @@ -72,6 +73,12 @@ impl StoreApi for StoreApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { @@ -108,10 +115,20 @@ impl StoreApi for StoreApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { - serde_json::from_str(&local_var_content).map_err(Error::from) + match local_var_content_type { + ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `std::collections::HashMap<String, i32>`"))), + ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, i32>`")))), + } } else { let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; @@ -136,10 +153,20 @@ impl StoreApi for StoreApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { - serde_json::from_str(&local_var_content).map_err(Error::from) + match local_var_content_type { + ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Order`"))), + ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::Order`")))), + } } else { let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; @@ -165,10 +192,20 @@ impl StoreApi for StoreApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { - serde_json::from_str(&local_var_content).map_err(Error::from) + match local_var_content_type { + ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Order`"))), + ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::Order`")))), + } } else { let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/testing_api.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/testing_api.rs index 9562cb8a90d3..d59233d2d981 100644 --- a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/testing_api.rs +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/testing_api.rs @@ -14,9 +14,10 @@ use async_trait::async_trait; use mockall::automock; use reqwest; use std::sync::Arc; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; use super::{Error, configuration}; +use crate::apis::ContentType; #[cfg_attr(feature = "mockall", automock)] #[async_trait] @@ -63,10 +64,20 @@ impl TestingApi for TestingApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { - serde_json::from_str(&local_var_content).map_err(Error::from) + match local_var_content_type { + ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `std::path::PathBuf`"))), + ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `std::path::PathBuf`")))), + } } else { let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; @@ -90,10 +101,20 @@ impl TestingApi for TestingApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { - serde_json::from_str(&local_var_content).map_err(Error::from) + match local_var_content_type { + ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TypeTesting`"))), + ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::TypeTesting`")))), + } } else { let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/user_api.rs index 7e3f79c7d2b0..42c96045daad 100644 --- a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/user_api.rs @@ -14,9 +14,10 @@ use async_trait::async_trait; use mockall::automock; use reqwest; use std::sync::Arc; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; use super::{Error, configuration}; +use crate::apis::ContentType; #[cfg_attr(feature = "mockall", automock)] #[async_trait] @@ -93,6 +94,12 @@ impl UserApi for UserApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { @@ -130,6 +137,12 @@ impl UserApi for UserApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { @@ -167,6 +180,12 @@ impl UserApi for UserApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { @@ -203,6 +222,12 @@ impl UserApi for UserApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { @@ -231,10 +256,20 @@ impl UserApi for UserApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { - serde_json::from_str(&local_var_content).map_err(Error::from) + match local_var_content_type { + ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::User`"))), + ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::User`")))), + } } else { let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; @@ -261,10 +296,20 @@ impl UserApi for UserApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { - serde_json::from_str(&local_var_content).map_err(Error::from) + match local_var_content_type { + ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from), + ContentType::Text => return Ok(local_var_content), + ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `String`")))), + } } else { let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; @@ -297,6 +342,12 @@ impl UserApi for UserApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { @@ -334,6 +385,12 @@ impl UserApi for UserApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); + let local_var_content_type = local_var_resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { From 560fd6038c4b79467632e10174730e7cc42357d6 Mon Sep 17 00:00:00 2001 From: Ross Sullivan Date: Tue, 11 Feb 2025 22:23:40 +0900 Subject: [PATCH 3/8] [rust] Added support for text/plain to reqwest client --- .../main/resources/rust/reqwest/api.mustache | 25 ++++++++++++++++--- .../resources/rust/reqwest/api_mod.mustache | 20 +++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache b/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache index ffe0f199a980..9f61507db892 100644 --- a/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache +++ b/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache @@ -1,9 +1,9 @@ {{>partial_header}} use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; {{#operations}} {{#operation}} @@ -355,6 +355,16 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: let resp = configuration.client.execute(req){{#supportAsync}}.await{{/supportAsync}}?; let status = resp.status(); + {{^isResponseFile}} + {{#returnType}} + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); + {{/returnType}} + {{/isResponseFile}} if !status.is_client_error() && !status.is_server_error() { {{^supportMultipleResponses}} @@ -367,7 +377,16 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: {{/returnType}} {{#returnType}} let content = resp.text(){{#supportAsync}}.await{{/supportAsync}}?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + {{#vendorExtensions.x-supports-plain-text}} + ContentType::Text => return Ok(content), + {{/vendorExtensions.x-supports-plain-text}} + {{^vendorExtensions.x-supports-plain-text}} + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `{{returnType}}`"))), + {{/vendorExtensions.x-supports-plain-text}} + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `{{returnType}}`")))), + } {{/returnType}} {{/isResponseFile}} {{/supportMultipleResponses}} diff --git a/modules/openapi-generator/src/main/resources/rust/reqwest/api_mod.mustache b/modules/openapi-generator/src/main/resources/rust/reqwest/api_mod.mustache index bc5f68f44074..4cce6f001848 100644 --- a/modules/openapi-generator/src/main/resources/rust/reqwest/api_mod.mustache +++ b/modules/openapi-generator/src/main/resources/rust/reqwest/api_mod.mustache @@ -134,6 +134,26 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String unimplemented!("Only objects are supported with style=deepObject") } +/// Internal use only +/// A content type supported by this client. +enum ContentType { + Json, + Text, + Unsupported(String) +} + +impl From<&str> for ContentType { + fn from(content_type: &str) -> Self { + if content_type.starts_with("application") && content_type.contains("json") { + return Self::Json; + } else if content_type == "text/plain" { + return Self::Text; + } else { + return Self::Unsupported(content_type.to_string()); + } + } +} + {{#apiInfo}} {{#apis}} pub mod {{{classFilename}}}; From 83c6260e2e8f453f0a04a533c81302355d953d3f Mon Sep 17 00:00:00 2001 From: Ross Sullivan Date: Tue, 11 Feb 2025 22:24:31 +0900 Subject: [PATCH 4/8] Updated samples --- .../src/apis/default_api.rs | 16 +++- .../reqwest-regression-16119/src/apis/mod.rs | 20 +++++ .../src/apis/default_api.rs | 4 +- .../api-with-ref-param/src/apis/mod.rs | 20 +++++ .../composed-oneof/src/apis/default_api.rs | 16 +++- .../reqwest/composed-oneof/src/apis/mod.rs | 20 +++++ .../emptyObject/src/apis/default_api.rs | 16 +++- .../rust/reqwest/emptyObject/src/apis/mod.rs | 20 +++++ .../oneOf-array-map/src/apis/default_api.rs | 16 +++- .../reqwest/oneOf-array-map/src/apis/mod.rs | 20 +++++ .../oneOf-reuseRef/src/apis/default_api.rs | 16 +++- .../reqwest/oneOf-reuseRef/src/apis/mod.rs | 20 +++++ .../rust/reqwest/oneOf/src/apis/bar_api.rs | 16 +++- .../rust/reqwest/oneOf/src/apis/foo_api.rs | 28 ++++++- .../others/rust/reqwest/oneOf/src/apis/mod.rs | 20 +++++ .../reqwest/name-mapping/src/apis/fake_api.rs | 4 +- .../rust/reqwest/name-mapping/src/apis/mod.rs | 20 +++++ .../src/apis/fake_api.rs | 4 +- .../petstore-async-middleware/src/apis/mod.rs | 20 +++++ .../src/apis/pet_api.rs | 40 +++++++++- .../src/apis/store_api.rs | 22 +++++- .../src/apis/testing_api.rs | 10 ++- .../src/apis/user_api.rs | 16 +++- .../src/apis/fake_api.rs | 4 +- .../src/apis/mod.rs | 20 +++++ .../src/apis/pet_api.rs | 40 +++++++++- .../src/apis/store_api.rs | 22 +++++- .../src/apis/testing_api.rs | 10 ++- .../src/apis/user_api.rs | 16 +++- .../petstore-async/src/apis/fake_api.rs | 4 +- .../reqwest/petstore-async/src/apis/mod.rs | 20 +++++ .../petstore-async/src/apis/pet_api.rs | 40 +++++++++- .../petstore-async/src/apis/store_api.rs | 22 +++++- .../petstore-async/src/apis/testing_api.rs | 10 ++- .../petstore-async/src/apis/user_api.rs | 16 +++- .../petstore-avoid-box/src/apis/fake_api.rs | 4 +- .../petstore-avoid-box/src/apis/mod.rs | 20 +++++ .../petstore-avoid-box/src/apis/pet_api.rs | 40 +++++++++- .../petstore-avoid-box/src/apis/store_api.rs | 22 +++++- .../src/apis/testing_api.rs | 10 ++- .../petstore-avoid-box/src/apis/user_api.rs | 16 +++- .../src/apis/fake_api.rs | 4 +- .../petstore-awsv4signature/src/apis/mod.rs | 20 +++++ .../src/apis/pet_api.rs | 76 +++++++++++++++++-- .../src/apis/store_api.rs | 40 ++++++++-- .../src/apis/testing_api.rs | 16 +++- .../src/apis/user_api.rs | 28 ++++++- .../src/apis/fake_api.rs | 4 +- .../src/apis/mod.rs | 20 +++++ .../src/apis/pet_api.rs | 76 +++++++++++++++++-- .../src/apis/store_api.rs | 40 ++++++++-- .../src/apis/testing_api.rs | 16 +++- .../src/apis/user_api.rs | 28 ++++++- .../reqwest/petstore/src/apis/fake_api.rs | 4 +- .../rust/reqwest/petstore/src/apis/mod.rs | 20 +++++ .../rust/reqwest/petstore/src/apis/pet_api.rs | 76 +++++++++++++++++-- .../reqwest/petstore/src/apis/store_api.rs | 40 ++++++++-- .../reqwest/petstore/src/apis/testing_api.rs | 16 +++- .../reqwest/petstore/src/apis/user_api.rs | 28 ++++++- 59 files changed, 1160 insertions(+), 132 deletions(-) diff --git a/samples/client/others/rust/reqwest-regression-16119/src/apis/default_api.rs b/samples/client/others/rust/reqwest-regression-16119/src/apis/default_api.rs index 382dc5a2ce0d..79730fd260f7 100644 --- a/samples/client/others/rust/reqwest-regression-16119/src/apis/default_api.rs +++ b/samples/client/others/rust/reqwest-regression-16119/src/apis/default_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for typed errors of method [`repro`] @@ -36,10 +36,20 @@ pub fn repro(configuration: &configuration::Configuration, ) -> Result serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Parent`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Parent`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); diff --git a/samples/client/others/rust/reqwest-regression-16119/src/apis/mod.rs b/samples/client/others/rust/reqwest-regression-16119/src/apis/mod.rs index 4b09ba50b401..96e86546ec6d 100644 --- a/samples/client/others/rust/reqwest-regression-16119/src/apis/mod.rs +++ b/samples/client/others/rust/reqwest-regression-16119/src/apis/mod.rs @@ -90,6 +90,26 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String unimplemented!("Only objects are supported with style=deepObject") } +/// Internal use only +/// A content type supported by this client. +enum ContentType { + Json, + Text, + Unsupported(String) +} + +impl From<&str> for ContentType { + fn from(content_type: &str) -> Self { + if content_type.starts_with("application") && content_type.contains("json") { + return Self::Json; + } else if content_type == "text/plain" { + return Self::Text; + } else { + return Self::Unsupported(content_type.to_string()); + } + } +} + pub mod default_api; pub mod configuration; diff --git a/samples/client/others/rust/reqwest/api-with-ref-param/src/apis/default_api.rs b/samples/client/others/rust/reqwest/api-with-ref-param/src/apis/default_api.rs index 562421a76248..5f0e129882a3 100644 --- a/samples/client/others/rust/reqwest/api-with-ref-param/src/apis/default_api.rs +++ b/samples/client/others/rust/reqwest/api-with-ref-param/src/apis/default_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for typed errors of method [`demo_color_get`] diff --git a/samples/client/others/rust/reqwest/api-with-ref-param/src/apis/mod.rs b/samples/client/others/rust/reqwest/api-with-ref-param/src/apis/mod.rs index 4b09ba50b401..96e86546ec6d 100644 --- a/samples/client/others/rust/reqwest/api-with-ref-param/src/apis/mod.rs +++ b/samples/client/others/rust/reqwest/api-with-ref-param/src/apis/mod.rs @@ -90,6 +90,26 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String unimplemented!("Only objects are supported with style=deepObject") } +/// Internal use only +/// A content type supported by this client. +enum ContentType { + Json, + Text, + Unsupported(String) +} + +impl From<&str> for ContentType { + fn from(content_type: &str) -> Self { + if content_type.starts_with("application") && content_type.contains("json") { + return Self::Json; + } else if content_type == "text/plain" { + return Self::Text; + } else { + return Self::Unsupported(content_type.to_string()); + } + } +} + pub mod default_api; pub mod configuration; diff --git a/samples/client/others/rust/reqwest/composed-oneof/src/apis/default_api.rs b/samples/client/others/rust/reqwest/composed-oneof/src/apis/default_api.rs index 593abfd48216..cc749951d6eb 100644 --- a/samples/client/others/rust/reqwest/composed-oneof/src/apis/default_api.rs +++ b/samples/client/others/rust/reqwest/composed-oneof/src/apis/default_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for typed errors of method [`create_state`] @@ -69,10 +69,20 @@ pub fn get_state(configuration: &configuration::Configuration, ) -> Result serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetState200Response`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetState200Response`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); diff --git a/samples/client/others/rust/reqwest/composed-oneof/src/apis/mod.rs b/samples/client/others/rust/reqwest/composed-oneof/src/apis/mod.rs index 4b09ba50b401..96e86546ec6d 100644 --- a/samples/client/others/rust/reqwest/composed-oneof/src/apis/mod.rs +++ b/samples/client/others/rust/reqwest/composed-oneof/src/apis/mod.rs @@ -90,6 +90,26 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String unimplemented!("Only objects are supported with style=deepObject") } +/// Internal use only +/// A content type supported by this client. +enum ContentType { + Json, + Text, + Unsupported(String) +} + +impl From<&str> for ContentType { + fn from(content_type: &str) -> Self { + if content_type.starts_with("application") && content_type.contains("json") { + return Self::Json; + } else if content_type == "text/plain" { + return Self::Text; + } else { + return Self::Unsupported(content_type.to_string()); + } + } +} + pub mod default_api; pub mod configuration; diff --git a/samples/client/others/rust/reqwest/emptyObject/src/apis/default_api.rs b/samples/client/others/rust/reqwest/emptyObject/src/apis/default_api.rs index 6b5803fd2423..e89c27b8eb3c 100644 --- a/samples/client/others/rust/reqwest/emptyObject/src/apis/default_api.rs +++ b/samples/client/others/rust/reqwest/emptyObject/src/apis/default_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for typed errors of method [`endpoint_get`] @@ -36,10 +36,20 @@ pub fn endpoint_get(configuration: &configuration::Configuration, ) -> Result serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::EmptyObject`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::EmptyObject`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); diff --git a/samples/client/others/rust/reqwest/emptyObject/src/apis/mod.rs b/samples/client/others/rust/reqwest/emptyObject/src/apis/mod.rs index 4b09ba50b401..96e86546ec6d 100644 --- a/samples/client/others/rust/reqwest/emptyObject/src/apis/mod.rs +++ b/samples/client/others/rust/reqwest/emptyObject/src/apis/mod.rs @@ -90,6 +90,26 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String unimplemented!("Only objects are supported with style=deepObject") } +/// Internal use only +/// A content type supported by this client. +enum ContentType { + Json, + Text, + Unsupported(String) +} + +impl From<&str> for ContentType { + fn from(content_type: &str) -> Self { + if content_type.starts_with("application") && content_type.contains("json") { + return Self::Json; + } else if content_type == "text/plain" { + return Self::Text; + } else { + return Self::Unsupported(content_type.to_string()); + } + } +} + pub mod default_api; pub mod configuration; diff --git a/samples/client/others/rust/reqwest/oneOf-array-map/src/apis/default_api.rs b/samples/client/others/rust/reqwest/oneOf-array-map/src/apis/default_api.rs index d7fbf92af0ad..b5fb8c4fd942 100644 --- a/samples/client/others/rust/reqwest/oneOf-array-map/src/apis/default_api.rs +++ b/samples/client/others/rust/reqwest/oneOf-array-map/src/apis/default_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for typed errors of method [`root_get`] @@ -43,10 +43,20 @@ pub fn root_get(configuration: &configuration::Configuration, ) -> Result serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Fruit`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Fruit`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); diff --git a/samples/client/others/rust/reqwest/oneOf-array-map/src/apis/mod.rs b/samples/client/others/rust/reqwest/oneOf-array-map/src/apis/mod.rs index 4b09ba50b401..96e86546ec6d 100644 --- a/samples/client/others/rust/reqwest/oneOf-array-map/src/apis/mod.rs +++ b/samples/client/others/rust/reqwest/oneOf-array-map/src/apis/mod.rs @@ -90,6 +90,26 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String unimplemented!("Only objects are supported with style=deepObject") } +/// Internal use only +/// A content type supported by this client. +enum ContentType { + Json, + Text, + Unsupported(String) +} + +impl From<&str> for ContentType { + fn from(content_type: &str) -> Self { + if content_type.starts_with("application") && content_type.contains("json") { + return Self::Json; + } else if content_type == "text/plain" { + return Self::Text; + } else { + return Self::Unsupported(content_type.to_string()); + } + } +} + pub mod default_api; pub mod configuration; diff --git a/samples/client/others/rust/reqwest/oneOf-reuseRef/src/apis/default_api.rs b/samples/client/others/rust/reqwest/oneOf-reuseRef/src/apis/default_api.rs index 3dceb3f7d040..ab51a425448a 100644 --- a/samples/client/others/rust/reqwest/oneOf-reuseRef/src/apis/default_api.rs +++ b/samples/client/others/rust/reqwest/oneOf-reuseRef/src/apis/default_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for typed errors of method [`get_fruit`] @@ -36,10 +36,20 @@ pub fn get_fruit(configuration: &configuration::Configuration, ) -> Result serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Fruit`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Fruit`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); diff --git a/samples/client/others/rust/reqwest/oneOf-reuseRef/src/apis/mod.rs b/samples/client/others/rust/reqwest/oneOf-reuseRef/src/apis/mod.rs index 4b09ba50b401..96e86546ec6d 100644 --- a/samples/client/others/rust/reqwest/oneOf-reuseRef/src/apis/mod.rs +++ b/samples/client/others/rust/reqwest/oneOf-reuseRef/src/apis/mod.rs @@ -90,6 +90,26 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String unimplemented!("Only objects are supported with style=deepObject") } +/// Internal use only +/// A content type supported by this client. +enum ContentType { + Json, + Text, + Unsupported(String) +} + +impl From<&str> for ContentType { + fn from(content_type: &str) -> Self { + if content_type.starts_with("application") && content_type.contains("json") { + return Self::Json; + } else if content_type == "text/plain" { + return Self::Text; + } else { + return Self::Unsupported(content_type.to_string()); + } + } +} + pub mod default_api; pub mod configuration; diff --git a/samples/client/others/rust/reqwest/oneOf/src/apis/bar_api.rs b/samples/client/others/rust/reqwest/oneOf/src/apis/bar_api.rs index 6af94c62e442..797ac77c279d 100644 --- a/samples/client/others/rust/reqwest/oneOf/src/apis/bar_api.rs +++ b/samples/client/others/rust/reqwest/oneOf/src/apis/bar_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for typed errors of method [`create_bar`] @@ -39,10 +39,20 @@ pub fn create_bar(configuration: &configuration::Configuration, bar_create: mode let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Bar`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Bar`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); diff --git a/samples/client/others/rust/reqwest/oneOf/src/apis/foo_api.rs b/samples/client/others/rust/reqwest/oneOf/src/apis/foo_api.rs index 8fefb3f45904..d71a4e6a152d 100644 --- a/samples/client/others/rust/reqwest/oneOf/src/apis/foo_api.rs +++ b/samples/client/others/rust/reqwest/oneOf/src/apis/foo_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for typed errors of method [`create_foo`] @@ -46,10 +46,20 @@ pub fn create_foo(configuration: &configuration::Configuration, foo: Option serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::FooRefOrValue`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::FooRefOrValue`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); @@ -70,10 +80,20 @@ pub fn get_all_foos(configuration: &configuration::Configuration, ) -> Result serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::FooRefOrValue>`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::FooRefOrValue>`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); diff --git a/samples/client/others/rust/reqwest/oneOf/src/apis/mod.rs b/samples/client/others/rust/reqwest/oneOf/src/apis/mod.rs index 96f98fdcb6e1..28a73c0be6b8 100644 --- a/samples/client/others/rust/reqwest/oneOf/src/apis/mod.rs +++ b/samples/client/others/rust/reqwest/oneOf/src/apis/mod.rs @@ -90,6 +90,26 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String unimplemented!("Only objects are supported with style=deepObject") } +/// Internal use only +/// A content type supported by this client. +enum ContentType { + Json, + Text, + Unsupported(String) +} + +impl From<&str> for ContentType { + fn from(content_type: &str) -> Self { + if content_type.starts_with("application") && content_type.contains("json") { + return Self::Json; + } else if content_type == "text/plain" { + return Self::Text; + } else { + return Self::Unsupported(content_type.to_string()); + } + } +} + pub mod bar_api; pub mod foo_api; diff --git a/samples/client/petstore/rust/reqwest/name-mapping/src/apis/fake_api.rs b/samples/client/petstore/rust/reqwest/name-mapping/src/apis/fake_api.rs index 7e45b087616c..156ab2a1a597 100644 --- a/samples/client/petstore/rust/reqwest/name-mapping/src/apis/fake_api.rs +++ b/samples/client/petstore/rust/reqwest/name-mapping/src/apis/fake_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for typed errors of method [`get_parameter_name_mapping`] diff --git a/samples/client/petstore/rust/reqwest/name-mapping/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/name-mapping/src/apis/mod.rs index 006006c1ad1d..e545f0bc7d24 100644 --- a/samples/client/petstore/rust/reqwest/name-mapping/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/name-mapping/src/apis/mod.rs @@ -90,6 +90,26 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String unimplemented!("Only objects are supported with style=deepObject") } +/// Internal use only +/// A content type supported by this client. +enum ContentType { + Json, + Text, + Unsupported(String) +} + +impl From<&str> for ContentType { + fn from(content_type: &str) -> Self { + if content_type.starts_with("application") && content_type.contains("json") { + return Self::Json; + } else if content_type == "text/plain" { + return Self::Text; + } else { + return Self::Unsupported(content_type.to_string()); + } + } +} + pub mod fake_api; pub mod configuration; diff --git a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/fake_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/fake_api.rs index be9503699260..6be823ab5c83 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/fake_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/fake_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for passing parameters to the method [`test_nullable_required_param`] #[derive(Clone, Debug)] diff --git a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/mod.rs index 33b8ca9e647e..7974c2c6bc8a 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/mod.rs @@ -99,6 +99,26 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String unimplemented!("Only objects are supported with style=deepObject") } +/// Internal use only +/// A content type supported by this client. +enum ContentType { + Json, + Text, + Unsupported(String) +} + +impl From<&str> for ContentType { + fn from(content_type: &str) -> Self { + if content_type.starts_with("application") && content_type.contains("json") { + return Self::Json; + } else if content_type == "text/plain" { + return Self::Text; + } else { + return Self::Unsupported(content_type.to_string()); + } + } +} + pub mod fake_api; pub mod pet_api; pub mod store_api; diff --git a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/pet_api.rs index c8055993606e..b5670d7a73bd 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/pet_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for passing parameters to the method [`add_pet`] #[derive(Clone, Debug)] @@ -229,6 +229,12 @@ pub async fn add_pet(configuration: &configuration::Configuration, params: AddPe let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -300,6 +306,12 @@ pub async fn find_pets_by_status(configuration: &configuration::Configuration, p let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -333,6 +345,12 @@ pub async fn find_pets_by_tags(configuration: &configuration::Configuration, par let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -367,6 +385,12 @@ pub async fn get_pet_by_id(configuration: &configuration::Configuration, params: let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -397,6 +421,12 @@ pub async fn update_pet(configuration: &configuration::Configuration, params: Up let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -469,6 +499,12 @@ pub async fn upload_file(configuration: &configuration::Configuration, params: U let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; diff --git a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/store_api.rs index 17760b176768..e1f663cf6ed7 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/store_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for passing parameters to the method [`delete_order`] #[derive(Clone, Debug)] @@ -149,6 +149,12 @@ pub async fn get_inventory(configuration: &configuration::Configuration) -> Resu let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -175,6 +181,12 @@ pub async fn get_order_by_id(configuration: &configuration::Configuration, param let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -202,6 +214,12 @@ pub async fn place_order(configuration: &configuration::Configuration, params: P let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; diff --git a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/testing_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/testing_api.rs index 3f365095bf63..2d3f6ef7ec2f 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/testing_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/testing_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for typed successes of method [`tests_file_response_get`] @@ -82,6 +82,12 @@ pub async fn tests_type_testing_get(configuration: &configuration::Configuration let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; diff --git a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/user_api.rs index e4dfae546d4c..9b8c702df9c6 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/user_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for passing parameters to the method [`create_user`] #[derive(Clone, Debug)] @@ -347,6 +347,12 @@ pub async fn get_user_by_name(configuration: &configuration::Configuration, para let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -375,6 +381,12 @@ pub async fn login_user(configuration: &configuration::Configuration, params: Lo let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; diff --git a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/fake_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/fake_api.rs index be9503699260..6be823ab5c83 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/fake_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/fake_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for passing parameters to the method [`test_nullable_required_param`] #[derive(Clone, Debug)] diff --git a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/mod.rs index 3f68c684126e..94b68d0b2b1d 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/mod.rs @@ -93,6 +93,26 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String unimplemented!("Only objects are supported with style=deepObject") } +/// Internal use only +/// A content type supported by this client. +enum ContentType { + Json, + Text, + Unsupported(String) +} + +impl From<&str> for ContentType { + fn from(content_type: &str) -> Self { + if content_type.starts_with("application") && content_type.contains("json") { + return Self::Json; + } else if content_type == "text/plain" { + return Self::Text; + } else { + return Self::Unsupported(content_type.to_string()); + } + } +} + pub mod fake_api; pub mod pet_api; pub mod store_api; diff --git a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/pet_api.rs index 185acd30b033..7155a74c8af4 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/pet_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for passing parameters to the method [`add_pet`] #[derive(Clone, Debug)] @@ -231,6 +231,12 @@ pub async fn add_pet(configuration: &configuration::Configuration, params: AddPe let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -306,6 +312,12 @@ pub async fn find_pets_by_status(configuration: &configuration::Configuration, p let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -341,6 +353,12 @@ pub async fn find_pets_by_tags(configuration: &configuration::Configuration, par let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -372,6 +390,12 @@ pub async fn get_pet_by_id(configuration: &configuration::Configuration, params: let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -404,6 +428,12 @@ pub async fn update_pet(configuration: &configuration::Configuration, params: Up let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -480,6 +510,12 @@ pub async fn upload_file(configuration: &configuration::Configuration, params: U let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; diff --git a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/store_api.rs index 859e3088916d..5f9a4ffecc87 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/store_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for passing parameters to the method [`delete_order`] #[derive(Clone, Debug)] @@ -146,6 +146,12 @@ pub async fn get_inventory(configuration: &configuration::Configuration) -> Resu let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -172,6 +178,12 @@ pub async fn get_order_by_id(configuration: &configuration::Configuration, param let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -199,6 +211,12 @@ pub async fn place_order(configuration: &configuration::Configuration, params: P let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; diff --git a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/testing_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/testing_api.rs index 3f365095bf63..2d3f6ef7ec2f 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/testing_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/testing_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for typed successes of method [`tests_file_response_get`] @@ -82,6 +82,12 @@ pub async fn tests_type_testing_get(configuration: &configuration::Configuration let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; diff --git a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/user_api.rs index ddfebdf33851..e9e0da8fe34b 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/user_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for passing parameters to the method [`create_user`] #[derive(Clone, Debug)] @@ -335,6 +335,12 @@ pub async fn get_user_by_name(configuration: &configuration::Configuration, para let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -363,6 +369,12 @@ pub async fn login_user(configuration: &configuration::Configuration, params: Lo let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/fake_api.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/fake_api.rs index be9503699260..6be823ab5c83 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/fake_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/fake_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for passing parameters to the method [`test_nullable_required_param`] #[derive(Clone, Debug)] diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/mod.rs index d791dfb5a892..a11350a33471 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/mod.rs @@ -90,6 +90,26 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String unimplemented!("Only objects are supported with style=deepObject") } +/// Internal use only +/// A content type supported by this client. +enum ContentType { + Json, + Text, + Unsupported(String) +} + +impl From<&str> for ContentType { + fn from(content_type: &str) -> Self { + if content_type.starts_with("application") && content_type.contains("json") { + return Self::Json; + } else if content_type == "text/plain" { + return Self::Text; + } else { + return Self::Unsupported(content_type.to_string()); + } + } +} + pub mod fake_api; pub mod pet_api; pub mod store_api; diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/pet_api.rs index c8055993606e..b5670d7a73bd 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/pet_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for passing parameters to the method [`add_pet`] #[derive(Clone, Debug)] @@ -229,6 +229,12 @@ pub async fn add_pet(configuration: &configuration::Configuration, params: AddPe let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -300,6 +306,12 @@ pub async fn find_pets_by_status(configuration: &configuration::Configuration, p let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -333,6 +345,12 @@ pub async fn find_pets_by_tags(configuration: &configuration::Configuration, par let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -367,6 +385,12 @@ pub async fn get_pet_by_id(configuration: &configuration::Configuration, params: let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -397,6 +421,12 @@ pub async fn update_pet(configuration: &configuration::Configuration, params: Up let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -469,6 +499,12 @@ pub async fn upload_file(configuration: &configuration::Configuration, params: U let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/store_api.rs index 17760b176768..e1f663cf6ed7 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/store_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for passing parameters to the method [`delete_order`] #[derive(Clone, Debug)] @@ -149,6 +149,12 @@ pub async fn get_inventory(configuration: &configuration::Configuration) -> Resu let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -175,6 +181,12 @@ pub async fn get_order_by_id(configuration: &configuration::Configuration, param let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -202,6 +214,12 @@ pub async fn place_order(configuration: &configuration::Configuration, params: P let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/testing_api.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/testing_api.rs index 3f365095bf63..2d3f6ef7ec2f 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/testing_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/testing_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for typed successes of method [`tests_file_response_get`] @@ -82,6 +82,12 @@ pub async fn tests_type_testing_get(configuration: &configuration::Configuration let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/user_api.rs index e4dfae546d4c..9b8c702df9c6 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/user_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for passing parameters to the method [`create_user`] #[derive(Clone, Debug)] @@ -347,6 +347,12 @@ pub async fn get_user_by_name(configuration: &configuration::Configuration, para let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -375,6 +381,12 @@ pub async fn login_user(configuration: &configuration::Configuration, params: Lo let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; diff --git a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/fake_api.rs b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/fake_api.rs index be9503699260..6be823ab5c83 100644 --- a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/fake_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/fake_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for passing parameters to the method [`test_nullable_required_param`] #[derive(Clone, Debug)] diff --git a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/mod.rs index d791dfb5a892..a11350a33471 100644 --- a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/mod.rs @@ -90,6 +90,26 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String unimplemented!("Only objects are supported with style=deepObject") } +/// Internal use only +/// A content type supported by this client. +enum ContentType { + Json, + Text, + Unsupported(String) +} + +impl From<&str> for ContentType { + fn from(content_type: &str) -> Self { + if content_type.starts_with("application") && content_type.contains("json") { + return Self::Json; + } else if content_type == "text/plain" { + return Self::Text; + } else { + return Self::Unsupported(content_type.to_string()); + } + } +} + pub mod fake_api; pub mod pet_api; pub mod store_api; diff --git a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/pet_api.rs index c8055993606e..b5670d7a73bd 100644 --- a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/pet_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for passing parameters to the method [`add_pet`] #[derive(Clone, Debug)] @@ -229,6 +229,12 @@ pub async fn add_pet(configuration: &configuration::Configuration, params: AddPe let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -300,6 +306,12 @@ pub async fn find_pets_by_status(configuration: &configuration::Configuration, p let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -333,6 +345,12 @@ pub async fn find_pets_by_tags(configuration: &configuration::Configuration, par let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -367,6 +385,12 @@ pub async fn get_pet_by_id(configuration: &configuration::Configuration, params: let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -397,6 +421,12 @@ pub async fn update_pet(configuration: &configuration::Configuration, params: Up let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -469,6 +499,12 @@ pub async fn upload_file(configuration: &configuration::Configuration, params: U let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; diff --git a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/store_api.rs index 17760b176768..e1f663cf6ed7 100644 --- a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/store_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for passing parameters to the method [`delete_order`] #[derive(Clone, Debug)] @@ -149,6 +149,12 @@ pub async fn get_inventory(configuration: &configuration::Configuration) -> Resu let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -175,6 +181,12 @@ pub async fn get_order_by_id(configuration: &configuration::Configuration, param let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -202,6 +214,12 @@ pub async fn place_order(configuration: &configuration::Configuration, params: P let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; diff --git a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/testing_api.rs b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/testing_api.rs index 3f365095bf63..2d3f6ef7ec2f 100644 --- a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/testing_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/testing_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for typed successes of method [`tests_file_response_get`] @@ -82,6 +82,12 @@ pub async fn tests_type_testing_get(configuration: &configuration::Configuration let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; diff --git a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/user_api.rs index e4dfae546d4c..9b8c702df9c6 100644 --- a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/user_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for passing parameters to the method [`create_user`] #[derive(Clone, Debug)] @@ -347,6 +347,12 @@ pub async fn get_user_by_name(configuration: &configuration::Configuration, para let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -375,6 +381,12 @@ pub async fn login_user(configuration: &configuration::Configuration, params: Lo let resp = configuration.client.execute(req).await?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; diff --git a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/fake_api.rs b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/fake_api.rs index 84059e46e596..a364dafd0e72 100644 --- a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/fake_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/fake_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for typed errors of method [`test_nullable_required_param`] diff --git a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/mod.rs index 9b4554aa07fe..fbd226540838 100644 --- a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/mod.rs @@ -94,6 +94,26 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String unimplemented!("Only objects are supported with style=deepObject") } +/// Internal use only +/// A content type supported by this client. +enum ContentType { + Json, + Text, + Unsupported(String) +} + +impl From<&str> for ContentType { + fn from(content_type: &str) -> Self { + if content_type.starts_with("application") && content_type.contains("json") { + return Self::Json; + } else if content_type == "text/plain" { + return Self::Text; + } else { + return Self::Unsupported(content_type.to_string()); + } + } +} + pub mod fake_api; pub mod pet_api; pub mod store_api; diff --git a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/pet_api.rs index cb4a4d7c038c..bc728dd02451 100644 --- a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/pet_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for typed errors of method [`add_pet`] @@ -115,10 +115,20 @@ pub fn add_pet(configuration: &configuration::Configuration, pet: models::Pet) - let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Pet`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Pet`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); @@ -215,10 +225,20 @@ pub fn find_pets_by_status(configuration: &configuration::Configuration, status: let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::Pet>`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::Pet>`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); @@ -262,10 +282,20 @@ pub fn find_pets_by_tags(configuration: &configuration::Configuration, tags: Vec let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::Pet>`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::Pet>`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); @@ -310,10 +340,20 @@ pub fn get_pet_by_id(configuration: &configuration::Configuration, pet_id: i64) let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Pet`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Pet`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); @@ -354,10 +394,20 @@ pub fn update_pet(configuration: &configuration::Configuration, pet: models::Pet let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Pet`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Pet`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); @@ -459,10 +509,20 @@ pub fn upload_file(configuration: &configuration::Configuration, pet_id: i64, ad let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ApiResponse`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ApiResponse`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); diff --git a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/store_api.rs index c4d6b07478e1..78dcac90360d 100644 --- a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/store_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for typed errors of method [`delete_order`] @@ -110,10 +110,20 @@ pub fn get_inventory(configuration: &configuration::Configuration, ) -> Result serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `std::collections::HashMap<String, i32>`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, i32>`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); @@ -137,10 +147,20 @@ pub fn get_order_by_id(configuration: &configuration::Configuration, order_id: i let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Order`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Order`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); @@ -165,10 +185,20 @@ pub fn place_order(configuration: &configuration::Configuration, order: models:: let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Order`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Order`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); diff --git a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/testing_api.rs b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/testing_api.rs index 285fc2e06996..ed232269085a 100644 --- a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/testing_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/testing_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for typed errors of method [`tests_file_response_get`] @@ -66,10 +66,20 @@ pub fn tests_type_testing_get(configuration: &configuration::Configuration, ) -> let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TypeTesting`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::TypeTesting`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); diff --git a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/user_api.rs index c1fc777613d1..da93971ba232 100644 --- a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/user_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for typed errors of method [`create_user`] @@ -290,10 +290,20 @@ pub fn get_user_by_name(configuration: &configuration::Configuration, username: let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::User`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::User`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); @@ -320,10 +330,20 @@ pub fn login_user(configuration: &configuration::Configuration, username: &str, let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Ok(content), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `String`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); diff --git a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/fake_api.rs b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/fake_api.rs index 84059e46e596..a364dafd0e72 100644 --- a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/fake_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/fake_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for typed errors of method [`test_nullable_required_param`] diff --git a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/mod.rs index d791dfb5a892..a11350a33471 100644 --- a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/mod.rs @@ -90,6 +90,26 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String unimplemented!("Only objects are supported with style=deepObject") } +/// Internal use only +/// A content type supported by this client. +enum ContentType { + Json, + Text, + Unsupported(String) +} + +impl From<&str> for ContentType { + fn from(content_type: &str) -> Self { + if content_type.starts_with("application") && content_type.contains("json") { + return Self::Json; + } else if content_type == "text/plain" { + return Self::Text; + } else { + return Self::Unsupported(content_type.to_string()); + } + } +} + pub mod fake_api; pub mod pet_api; pub mod store_api; diff --git a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/pet_api.rs index 9c15cc673f7e..4f3780b34bee 100644 --- a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/pet_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for typed errors of method [`add_pet`] @@ -102,10 +102,20 @@ pub fn add_pet(configuration: &configuration::Configuration, foo_pet: models::Fo let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::FooPet`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::FooPet`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); @@ -176,10 +186,20 @@ pub fn find_pets_by_status(configuration: &configuration::Configuration, status: let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::FooPet>`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::FooPet>`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); @@ -210,10 +230,20 @@ pub fn find_pets_by_tags(configuration: &configuration::Configuration, tags: Vec let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::FooPet>`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::FooPet>`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); @@ -245,10 +275,20 @@ pub fn get_pet_by_id(configuration: &configuration::Configuration, pet_id: i64) let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::FooPet`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::FooPet`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); @@ -276,10 +316,20 @@ pub fn update_pet(configuration: &configuration::Configuration, foo_pet: models: let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::FooPet`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::FooPet`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); @@ -355,10 +405,20 @@ pub fn upload_file(configuration: &configuration::Configuration, pet_id: i64, ad let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::FooApiResponse`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::FooApiResponse`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); diff --git a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/store_api.rs index bfcdf8e075eb..d6cdf8ae9508 100644 --- a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/store_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for typed errors of method [`delete_order`] @@ -97,10 +97,20 @@ pub fn get_inventory(configuration: &configuration::Configuration, ) -> Result serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `std::collections::HashMap<String, i32>`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, i32>`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); @@ -124,10 +134,20 @@ pub fn get_order_by_id(configuration: &configuration::Configuration, order_id: i let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::FooOrder`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::FooOrder`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); @@ -152,10 +172,20 @@ pub fn place_order(configuration: &configuration::Configuration, foo_order: mode let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::FooOrder`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::FooOrder`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); diff --git a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/testing_api.rs b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/testing_api.rs index fb0745d6a62c..9aeb411aed45 100644 --- a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/testing_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/testing_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for typed errors of method [`tests_file_response_get`] @@ -66,10 +66,20 @@ pub fn tests_type_testing_get(configuration: &configuration::Configuration, ) -> let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::FooTypeTesting`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::FooTypeTesting`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); diff --git a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/user_api.rs index 0d2f0f327ddd..b50ce1caaab5 100644 --- a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/user_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for typed errors of method [`create_user`] @@ -238,10 +238,20 @@ pub fn get_user_by_name(configuration: &configuration::Configuration, username: let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::FooUser`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::FooUser`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); @@ -268,10 +278,20 @@ pub fn login_user(configuration: &configuration::Configuration, username: &str, let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Ok(content), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `String`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); diff --git a/samples/client/petstore/rust/reqwest/petstore/src/apis/fake_api.rs b/samples/client/petstore/rust/reqwest/petstore/src/apis/fake_api.rs index 84059e46e596..a364dafd0e72 100644 --- a/samples/client/petstore/rust/reqwest/petstore/src/apis/fake_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore/src/apis/fake_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for typed errors of method [`test_nullable_required_param`] diff --git a/samples/client/petstore/rust/reqwest/petstore/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/petstore/src/apis/mod.rs index d791dfb5a892..a11350a33471 100644 --- a/samples/client/petstore/rust/reqwest/petstore/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/petstore/src/apis/mod.rs @@ -90,6 +90,26 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String unimplemented!("Only objects are supported with style=deepObject") } +/// Internal use only +/// A content type supported by this client. +enum ContentType { + Json, + Text, + Unsupported(String) +} + +impl From<&str> for ContentType { + fn from(content_type: &str) -> Self { + if content_type.starts_with("application") && content_type.contains("json") { + return Self::Json; + } else if content_type == "text/plain" { + return Self::Text; + } else { + return Self::Unsupported(content_type.to_string()); + } + } +} + pub mod fake_api; pub mod pet_api; pub mod store_api; diff --git a/samples/client/petstore/rust/reqwest/petstore/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest/petstore/src/apis/pet_api.rs index 35c663eb7148..f30857ad8724 100644 --- a/samples/client/petstore/rust/reqwest/petstore/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore/src/apis/pet_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for typed errors of method [`add_pet`] @@ -102,10 +102,20 @@ pub fn add_pet(configuration: &configuration::Configuration, pet: models::Pet) - let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Pet`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Pet`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); @@ -176,10 +186,20 @@ pub fn find_pets_by_status(configuration: &configuration::Configuration, status: let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::Pet>`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::Pet>`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); @@ -210,10 +230,20 @@ pub fn find_pets_by_tags(configuration: &configuration::Configuration, tags: Vec let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::Pet>`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::Pet>`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); @@ -245,10 +275,20 @@ pub fn get_pet_by_id(configuration: &configuration::Configuration, pet_id: i64) let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Pet`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Pet`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); @@ -276,10 +316,20 @@ pub fn update_pet(configuration: &configuration::Configuration, pet: models::Pet let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Pet`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Pet`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); @@ -355,10 +405,20 @@ pub fn upload_file(configuration: &configuration::Configuration, pet_id: i64, ad let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ApiResponse`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ApiResponse`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); diff --git a/samples/client/petstore/rust/reqwest/petstore/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest/petstore/src/apis/store_api.rs index 9918f21ad4a4..ee5e6a5d2d46 100644 --- a/samples/client/petstore/rust/reqwest/petstore/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore/src/apis/store_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for typed errors of method [`delete_order`] @@ -97,10 +97,20 @@ pub fn get_inventory(configuration: &configuration::Configuration, ) -> Result serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `std::collections::HashMap<String, i32>`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, i32>`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); @@ -124,10 +134,20 @@ pub fn get_order_by_id(configuration: &configuration::Configuration, order_id: i let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Order`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Order`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); @@ -152,10 +172,20 @@ pub fn place_order(configuration: &configuration::Configuration, order: models:: let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Order`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Order`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); diff --git a/samples/client/petstore/rust/reqwest/petstore/src/apis/testing_api.rs b/samples/client/petstore/rust/reqwest/petstore/src/apis/testing_api.rs index 285fc2e06996..ed232269085a 100644 --- a/samples/client/petstore/rust/reqwest/petstore/src/apis/testing_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore/src/apis/testing_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for typed errors of method [`tests_file_response_get`] @@ -66,10 +66,20 @@ pub fn tests_type_testing_get(configuration: &configuration::Configuration, ) -> let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TypeTesting`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::TypeTesting`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); diff --git a/samples/client/petstore/rust/reqwest/petstore/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest/petstore/src/apis/user_api.rs index 299e19063df2..db7d7313ece1 100644 --- a/samples/client/petstore/rust/reqwest/petstore/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore/src/apis/user_api.rs @@ -10,9 +10,9 @@ use reqwest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Error as _}; use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; +use super::{Error, configuration, ContentType}; /// struct for typed errors of method [`create_user`] @@ -238,10 +238,20 @@ pub fn get_user_by_name(configuration: &configuration::Configuration, username: let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::User`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::User`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); @@ -268,10 +278,20 @@ pub fn login_user(configuration: &configuration::Configuration, username: &str, let resp = configuration.client.execute(req)?; let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text()?; - serde_json::from_str(&content).map_err(Error::from) + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Ok(content), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `String`")))), + } } else { let content = resp.text()?; let entity: Option = serde_json::from_str(&content).ok(); From 413310fdbaeefe1f8657e30b3bf35e3364ef9620 Mon Sep 17 00:00:00 2001 From: Ross Sullivan Date: Tue, 11 Feb 2025 22:42:03 +0900 Subject: [PATCH 5/8] cleanup --- .../resources/rust/reqwest-trait/api.mustache | 2 ++ .../petstore/src/apis/fake_api.rs | 6 ---- .../petstore/src/apis/pet_api.rs | 12 ------- .../petstore/src/apis/store_api.rs | 6 ---- .../petstore/src/apis/user_api.rs | 36 ------------------- 5 files changed, 2 insertions(+), 60 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api.mustache b/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api.mustache index 911578939337..d9b46c9706b8 100644 --- a/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api.mustache +++ b/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api.mustache @@ -337,12 +337,14 @@ impl {{classname}} for {{classname}}Client { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); + {{#returnType}} let local_var_content_type = local_var_resp .headers() .get("content-type") .and_then(|v| v.to_str().ok()) .unwrap_or("application/octet-stream"); let local_var_content_type = super::ContentType::from(local_var_content_type); + {{/returnType}} let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/fake_api.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/fake_api.rs index d16294784ce4..b4eb9420cdb1 100644 --- a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/fake_api.rs +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/fake_api.rs @@ -69,12 +69,6 @@ impl FakeApi for FakeApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content_type = local_var_resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/pet_api.rs index 951e4d5d08a4..d1dafb82af4d 100644 --- a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/pet_api.rs @@ -135,12 +135,6 @@ impl PetApi for PetApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content_type = local_var_resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { @@ -364,12 +358,6 @@ impl PetApi for PetApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content_type = local_var_resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/store_api.rs index 2e0f8f4a3c76..7adfa7218540 100644 --- a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/store_api.rs @@ -73,12 +73,6 @@ impl StoreApi for StoreApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content_type = local_var_resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/user_api.rs index 42c96045daad..ba2c479df495 100644 --- a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/user_api.rs @@ -94,12 +94,6 @@ impl UserApi for UserApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content_type = local_var_resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { @@ -137,12 +131,6 @@ impl UserApi for UserApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content_type = local_var_resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { @@ -180,12 +168,6 @@ impl UserApi for UserApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content_type = local_var_resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { @@ -222,12 +204,6 @@ impl UserApi for UserApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content_type = local_var_resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { @@ -342,12 +318,6 @@ impl UserApi for UserApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content_type = local_var_resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { @@ -385,12 +355,6 @@ impl UserApi for UserApiClient { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); - let local_var_content_type = local_var_resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let local_var_content_type = super::ContentType::from(local_var_content_type); let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { From ec2606a7200c35cc64db4bd8f3e9cdbcfce5dfc3 Mon Sep 17 00:00:00 2001 From: Ross Sullivan Date: Tue, 11 Feb 2025 22:53:14 +0900 Subject: [PATCH 6/8] reduced compiler warnings --- .../resources/rust/reqwest-trait/api.mustache | 2 ++ .../rust/reqwest-trait/api_mod.mustache | 1 + .../main/resources/rust/reqwest/api.mustache | 2 ++ .../resources/rust/reqwest/api_mod.mustache | 1 + .../reqwest-regression-16119/src/apis/mod.rs | 1 + .../api-with-ref-param/src/apis/mod.rs | 1 + .../reqwest/composed-oneof/src/apis/mod.rs | 1 + .../rust/reqwest/emptyObject/src/apis/mod.rs | 1 + .../reqwest/oneOf-array-map/src/apis/mod.rs | 1 + .../reqwest/oneOf-reuseRef/src/apis/mod.rs | 1 + .../others/rust/reqwest/oneOf/src/apis/mod.rs | 1 + .../reqwest-trait/petstore/src/apis/mod.rs | 1 + .../rust/reqwest/name-mapping/src/apis/mod.rs | 1 + .../petstore-async-middleware/src/apis/mod.rs | 1 + .../src/apis/pet_api.rs | 36 ------------------- .../src/apis/store_api.rs | 18 ---------- .../src/apis/testing_api.rs | 6 ---- .../src/apis/user_api.rs | 12 ------- .../src/apis/mod.rs | 1 + .../src/apis/pet_api.rs | 36 ------------------- .../src/apis/store_api.rs | 18 ---------- .../src/apis/testing_api.rs | 6 ---- .../src/apis/user_api.rs | 12 ------- .../reqwest/petstore-async/src/apis/mod.rs | 1 + .../petstore-async/src/apis/pet_api.rs | 36 ------------------- .../petstore-async/src/apis/store_api.rs | 18 ---------- .../petstore-async/src/apis/testing_api.rs | 6 ---- .../petstore-async/src/apis/user_api.rs | 12 ------- .../petstore-avoid-box/src/apis/mod.rs | 1 + .../petstore-avoid-box/src/apis/pet_api.rs | 36 ------------------- .../petstore-avoid-box/src/apis/store_api.rs | 18 ---------- .../src/apis/testing_api.rs | 6 ---- .../petstore-avoid-box/src/apis/user_api.rs | 12 ------- .../petstore-awsv4signature/src/apis/mod.rs | 1 + .../src/apis/mod.rs | 1 + .../rust/reqwest/petstore/src/apis/mod.rs | 1 + 36 files changed, 22 insertions(+), 288 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api.mustache b/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api.mustache index d9b46c9706b8..b868e0354c32 100644 --- a/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api.mustache +++ b/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api.mustache @@ -337,6 +337,7 @@ impl {{classname}} for {{classname}}Client { let local_var_resp = local_var_client.execute(local_var_req).await?; let local_var_status = local_var_resp.status(); + {{^supportMultipleResponses}} {{#returnType}} let local_var_content_type = local_var_resp .headers() @@ -345,6 +346,7 @@ impl {{classname}} for {{classname}}Client { .unwrap_or("application/octet-stream"); let local_var_content_type = super::ContentType::from(local_var_content_type); {{/returnType}} + {{/supportMultipleResponses}} let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { diff --git a/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api_mod.mustache b/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api_mod.mustache index 9b3e6d714046..4356b685accf 100644 --- a/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api_mod.mustache +++ b/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api_mod.mustache @@ -130,6 +130,7 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String /// Internal use only /// A content type supported by this client. +#[allow(dead_code)] enum ContentType { Json, Text, diff --git a/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache b/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache index 9f61507db892..d43f0e854c39 100644 --- a/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache +++ b/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache @@ -355,6 +355,7 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: let resp = configuration.client.execute(req){{#supportAsync}}.await{{/supportAsync}}?; let status = resp.status(); + {{^supportMultipleResponses}} {{^isResponseFile}} {{#returnType}} let content_type = resp @@ -365,6 +366,7 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: let content_type = super::ContentType::from(content_type); {{/returnType}} {{/isResponseFile}} + {{/supportMultipleResponses}} if !status.is_client_error() && !status.is_server_error() { {{^supportMultipleResponses}} diff --git a/modules/openapi-generator/src/main/resources/rust/reqwest/api_mod.mustache b/modules/openapi-generator/src/main/resources/rust/reqwest/api_mod.mustache index 4cce6f001848..6542f1baf066 100644 --- a/modules/openapi-generator/src/main/resources/rust/reqwest/api_mod.mustache +++ b/modules/openapi-generator/src/main/resources/rust/reqwest/api_mod.mustache @@ -136,6 +136,7 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String /// Internal use only /// A content type supported by this client. +#[allow(dead_code)] enum ContentType { Json, Text, diff --git a/samples/client/others/rust/reqwest-regression-16119/src/apis/mod.rs b/samples/client/others/rust/reqwest-regression-16119/src/apis/mod.rs index 96e86546ec6d..9e6ae3f6453a 100644 --- a/samples/client/others/rust/reqwest-regression-16119/src/apis/mod.rs +++ b/samples/client/others/rust/reqwest-regression-16119/src/apis/mod.rs @@ -92,6 +92,7 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String /// Internal use only /// A content type supported by this client. +#[allow(dead_code)] enum ContentType { Json, Text, diff --git a/samples/client/others/rust/reqwest/api-with-ref-param/src/apis/mod.rs b/samples/client/others/rust/reqwest/api-with-ref-param/src/apis/mod.rs index 96e86546ec6d..9e6ae3f6453a 100644 --- a/samples/client/others/rust/reqwest/api-with-ref-param/src/apis/mod.rs +++ b/samples/client/others/rust/reqwest/api-with-ref-param/src/apis/mod.rs @@ -92,6 +92,7 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String /// Internal use only /// A content type supported by this client. +#[allow(dead_code)] enum ContentType { Json, Text, diff --git a/samples/client/others/rust/reqwest/composed-oneof/src/apis/mod.rs b/samples/client/others/rust/reqwest/composed-oneof/src/apis/mod.rs index 96e86546ec6d..9e6ae3f6453a 100644 --- a/samples/client/others/rust/reqwest/composed-oneof/src/apis/mod.rs +++ b/samples/client/others/rust/reqwest/composed-oneof/src/apis/mod.rs @@ -92,6 +92,7 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String /// Internal use only /// A content type supported by this client. +#[allow(dead_code)] enum ContentType { Json, Text, diff --git a/samples/client/others/rust/reqwest/emptyObject/src/apis/mod.rs b/samples/client/others/rust/reqwest/emptyObject/src/apis/mod.rs index 96e86546ec6d..9e6ae3f6453a 100644 --- a/samples/client/others/rust/reqwest/emptyObject/src/apis/mod.rs +++ b/samples/client/others/rust/reqwest/emptyObject/src/apis/mod.rs @@ -92,6 +92,7 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String /// Internal use only /// A content type supported by this client. +#[allow(dead_code)] enum ContentType { Json, Text, diff --git a/samples/client/others/rust/reqwest/oneOf-array-map/src/apis/mod.rs b/samples/client/others/rust/reqwest/oneOf-array-map/src/apis/mod.rs index 96e86546ec6d..9e6ae3f6453a 100644 --- a/samples/client/others/rust/reqwest/oneOf-array-map/src/apis/mod.rs +++ b/samples/client/others/rust/reqwest/oneOf-array-map/src/apis/mod.rs @@ -92,6 +92,7 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String /// Internal use only /// A content type supported by this client. +#[allow(dead_code)] enum ContentType { Json, Text, diff --git a/samples/client/others/rust/reqwest/oneOf-reuseRef/src/apis/mod.rs b/samples/client/others/rust/reqwest/oneOf-reuseRef/src/apis/mod.rs index 96e86546ec6d..9e6ae3f6453a 100644 --- a/samples/client/others/rust/reqwest/oneOf-reuseRef/src/apis/mod.rs +++ b/samples/client/others/rust/reqwest/oneOf-reuseRef/src/apis/mod.rs @@ -92,6 +92,7 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String /// Internal use only /// A content type supported by this client. +#[allow(dead_code)] enum ContentType { Json, Text, diff --git a/samples/client/others/rust/reqwest/oneOf/src/apis/mod.rs b/samples/client/others/rust/reqwest/oneOf/src/apis/mod.rs index 28a73c0be6b8..99568d266415 100644 --- a/samples/client/others/rust/reqwest/oneOf/src/apis/mod.rs +++ b/samples/client/others/rust/reqwest/oneOf/src/apis/mod.rs @@ -92,6 +92,7 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String /// Internal use only /// A content type supported by this client. +#[allow(dead_code)] enum ContentType { Json, Text, diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/mod.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/mod.rs index 86a9f0597206..85c99fbd7629 100644 --- a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/mod.rs @@ -92,6 +92,7 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String /// Internal use only /// A content type supported by this client. +#[allow(dead_code)] enum ContentType { Json, Text, diff --git a/samples/client/petstore/rust/reqwest/name-mapping/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/name-mapping/src/apis/mod.rs index e545f0bc7d24..2fa363a4514a 100644 --- a/samples/client/petstore/rust/reqwest/name-mapping/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/name-mapping/src/apis/mod.rs @@ -92,6 +92,7 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String /// Internal use only /// A content type supported by this client. +#[allow(dead_code)] enum ContentType { Json, Text, diff --git a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/mod.rs index 7974c2c6bc8a..a7d5939a564c 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/mod.rs @@ -101,6 +101,7 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String /// Internal use only /// A content type supported by this client. +#[allow(dead_code)] enum ContentType { Json, Text, diff --git a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/pet_api.rs index b5670d7a73bd..342302918d25 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/pet_api.rs @@ -229,12 +229,6 @@ pub async fn add_pet(configuration: &configuration::Configuration, params: AddPe let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -306,12 +300,6 @@ pub async fn find_pets_by_status(configuration: &configuration::Configuration, p let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -345,12 +333,6 @@ pub async fn find_pets_by_tags(configuration: &configuration::Configuration, par let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -385,12 +367,6 @@ pub async fn get_pet_by_id(configuration: &configuration::Configuration, params: let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -421,12 +397,6 @@ pub async fn update_pet(configuration: &configuration::Configuration, params: Up let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -499,12 +469,6 @@ pub async fn upload_file(configuration: &configuration::Configuration, params: U let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; diff --git a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/store_api.rs index e1f663cf6ed7..d14c940610bf 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/store_api.rs @@ -149,12 +149,6 @@ pub async fn get_inventory(configuration: &configuration::Configuration) -> Resu let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -181,12 +175,6 @@ pub async fn get_order_by_id(configuration: &configuration::Configuration, param let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -214,12 +202,6 @@ pub async fn place_order(configuration: &configuration::Configuration, params: P let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; diff --git a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/testing_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/testing_api.rs index 2d3f6ef7ec2f..24717a365382 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/testing_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/testing_api.rs @@ -82,12 +82,6 @@ pub async fn tests_type_testing_get(configuration: &configuration::Configuration let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; diff --git a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/user_api.rs index 9b8c702df9c6..c377f41f4e08 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/user_api.rs @@ -347,12 +347,6 @@ pub async fn get_user_by_name(configuration: &configuration::Configuration, para let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -381,12 +375,6 @@ pub async fn login_user(configuration: &configuration::Configuration, params: Lo let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; diff --git a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/mod.rs index 94b68d0b2b1d..2ecc0120146b 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/mod.rs @@ -95,6 +95,7 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String /// Internal use only /// A content type supported by this client. +#[allow(dead_code)] enum ContentType { Json, Text, diff --git a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/pet_api.rs index 7155a74c8af4..7ff1983fc3af 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/pet_api.rs @@ -231,12 +231,6 @@ pub async fn add_pet(configuration: &configuration::Configuration, params: AddPe let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -312,12 +306,6 @@ pub async fn find_pets_by_status(configuration: &configuration::Configuration, p let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -353,12 +341,6 @@ pub async fn find_pets_by_tags(configuration: &configuration::Configuration, par let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -390,12 +372,6 @@ pub async fn get_pet_by_id(configuration: &configuration::Configuration, params: let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -428,12 +404,6 @@ pub async fn update_pet(configuration: &configuration::Configuration, params: Up let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -510,12 +480,6 @@ pub async fn upload_file(configuration: &configuration::Configuration, params: U let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; diff --git a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/store_api.rs index 5f9a4ffecc87..70d5b105a402 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/store_api.rs @@ -146,12 +146,6 @@ pub async fn get_inventory(configuration: &configuration::Configuration) -> Resu let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -178,12 +172,6 @@ pub async fn get_order_by_id(configuration: &configuration::Configuration, param let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -211,12 +199,6 @@ pub async fn place_order(configuration: &configuration::Configuration, params: P let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; diff --git a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/testing_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/testing_api.rs index 2d3f6ef7ec2f..24717a365382 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/testing_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/testing_api.rs @@ -82,12 +82,6 @@ pub async fn tests_type_testing_get(configuration: &configuration::Configuration let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; diff --git a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/user_api.rs index e9e0da8fe34b..f44d949fefaf 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/user_api.rs @@ -335,12 +335,6 @@ pub async fn get_user_by_name(configuration: &configuration::Configuration, para let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -369,12 +363,6 @@ pub async fn login_user(configuration: &configuration::Configuration, params: Lo let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/mod.rs index a11350a33471..0803993e32b0 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/mod.rs @@ -92,6 +92,7 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String /// Internal use only /// A content type supported by this client. +#[allow(dead_code)] enum ContentType { Json, Text, diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/pet_api.rs index b5670d7a73bd..342302918d25 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/pet_api.rs @@ -229,12 +229,6 @@ pub async fn add_pet(configuration: &configuration::Configuration, params: AddPe let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -306,12 +300,6 @@ pub async fn find_pets_by_status(configuration: &configuration::Configuration, p let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -345,12 +333,6 @@ pub async fn find_pets_by_tags(configuration: &configuration::Configuration, par let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -385,12 +367,6 @@ pub async fn get_pet_by_id(configuration: &configuration::Configuration, params: let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -421,12 +397,6 @@ pub async fn update_pet(configuration: &configuration::Configuration, params: Up let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -499,12 +469,6 @@ pub async fn upload_file(configuration: &configuration::Configuration, params: U let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/store_api.rs index e1f663cf6ed7..d14c940610bf 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/store_api.rs @@ -149,12 +149,6 @@ pub async fn get_inventory(configuration: &configuration::Configuration) -> Resu let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -181,12 +175,6 @@ pub async fn get_order_by_id(configuration: &configuration::Configuration, param let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -214,12 +202,6 @@ pub async fn place_order(configuration: &configuration::Configuration, params: P let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/testing_api.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/testing_api.rs index 2d3f6ef7ec2f..24717a365382 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/testing_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/testing_api.rs @@ -82,12 +82,6 @@ pub async fn tests_type_testing_get(configuration: &configuration::Configuration let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/user_api.rs index 9b8c702df9c6..c377f41f4e08 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/user_api.rs @@ -347,12 +347,6 @@ pub async fn get_user_by_name(configuration: &configuration::Configuration, para let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -381,12 +375,6 @@ pub async fn login_user(configuration: &configuration::Configuration, params: Lo let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; diff --git a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/mod.rs index a11350a33471..0803993e32b0 100644 --- a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/mod.rs @@ -92,6 +92,7 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String /// Internal use only /// A content type supported by this client. +#[allow(dead_code)] enum ContentType { Json, Text, diff --git a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/pet_api.rs index b5670d7a73bd..342302918d25 100644 --- a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/pet_api.rs @@ -229,12 +229,6 @@ pub async fn add_pet(configuration: &configuration::Configuration, params: AddPe let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -306,12 +300,6 @@ pub async fn find_pets_by_status(configuration: &configuration::Configuration, p let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -345,12 +333,6 @@ pub async fn find_pets_by_tags(configuration: &configuration::Configuration, par let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -385,12 +367,6 @@ pub async fn get_pet_by_id(configuration: &configuration::Configuration, params: let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -421,12 +397,6 @@ pub async fn update_pet(configuration: &configuration::Configuration, params: Up let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -499,12 +469,6 @@ pub async fn upload_file(configuration: &configuration::Configuration, params: U let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; diff --git a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/store_api.rs index e1f663cf6ed7..d14c940610bf 100644 --- a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/store_api.rs @@ -149,12 +149,6 @@ pub async fn get_inventory(configuration: &configuration::Configuration) -> Resu let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -181,12 +175,6 @@ pub async fn get_order_by_id(configuration: &configuration::Configuration, param let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -214,12 +202,6 @@ pub async fn place_order(configuration: &configuration::Configuration, params: P let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; diff --git a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/testing_api.rs b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/testing_api.rs index 2d3f6ef7ec2f..24717a365382 100644 --- a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/testing_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/testing_api.rs @@ -82,12 +82,6 @@ pub async fn tests_type_testing_get(configuration: &configuration::Configuration let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; diff --git a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/user_api.rs index 9b8c702df9c6..c377f41f4e08 100644 --- a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/user_api.rs @@ -347,12 +347,6 @@ pub async fn get_user_by_name(configuration: &configuration::Configuration, para let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; @@ -381,12 +375,6 @@ pub async fn login_user(configuration: &configuration::Configuration, params: Lo let resp = configuration.client.execute(req).await?; let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); if !status.is_client_error() && !status.is_server_error() { let content = resp.text().await?; diff --git a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/mod.rs index fbd226540838..b1986b0cece0 100644 --- a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/mod.rs @@ -96,6 +96,7 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String /// Internal use only /// A content type supported by this client. +#[allow(dead_code)] enum ContentType { Json, Text, diff --git a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/mod.rs index a11350a33471..0803993e32b0 100644 --- a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/mod.rs @@ -92,6 +92,7 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String /// Internal use only /// A content type supported by this client. +#[allow(dead_code)] enum ContentType { Json, Text, diff --git a/samples/client/petstore/rust/reqwest/petstore/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/petstore/src/apis/mod.rs index a11350a33471..0803993e32b0 100644 --- a/samples/client/petstore/rust/reqwest/petstore/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/petstore/src/apis/mod.rs @@ -92,6 +92,7 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String /// Internal use only /// A content type supported by this client. +#[allow(dead_code)] enum ContentType { Json, Text, From 59195acfd6e5c582ffff741ade5cd4b11b1b4548 Mon Sep 17 00:00:00 2001 From: Ross Sullivan Date: Tue, 11 Feb 2025 23:07:05 +0900 Subject: [PATCH 7/8] fixed text/plain content with charset --- .../src/main/resources/rust/reqwest-trait/api_mod.mustache | 2 +- .../src/main/resources/rust/reqwest/api_mod.mustache | 2 +- .../client/others/rust/reqwest-regression-16119/src/apis/mod.rs | 2 +- .../others/rust/reqwest/api-with-ref-param/src/apis/mod.rs | 2 +- .../client/others/rust/reqwest/composed-oneof/src/apis/mod.rs | 2 +- samples/client/others/rust/reqwest/emptyObject/src/apis/mod.rs | 2 +- .../client/others/rust/reqwest/oneOf-array-map/src/apis/mod.rs | 2 +- .../client/others/rust/reqwest/oneOf-reuseRef/src/apis/mod.rs | 2 +- samples/client/others/rust/reqwest/oneOf/src/apis/mod.rs | 2 +- .../client/petstore/rust/reqwest-trait/petstore/src/apis/mod.rs | 2 +- .../client/petstore/rust/reqwest/name-mapping/src/apis/mod.rs | 2 +- .../rust/reqwest/petstore-async-middleware/src/apis/mod.rs | 2 +- .../rust/reqwest/petstore-async-tokensource/src/apis/mod.rs | 2 +- .../client/petstore/rust/reqwest/petstore-async/src/apis/mod.rs | 2 +- .../petstore/rust/reqwest/petstore-avoid-box/src/apis/mod.rs | 2 +- .../rust/reqwest/petstore-awsv4signature/src/apis/mod.rs | 2 +- .../rust/reqwest/petstore-model-name-prefix/src/apis/mod.rs | 2 +- samples/client/petstore/rust/reqwest/petstore/src/apis/mod.rs | 2 +- 18 files changed, 18 insertions(+), 18 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api_mod.mustache b/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api_mod.mustache index 4356b685accf..41a4ba0f81f6 100644 --- a/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api_mod.mustache +++ b/modules/openapi-generator/src/main/resources/rust/reqwest-trait/api_mod.mustache @@ -141,7 +141,7 @@ impl From<&str> for ContentType { fn from(content_type: &str) -> Self { if content_type.starts_with("application") && content_type.contains("json") { return Self::Json; - } else if content_type == "text/plain" { + } else if content_type.starts_with("text/plain") { return Self::Text; } else { return Self::Unsupported(content_type.to_string()); diff --git a/modules/openapi-generator/src/main/resources/rust/reqwest/api_mod.mustache b/modules/openapi-generator/src/main/resources/rust/reqwest/api_mod.mustache index 6542f1baf066..4d5df28e9bb8 100644 --- a/modules/openapi-generator/src/main/resources/rust/reqwest/api_mod.mustache +++ b/modules/openapi-generator/src/main/resources/rust/reqwest/api_mod.mustache @@ -147,7 +147,7 @@ impl From<&str> for ContentType { fn from(content_type: &str) -> Self { if content_type.starts_with("application") && content_type.contains("json") { return Self::Json; - } else if content_type == "text/plain" { + } else if content_type.starts_with("text/plain") { return Self::Text; } else { return Self::Unsupported(content_type.to_string()); diff --git a/samples/client/others/rust/reqwest-regression-16119/src/apis/mod.rs b/samples/client/others/rust/reqwest-regression-16119/src/apis/mod.rs index 9e6ae3f6453a..fdcc89b36066 100644 --- a/samples/client/others/rust/reqwest-regression-16119/src/apis/mod.rs +++ b/samples/client/others/rust/reqwest-regression-16119/src/apis/mod.rs @@ -103,7 +103,7 @@ impl From<&str> for ContentType { fn from(content_type: &str) -> Self { if content_type.starts_with("application") && content_type.contains("json") { return Self::Json; - } else if content_type == "text/plain" { + } else if content_type.starts_with("text/plain") { return Self::Text; } else { return Self::Unsupported(content_type.to_string()); diff --git a/samples/client/others/rust/reqwest/api-with-ref-param/src/apis/mod.rs b/samples/client/others/rust/reqwest/api-with-ref-param/src/apis/mod.rs index 9e6ae3f6453a..fdcc89b36066 100644 --- a/samples/client/others/rust/reqwest/api-with-ref-param/src/apis/mod.rs +++ b/samples/client/others/rust/reqwest/api-with-ref-param/src/apis/mod.rs @@ -103,7 +103,7 @@ impl From<&str> for ContentType { fn from(content_type: &str) -> Self { if content_type.starts_with("application") && content_type.contains("json") { return Self::Json; - } else if content_type == "text/plain" { + } else if content_type.starts_with("text/plain") { return Self::Text; } else { return Self::Unsupported(content_type.to_string()); diff --git a/samples/client/others/rust/reqwest/composed-oneof/src/apis/mod.rs b/samples/client/others/rust/reqwest/composed-oneof/src/apis/mod.rs index 9e6ae3f6453a..fdcc89b36066 100644 --- a/samples/client/others/rust/reqwest/composed-oneof/src/apis/mod.rs +++ b/samples/client/others/rust/reqwest/composed-oneof/src/apis/mod.rs @@ -103,7 +103,7 @@ impl From<&str> for ContentType { fn from(content_type: &str) -> Self { if content_type.starts_with("application") && content_type.contains("json") { return Self::Json; - } else if content_type == "text/plain" { + } else if content_type.starts_with("text/plain") { return Self::Text; } else { return Self::Unsupported(content_type.to_string()); diff --git a/samples/client/others/rust/reqwest/emptyObject/src/apis/mod.rs b/samples/client/others/rust/reqwest/emptyObject/src/apis/mod.rs index 9e6ae3f6453a..fdcc89b36066 100644 --- a/samples/client/others/rust/reqwest/emptyObject/src/apis/mod.rs +++ b/samples/client/others/rust/reqwest/emptyObject/src/apis/mod.rs @@ -103,7 +103,7 @@ impl From<&str> for ContentType { fn from(content_type: &str) -> Self { if content_type.starts_with("application") && content_type.contains("json") { return Self::Json; - } else if content_type == "text/plain" { + } else if content_type.starts_with("text/plain") { return Self::Text; } else { return Self::Unsupported(content_type.to_string()); diff --git a/samples/client/others/rust/reqwest/oneOf-array-map/src/apis/mod.rs b/samples/client/others/rust/reqwest/oneOf-array-map/src/apis/mod.rs index 9e6ae3f6453a..fdcc89b36066 100644 --- a/samples/client/others/rust/reqwest/oneOf-array-map/src/apis/mod.rs +++ b/samples/client/others/rust/reqwest/oneOf-array-map/src/apis/mod.rs @@ -103,7 +103,7 @@ impl From<&str> for ContentType { fn from(content_type: &str) -> Self { if content_type.starts_with("application") && content_type.contains("json") { return Self::Json; - } else if content_type == "text/plain" { + } else if content_type.starts_with("text/plain") { return Self::Text; } else { return Self::Unsupported(content_type.to_string()); diff --git a/samples/client/others/rust/reqwest/oneOf-reuseRef/src/apis/mod.rs b/samples/client/others/rust/reqwest/oneOf-reuseRef/src/apis/mod.rs index 9e6ae3f6453a..fdcc89b36066 100644 --- a/samples/client/others/rust/reqwest/oneOf-reuseRef/src/apis/mod.rs +++ b/samples/client/others/rust/reqwest/oneOf-reuseRef/src/apis/mod.rs @@ -103,7 +103,7 @@ impl From<&str> for ContentType { fn from(content_type: &str) -> Self { if content_type.starts_with("application") && content_type.contains("json") { return Self::Json; - } else if content_type == "text/plain" { + } else if content_type.starts_with("text/plain") { return Self::Text; } else { return Self::Unsupported(content_type.to_string()); diff --git a/samples/client/others/rust/reqwest/oneOf/src/apis/mod.rs b/samples/client/others/rust/reqwest/oneOf/src/apis/mod.rs index 99568d266415..36835a5e8fa6 100644 --- a/samples/client/others/rust/reqwest/oneOf/src/apis/mod.rs +++ b/samples/client/others/rust/reqwest/oneOf/src/apis/mod.rs @@ -103,7 +103,7 @@ impl From<&str> for ContentType { fn from(content_type: &str) -> Self { if content_type.starts_with("application") && content_type.contains("json") { return Self::Json; - } else if content_type == "text/plain" { + } else if content_type.starts_with("text/plain") { return Self::Text; } else { return Self::Unsupported(content_type.to_string()); diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/mod.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/mod.rs index 85c99fbd7629..9336a17460d3 100644 --- a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/mod.rs @@ -103,7 +103,7 @@ impl From<&str> for ContentType { fn from(content_type: &str) -> Self { if content_type.starts_with("application") && content_type.contains("json") { return Self::Json; - } else if content_type == "text/plain" { + } else if content_type.starts_with("text/plain") { return Self::Text; } else { return Self::Unsupported(content_type.to_string()); diff --git a/samples/client/petstore/rust/reqwest/name-mapping/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/name-mapping/src/apis/mod.rs index 2fa363a4514a..df474de37822 100644 --- a/samples/client/petstore/rust/reqwest/name-mapping/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/name-mapping/src/apis/mod.rs @@ -103,7 +103,7 @@ impl From<&str> for ContentType { fn from(content_type: &str) -> Self { if content_type.starts_with("application") && content_type.contains("json") { return Self::Json; - } else if content_type == "text/plain" { + } else if content_type.starts_with("text/plain") { return Self::Text; } else { return Self::Unsupported(content_type.to_string()); diff --git a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/mod.rs index a7d5939a564c..b27445925dc4 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/mod.rs @@ -112,7 +112,7 @@ impl From<&str> for ContentType { fn from(content_type: &str) -> Self { if content_type.starts_with("application") && content_type.contains("json") { return Self::Json; - } else if content_type == "text/plain" { + } else if content_type.starts_with("text/plain") { return Self::Text; } else { return Self::Unsupported(content_type.to_string()); diff --git a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/mod.rs index 2ecc0120146b..c55f52db30b2 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/mod.rs @@ -106,7 +106,7 @@ impl From<&str> for ContentType { fn from(content_type: &str) -> Self { if content_type.starts_with("application") && content_type.contains("json") { return Self::Json; - } else if content_type == "text/plain" { + } else if content_type.starts_with("text/plain") { return Self::Text; } else { return Self::Unsupported(content_type.to_string()); diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/mod.rs index 0803993e32b0..a075c8414431 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/mod.rs @@ -103,7 +103,7 @@ impl From<&str> for ContentType { fn from(content_type: &str) -> Self { if content_type.starts_with("application") && content_type.contains("json") { return Self::Json; - } else if content_type == "text/plain" { + } else if content_type.starts_with("text/plain") { return Self::Text; } else { return Self::Unsupported(content_type.to_string()); diff --git a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/mod.rs index 0803993e32b0..a075c8414431 100644 --- a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/mod.rs @@ -103,7 +103,7 @@ impl From<&str> for ContentType { fn from(content_type: &str) -> Self { if content_type.starts_with("application") && content_type.contains("json") { return Self::Json; - } else if content_type == "text/plain" { + } else if content_type.starts_with("text/plain") { return Self::Text; } else { return Self::Unsupported(content_type.to_string()); diff --git a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/mod.rs index b1986b0cece0..c03ebdf001fc 100644 --- a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/mod.rs @@ -107,7 +107,7 @@ impl From<&str> for ContentType { fn from(content_type: &str) -> Self { if content_type.starts_with("application") && content_type.contains("json") { return Self::Json; - } else if content_type == "text/plain" { + } else if content_type.starts_with("text/plain") { return Self::Text; } else { return Self::Unsupported(content_type.to_string()); diff --git a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/mod.rs index 0803993e32b0..a075c8414431 100644 --- a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/mod.rs @@ -103,7 +103,7 @@ impl From<&str> for ContentType { fn from(content_type: &str) -> Self { if content_type.starts_with("application") && content_type.contains("json") { return Self::Json; - } else if content_type == "text/plain" { + } else if content_type.starts_with("text/plain") { return Self::Text; } else { return Self::Unsupported(content_type.to_string()); diff --git a/samples/client/petstore/rust/reqwest/petstore/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/petstore/src/apis/mod.rs index 0803993e32b0..a075c8414431 100644 --- a/samples/client/petstore/rust/reqwest/petstore/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/petstore/src/apis/mod.rs @@ -103,7 +103,7 @@ impl From<&str> for ContentType { fn from(content_type: &str) -> Self { if content_type.starts_with("application") && content_type.contains("json") { return Self::Json; - } else if content_type == "text/plain" { + } else if content_type.starts_with("text/plain") { return Self::Text; } else { return Self::Unsupported(content_type.to_string()); From 149eaa47cb2f4bf5d19a405cbf9e5bbb7b65d622 Mon Sep 17 00:00:00 2001 From: Ross Sullivan Date: Wed, 12 Feb 2025 23:12:07 +0900 Subject: [PATCH 8/8] Only deserialize text/plain if the API produces it --- .../openapitools/codegen/CodegenOperation.java | 18 ++++++++++++++++++ .../codegen/languages/JavaClientCodegen.java | 11 ++--------- .../codegen/languages/RustClientCodegen.java | 2 +- .../src/test/resources/3_0/rust/petstore.yaml | 4 ++++ .../rust/hyper/petstore/docs/UserApi.md | 2 +- .../rust/hyper0x/petstore/docs/UserApi.md | 2 +- .../reqwest-trait/petstore/docs/UserApi.md | 2 +- .../petstore-async-middleware/docs/UserApi.md | 2 +- .../petstore-async-tokensource/docs/UserApi.md | 2 +- .../reqwest/petstore-async/docs/UserApi.md | 2 +- .../reqwest/petstore-avoid-box/docs/UserApi.md | 2 +- .../petstore-awsv4signature/docs/UserApi.md | 2 +- .../petstore-model-name-prefix/docs/UserApi.md | 2 +- .../rust/reqwest/petstore/docs/UserApi.md | 2 +- 14 files changed, 35 insertions(+), 20 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenOperation.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenOperation.java index 127853a88fe7..74ddd477387e 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenOperation.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenOperation.java @@ -315,6 +315,24 @@ public boolean isRestful() { return isRestfulIndex() || isRestfulShow() || isRestfulCreate() || isRestfulUpdate() || isRestfulDestroy(); } + /** + * Check if operation produces text/plain responses. + * NOTE: This does not mean it _only_ produces text/plain, just that it is one of the produces types. + * + * @return true if at least one produces is text/plain + */ + public boolean producesTextPlain() { + if (produces != null) { + for (Map produce : produces) { + if ("text/plain".equalsIgnoreCase(produce.get("mediaType").split(";")[0].trim()) + && "String".equals(returnType)) { + return true; + } + } + } + return false; + } + /** * Get the substring except baseName from path * diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java index 726a05d1a615..2cdd367aaad7 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java @@ -817,17 +817,10 @@ public int compare(CodegenParameter one, CodegenParameter another) { if (NATIVE.equals(getLibrary()) || APACHE.equals(getLibrary())) { OperationMap operations = objs.getOperations(); List operationList = operations.getOperation(); - Pattern methodPattern = Pattern.compile("^(.*):([^:]*)$"); for (CodegenOperation op : operationList) { // add extension to indicate content type is `text/plain` and the response type is `String` - if (op.produces != null) { - for (Map produce : op.produces) { - if ("text/plain".equalsIgnoreCase(produce.get("mediaType").split(";")[0].trim()) - && "String".equals(op.returnType)) { - op.vendorExtensions.put("x-java-text-plain-string", true); - continue; - } - } + if ("String".equals(op.returnType) && op.producesTextPlain()) { + op.vendorExtensions.put("x-java-text-plain-string", true); } } } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java index c523ddf9f825..351282d5cc5c 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java @@ -677,7 +677,7 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List