1 year ago

#335861

test-img

user1563677

.net Core Swagger: SwaggerUIBundle is not defined

I am using .net core 3.1 and its a lambda. This is an API project which has our api endpoints and uses Swagger. Locally this works fine and I can see swagger ui loaded and I can see my endpoints fine. But when I push this to my server, the swagger ui is not loaded and in the console I see 502 error against swagger-ui-bundle.js.

Since this is an API project I am not adding this bundle anywhere in my project. May be this is part of the swashbuckle nuget packages. I have the following packages already added: Swashbuckle.AspNetCore Swashbuckle.AspNetCore.SwaggerUI

Below is the code I have:

public void ConfigureServices(IServiceCollection services)
{
   services.AddSwaggerGen(c =>
    {
        c.SwaggerDoc("v1", new OpenApiInfo
        {
            Title = "Data API",
            Version = "ver1"
        });
    });
}

 public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
 {
    app.UseMvc();
    app.UseSwagger();

    app.UseSwaggerUI(c =>  
    {  
       c.SwaggerEndpoint("/swagger/v1/swagger.json", "My Test1 Api v1");  
    });
 }

Below is the error I get in the console of my api:

 index.html:95 Uncaught ReferenceError: SwaggerUIBundle is not defined
    at window.onload (index.html:95:37)

Not sure if I am missing something here or I need to check with my team to configure something on our servers to make this work.

Thanks,

c#

asp.net-core

swagger

swagger-ui

swashbuckle.aspnetcore

0 Answers

Your Answer

Accepted video resources