aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio_22/Tango.Portal.Chat.Web/Services/SchemaRegistry.cs
blob: da6868bc5be745f9ca8381a075c3205930071c84 (plain)
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
using System.Text.Json;

namespace ChatADX.Web.Services
{
    public sealed class SchemaRegistry
    {
        private readonly IWebHostEnvironment _env;
        private readonly ILogger<SchemaRegistry> _log;
        private string? _cached;

        public SchemaRegistry(IWebHostEnvironment env, ILogger<SchemaRegistry> log)
        {
            _env = env; _log = log;
        }

        public string GetSchemaJson()
        {
            if (!string.IsNullOrEmpty(_cached)) return _cached!;
            var path = Path.Combine(_env.ContentRootPath, "Data", "schema.json");
            if (!File.Exists(path))
            {
                _log.LogWarning("Schema file not found at {Path}. Returning empty schema.", path);
                _cached = "{\"tables\":{}}";
                return _cached!;
            }
            _cached = File.ReadAllText(path);
            // Basic sanity check
            JsonDocument.Parse(_cached);
            return _cached!;
        }
    }
}