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
// Generated from definition com.github.openshift.api.build.v1.GitBuildSource

/// GitBuildSource defines the parameters of a Git SCM
#[derive(Clone, Debug, Default, PartialEq)]
pub struct GitBuildSource {
    /// httpProxy is a proxy used to reach the git repository over http
    pub http_proxy: Option<String>,

    /// httpsProxy is a proxy used to reach the git repository over https
    pub https_proxy: Option<String>,

    /// noProxy is the list of domains for which the proxy should not be used
    pub no_proxy: Option<String>,

    /// ref is the branch/tag/ref to build.
    pub ref_: Option<String>,

    /// uri points to the source that will be built. The structure of the source will depend on the type of build to run
    pub uri: String,
}

impl<'de> serde::Deserialize<'de> for GitBuildSource {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de> {
        #[allow(non_camel_case_types)]
        enum Field {
            Key_http_proxy,
            Key_https_proxy,
            Key_no_proxy,
            Key_ref_,
            Key_uri,
            Other,
        }

        impl<'de> serde::Deserialize<'de> for Field {
            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de> {
                struct Visitor;

                impl<'de> serde::de::Visitor<'de> for Visitor {
                    type Value = Field;

                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
                        f.write_str("field identifier")
                    }

                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: serde::de::Error {
                        Ok(match v {
                            "httpProxy" => Field::Key_http_proxy,
                            "httpsProxy" => Field::Key_https_proxy,
                            "noProxy" => Field::Key_no_proxy,
                            "ref" => Field::Key_ref_,
                            "uri" => Field::Key_uri,
                            _ => Field::Other,
                        })
                    }
                }

                deserializer.deserialize_identifier(Visitor)
            }
        }

        struct Visitor;

        impl<'de> serde::de::Visitor<'de> for Visitor {
            type Value = GitBuildSource;

            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
                f.write_str("GitBuildSource")
            }

            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: serde::de::MapAccess<'de> {
                let mut value_http_proxy: Option<String> = None;
                let mut value_https_proxy: Option<String> = None;
                let mut value_no_proxy: Option<String> = None;
                let mut value_ref_: Option<String> = None;
                let mut value_uri: Option<String> = None;

                while let Some(key) = serde::de::MapAccess::next_key::<Field>(&mut map)? {
                    match key {
                        Field::Key_http_proxy => value_http_proxy = serde::de::MapAccess::next_value(&mut map)?,
                        Field::Key_https_proxy => value_https_proxy = serde::de::MapAccess::next_value(&mut map)?,
                        Field::Key_no_proxy => value_no_proxy = serde::de::MapAccess::next_value(&mut map)?,
                        Field::Key_ref_ => value_ref_ = serde::de::MapAccess::next_value(&mut map)?,
                        Field::Key_uri => value_uri = Some(serde::de::MapAccess::next_value(&mut map)?),
                        Field::Other => { let _: serde::de::IgnoredAny = serde::de::MapAccess::next_value(&mut map)?; },
                    }
                }

                Ok(GitBuildSource {
                    http_proxy: value_http_proxy,
                    https_proxy: value_https_proxy,
                    no_proxy: value_no_proxy,
                    ref_: value_ref_,
                    uri: value_uri.ok_or_else(|| serde::de::Error::missing_field("uri"))?,
                })
            }
        }

        deserializer.deserialize_struct(
            "GitBuildSource",
            &[
                "httpProxy",
                "httpsProxy",
                "noProxy",
                "ref",
                "uri",
            ],
            Visitor,
        )
    }
}

impl serde::Serialize for GitBuildSource {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer {
        let mut state = serializer.serialize_struct(
            "GitBuildSource",
            1 +
            self.http_proxy.as_ref().map_or(0, |_| 1) +
            self.https_proxy.as_ref().map_or(0, |_| 1) +
            self.no_proxy.as_ref().map_or(0, |_| 1) +
            self.ref_.as_ref().map_or(0, |_| 1),
        )?;
        if let Some(value) = &self.http_proxy {
            serde::ser::SerializeStruct::serialize_field(&mut state, "httpProxy", value)?;
        }
        if let Some(value) = &self.https_proxy {
            serde::ser::SerializeStruct::serialize_field(&mut state, "httpsProxy", value)?;
        }
        if let Some(value) = &self.no_proxy {
            serde::ser::SerializeStruct::serialize_field(&mut state, "noProxy", value)?;
        }
        if let Some(value) = &self.ref_ {
            serde::ser::SerializeStruct::serialize_field(&mut state, "ref", value)?;
        }
        serde::ser::SerializeStruct::serialize_field(&mut state, "uri", &self.uri)?;
        serde::ser::SerializeStruct::end(state)
    }
}