dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.

Home Page:https://asp.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[9.0-preview.4] OpenAPI response does get served if a static file with the same path exists as a file

martincostello opened this issue · comments

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I'm not sure if this is a bug or not, but it's certainly an unexpected behaviour to me.

Because NSwag doesn't support native AoT, I have an application where I have a setup like the following:

  • NSwag renders the OpenAPI response when dynamic code is supported.
  • A copy of that document is stored in wwwroot as a fall back for the deployed native AoT app.
  • UseOpenApi() is registered before UseStaticFiles().

For the purposes of comparison, I disabled NSwag and configured the new OpenAPI support for .NET 9 preview 4 to serve the new generated document from the same URL:

app.MapOpenApi("/swagger/api/swagger.json");
app.UseStaticFiles();

In this scenario I would expect the application to behave the same, but instead I always get the content from the static file instead.

If I delete the file, then I get the generated content. If I then restore the file, I get the static one again.

Expected Behavior

I would expect the generated content to always be served as the OpenAPI middleware is registered before static files.

Steps To Reproduce

  1. Configure an API application with the new OpenAPI support and static files.
  2. Save the content generated by MapOpenApi() into wwwroot at a location that has the same path, but make a trivial edit so you can tell which content is served.
  3. Run the application and request the URL for the Open API document.

Exceptions (if any)

No response

.NET Version

9.0.100-preview.4.24267.66

Anything else?

No response