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 = 4;
70
71#[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
73pub struct GlobalCacheMetadata {
74 pub cache_format_version: u32,
76 pub specs: std::collections::HashMap<String, SpecMetadata>,
78}
79
80#[derive(Debug, Deserialize, Serialize, PartialEq, Eq, Clone)]
82pub struct SpecMetadata {
83 pub updated_at: String, pub file_size: u64,
87}
88
89impl Default for GlobalCacheMetadata {
90 fn default() -> Self {
91 Self {
92 cache_format_version: CACHE_FORMAT_VERSION,
93 specs: std::collections::HashMap::new(),
94 }
95 }
96}
97
98#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
99pub struct CachedCommand {
100 pub name: String,
101 pub description: Option<String>,
102 pub summary: Option<String>,
103 pub operation_id: String,
104 pub method: String,
105 pub path: String,
106 pub parameters: Vec<CachedParameter>,
107 pub request_body: Option<CachedRequestBody>,
108 pub responses: Vec<CachedResponse>,
109 pub security_requirements: Vec<String>,
111 pub tags: Vec<String>,
113 pub deprecated: bool,
115 pub external_docs_url: Option<String>,
117 #[serde(default)]
119 pub examples: Vec<CommandExample>,
120}
121
122#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
123pub struct CachedParameter {
124 pub name: String,
125 pub location: String,
126 pub required: bool,
127 pub description: Option<String>,
128 pub schema: Option<String>,
129 pub schema_type: Option<String>,
130 pub format: Option<String>,
131 pub default_value: Option<String>,
132 pub enum_values: Vec<String>,
133 pub example: Option<String>,
134}
135
136#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
137pub struct CachedRequestBody {
138 pub content_type: String,
139 pub schema: String,
140 pub required: bool,
141 pub description: Option<String>,
142 pub example: Option<String>,
143}
144
145#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
146pub struct CachedResponse {
147 pub status_code: String,
148 pub description: Option<String>,
149 pub content_type: Option<String>,
150 pub schema: Option<String>,
151 #[serde(default)]
153 pub example: Option<String>,
154}
155
156#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
158pub struct CachedSecurityScheme {
159 pub name: String,
161 pub scheme_type: String,
163 pub scheme: Option<String>,
165 pub location: Option<String>,
167 pub parameter_name: Option<String>,
169 pub description: Option<String>,
171 pub bearer_format: Option<String>,
173 pub aperture_secret: Option<CachedApertureSecret>,
175}
176
177#[derive(Debug, Deserialize, Serialize, PartialEq, Eq, Clone)]
179pub struct CachedApertureSecret {
180 pub source: String,
182 pub name: String,
184}
185
186#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
188pub struct ServerVariable {
189 pub default: Option<String>,
191 pub enum_values: Vec<String>,
193 pub description: Option<String>,
195}