Skip to main content

AirLibrary/Configuration/
Schema.rs

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