1

I have configured swagger with a Blazor Wasm Hosted application and I am getting the following error:

Unable to render this definition. The provided definition does not specify a valid version field. I have included a screenshot of the message as well as the code for configuring swagger.

enter image description here

//

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

****************** EDIT ********************

When I generate a new Web API project, this seems to work in the temp project. When I add these same lines to my project the issue persists:

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
    services.AddControllers();
    services.AddSwaggerGen(c =>
    {
        c.SwaggerDoc("v1", new OpenApiInfo {Title = "SwaggerTest", Version = "v1"});
    });
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
        app.UseSwagger();
        app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "SwaggerTest v1"));
    }

    app.UseHttpsRedirection();

    app.UseRouting();

    app.UseAuthorization();

    app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
}
bbqchickenrobot
  • 3,592
  • 3
  • 45
  • 67
  • Is your generated swagger.json missing the `swagger` property? According to https://github.com/domaindrivendev/Swashbuckle.AspNetCore#serialize-swagger-in-the-20-format it should default to "3.0.n" – Babak Naffas Jan 26 '21 at 18:29
  • @BabakNaffas - it's not being generated. I'm getting the error message displayed in the post. No swagger.json. – bbqchickenrobot Jan 28 '21 at 16:29

0 Answers0