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 pub fn new_for_test(name: &str) -> Self {
29 Self {
30 cache_format_version: CACHE_FORMAT_VERSION,
31 name: name.to_string(),
32 version: "1.0.0".to_string(),
33 commands: vec![],
34 base_url: None,
35 servers: vec![],
36 security_schemes: HashMap::new(),
37 skipped_endpoints: vec![],
38 server_variables: HashMap::new(),
39 }
40 }
41}
42
43#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
45pub struct CommandExample {
46 pub description: String,
48 pub command_line: String,
50 pub explanation: Option<String>,
52}
53
54#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
56pub struct SkippedEndpoint {
57 pub path: String,
58 pub method: String,
59 pub content_type: String,
60 pub reason: String,
61}
62
63pub const CACHE_FORMAT_VERSION: u32 = 3;
68
69#[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
71pub struct GlobalCacheMetadata {
72 pub cache_format_version: u32,
74 pub specs: std::collections::HashMap<String, SpecMetadata>,
76}
77
78#[derive(Debug, Deserialize, Serialize, PartialEq, Eq, Clone)]
80pub struct SpecMetadata {
81 pub updated_at: String, pub file_size: u64,
85}
86
87impl Default for GlobalCacheMetadata {
88 fn default() -> Self {
89 Self {
90 cache_format_version: CACHE_FORMAT_VERSION,
91 specs: std::collections::HashMap::new(),
92 }
93 }
94}
95
96#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
97pub struct CachedCommand {
98 pub name: String,
99 pub description: Option<String>,
100 pub summary: Option<String>,
101 pub operation_id: String,
102 pub method: String,
103 pub path: String,
104 pub parameters: Vec<CachedParameter>,
105 pub request_body: Option<CachedRequestBody>,
106 pub responses: Vec<CachedResponse>,
107 pub security_requirements: Vec<String>,
109 pub tags: Vec<String>,
111 pub deprecated: bool,
113 pub external_docs_url: Option<String>,
115 #[serde(default)]
117 pub examples: Vec<CommandExample>,
118}
119
120#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
121pub struct CachedParameter {
122 pub name: String,
123 pub location: String,
124 pub required: bool,
125 pub description: Option<String>,
126 pub schema: Option<String>,
127 pub schema_type: Option<String>,
128 pub format: Option<String>,
129 pub default_value: Option<String>,
130 pub enum_values: Vec<String>,
131 pub example: Option<String>,
132}
133
134#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
135pub struct CachedRequestBody {
136 pub content_type: String,
137 pub schema: String,
138 pub required: bool,
139 pub description: Option<String>,
140 pub example: Option<String>,
141}
142
143#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
144pub struct CachedResponse {
145 pub status_code: String,
146 pub description: Option<String>,
147 pub content_type: Option<String>,
148 pub schema: Option<String>,
149}
150
151#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
153pub struct CachedSecurityScheme {
154 pub name: String,
156 pub scheme_type: String,
158 pub scheme: Option<String>,
160 pub location: Option<String>,
162 pub parameter_name: Option<String>,
164 pub description: Option<String>,
166 pub bearer_format: Option<String>,
168 pub aperture_secret: Option<CachedApertureSecret>,
170}
171
172#[derive(Debug, Deserialize, Serialize, PartialEq, Eq, Clone)]
174pub struct CachedApertureSecret {
175 pub source: String,
177 pub name: String,
179}
180
181#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
183pub struct ServerVariable {
184 pub default: Option<String>,
186 pub enum_values: Vec<String>,
188 pub description: Option<String>,
190}