diff --git a/modules/openapi-generator/src/main/resources/rust-axum/models.mustache b/modules/openapi-generator/src/main/resources/rust-axum/models.mustache index f50ac45f00d5..cbac6af16491 100644 --- a/modules/openapi-generator/src/main/resources/rust-axum/models.mustache +++ b/modules/openapi-generator/src/main/resources/rust-axum/models.mustache @@ -533,7 +533,7 @@ pub fn check_xss_map(v: &std::collections::HashMap) -> std::result /// which helps with FFI. #[allow(non_camel_case_types, clippy::large_enum_variant)] #[repr(C)] -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, {{^isAnyType}}PartialOrd, Ord,{{/isAnyType}} serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk_enum_derive::LabelledGenericEnum))] pub enum {{{classname}}} { {{#allowableValues}} @@ -584,7 +584,7 @@ impl std::str::FromStr for {{{classname}}} { #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] {{/isMap}} {{^isMap}} -#[derive(Debug, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)] +#[derive(Debug, Clone, PartialEq, {{^isAnyType}}PartialOrd, {{/isAnyType}} serde::Serialize, serde::Deserialize)] {{/isMap}} #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct {{{classname}}}(pub {{{dataType}}}); diff --git a/samples/server/petstore/rust-axum/output/openapi-v3/src/models.rs b/samples/server/petstore/rust-axum/output/openapi-v3/src/models.rs index 5f05dcdc3798..4c676a174121 100644 --- a/samples/server/petstore/rust-axum/output/openapi-v3/src/models.rs +++ b/samples/server/petstore/rust-axum/output/openapi-v3/src/models.rs @@ -1338,15 +1338,20 @@ impl std::ops::DerefMut for Error { pub struct FormTestRequest { #[serde(rename = "requiredArray")] #[validate(custom(function = "check_xss_vec_string"))] - #[serde(skip_serializing_if = "Option::is_none")] - pub required_array: Option>, + pub required_array: Vec, + + /// Note: inline enums are not fully supported by openapi-generator + #[serde(rename = "enum_field")] + #[validate(custom(function = "check_xss_string"))] + pub enum_field: String, } impl FormTestRequest { #[allow(clippy::new_without_default, clippy::too_many_arguments)] - pub fn new() -> FormTestRequest { + pub fn new(required_array: Vec, enum_field: String) -> FormTestRequest { FormTestRequest { - required_array: None, + required_array, + enum_field, } } } @@ -1356,18 +1361,18 @@ impl FormTestRequest { /// Should be implemented in a serde serializer impl std::fmt::Display for FormTestRequest { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let params: Vec> = - vec![self.required_array.as_ref().map(|required_array| { - [ - "requiredArray".to_string(), - required_array - .iter() - .map(|x| x.to_string()) - .collect::>() - .join(","), - ] - .join(",") - })]; + let params: Vec> = vec![ + Some("requiredArray".to_string()), + Some( + self.required_array + .iter() + .map(|x| x.to_string()) + .collect::>() + .join(","), + ), + Some("enum_field".to_string()), + Some(self.enum_field.to_string()), + ]; write!( f, @@ -1389,6 +1394,7 @@ impl std::str::FromStr for FormTestRequest { #[allow(dead_code)] struct IntermediateRep { pub required_array: Vec>, + pub enum_field: Vec, } let mut intermediate_rep = IntermediateRep::default(); @@ -1416,6 +1422,10 @@ impl std::str::FromStr for FormTestRequest { .to_string(), ); } + #[allow(clippy::redundant_clone)] + "enum_field" => intermediate_rep.enum_field.push( + ::from_str(val).map_err(|x| x.to_string())?, + ), _ => { return std::result::Result::Err( "Unexpected key while parsing FormTestRequest".to_string(), @@ -1430,7 +1440,16 @@ impl std::str::FromStr for FormTestRequest { // Use the intermediate representation to return the struct std::result::Result::Ok(FormTestRequest { - required_array: intermediate_rep.required_array.into_iter().next(), + required_array: intermediate_rep + .required_array + .into_iter() + .next() + .ok_or_else(|| "requiredArray missing in FormTestRequest".to_string())?, + enum_field: intermediate_rep + .enum_field + .into_iter() + .next() + .ok_or_else(|| "enum_field missing in FormTestRequest".to_string())?, }) } } @@ -1815,6 +1834,42 @@ impl std::convert::TryFrom for header::IntoHeaderValue { } } +/// An object with no type +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] +#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] +pub struct NoTypeObject(pub crate::types::Object); + +impl validator::Validate for NoTypeObject { + fn validate(&self) -> std::result::Result<(), validator::ValidationErrors> { + std::result::Result::Ok(()) + } +} + +impl std::convert::From for NoTypeObject { + fn from(x: crate::types::Object) -> Self { + NoTypeObject(x) + } +} + +impl std::convert::From for crate::types::Object { + fn from(x: NoTypeObject) -> Self { + x.0 + } +} + +impl std::ops::Deref for NoTypeObject { + type Target = crate::types::Object; + fn deref(&self) -> &crate::types::Object { + &self.0 + } +} + +impl std::ops::DerefMut for NoTypeObject { + fn deref_mut(&mut self) -> &mut crate::types::Object { + &mut self.0 + } +} + #[derive(Debug, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct NullableObject(pub String);