将Swashbuckle与c.MultipleApiVersions((apiDesc, version) =>
结合使用...结果是我们的swagger文件驻留在例如:https://host/api/swagger/docs/ {version}。我想在https://host/api/ {version} / swagger实际拥有swagger文件。是否有可能我可以在我的SwaggerConfig .EnableSwagger()
中设置它?
这将允许以下网址:
感谢帮助。
答案 0 :(得分:2)
为此,您可以更新swaggerconfig文件,如下所示:
.EnableSwagger("{apiVersion}/swagger", c =>
{
c.MultipleApiVersions(
(apiDesc, targetApiVersion) => ResolveVersionSupportByRouteConstraint(apiDesc, targetApiVersion),
(vc) =>
{
vc.Version("v2", "Swashbuckle Dummy API V2");
vc.Version("v1", "Swashbuckle Dummy API V1");
});
});
答案 1 :(得分:0)
只是为了进一步参考asp.net core 2.2,它会像这样
app.UseSwagger(options =>
{
options.RouteTemplate = "docs/{documentName}/docs.json";
});
app.UseSwaggerUI(options =>
{
//Build a swagger endpoint for each discovered API version
foreach (var description in provider.ApiVersionDescriptions.OrderByDescending(x=>x.ApiVersion).AsList())
{
options.SwaggerEndpoint($"/docs/{description.GroupName}/docs.json", description.GroupName);
}
options.RoutePrefix = "docs";
}
);
其中provider
是由DI注入的IApiVersionDescriptionProvider