Skip to main content

mockserver_client/
model.rs

1//! Domain model types for the MockServer control-plane API.
2//!
3//! All types implement `Serialize`/`Deserialize` and use builder methods that
4//! take `self` and return `Self`, enabling fluent construction.
5
6use serde::{Deserialize, Serialize};
7use std::collections::HashMap;
8
9// ---------------------------------------------------------------------------
10// HttpRequest
11// ---------------------------------------------------------------------------
12
13/// Matcher for an HTTP request. Uses builder methods for fluent construction.
14///
15/// # Example
16/// ```
17/// use mockserver_client::HttpRequest;
18///
19/// let request = HttpRequest::new()
20///     .method("POST")
21///     .path("/api/users")
22///     .header("Content-Type", "application/json")
23///     .query_param("page", "1")
24///     .body("{}");
25/// ```
26#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
27#[serde(rename_all = "camelCase")]
28pub struct HttpRequest {
29    #[serde(skip_serializing_if = "Option::is_none")]
30    pub method: Option<String>,
31
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub path: Option<String>,
34
35    #[serde(skip_serializing_if = "Option::is_none")]
36    pub query_string_parameters: Option<HashMap<String, Vec<String>>>,
37
38    #[serde(skip_serializing_if = "Option::is_none")]
39    pub headers: Option<HashMap<String, Vec<String>>>,
40
41    #[serde(skip_serializing_if = "Option::is_none")]
42    pub body: Option<Body>,
43}
44
45impl HttpRequest {
46    /// Create a new empty request matcher.
47    pub fn new() -> Self {
48        Self::default()
49    }
50
51    /// Set the HTTP method to match.
52    pub fn method(mut self, method: impl Into<String>) -> Self {
53        self.method = Some(method.into());
54        self
55    }
56
57    /// Set the path to match.
58    pub fn path(mut self, path: impl Into<String>) -> Self {
59        self.path = Some(path.into());
60        self
61    }
62
63    /// Add a query string parameter (multiple values per key supported).
64    pub fn query_param(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
65        let params = self.query_string_parameters.get_or_insert_with(HashMap::new);
66        params
67            .entry(key.into())
68            .or_default()
69            .push(value.into());
70        self
71    }
72
73    /// Add a header (multiple values per key supported).
74    pub fn header(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
75        let headers = self.headers.get_or_insert_with(HashMap::new);
76        headers
77            .entry(key.into())
78            .or_default()
79            .push(value.into());
80        self
81    }
82
83    /// Set a plain string body matcher.
84    pub fn body(mut self, body: impl Into<String>) -> Self {
85        self.body = Some(Body::Plain(body.into()));
86        self
87    }
88
89    /// Set a typed JSON body matcher.
90    pub fn json_body(mut self, json: serde_json::Value) -> Self {
91        self.body = Some(Body::Typed {
92            body_type: "JSON".to_string(),
93            json: json.to_string(),
94        });
95        self
96    }
97
98    /// Set a file body (type "FILE") with optional content type and template type.
99    ///
100    /// Use [`Body::file`] for richer construction if you need content type or
101    /// template type set.
102    pub fn file_body(mut self, file_path: impl Into<String>) -> Self {
103        self.body = Some(Body::File {
104            file_path: file_path.into(),
105            content_type: None,
106            template_type: None,
107        });
108        self
109    }
110
111    /// Set a pre-built [`Body`] value (use with [`Body::file`] for FILE bodies).
112    pub fn body_value(mut self, body: Body) -> Self {
113        self.body = Some(body);
114        self
115    }
116}
117
118// ---------------------------------------------------------------------------
119// Body
120// ---------------------------------------------------------------------------
121
122/// Request/response body — either a plain string, a typed object, or a file reference.
123#[derive(Debug, Clone, PartialEq)]
124pub enum Body {
125    /// A plain string body.
126    Plain(String),
127    /// A typed body (e.g., JSON).
128    Typed { body_type: String, json: String },
129    /// A file body (`type: "FILE"`), with optional template evaluation.
130    File {
131        file_path: String,
132        content_type: Option<String>,
133        template_type: Option<String>,
134    },
135}
136
137impl Body {
138    /// Create a FILE body referencing a path on the server filesystem.
139    ///
140    /// # Example
141    /// ```
142    /// use mockserver_client::Body;
143    ///
144    /// let body = Body::file("/data/response.json")
145    ///     .with_content_type("application/json")
146    ///     .with_template_type("VELOCITY");
147    /// ```
148    pub fn file(file_path: impl Into<String>) -> Self {
149        Body::File {
150            file_path: file_path.into(),
151            content_type: None,
152            template_type: None,
153        }
154    }
155
156    /// Set the content type on a FILE body. No-op on other variants.
157    pub fn with_content_type(mut self, content_type: impl Into<String>) -> Self {
158        if let Body::File {
159            content_type: ref mut ct,
160            ..
161        } = self
162        {
163            *ct = Some(content_type.into());
164        }
165        self
166    }
167
168    /// Set the template type (e.g., "VELOCITY", "MUSTACHE") on a FILE body.
169    /// No-op on other variants.
170    pub fn with_template_type(mut self, template_type: impl Into<String>) -> Self {
171        if let Body::File {
172            template_type: ref mut tt,
173            ..
174        } = self
175        {
176            *tt = Some(template_type.into());
177        }
178        self
179    }
180}
181
182impl Serialize for Body {
183    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
184    where
185        S: serde::Serializer,
186    {
187        match self {
188            Body::Plain(s) => serializer.serialize_str(s),
189            Body::Typed { body_type, json } => {
190                use serde::ser::SerializeMap;
191                let mut map = serializer.serialize_map(Some(2))?;
192                map.serialize_entry("type", body_type)?;
193                map.serialize_entry("json", json)?;
194                map.end()
195            }
196            Body::File {
197                file_path,
198                content_type,
199                template_type,
200            } => {
201                use serde::ser::SerializeMap;
202                let count = 2
203                    + content_type.as_ref().map_or(0, |_| 1)
204                    + template_type.as_ref().map_or(0, |_| 1);
205                let mut map = serializer.serialize_map(Some(count))?;
206                map.serialize_entry("type", "FILE")?;
207                map.serialize_entry("filePath", file_path)?;
208                if let Some(ct) = content_type {
209                    map.serialize_entry("contentType", ct)?;
210                }
211                if let Some(tt) = template_type {
212                    map.serialize_entry("templateType", tt)?;
213                }
214                map.end()
215            }
216        }
217    }
218}
219
220impl<'de> Deserialize<'de> for Body {
221    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
222    where
223        D: serde::Deserializer<'de>,
224    {
225        use serde_json::Value;
226        let v = Value::deserialize(deserializer)?;
227        match v {
228            Value::String(s) => Ok(Body::Plain(s)),
229            Value::Object(map) => {
230                let body_type = map
231                    .get("type")
232                    .and_then(|v| v.as_str())
233                    .unwrap_or("JSON")
234                    .to_string();
235                if body_type == "FILE" {
236                    let file_path = map
237                        .get("filePath")
238                        .and_then(|v| v.as_str())
239                        .unwrap_or("")
240                        .to_string();
241                    let content_type = map
242                        .get("contentType")
243                        .and_then(|v| v.as_str())
244                        .map(|s| s.to_string());
245                    let template_type = map
246                        .get("templateType")
247                        .and_then(|v| v.as_str())
248                        .map(|s| s.to_string());
249                    Ok(Body::File {
250                        file_path,
251                        content_type,
252                        template_type,
253                    })
254                } else {
255                    let json = map
256                        .get("json")
257                        .and_then(|v| v.as_str())
258                        .unwrap_or("")
259                        .to_string();
260                    Ok(Body::Typed { body_type, json })
261                }
262            }
263            _ => Ok(Body::Plain(v.to_string())),
264        }
265    }
266}
267
268// ---------------------------------------------------------------------------
269// HttpResponse
270// ---------------------------------------------------------------------------
271
272/// Builder for an HTTP response action.
273///
274/// # Example
275/// ```
276/// use mockserver_client::HttpResponse;
277///
278/// let response = HttpResponse::new()
279///     .status_code(201)
280///     .header("Location", "/api/users/42")
281///     .body("{\"id\": 42}");
282/// ```
283#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
284#[serde(rename_all = "camelCase")]
285pub struct HttpResponse {
286    #[serde(skip_serializing_if = "Option::is_none")]
287    pub status_code: Option<u16>,
288
289    #[serde(skip_serializing_if = "Option::is_none")]
290    pub headers: Option<HashMap<String, Vec<String>>>,
291
292    #[serde(skip_serializing_if = "Option::is_none")]
293    pub body: Option<String>,
294
295    #[serde(skip_serializing_if = "Option::is_none")]
296    pub delay: Option<Delay>,
297}
298
299impl HttpResponse {
300    /// Create a new empty response.
301    pub fn new() -> Self {
302        Self::default()
303    }
304
305    /// Set the HTTP status code.
306    pub fn status_code(mut self, code: u16) -> Self {
307        self.status_code = Some(code);
308        self
309    }
310
311    /// Add a response header.
312    pub fn header(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
313        let headers = self.headers.get_or_insert_with(HashMap::new);
314        headers
315            .entry(key.into())
316            .or_default()
317            .push(value.into());
318        self
319    }
320
321    /// Set the response body as a string.
322    pub fn body(mut self, body: impl Into<String>) -> Self {
323        self.body = Some(body.into());
324        self
325    }
326
327    /// Set a response delay.
328    pub fn delay(mut self, delay: Delay) -> Self {
329        self.delay = Some(delay);
330        self
331    }
332}
333
334// ---------------------------------------------------------------------------
335// HttpTemplate (response or forward)
336// ---------------------------------------------------------------------------
337
338/// Template action — evaluate a response or forward template (Velocity, Mustache, etc.).
339///
340/// Used as `httpResponseTemplate` or `httpForwardTemplate` in an expectation.
341///
342/// # Example
343/// ```
344/// use mockserver_client::HttpTemplate;
345///
346/// let tmpl = HttpTemplate::new("VELOCITY", "{ \"statusCode\": 200 }")
347///     .template_file("/path/to/template.vm");
348/// ```
349#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
350#[serde(rename_all = "camelCase")]
351pub struct HttpTemplate {
352    #[serde(skip_serializing_if = "Option::is_none")]
353    pub template_type: Option<String>,
354
355    #[serde(skip_serializing_if = "Option::is_none")]
356    pub template: Option<String>,
357
358    #[serde(skip_serializing_if = "Option::is_none")]
359    pub template_file: Option<String>,
360}
361
362impl HttpTemplate {
363    /// Create a template action with the given type and inline template body.
364    pub fn new(template_type: impl Into<String>, template: impl Into<String>) -> Self {
365        Self {
366            template_type: Some(template_type.into()),
367            template: Some(template.into()),
368            template_file: None,
369        }
370    }
371
372    /// Create a template action that loads from a file path.
373    pub fn from_file(template_type: impl Into<String>, file_path: impl Into<String>) -> Self {
374        Self {
375            template_type: Some(template_type.into()),
376            template: None,
377            template_file: Some(file_path.into()),
378        }
379    }
380
381    /// Set the template type (e.g., "VELOCITY", "MUSTACHE").
382    pub fn template_type(mut self, template_type: impl Into<String>) -> Self {
383        self.template_type = Some(template_type.into());
384        self
385    }
386
387    /// Set the inline template body.
388    pub fn template(mut self, template: impl Into<String>) -> Self {
389        self.template = Some(template.into());
390        self
391    }
392
393    /// Set the template file path (alternative to inline template).
394    pub fn template_file(mut self, file_path: impl Into<String>) -> Self {
395        self.template_file = Some(file_path.into());
396        self
397    }
398}
399
400// ---------------------------------------------------------------------------
401// HttpForward
402// ---------------------------------------------------------------------------
403
404/// Forward action — proxy the matched request to another host.
405///
406/// # Example
407/// ```
408/// use mockserver_client::HttpForward;
409///
410/// let forward = HttpForward::new("backend.local", 8080);
411/// ```
412#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
413#[serde(rename_all = "camelCase")]
414pub struct HttpForward {
415    pub host: String,
416
417    #[serde(skip_serializing_if = "Option::is_none")]
418    pub port: Option<u16>,
419
420    #[serde(skip_serializing_if = "Option::is_none")]
421    pub scheme: Option<String>,
422}
423
424impl HttpForward {
425    /// Create a forward action to the given host and port.
426    pub fn new(host: impl Into<String>, port: u16) -> Self {
427        Self {
428            host: host.into(),
429            port: Some(port),
430            scheme: None,
431        }
432    }
433
434    /// Set the scheme (HTTP or HTTPS).
435    pub fn scheme(mut self, scheme: impl Into<String>) -> Self {
436        self.scheme = Some(scheme.into());
437        self
438    }
439}
440
441// ---------------------------------------------------------------------------
442// HttpError
443// ---------------------------------------------------------------------------
444
445/// Error action — return a connection-level error to the caller.
446#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
447#[serde(rename_all = "camelCase")]
448pub struct HttpError {
449    #[serde(skip_serializing_if = "Option::is_none")]
450    pub drop_connection: Option<bool>,
451
452    #[serde(skip_serializing_if = "Option::is_none")]
453    pub response_bytes: Option<String>,
454}
455
456impl HttpError {
457    /// Create a new error action.
458    pub fn new() -> Self {
459        Self::default()
460    }
461
462    /// Drop the connection without a response.
463    pub fn drop_connection(mut self, drop: bool) -> Self {
464        self.drop_connection = Some(drop);
465        self
466    }
467
468    /// Send arbitrary bytes then close.
469    pub fn response_bytes(mut self, bytes: impl Into<String>) -> Self {
470        self.response_bytes = Some(bytes.into());
471        self
472    }
473}
474
475// ---------------------------------------------------------------------------
476// Delay
477// ---------------------------------------------------------------------------
478
479/// A time delay (e.g., for response delays).
480#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
481#[serde(rename_all = "camelCase")]
482pub struct Delay {
483    pub time_unit: String,
484    pub value: u64,
485}
486
487impl Delay {
488    /// Create a delay in milliseconds.
489    pub fn milliseconds(value: u64) -> Self {
490        Self {
491            time_unit: "MILLISECONDS".to_string(),
492            value,
493        }
494    }
495
496    /// Create a delay in seconds.
497    pub fn seconds(value: u64) -> Self {
498        Self {
499            time_unit: "SECONDS".to_string(),
500            value,
501        }
502    }
503}
504
505// ---------------------------------------------------------------------------
506// Times
507// ---------------------------------------------------------------------------
508
509/// How many times an expectation should be matched.
510#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
511#[serde(rename_all = "camelCase")]
512pub struct Times {
513    #[serde(skip_serializing_if = "Option::is_none")]
514    pub remaining_times: Option<u32>,
515
516    pub unlimited: bool,
517}
518
519impl Times {
520    /// Match unlimited times.
521    pub fn unlimited() -> Self {
522        Self {
523            remaining_times: None,
524            unlimited: true,
525        }
526    }
527
528    /// Match exactly `n` times.
529    pub fn exactly(n: u32) -> Self {
530        Self {
531            remaining_times: Some(n),
532            unlimited: false,
533        }
534    }
535
536    /// Match once.
537    pub fn once() -> Self {
538        Self::exactly(1)
539    }
540}
541
542// ---------------------------------------------------------------------------
543// TimeToLive
544// ---------------------------------------------------------------------------
545
546/// How long an expectation remains active.
547#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
548#[serde(rename_all = "camelCase")]
549pub struct TimeToLive {
550    #[serde(skip_serializing_if = "Option::is_none")]
551    pub time_unit: Option<String>,
552
553    #[serde(skip_serializing_if = "Option::is_none")]
554    pub time_to_live: Option<u64>,
555
556    pub unlimited: bool,
557}
558
559impl TimeToLive {
560    /// Unlimited TTL (never expires).
561    pub fn unlimited() -> Self {
562        Self {
563            time_unit: None,
564            time_to_live: None,
565            unlimited: true,
566        }
567    }
568
569    /// Expire after the given number of seconds.
570    pub fn seconds(seconds: u64) -> Self {
571        Self {
572            time_unit: Some("SECONDS".to_string()),
573            time_to_live: Some(seconds),
574            unlimited: false,
575        }
576    }
577
578    /// Expire after the given number of milliseconds.
579    pub fn milliseconds(millis: u64) -> Self {
580        Self {
581            time_unit: Some("MILLISECONDS".to_string()),
582            time_to_live: Some(millis),
583            unlimited: false,
584        }
585    }
586}
587
588// ---------------------------------------------------------------------------
589// VerificationTimes
590// ---------------------------------------------------------------------------
591
592/// Verification constraints — how many times a request must have been received.
593#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
594#[serde(rename_all = "camelCase")]
595pub struct VerificationTimes {
596    #[serde(skip_serializing_if = "Option::is_none")]
597    pub at_least: Option<u32>,
598
599    #[serde(skip_serializing_if = "Option::is_none")]
600    pub at_most: Option<u32>,
601}
602
603impl VerificationTimes {
604    /// Require at least `n` matching requests.
605    pub fn at_least(n: u32) -> Self {
606        Self {
607            at_least: Some(n),
608            at_most: None,
609        }
610    }
611
612    /// Require at most `n` matching requests.
613    pub fn at_most(n: u32) -> Self {
614        Self {
615            at_least: None,
616            at_most: Some(n),
617        }
618    }
619
620    /// Require exactly `n` matching requests.
621    pub fn exactly(n: u32) -> Self {
622        Self {
623            at_least: Some(n),
624            at_most: Some(n),
625        }
626    }
627
628    /// Require between `min` and `max` matching requests (inclusive).
629    pub fn between(min: u32, max: u32) -> Self {
630        Self {
631            at_least: Some(min),
632            at_most: Some(max),
633        }
634    }
635}
636
637// ---------------------------------------------------------------------------
638// Expectation
639// ---------------------------------------------------------------------------
640
641/// A full expectation combining a request matcher with an action.
642#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
643#[serde(rename_all = "camelCase")]
644pub struct Expectation {
645    #[serde(skip_serializing_if = "Option::is_none")]
646    pub id: Option<String>,
647
648    #[serde(skip_serializing_if = "Option::is_none")]
649    pub priority: Option<i32>,
650
651    pub http_request: HttpRequest,
652
653    #[serde(skip_serializing_if = "Option::is_none")]
654    pub http_response: Option<HttpResponse>,
655
656    #[serde(skip_serializing_if = "Option::is_none")]
657    pub http_forward: Option<HttpForward>,
658
659    #[serde(skip_serializing_if = "Option::is_none")]
660    pub http_response_template: Option<HttpTemplate>,
661
662    #[serde(skip_serializing_if = "Option::is_none")]
663    pub http_forward_template: Option<HttpTemplate>,
664
665    #[serde(skip_serializing_if = "Option::is_none")]
666    pub http_error: Option<HttpError>,
667
668    #[serde(skip_serializing_if = "Option::is_none")]
669    pub times: Option<Times>,
670
671    #[serde(skip_serializing_if = "Option::is_none")]
672    pub time_to_live: Option<TimeToLive>,
673}
674
675impl Expectation {
676    /// Create a new expectation with the given request matcher.
677    pub fn new(request: HttpRequest) -> Self {
678        Self {
679            http_request: request,
680            ..Default::default()
681        }
682    }
683
684    /// Set the expectation ID (for upsert semantics).
685    pub fn id(mut self, id: impl Into<String>) -> Self {
686        self.id = Some(id.into());
687        self
688    }
689
690    /// Set the priority (higher = matched first).
691    pub fn priority(mut self, priority: i32) -> Self {
692        self.priority = Some(priority);
693        self
694    }
695
696    /// Set a response action.
697    pub fn respond(mut self, response: HttpResponse) -> Self {
698        self.http_response = Some(response);
699        self
700    }
701
702    /// Set a forward action.
703    pub fn forward(mut self, forward: HttpForward) -> Self {
704        self.http_forward = Some(forward);
705        self
706    }
707
708    /// Set a response template action.
709    pub fn respond_template(mut self, template: HttpTemplate) -> Self {
710        self.http_response_template = Some(template);
711        self
712    }
713
714    /// Set a forward template action.
715    pub fn forward_template(mut self, template: HttpTemplate) -> Self {
716        self.http_forward_template = Some(template);
717        self
718    }
719
720    /// Set an error action.
721    pub fn error(mut self, error: HttpError) -> Self {
722        self.http_error = Some(error);
723        self
724    }
725
726    /// Set the number of times this expectation matches.
727    pub fn times(mut self, times: Times) -> Self {
728        self.times = Some(times);
729        self
730    }
731
732    /// Set the time-to-live.
733    pub fn time_to_live(mut self, ttl: TimeToLive) -> Self {
734        self.time_to_live = Some(ttl);
735        self
736    }
737}
738
739// ---------------------------------------------------------------------------
740// Verification
741// ---------------------------------------------------------------------------
742
743/// A verification request sent to MockServer.
744///
745/// At least one of `http_request` or `http_response` must be set.
746/// `http_response` uses the same [`HttpResponse`] type as expectations —
747/// the server matches against the recorded response's status code, headers,
748/// and body.
749#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
750#[serde(rename_all = "camelCase")]
751pub struct Verification {
752    #[serde(skip_serializing_if = "Option::is_none")]
753    pub http_request: Option<HttpRequest>,
754
755    #[serde(skip_serializing_if = "Option::is_none")]
756    pub http_response: Option<HttpResponse>,
757
758    #[serde(skip_serializing_if = "Option::is_none")]
759    pub times: Option<VerificationTimes>,
760
761    #[serde(skip_serializing_if = "Option::is_none")]
762    pub maximum_number_of_request_to_return_in_verification_failure: Option<u32>,
763}
764
765/// A verification sequence request.
766///
767/// `http_responses` is index-aligned with `http_requests` — each entry
768/// constrains the response that must have been returned for the
769/// corresponding request.
770#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
771#[serde(rename_all = "camelCase")]
772pub struct VerificationSequence {
773    #[serde(skip_serializing_if = "Option::is_none")]
774    pub http_requests: Option<Vec<HttpRequest>>,
775
776    #[serde(skip_serializing_if = "Option::is_none")]
777    pub http_responses: Option<Vec<HttpResponse>>,
778}
779
780// ---------------------------------------------------------------------------
781// Ports
782// ---------------------------------------------------------------------------
783
784/// Port list (used by status and bind endpoints).
785#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
786pub struct Ports {
787    pub ports: Vec<u16>,
788}
789
790// ---------------------------------------------------------------------------
791// Retrieve types
792// ---------------------------------------------------------------------------
793
794/// The type of data to retrieve from MockServer.
795#[derive(Debug, Clone, Copy, PartialEq, Eq)]
796pub enum RetrieveType {
797    /// Recorded inbound requests.
798    Requests,
799    /// Active (live) expectations.
800    ActiveExpectations,
801    /// Recorded expectations (from proxy mode).
802    RecordedExpectations,
803    /// Log messages.
804    Logs,
805    /// Request/response pairs.
806    RequestResponses,
807}
808
809impl RetrieveType {
810    /// The query parameter value for this type.
811    pub fn as_str(&self) -> &'static str {
812        match self {
813            RetrieveType::Requests => "REQUESTS",
814            RetrieveType::ActiveExpectations => "ACTIVE_EXPECTATIONS",
815            RetrieveType::RecordedExpectations => "RECORDED_EXPECTATIONS",
816            RetrieveType::Logs => "LOGS",
817            RetrieveType::RequestResponses => "REQUEST_RESPONSES",
818        }
819    }
820}
821
822/// The response format for retrieve calls.
823#[derive(Debug, Clone, Copy, PartialEq, Eq)]
824pub enum RetrieveFormat {
825    Json,
826    LogEntries,
827}
828
829impl RetrieveFormat {
830    /// The query parameter value for this format.
831    pub fn as_str(&self) -> &'static str {
832        match self {
833            RetrieveFormat::Json => "JSON",
834            RetrieveFormat::LogEntries => "LOG_ENTRIES",
835        }
836    }
837}
838
839/// The type of data to clear from MockServer.
840#[derive(Debug, Clone, Copy, PartialEq, Eq)]
841pub enum ClearType {
842    All,
843    Log,
844    Expectations,
845}
846
847impl ClearType {
848    /// The query parameter value for this type.
849    pub fn as_str(&self) -> &'static str {
850        match self {
851            ClearType::All => "ALL",
852            ClearType::Log => "LOG",
853            ClearType::Expectations => "EXPECTATIONS",
854        }
855    }
856}