diff options
Diffstat (limited to 'Software/Visual_Studio_22/Tango.Portal.Chat.Web/Services/SchemaRegistry.cs')
| -rw-r--r-- | Software/Visual_Studio_22/Tango.Portal.Chat.Web/Services/SchemaRegistry.cs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Software/Visual_Studio_22/Tango.Portal.Chat.Web/Services/SchemaRegistry.cs b/Software/Visual_Studio_22/Tango.Portal.Chat.Web/Services/SchemaRegistry.cs new file mode 100644 index 000000000..da6868bc5 --- /dev/null +++ b/Software/Visual_Studio_22/Tango.Portal.Chat.Web/Services/SchemaRegistry.cs @@ -0,0 +1,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!; + } + } +} |
