A component of ASP.NET Core for creating RESTful web services that support HTTP-based communication between clients and servers.
Hello @prince ,
You’ll see that message when Swagger UI isn’t receiving a valid OpenAPI/Swagger document. A quick way to fix it is to verify the document exists and that your app generates it correctly.
Try this minimal setup (ASP.NET Core + Swashbuckle):
// Program.cs
using Microsoft.OpenApi.Models;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(c =>
{
// The UI title/version label; not the OpenAPI version
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
});
var app = builder.Build();
app.UseSwagger(); // Generates /swagger/v1/swagger.json
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});
app.MapControllers();
app.Run();
Then check these specifics:
- Open
/swagger/v1/swagger.jsondirectly in the browser. It must begin with either:-
{ "openapi": "3.x.y", ... }or{ "swagger": "2.0", ... }
-
- If you see HTML or a 404, the UI is pointing to the wrong path (adjust the
SwaggerEndpointto your base path if the app is behind a proxy or virtual directory). - Don’t run both Swashbuckle and NSwag at the same time; use one generator.
- Ensure no custom middleware/filters rewrite or strip the top-level
"openapi"/"swagger"property. - Order matters: call
app.UseSwagger()beforeapp.UseSwaggerUI()and before mapping controllers.
If the raw JSON starts with "openapi" or "swagger" and loads at the configured path, Swagger UI will render correctly.
Hope this solves your problem.