using System.Runtime.CompilerServices; using System.Text.Json; namespace Bff.Tests; /// /// Guards the committed OpenAPI contract (services/bff/openapi.json) against drift: it must /// equal the document the running BFF serves. S-08's Angular client is generated from this file, so a /// stale spec is a bug. To regenerate: run the BFF and save /openapi/v1.json over the file. /// public class OpenApiSpecTests { [Fact] public async Task Committed_openapi_spec_matches_the_served_document() { using var factory = new BffFactory(); var served = await factory.CreateClient().GetStringAsync("/openapi/v1.json"); var committed = await File.ReadAllTextAsync(SpecPath()); Assert.Equal(Canonical(committed), Canonical(served)); } // Reformat both sides identically so the comparison is about content, not whitespace. private static string Canonical(string json) { using var doc = JsonDocument.Parse(json); return JsonSerializer.Serialize(doc.RootElement, new JsonSerializerOptions { WriteIndented = true }); } // The committed spec sits at services/bff/openapi.json — one level up from this test file. private static string SpecPath([CallerFilePath] string thisFile = "") => Path.Combine(Path.GetDirectoryName(thisFile)!, "..", "openapi.json"); }