aperture_cli/cache/
models.rs

1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3
4#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
5pub struct CachedSpec {
6    /// Cache format version to detect incompatible changes
7    pub cache_format_version: u32,
8    pub name: String,
9    pub version: String,
10    pub commands: Vec<CachedCommand>,
11    /// Base URL extracted from the first server in the `OpenAPI` spec
12    pub base_url: Option<String>,
13    /// All server URLs from the `OpenAPI` spec for future multi-environment support
14    pub servers: Vec<String>,
15    /// Security schemes defined in the `OpenAPI` spec with `x-aperture-secret` mappings
16    pub security_schemes: HashMap<String, CachedSecurityScheme>,
17}
18
19/// Current cache format version - increment when making breaking changes to `CachedSpec`
20pub const CACHE_FORMAT_VERSION: u32 = 1;
21
22/// Global cache metadata for all cached specifications
23#[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
24pub struct GlobalCacheMetadata {
25    /// Cache format version for all specs
26    pub cache_format_version: u32,
27    /// Individual spec metadata
28    pub specs: std::collections::HashMap<String, SpecMetadata>,
29}
30
31/// Metadata for a single cached specification
32#[derive(Debug, Deserialize, Serialize, PartialEq, Eq, Clone)]
33pub struct SpecMetadata {
34    /// When this spec cache was created/updated
35    pub updated_at: String, // Using String for simplicity in serialization
36    /// Size of the cached spec file in bytes
37    pub file_size: u64,
38}
39
40impl Default for GlobalCacheMetadata {
41    fn default() -> Self {
42        Self {
43            cache_format_version: CACHE_FORMAT_VERSION,
44            specs: std::collections::HashMap::new(),
45        }
46    }
47}
48
49#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
50pub struct CachedCommand {
51    pub name: String,
52    pub description: Option<String>,
53    pub summary: Option<String>,
54    pub operation_id: String,
55    pub method: String,
56    pub path: String,
57    pub parameters: Vec<CachedParameter>,
58    pub request_body: Option<CachedRequestBody>,
59    pub responses: Vec<CachedResponse>,
60    /// Security requirements for this operation (references to security scheme names)
61    pub security_requirements: Vec<String>,
62    /// All tags associated with this operation
63    pub tags: Vec<String>,
64    /// Whether this operation is deprecated
65    pub deprecated: bool,
66    /// External documentation URL if available
67    pub external_docs_url: Option<String>,
68}
69
70#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
71pub struct CachedParameter {
72    pub name: String,
73    pub location: String,
74    pub required: bool,
75    pub description: Option<String>,
76    pub schema: Option<String>,
77    pub schema_type: Option<String>,
78    pub format: Option<String>,
79    pub default_value: Option<String>,
80    pub enum_values: Vec<String>,
81    pub example: Option<String>,
82}
83
84#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
85pub struct CachedRequestBody {
86    pub content_type: String,
87    pub schema: String,
88    pub required: bool,
89    pub description: Option<String>,
90    pub example: Option<String>,
91}
92
93#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
94pub struct CachedResponse {
95    pub status_code: String,
96    pub description: Option<String>,
97    pub content_type: Option<String>,
98    pub schema: Option<String>,
99}
100
101/// Cached representation of a security scheme with x-aperture-secret mapping
102#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
103pub struct CachedSecurityScheme {
104    /// Security scheme name from the `OpenAPI` spec
105    pub name: String,
106    /// Type of security scheme (apiKey, http, oauth2, etc.)
107    pub scheme_type: String,
108    /// Subtype for http schemes (bearer, basic, etc.)
109    pub scheme: Option<String>,
110    /// Location for apiKey schemes (header, query, cookie)
111    pub location: Option<String>,
112    /// Parameter name for apiKey schemes (e.g., "Authorization", "X-API-Key")
113    pub parameter_name: Option<String>,
114    /// Description of the security scheme from `OpenAPI` spec
115    pub description: Option<String>,
116    /// Bearer format for HTTP bearer schemes (e.g., "JWT")
117    pub bearer_format: Option<String>,
118    /// x-aperture-secret mapping for environment variable resolution
119    pub aperture_secret: Option<CachedApertureSecret>,
120}
121
122/// Cached representation of x-aperture-secret extension
123#[derive(Debug, Deserialize, Serialize, PartialEq, Eq, Clone)]
124pub struct CachedApertureSecret {
125    /// Source of the secret (currently only "env" supported)
126    pub source: String,
127    /// Environment variable name to read the secret from
128    pub name: String,
129}