Skip to content

Commit d98b2bc

Browse files
committed
Snapshot the generated openapi as part of the OpenApi source generator tests
1 parent 8eb2713 commit d98b2bc

8 files changed

+2417
-0
lines changed

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/SnapshotTestHelper.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,14 @@ void OnEntryPointExit(Exception exception)
200200
using var writer = new FormattingStreamWriter(stream, CultureInfo.InvariantCulture) { AutoFlush = true };
201201
var targetMethod = serviceType.GetMethod("GenerateAsync", [typeof(string), typeof(TextWriter)]) ?? throw new InvalidOperationException("Could not resolve GenerateAsync method.");
202202
targetMethod.Invoke(service, ["v1", writer]);
203+
204+
var openApiString = Encoding.UTF8.GetString(stream.ToArray());
205+
await Verifier.Verify(openApiString)
206+
.UseTextForParameters("openapi.json")
207+
.UseDirectory(SkipOnHelixAttribute.OnHelix()
208+
? Path.Combine(Environment.GetEnvironmentVariable("HELIX_WORKITEM_ROOT"), "snapshots")
209+
: "snapshots");
210+
203211
stream.Position = 0;
204212
var (document, _) = await OpenApiDocument.LoadAsync(stream, "json");
205213
verifyFunc(document);

0 commit comments

Comments
 (0)