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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ pub fn check_xss_map<T>(v: &std::collections::HashMap<String, T>) -> 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}}
Expand Down Expand Up @@ -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}}});
Expand Down
89 changes: 72 additions & 17 deletions samples/server/petstore/rust-axum/output/openapi-v3/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<String>>,
pub required_array: Vec<String>,

/// 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<String>, enum_field: String) -> FormTestRequest {
FormTestRequest {
required_array: None,
required_array,
enum_field,
}
}
}
Expand All @@ -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<Option<String>> =
vec![self.required_array.as_ref().map(|required_array| {
[
"requiredArray".to_string(),
required_array
.iter()
.map(|x| x.to_string())
.collect::<Vec<_>>()
.join(","),
]
.join(",")
})];
let params: Vec<Option<String>> = vec![
Some("requiredArray".to_string()),
Some(
self.required_array
.iter()
.map(|x| x.to_string())
.collect::<Vec<_>>()
.join(","),
),
Some("enum_field".to_string()),
Some(self.enum_field.to_string()),
];

write!(
f,
Expand All @@ -1389,6 +1394,7 @@ impl std::str::FromStr for FormTestRequest {
#[allow(dead_code)]
struct IntermediateRep {
pub required_array: Vec<Vec<String>>,
pub enum_field: Vec<String>,
}

let mut intermediate_rep = IntermediateRep::default();
Expand Down Expand Up @@ -1416,6 +1422,10 @@ impl std::str::FromStr for FormTestRequest {
.to_string(),
);
}
#[allow(clippy::redundant_clone)]
"enum_field" => intermediate_rep.enum_field.push(
<String as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?,
),
_ => {
return std::result::Result::Err(
"Unexpected key while parsing FormTestRequest".to_string(),
Expand All @@ -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())?,
})
}
}
Expand Down Expand Up @@ -1815,6 +1834,42 @@ impl std::convert::TryFrom<HeaderValue> for header::IntoHeaderValue<MyIdList> {
}
}

/// 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<crate::types::Object> for NoTypeObject {
fn from(x: crate::types::Object) -> Self {
NoTypeObject(x)
}
}

impl std::convert::From<NoTypeObject> 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);
Expand Down
Loading