forked from OpenAPITools/openapi-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.rs
More file actions
164 lines (137 loc) · 6.73 KB
/
models.rs
File metadata and controls
164 lines (137 loc) · 6.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#![allow(unused_qualifications)]
#![allow(clippy::to_string_trait_impl)]
use validator::Validate;
use crate::models;
#[cfg(any(feature = "client", feature = "server"))]
use crate::header;
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)]
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
pub struct OpGetRequest {
#[serde(rename = "property")]
pub property: String,
}
impl OpGetRequest {
#[allow(clippy::new_without_default)]
pub fn new(property: String, ) -> OpGetRequest {
OpGetRequest {
property,
}
}
}
/// Converts the OpGetRequest value to the Query Parameters representation (style=form, explode=false)
/// specified in https://swagger.io/docs/specification/serialization/
/// Should be implemented in a serde serializer
impl std::string::ToString for OpGetRequest {
fn to_string(&self) -> String {
let params: Vec<Option<String>> = vec![
Some("property".to_string()),
Some(self.property.to_string()),
];
params.into_iter().flatten().collect::<Vec<_>>().join(",")
}
}
/// Converts Query Parameters representation (style=form, explode=false) to a OpGetRequest value
/// as specified in https://swagger.io/docs/specification/serialization/
/// Should be implemented in a serde deserializer
impl std::str::FromStr for OpGetRequest {
type Err = String;
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
/// An intermediate representation of the struct to use for parsing.
#[derive(Default)]
#[allow(dead_code)]
struct IntermediateRep {
pub property: Vec<String>,
}
let mut intermediate_rep = IntermediateRep::default();
// Parse into intermediate representation
let mut string_iter = s.split(',');
let mut key_result = string_iter.next();
while key_result.is_some() {
let val = match string_iter.next() {
Some(x) => x,
None => return std::result::Result::Err("Missing value while parsing OpGetRequest".to_string())
};
if let Some(key) = key_result {
#[allow(clippy::match_single_binding)]
match key {
#[allow(clippy::redundant_clone)]
"property" => intermediate_rep.property.push(<String as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?),
_ => return std::result::Result::Err("Unexpected key while parsing OpGetRequest".to_string())
}
}
// Get the next key
key_result = string_iter.next();
}
// Use the intermediate representation to return the struct
std::result::Result::Ok(OpGetRequest {
property: intermediate_rep.property.into_iter().next().ok_or_else(|| "property missing in OpGetRequest".to_string())?,
})
}
}
// Methods for converting between header::IntoHeaderValue<OpGetRequest> and hyper::header::HeaderValue
#[cfg(any(feature = "client", feature = "server"))]
impl std::convert::TryFrom<header::IntoHeaderValue<OpGetRequest>> for hyper::header::HeaderValue {
type Error = String;
fn try_from(hdr_value: header::IntoHeaderValue<OpGetRequest>) -> std::result::Result<Self, Self::Error> {
let hdr_value = hdr_value.to_string();
match hyper::header::HeaderValue::from_str(&hdr_value) {
std::result::Result::Ok(value) => std::result::Result::Ok(value),
std::result::Result::Err(e) => std::result::Result::Err(
format!("Invalid header value for OpGetRequest - value: {hdr_value} is invalid {e}"))
}
}
}
#[cfg(any(feature = "client", feature = "server"))]
impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<OpGetRequest> {
type Error = String;
fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
match hdr_value.to_str() {
std::result::Result::Ok(value) => {
match <OpGetRequest as std::str::FromStr>::from_str(value) {
std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
std::result::Result::Err(err) => std::result::Result::Err(
format!("Unable to convert header value '{value}' into OpGetRequest - {err}"))
}
},
std::result::Result::Err(e) => std::result::Result::Err(
format!("Unable to convert header: {hdr_value:?} to string: {e}"))
}
}
}
#[cfg(any(feature = "client", feature = "server"))]
impl std::convert::TryFrom<header::IntoHeaderValue<Vec<OpGetRequest>>> for hyper::header::HeaderValue {
type Error = String;
fn try_from(hdr_values: header::IntoHeaderValue<Vec<OpGetRequest>>) -> std::result::Result<Self, Self::Error> {
let hdr_values : Vec<String> = hdr_values.0.into_iter().map(|hdr_value| {
hdr_value.to_string()
}).collect();
match hyper::header::HeaderValue::from_str(&hdr_values.join(", ")) {
std::result::Result::Ok(hdr_value) => std::result::Result::Ok(hdr_value),
std::result::Result::Err(e) => std::result::Result::Err(format!("Unable to convert {hdr_values:?} into a header - {e}"))
}
}
}
#[cfg(any(feature = "client", feature = "server"))]
impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<Vec<OpGetRequest>> {
type Error = String;
fn try_from(hdr_values: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
match hdr_values.to_str() {
std::result::Result::Ok(hdr_values) => {
let hdr_values : std::vec::Vec<OpGetRequest> = hdr_values
.split(',')
.filter_map(|hdr_value| match hdr_value.trim() {
"" => std::option::Option::None,
hdr_value => std::option::Option::Some({
match <OpGetRequest as std::str::FromStr>::from_str(hdr_value) {
std::result::Result::Ok(value) => std::result::Result::Ok(value),
std::result::Result::Err(err) => std::result::Result::Err(
format!("Unable to convert header value '{hdr_value}' into OpGetRequest - {err}"))
}
})
}).collect::<std::result::Result<std::vec::Vec<_>, String>>()?;
std::result::Result::Ok(header::IntoHeaderValue(hdr_values))
},
std::result::Result::Err(e) => std::result::Result::Err(format!("Unable to parse header: {hdr_values:?} as a string - {e}")),
}
}
}