bbqchickenrobot
bbqchickenrobot

Reputation: 3709

Where is the OpenApi/Swagger version Specified in ASP.NET 5

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");
        });

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(); });
}

Upvotes: 1

Views: 1015

Answers (0)

Related Questions