1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3
4#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
5pub struct CachedSpec {
6 pub cache_format_version: u32,
8 pub name: String,
9 pub version: String,
10 pub commands: Vec<CachedCommand>,
11 pub base_url: Option<String>,
13 pub servers: Vec<String>,
15 pub security_schemes: HashMap<String, CachedSecurityScheme>,
17 #[serde(default)]
19 pub skipped_endpoints: Vec<SkippedEndpoint>,
20 #[serde(default)]
22 pub server_variables: HashMap<String, ServerVariable>,
23}
24
25impl CachedSpec {
26 #[cfg(test)]
28 #[must_use]
29 pub fn new_for_test(name: &str) -> Self {
30 Self {
31 cache_format_version: CACHE_FORMAT_VERSION,
32 name: name.to_string(),
33 version: "1.0.0".to_string(),
34 commands: vec![],
35 base_url: None,
36 servers: vec![],
37 security_schemes: HashMap::new(),
38 skipped_endpoints: vec![],
39 server_variables: HashMap::new(),
40 }
41 }
42}
43
44#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
46pub struct CommandExample {
47 pub description: String,
49 pub command_line: String,
51 pub explanation: Option<String>,
53}
54
55#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
57pub struct SkippedEndpoint {
58 pub path: String,
59 pub method: String,
60 pub content_type: String,
61 pub reason: String,
62}
63
64pub const CACHE_FORMAT_VERSION: u32 = 5;
71
72#[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
74pub struct GlobalCacheMetadata {
75 pub cache_format_version: u32,
77 pub specs: std::collections::HashMap<String, SpecMetadata>,
79}
80
81#[derive(Debug, Deserialize, Serialize, PartialEq, Eq, Clone)]
83pub struct SpecMetadata {
84 pub updated_at: String, pub file_size: u64,
88 #[serde(default)]
90 pub content_hash: Option<String>,
91 #[serde(default)]
93 pub mtime_secs: Option<u64>,
94 #[serde(default)]
96 pub spec_file_size: Option<u64>,
97}
98
99impl Default for GlobalCacheMetadata {
100 fn default() -> Self {
101 Self {
102 cache_format_version: CACHE_FORMAT_VERSION,
103 specs: std::collections::HashMap::new(),
104 }
105 }
106}
107
108#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
109pub struct CachedCommand {
110 pub name: String,
111 pub description: Option<String>,
112 pub summary: Option<String>,
113 pub operation_id: String,
114 pub method: String,
115 pub path: String,
116 pub parameters: Vec<CachedParameter>,
117 pub request_body: Option<CachedRequestBody>,
118 pub responses: Vec<CachedResponse>,
119 pub security_requirements: Vec<String>,
121 pub tags: Vec<String>,
123 pub deprecated: bool,
125 pub external_docs_url: Option<String>,
127 #[serde(default)]
129 pub examples: Vec<CommandExample>,
130 #[serde(default)]
132 pub display_group: Option<String>,
133 #[serde(default)]
135 pub display_name: Option<String>,
136 #[serde(default)]
138 pub aliases: Vec<String>,
139 #[serde(default)]
141 pub hidden: bool,
142}
143
144#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
145pub struct CachedParameter {
146 pub name: String,
147 pub location: String,
148 pub required: bool,
149 pub description: Option<String>,
150 pub schema: Option<String>,
151 pub schema_type: Option<String>,
152 pub format: Option<String>,
153 pub default_value: Option<String>,
154 pub enum_values: Vec<String>,
155 pub example: Option<String>,
156}
157
158#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
159pub struct CachedRequestBody {
160 pub content_type: String,
161 pub schema: String,
162 pub required: bool,
163 pub description: Option<String>,
164 pub example: Option<String>,
165}
166
167#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
168pub struct CachedResponse {
169 pub status_code: String,
170 pub description: Option<String>,
171 pub content_type: Option<String>,
172 pub schema: Option<String>,
173 #[serde(default)]
175 pub example: Option<String>,
176}
177
178#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
180pub struct CachedSecurityScheme {
181 pub name: String,
183 pub scheme_type: String,
185 pub scheme: Option<String>,
187 pub location: Option<String>,
189 pub parameter_name: Option<String>,
191 pub description: Option<String>,
193 pub bearer_format: Option<String>,
195 pub aperture_secret: Option<CachedApertureSecret>,
197}
198
199#[derive(Debug, Deserialize, Serialize, PartialEq, Eq, Clone)]
201pub struct CachedApertureSecret {
202 pub source: String,
204 pub name: String,
206}
207
208#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
210pub struct ServerVariable {
211 pub default: Option<String>,
213 pub enum_values: Vec<String>,
215 pub description: Option<String>,
217}