Commit 4e0fbf5
committed
## Summary
Resolves #6438(FR-2453)
Adds JSON Schema-based validation and autocomplete for model/service definition files when edited in the VFolder file editor (Monaco):
- **`model-definition.yaml` / `.yml`** — YAML syntax highlighting (built-in) + schema validation warnings + **schema-based autocomplete**
- **`service-definition.toml`** — TOML syntax highlighting (custom monarch tokenizer) + schema validation warnings
- **Shared validation core** (`monacoSchemaValidator.ts`) — Ajv compiled once per validator, version counter prevents stale async results
- **YAML autocomplete** (`monacoYamlCompletion.ts`) — CompletionItemProvider that suggests schema properties based on cursor context (indentation-aware path detection), marks required properties, provides value snippets
- Schema files: `resources/model-definition.schema.json` and `resources/service-definition.schema.json` (Draft 2020-12)
- Validation runs on mount and debounced on content changes (300ms)
- No interference with regular file editing
### Files Changed
| File | Description |
|------|-------------|
| `react/src/helper/monacoSchemaValidator.ts` | **New** — Shared schema validation core (Ajv caching, race condition guard, disposable pattern) |
| `react/src/helper/monacoYamlValidator.ts` | **New** — YAML-specific parser + error mapping |
| `react/src/helper/monacoYamlCompletion.ts` | **New** — Schema-based YAML autocomplete (indentation-aware path detection, $ref resolution) |
| `react/src/helper/monacoTomlValidator.ts` | **New** — TOML-specific parser + error mapping |
| `react/src/helper/monacoTomlLanguage.ts` | **New** — TOML language registration + monarch tokenizer |
| `react/src/components/VFolderTextFileEditorModal.tsx` | Schema dispatch by file type (YAML/TOML) |
| `react/package.json` | Add `yaml`, `ajv` (moved to deps) |
| `resources/model-definition.schema.json` | **New** — JSON Schema for model definition |
| `resources/service-definition.schema.json` | **New** — JSON Schema for service definition |
### Verification
```
=== Relay: PASS ===
=== Lint: PASS ===
=== Format: PASS ===
=== TypeScript: PASS ===
=== ALL PASS ===
```
### Design Notes
- Initially attempted `monaco-yaml` for full YAML autocomplete + validation, but its web worker is incompatible with CDN-loaded Monaco (`@monaco-editor/react` loads Monaco from jsDelivr). Implemented manual validation (yaml parser + ajv) and a custom CompletionItemProvider for autocomplete instead.
- Ajv schema compilation happens once per validator lifetime (not per keystroke). A version counter prevents stale async validation results from overwriting newer ones.
- YAML autocomplete uses indentation-aware path detection: splits array items into container + key entries, trims to ancestors based on cursor indent, then navigates the schema tree to suggest remaining properties.
## Test plan
- [x] Open `model-definition.yaml` in vFolder editor → YAML syntax highlighting + yellow warning markers for schema violations
- [x] In `model-definition.yaml`, type a property key → autocomplete suggests schema properties with descriptions and required markers
- [x] Open `service-definition.toml` in vFolder editor → TOML syntax highlighting + yellow warning markers for schema violations
- [x] Open a regular file (e.g., `.ts`) → no schema markers, no errors
- [x] `scripts/verify.sh` passes (Relay, Lint, Format, TypeScript)
## Screenshots
### YAML Schema Autocomplete (model-definition.yaml)

### YAML Schema Validation (model-definition.yaml)

### TOML Schema Validation (service-definition.toml)

1 parent b090ef2 commit 4e0fbf5
30 files changed
Lines changed: 1426 additions & 4 deletions
File tree
- react
- src
- components
- helper
- resources
- i18n
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
81 | 82 | | |
82 | 83 | | |
83 | 84 | | |
| 85 | + | |
84 | 86 | | |
85 | 87 | | |
86 | 88 | | |
| |||
131 | 133 | | |
132 | 134 | | |
133 | 135 | | |
134 | | - | |
135 | 136 | | |
136 | 137 | | |
137 | 138 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
24 | 31 | | |
25 | 32 | | |
26 | 33 | | |
| |||
57 | 64 | | |
58 | 65 | | |
59 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
60 | 87 | | |
61 | 88 | | |
62 | 89 | | |
| |||
69 | 96 | | |
70 | 97 | | |
71 | 98 | | |
72 | | - | |
| 99 | + | |
73 | 100 | | |
74 | 101 | | |
75 | 102 | | |
| |||
78 | 105 | | |
79 | 106 | | |
80 | 107 | | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
81 | 120 | | |
82 | 121 | | |
83 | 122 | | |
| |||
182 | 221 | | |
183 | 222 | | |
184 | 223 | | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
185 | 257 | | |
186 | 258 | | |
187 | 259 | | |
| |||
198 | 270 | | |
199 | 271 | | |
200 | 272 | | |
| 273 | + | |
201 | 274 | | |
202 | 275 | | |
203 | 276 | | |
| |||
211 | 284 | | |
212 | 285 | | |
213 | 286 | | |
214 | | - | |
| 287 | + | |
215 | 288 | | |
216 | 289 | | |
217 | 290 | | |
| |||
240 | 313 | | |
241 | 314 | | |
242 | 315 | | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
243 | 320 | | |
244 | 321 | | |
245 | 322 | | |
| |||
260 | 337 | | |
261 | 338 | | |
262 | 339 | | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
263 | 392 | | |
264 | 393 | | |
265 | 394 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
0 commit comments