I am trying to get Swagger documentation working for my ASP.NET Core application using Microsoft's aspnet-api-versioning and am following the instructions from here which seem to be out of date as I had to change things to make them compile.
However whenever I hit the /swagger end point I get the following error "Count not render e, see console":
I have configured things as follows:
public void ConfigureServices(IServiceCollection aServices)
{
aServices.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
aServices.AddMvcCore().AddVersionedApiExplorer(o => o.GroupNameFormat = "'v'VVV");
aServices.AddApiVersioning();
aServices.AddSwaggerGen(
aOptions =>
{
IApiVersionDescriptionProvider provider = aServices.BuildServiceProvider()
.GetRequiredService<IApiVersionDescriptionProvider>();
foreach (ApiVersionDescription description in provider.ApiVersionDescriptions)
{
aOptions.SwaggerDoc(
description.GroupName,
new Info
{
Title = $"Sample API {description.ApiVersion}",
Version = description.ApiVersion.ToString()
});
}
}
);
}
public void Configure(IApplicationBuilder aApp, IHostingEnvironment aEnv)
{
if (aEnv.IsDevelopment())
aApp.UseDeveloperExceptionPage();
else
aApp.UseHsts();
aApp.UseHttpsRedirection();
aApp.UseMvc();
aApp.UseSwagger();
aApp.UseSwaggerUI();
aApp.UseSwaggerUI(
aOptions =>
{
IApiVersionDescriptionProvider provider = aApp.ApplicationServices.GetRequiredService<IApiVersionDescriptionProvider>();
foreach (ApiVersionDescription description in provider.ApiVersionDescriptions)
{
aOptions.SwaggerEndpoint(
$"/swagger/{description.GroupName}/swagger.json",
description.GroupName.ToUpperInvariant());
}
}
);
}
And then a very simple controller:
[Route("v{version:apiVersion}/api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
// DELETE api/values/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
// GET api/values
[HttpGet]
public ActionResult<IEnumerable<string>> Get()
{
return new[] {"value1", "value2"};
}
// GET api/values/5
[HttpGet("{id}")]
public ActionResult<string> Get(int id)
{
return "value";
}
// POST api/values
[HttpPost]
public void Post([FromBody] string value)
{
}
// PUT api/values/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}
}
So it appears the error is missing the Url property. However I was expecting that to have come from the ASP.NET Api Versioning? What have I missed here and what do I need to do to make this work?