1use serde::{Deserialize, Serialize};
19use serde_json::Value;
20use std::collections::HashMap;
21use clap::ValueEnum;
22
23#[derive(ValueEnum, Clone, Debug, Serialize, Deserialize)]
24#[serde(rename_all = "lowercase")]
25pub enum Method {
26 #[serde(alias = "Get", alias = "GET")]
27 Get,
28 #[serde(alias = "Post", alias = "POST")]
29 Post,
30 #[serde(alias = "Put", alias = "PUT")]
31 Put,
32 #[serde(alias = "Delete", alias = "DELETE")]
33 Delete,
34 #[serde(alias = "Patch", alias = "PATCH")]
35 Patch,
36}
37
38#[derive(ValueEnum, Clone, Debug, Serialize, Deserialize)]
39#[serde(rename_all = "lowercase")]
40pub enum Scheme {
41 #[serde(alias = "Http", alias = "HTTP")]
42 Http,
43 #[serde(alias = "Https", alias = "HTTPS")]
44 Https,
45}
46
47impl std::fmt::Display for Scheme {
48 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
49 match self {
50 Scheme::Http => write!(f, "http"),
51 Scheme::Https => write!(f, "https"),
52 }
53 }
54}
55
56#[derive(Serialize, Deserialize, Debug)]
57pub struct Config {
58 pub capture: Option<Capture>,
59 pub run: Vec<Run>,
60}
61
62#[derive(Serialize, Deserialize, Debug)]
63pub struct Capture {
64 pub env_file: Option<std::path::PathBuf>,
65 pub environment_variables: Option<HashMap<String, String>>,
66 pub request: Option<Vec<CaptureRequest>>,
67}
68
69#[derive(Serialize, Deserialize, Debug)]
70#[serde(rename = "request")]
71pub struct CaptureRequest {
72 pub name: Option<String>,
73 pub headers: Option<HashMap<String, String>>,
74 pub method: Method,
75 pub scheme: Scheme,
76 pub host: String,
77 pub port: Option<u16>,
78 pub path: Option<String>,
79 pub body: Option<String>,
80 pub capture: Option<HashMap<String, String>>,
81}
82
83#[derive(Serialize, Deserialize, Debug)]
85pub struct Run {
86 pub name: String,
87 pub headers: Option<HashMap<String, String>>,
89 pub method: Option<Method>,
90 pub scheme: Option<Scheme>,
91 pub host: Option<String>,
92 pub port: Option<u16>,
93 pub path: Option<String>,
94 pub body: Option<String>,
95
96 pub request: Vec<Request>,
97}
98
99#[derive(Serialize, Deserialize, Debug)]
100pub struct Request {
101 pub name: String,
102 pub headers: Option<HashMap<String, String>>,
103 pub method: Option<Method>,
104 pub scheme: Option<Scheme>,
105 pub host: Option<String>,
106 pub port: Option<u16>,
107 pub path: Option<String>,
108 pub body: Option<String>,
109
110 pub capture: Option<HashMap<String, String>>,
111 pub assert: Option<Assert>,
112}
113
114#[derive(Serialize, Deserialize, Debug)]
115pub struct Assert {
116 #[serde(default)]
117 pub breaking: bool,
118 pub status: Option<u16>,
119 pub body_matches: Option<HashMap<String, Value>>,
120 pub subset_matches: Option<HashMap<String, Value>>,
121 pub subset_includes: Option<Vec<String>>,
122 pub subset_regex: Option<HashMap<String, Value>>,
123}