- 
                Notifications
    You must be signed in to change notification settings 
- Fork 10.5k
Closed
Labels
feature-openapiold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Milestone
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
https://github.com/dotnet/aspnetcore/blob/main/src/OpenApi/src/Extensions/OpenApiEndpointRouteBuilderExtensions.cs
There doesn't seem to be set ContentType to the doc returned
I solved this issue temporarily using middleware, and of course it would be nice to fix this internally
internal class OpenApiDocMiddleware
{
    private readonly RequestDelegate _next;
    public OpenApiDocMiddleware(RequestDelegate next)
    {
        _next = next;
    }
    public async Task Invoke(HttpContext context)
    {
        if (context.GetEndpoint()?.Metadata.GetMetadata<IRouteDiagnosticsMetadata>() is { } route &&
            route.Route.EndsWith("{documentName}.json"))
        {
            context.Response.ContentType = "application/json";
        }
        await _next(context);
    }
}Expected Behavior
No response
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
9.0.0-preview.4.24267.6
Anything else?
No response
Metadata
Metadata
Assignees
Labels
feature-openapiold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
