我实现了一个 API 并将其与Swagger集成。
启动配置服务:
services
.AddMvcCore()
.AddApiExplorer();
services.AddSwaggerGen(c => {
c.SwaggerDoc("v1", new Info {
Title = "API", Version = "v1"
});
});
启动配置
app.UseSwagger(c => {
c.RouteTemplate = "{documentName}/configuration.json";
});
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/v1/configuration.json", "API");
c.RoutePrefix = "v1/docs";
})
控制器
[Route("v1/[controller]")]
[ApiController]
public class SomeController : ControllerBase {}
到目前为止,一切都很好...
奇迹般有效。但是我升级到最新版本[Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer][2]
并没有
我遵循了样本和文档,但我无法显示我的操作......我在这里错过了什么?
启动配置服务
services
.AddMvcCore()
//.AddApiExplorer()
.AddVersionedApiExplorer( o => o.GroupNameFormat = "'v'VVV" );
services.AddApiVersioning(o => o.ReportApiVersions = true);
services.AddSwaggerGen(c => {
// c.SwaggerDoc("v1", new Info {
// Title = "API", Version = "v1"
// });
foreach (var description in provider.ApiVersionDescriptions)
{
c.SwaggerDoc(
description.GroupName,
new Info()
{
Title = $"API",
Version = description.ApiVersion.ToString()
});
}
c.OperationFilter<SwaggerDefaultValues>();
});
启动配置
app.UseSwagger(c => {
c.RouteTemplate = "{documentName}/configuration.json";
});
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/v1/configuration.json", "API");
c.RoutePrefix = "v1/docs";
foreach (var description in apiProvider.ApiVersionDescriptions)
{
c.SwaggerEndpoint($"/{description.GroupName}/configuration.json", description.GroupName.ToUpperInvariant());
}
})
控制器
//[Route("v1/[controller]")]
[ApiController]
[Route("v{version:apiVersion}/[controller]")]
[ApiVersion("1.0")]
public class SomeController : ControllerBase {}