openstack_sdk/api/network/v2/floatingip/tag/
delete.rs

1// Licensed under the Apache License, Version 2.0 (the "License");
2// you may not use this file except in compliance with the License.
3// You may obtain a copy of the License at
4//
5//     http://www.apache.org/licenses/LICENSE-2.0
6//
7// Unless required by applicable law or agreed to in writing, software
8// distributed under the License is distributed on an "AS IS" BASIS,
9// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10// See the License for the specific language governing permissions and
11// limitations under the License.
12//
13// SPDX-License-Identifier: Apache-2.0
14//
15// WARNING: This file is automatically generated from OpenAPI schema using
16// `openstack-codegenerator`.
17
18use derive_builder::Builder;
19use http::{HeaderMap, HeaderName, HeaderValue};
20
21use crate::api::rest_endpoint_prelude::*;
22
23use std::borrow::Cow;
24
25#[derive(Builder, Debug, Clone)]
26#[builder(setter(strip_option))]
27pub struct Request<'a> {
28    /// floatingip_id parameter for /v2.0/floatingips/{floatingip_id}/tags/{id}
29    /// API
30    #[builder(default, setter(into))]
31    floatingip_id: Cow<'a, str>,
32
33    /// id parameter for /v2.0/floatingips/{floatingip_id}/tags/{id} API
34    #[builder(default, setter(into))]
35    id: Cow<'a, str>,
36
37    #[builder(setter(name = "_headers"), default, private)]
38    _headers: Option<HeaderMap>,
39}
40impl<'a> Request<'a> {
41    /// Create a builder for the endpoint.
42    pub fn builder() -> RequestBuilder<'a> {
43        RequestBuilder::default()
44    }
45}
46
47impl<'a> RequestBuilder<'a> {
48    /// Add a single header to the Tag.
49    pub fn header<K, V>(&mut self, header_name: K, header_value: V) -> &mut Self
50    where
51        K: Into<HeaderName>,
52        V: Into<HeaderValue>,
53    {
54        self._headers
55            .get_or_insert(None)
56            .get_or_insert_with(HeaderMap::new)
57            .insert(header_name.into(), header_value.into());
58        self
59    }
60
61    /// Add multiple headers.
62    pub fn headers<I, T>(&mut self, iter: I) -> &mut Self
63    where
64        I: Iterator<Item = T>,
65        T: Into<(Option<HeaderName>, HeaderValue)>,
66    {
67        self._headers
68            .get_or_insert(None)
69            .get_or_insert_with(HeaderMap::new)
70            .extend(iter.map(Into::into));
71        self
72    }
73}
74
75impl RestEndpoint for Request<'_> {
76    fn method(&self) -> http::Method {
77        http::Method::DELETE
78    }
79
80    fn endpoint(&self) -> Cow<'static, str> {
81        format!(
82            "floatingips/{floatingip_id}/tags/{id}",
83            floatingip_id = self.floatingip_id.as_ref(),
84            id = self.id.as_ref(),
85        )
86        .into()
87    }
88
89    fn parameters(&self) -> QueryParams<'_> {
90        QueryParams::default()
91    }
92
93    fn service_type(&self) -> ServiceType {
94        ServiceType::Network
95    }
96
97    fn response_key(&self) -> Option<Cow<'static, str>> {
98        None
99    }
100
101    /// Returns headers to be set into the request
102    fn request_headers(&self) -> Option<&HeaderMap> {
103        self._headers.as_ref()
104    }
105
106    /// Returns required API version
107    fn api_version(&self) -> Option<ApiVersion> {
108        Some(ApiVersion::new(2, 0))
109    }
110}
111
112#[cfg(test)]
113mod tests {
114    use super::*;
115    #[cfg(feature = "sync")]
116    use crate::api::Query;
117    use crate::test::client::FakeOpenStackClient;
118    use crate::types::ServiceType;
119    use http::{HeaderName, HeaderValue};
120    use httpmock::MockServer;
121    use serde_json::json;
122
123    #[test]
124    fn test_service_type() {
125        assert_eq!(
126            Request::builder().build().unwrap().service_type(),
127            ServiceType::Network
128        );
129    }
130
131    #[test]
132    fn test_response_key() {
133        assert!(Request::builder().build().unwrap().response_key().is_none())
134    }
135
136    #[cfg(feature = "sync")]
137    #[test]
138    fn endpoint() {
139        let server = MockServer::start();
140        let client = FakeOpenStackClient::new(server.base_url());
141        let mock = server.mock(|when, then| {
142            when.method(httpmock::Method::DELETE).path(format!(
143                "/floatingips/{floatingip_id}/tags/{id}",
144                floatingip_id = "floatingip_id",
145                id = "id",
146            ));
147
148            then.status(200)
149                .header("content-type", "application/json")
150                .json_body(json!({ "dummy": {} }));
151        });
152
153        let endpoint = Request::builder()
154            .floatingip_id("floatingip_id")
155            .id("id")
156            .build()
157            .unwrap();
158        let _: serde_json::Value = endpoint.query(&client).unwrap();
159        mock.assert();
160    }
161
162    #[cfg(feature = "sync")]
163    #[test]
164    fn endpoint_headers() {
165        let server = MockServer::start();
166        let client = FakeOpenStackClient::new(server.base_url());
167        let mock = server.mock(|when, then| {
168            when.method(httpmock::Method::DELETE)
169                .path(format!(
170                    "/floatingips/{floatingip_id}/tags/{id}",
171                    floatingip_id = "floatingip_id",
172                    id = "id",
173                ))
174                .header("foo", "bar")
175                .header("not_foo", "not_bar");
176            then.status(200)
177                .header("content-type", "application/json")
178                .json_body(json!({ "dummy": {} }));
179        });
180
181        let endpoint = Request::builder()
182            .floatingip_id("floatingip_id")
183            .id("id")
184            .headers(
185                [(
186                    Some(HeaderName::from_static("foo")),
187                    HeaderValue::from_static("bar"),
188                )]
189                .into_iter(),
190            )
191            .header(
192                HeaderName::from_static("not_foo"),
193                HeaderValue::from_static("not_bar"),
194            )
195            .build()
196            .unwrap();
197        let _: serde_json::Value = endpoint.query(&client).unwrap();
198        mock.assert();
199    }
200}