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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
use conjure_object::serde::ser::SerializeStruct as SerializeStruct_;
use conjure_object::serde::{de, ser};
use std::fmt;
#[doc = "The JSON-serializable representation of an error."]
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
pub struct SerializableError {
    error_code: super::ErrorCode,
    error_name: String,
    error_instance_id: conjure_object::Uuid,
    parameters: std::collections::BTreeMap<String, String>,
}
impl SerializableError {
    #[doc = r" Returns a new builder."]
    #[inline]
    pub fn builder() -> Builder {
        Default::default()
    }
    #[doc = "The broad category of the error."]
    #[doc = ""]
    #[doc = "When transmitted over HTTP, this determines the response's status code."]
    #[inline]
    pub fn error_code(&self) -> &super::ErrorCode {
        &self.error_code
    }
    #[doc = "The error's name."]
    #[doc = ""]
    #[doc = "The name is made up of a namespace and more specific error name, separated by a `:`."]
    #[inline]
    pub fn error_name(&self) -> &str {
        &*self.error_name
    }
    #[doc = "A unique identifier for this error instance."]
    #[doc = ""]
    #[doc = "This can be used to correlate reporting about the error as it transfers between components of a"]
    #[doc = "distributed system."]
    #[inline]
    pub fn error_instance_id(&self) -> conjure_object::Uuid {
        self.error_instance_id
    }
    #[doc = "Parameters providing more information about the error."]
    #[inline]
    pub fn parameters(&self) -> &std::collections::BTreeMap<String, String> {
        &self.parameters
    }
}
#[doc = "A builder for the `SerializableError` type."]
#[derive(Debug, Clone, Default)]
pub struct Builder {
    error_code: Option<super::ErrorCode>,
    error_name: Option<String>,
    error_instance_id: Option<conjure_object::Uuid>,
    parameters: std::collections::BTreeMap<String, String>,
}
impl Builder {
    #[doc = "The broad category of the error."]
    #[doc = ""]
    #[doc = "When transmitted over HTTP, this determines the response's status code."]
    #[doc = r""]
    #[doc = r" Required."]
    #[inline]
    pub fn error_code(&mut self, error_code: super::ErrorCode) -> &mut Self {
        self.error_code = Some(error_code);
        self
    }
    #[doc = "The error's name."]
    #[doc = ""]
    #[doc = "The name is made up of a namespace and more specific error name, separated by a `:`."]
    #[doc = r""]
    #[doc = r" Required."]
    pub fn error_name<T>(&mut self, error_name: T) -> &mut Self
    where
        T: Into<String>,
    {
        self.error_name = Some(error_name.into());
        self
    }
    #[doc = "A unique identifier for this error instance."]
    #[doc = ""]
    #[doc = "This can be used to correlate reporting about the error as it transfers between components of a"]
    #[doc = "distributed system."]
    #[doc = r""]
    #[doc = r" Required."]
    #[inline]
    pub fn error_instance_id(&mut self, error_instance_id: conjure_object::Uuid) -> &mut Self {
        self.error_instance_id = Some(error_instance_id);
        self
    }
    #[doc = "Parameters providing more information about the error."]
    pub fn parameters<T>(&mut self, parameters: T) -> &mut Self
    where
        T: IntoIterator<Item = (String, String)>,
    {
        self.parameters = parameters.into_iter().collect();
        self
    }
    #[doc = "Parameters providing more information about the error."]
    pub fn extend_parameters<T>(&mut self, parameters: T) -> &mut Self
    where
        T: IntoIterator<Item = (String, String)>,
    {
        self.parameters.extend(parameters);
        self
    }
    #[doc = "Parameters providing more information about the error."]
    pub fn insert_parameters<K, V>(&mut self, key: K, value: V) -> &mut Self
    where
        K: Into<String>,
        V: Into<String>,
    {
        self.parameters.insert(key.into(), value.into());
        self
    }
    #[doc = r" Constructs a new instance of the type."]
    #[doc = r""]
    #[doc = r" # Panics"]
    #[doc = r""]
    #[doc = r" Panics if a required field was not set."]
    #[inline]
    pub fn build(&self) -> SerializableError {
        SerializableError {
            error_code: self
                .error_code
                .clone()
                .expect("field error_code was not set"),
            error_name: self
                .error_name
                .clone()
                .expect("field error_name was not set"),
            error_instance_id: self
                .error_instance_id
                .clone()
                .expect("field error_instance_id was not set"),
            parameters: self.parameters.clone(),
        }
    }
}
impl From<SerializableError> for Builder {
    #[inline]
    fn from(_v: SerializableError) -> Builder {
        Builder {
            error_code: Some(_v.error_code),
            error_name: Some(_v.error_name),
            error_instance_id: Some(_v.error_instance_id),
            parameters: _v.parameters,
        }
    }
}
impl ser::Serialize for SerializableError {
    fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
    where
        S: ser::Serializer,
    {
        let mut size = 3usize;
        let skip_parameters = self.parameters.is_empty();
        if !skip_parameters {
            size += 1;
        }
        let mut s = s.serialize_struct("SerializableError", size)?;
        s.serialize_field("errorCode", &self.error_code)?;
        s.serialize_field("errorName", &self.error_name)?;
        s.serialize_field("errorInstanceId", &self.error_instance_id)?;
        if skip_parameters {
            s.skip_field("parameters")?;
        } else {
            s.serialize_field("parameters", &self.parameters)?;
        }
        s.end()
    }
}
impl<'de> de::Deserialize<'de> for SerializableError {
    fn deserialize<D>(d: D) -> Result<SerializableError, D::Error>
    where
        D: de::Deserializer<'de>,
    {
        d.deserialize_struct(
            "SerializableError",
            &["errorCode", "errorName", "errorInstanceId", "parameters"],
            Visitor_,
        )
    }
}
struct Visitor_;
impl<'de> de::Visitor<'de> for Visitor_ {
    type Value = SerializableError;
    fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
        fmt.write_str("map")
    }
    fn visit_map<A>(self, mut map_: A) -> Result<SerializableError, A::Error>
    where
        A: de::MapAccess<'de>,
    {
        let mut error_code = None;
        let mut error_name = None;
        let mut error_instance_id = None;
        let mut parameters = None;
        while let Some(field_) = map_.next_key()? {
            match field_ {
                Field_::ErrorCode => error_code = Some(map_.next_value()?),
                Field_::ErrorName => error_name = Some(map_.next_value()?),
                Field_::ErrorInstanceId => error_instance_id = Some(map_.next_value()?),
                Field_::Parameters => parameters = Some(map_.next_value()?),
                Field_::Unknown_ => {
                    map_.next_value::<de::IgnoredAny>()?;
                }
            }
        }
        let error_code = match error_code {
            Some(v) => v,
            None => return Err(de::Error::missing_field("errorCode")),
        };
        let error_name = match error_name {
            Some(v) => v,
            None => return Err(de::Error::missing_field("errorName")),
        };
        let error_instance_id = match error_instance_id {
            Some(v) => v,
            None => return Err(de::Error::missing_field("errorInstanceId")),
        };
        let parameters = match parameters {
            Some(v) => v,
            None => Default::default(),
        };
        Ok(SerializableError {
            error_code,
            error_name,
            error_instance_id,
            parameters,
        })
    }
}
enum Field_ {
    ErrorCode,
    ErrorName,
    ErrorInstanceId,
    Parameters,
    Unknown_,
}
impl<'de> de::Deserialize<'de> for Field_ {
    fn deserialize<D>(d: D) -> Result<Field_, D::Error>
    where
        D: de::Deserializer<'de>,
    {
        d.deserialize_str(FieldVisitor_)
    }
}
struct FieldVisitor_;
impl<'de> de::Visitor<'de> for FieldVisitor_ {
    type Value = Field_;
    fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
        fmt.write_str("string")
    }
    fn visit_str<E>(self, value: &str) -> Result<Field_, E>
    where
        E: de::Error,
    {
        let v = match value {
            "errorCode" => Field_::ErrorCode,
            "errorName" => Field_::ErrorName,
            "errorInstanceId" => Field_::ErrorInstanceId,
            "parameters" => Field_::Parameters,
            _ => Field_::Unknown_,
        };
        Ok(v)
    }
}