feat(bff): committed OpenAPI contract + drift guard (refs #8)
Document typed responses (202 SubmitAccepted / 400 / 401 on self-service; 200 OpenbaarEntry[] on openbaar) so the generated spec carries real schemas for S-08's client. A document transformer clears the auto-populated servers block so the spec is host-independent and deterministic. Commit services/bff/openapi.json and add a test asserting it matches the served /openapi/v1.json (fails on drift). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
34
services/bff/Bff.Tests/OpenApiSpecTests.cs
Normal file
34
services/bff/Bff.Tests/OpenApiSpecTests.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Bff.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Guards the committed OpenAPI contract (<c>services/bff/openapi.json</c>) 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 <c>/openapi/v1.json</c> over the file.
|
||||
/// </summary>
|
||||
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");
|
||||
}
|
||||
Reference in New Issue
Block a user