Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,23 @@ public static IEndpointConventionBuilder MapOpenApi(this IEndpointRouteBuilder e
{
var document = await documentService.GetOpenApiDocumentAsync(context.RequestServices, context.Request, context.RequestAborted);
var documentOptions = options.Get(lowercasedDocumentName);
using var output = MemoryBufferWriter.Get();
using var writer = Utf8BufferTextWriter.Get(output);
try

using var writer = new Utf8BufferTextWriter();
writer.SetWriter(context.Response.BodyWriter);

if (UseYaml(pattern))
{
if (UseYaml(pattern))
{
await document.SerializeAsync(new OpenApiYamlWriter(writer), documentOptions.OpenApiVersion);
context.Response.ContentType = "text/plain+yaml;charset=utf-8";
}
else
{
await document.SerializeAsync(new OpenApiJsonWriter(writer), documentOptions.OpenApiVersion);
context.Response.ContentType = "application/json;charset=utf-8";
}
await context.Response.BodyWriter.WriteAsync(output.ToArray(), context.RequestAborted);
await context.Response.BodyWriter.FlushAsync(context.RequestAborted);
context.Response.ContentType = "text/plain+yaml;charset=utf-8";
await context.Response.StartAsync();
await document.SerializeAsync(new OpenApiYamlWriter(writer), documentOptions.OpenApiVersion, context.RequestAborted);
}
finally
else
{
MemoryBufferWriter.Return(output);
Utf8BufferTextWriter.Return(writer);
context.Response.ContentType = "application/json;charset=utf-8";
await context.Response.StartAsync();
await document.SerializeAsync(new OpenApiJsonWriter(writer), documentOptions.OpenApiVersion, context.RequestAborted);
}

await context.Response.BodyWriter.FlushAsync(context.RequestAborted);
}
}).ExcludeFromDescription();
}
Expand Down
Loading