Skip to main content

AirLibrary/Configuration/
Schema.rs

1//! JSON Schema generation for Air configuration validation.
2//!
3//! `generate_schema()` returns a Draft-07 JSON Schema object describing every
4//! field of `AirConfiguration`. The schema is used by `ConfigurationManager::
5//! SchemaValidate` and can be exported for editor tooling or CI validation.
6
7use serde_json::{Value as JsonValue, json};
8
9/// Generate the JSON Schema (Draft-07) for `AirConfiguration`.
10/// The returned object describes every sub-configuration section
11/// (grpc, authentication, updates, downloader, indexing, logging,
12/// performance) with their types, enums, ranges, and formats.
13pub fn generate_schema() -> JsonValue {
14	json!({
15		"$schema": "http://json-schema.org/draft-07/schema#",
16		"title": "Air Configuration Schema",
17		"description": "Configuration schema for Air daemon",
18		"type": "object",
19		"required": ["SchemaVersion", "profile"],
20		"properties": {
21			"SchemaVersion": {
22				"type": "string",
23				"description": "Configuration schema version for migration tracking",
24				"pattern": "^\\d+\\.\\d+\\.\\d+$"
25			},
26			"profile": {
27				"type": "string",
28				"description": "Profile name (dev, staging, prod, custom)",
29				"enum": ["dev", "staging", "prod", "custom"]
30			},
31			"grpc": {
32				"type": "object",
33				"description": "gRPC server configuration",
34				"properties": {
35					"BindAddress": {
36						"type": "string",
37						"description": "gRPC server bind address",
38						"format": "hostname-port"
39					},
40					"MaxConnections": {
41						"type": "integer",
42						"minimum": 10,
43						"maximum": 10000
44					},
45					"RequestTimeoutSecs": {
46						"type": "integer",
47						"minimum": 1,
48						"maximum": 3600
49					}
50				}
51			},
52			"authentication": {
53				"type": "object",
54				"description": "Authentication configuration",
55				"properties": {
56					"enabled": {"type": "boolean"},
57					"CredentialsPath": {"type": "string"},
58					"TokenExpirationHours": {
59						"type": "integer",
60						"minimum": 1,
61						"maximum": 8760
62					},
63					"MaxSessions": {
64						"type": "integer",
65						"minimum": 1,
66						"maximum": 1000
67					}
68				}
69			},
70			"updates": {
71				"type": "object",
72				"properties": {
73					"enabled": {"type": "boolean"},
74					"CheckIntervalHours": {
75						"type": "integer",
76						"minimum": 1,
77						"maximum": 168
78					},
79					"UpdateServerUrl": {
80						"type": "string",
81						"pattern": "^https://"
82					},
83					"AutoDownload": {"type": "boolean"},
84					"AutoInstall": {"type": "boolean"},
85					"channel": {
86						"type": "string",
87						"enum": ["stable", "insiders", "preview"]
88					}
89				}
90			},
91			"downloader": {
92				"type": "object",
93				"properties": {
94					"enabled": {"type": "boolean"},
95					"MaxConcurrentDownloads": {
96						"type": "integer",
97						"minimum": 1,
98						"maximum": 50
99					},
100					"DownloadTimeoutSecs": {
101						"type": "integer",
102						"minimum": 10,
103						"maximum": 3600
104					},
105					"MaxRetries": {
106						"type": "integer",
107						"minimum": 0,
108						"maximum": 10
109					},
110					"CacheDirectory": {"type": "string"}
111				}
112			},
113			"indexing": {
114				"type": "object",
115				"properties": {
116					"enabled": {"type": "boolean"},
117					"MaxFileSizeMb": {
118						"type": "integer",
119						"minimum": 1,
120						"maximum": 1024
121					},
122					"FileTypes": {
123						"type": "array",
124						"items": {"type": "string"}
125					},
126					"UpdateIntervalMinutes": {
127						"type": "integer",
128						"minimum": 1,
129						"maximum": 1440
130					},
131					"IndexDirectory": {"type": "string"}
132				}
133			},
134			"logging": {
135				"type": "object",
136				"properties": {
137					"level": {
138						"type": "string",
139						"enum": ["trace", "debug", "info", "warn", "error"]
140					},
141					"FilePath": {"type": ["string", "null"]},
142					"ConsoleEnabled": {"type": "boolean"},
143					"MaxFileSizeMb": {
144						"type": "integer",
145						"minimum": 1,
146						"maximum": 1000
147					},
148					"MaxFiles": {
149						"type": "integer",
150						"minimum": 1,
151						"maximum": 50
152					}
153				}
154			},
155			"performance": {
156				"type": "object",
157				"properties": {
158					"MemoryLimitMb": {
159						"type": "integer",
160						"minimum": 64,
161						"maximum": 16384
162					},
163					"CPULimitPercent": {
164						"type": "integer",
165						"minimum": 10,
166						"maximum": 100
167					},
168					"DiskLimitMb": {
169						"type": "integer",
170						"minimum": 100,
171						"maximum": 102400
172					},
173					"BackgroundTaskIntervalSecs": {
174						"type": "integer",
175						"minimum": 1,
176						"maximum": 3600
177					}
178				}
179			}
180		}
181	})
182}