Emmanuel Nuyttens
Emmanuel Nuyttens

Reputation: 311

Swagger UI : Failed to Load API Definition

I've deployed a simple Web API in net5 with swagger enabled (using default settings), which means in Startup.cs:

    services.AddSwaggerGen(c =>
                {
                    c.SwaggerDoc("v1", new OpenApiInfo { Title = "MyCompany.WebApi", Version = "v1" });
                });
app.UseSwagger();
            app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "MyCompany.WebApi v1"));

And i deploy the same application to 2 Local IIS websites, the first as an application of the Default WebSite running on default port 80, as shown below:

enter image description here

And the second as a Separate WebSite node running on port 8085, as shown below:

enter image description here

Then for the second (hosted as a separate WebSite node), all works fine, so i can see my API definition:

enter image description here

But for the first, hosted as an application under the Default Web Site the API documentation can not be loaded: enter image description here

Even though the swagger.json file is accessible: enter image description here

So it look's like swagger is searching for the index.html to display the Swagger-UI in the "root" of the WebSite, and in the case of the first option where the application is hosted under the Default WebSite folder it can not find a way to display the swagger UI. Do we need to add something specific in the swagger definition in this case ?

Thx for any responses !

Emmanuel.

Upvotes: 7

Views: 8982

Answers (1)

mustafa
mustafa

Reputation: 410

Did you tried this:

app.UseSwaggerUI(c => c.SwaggerEndpoint("swagger/v1/swagger.json", "MyCompany.WebApi v1"));

i removed beginning '/' from swagger json path.

Upvotes: 2

Related Questions