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