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.
//
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(); });
}
question from:
https://stackoverflow.com/questions/65895541/where-is-the-openapi-swagger-version-specified-in-asp-net-5 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…