更改默认版本 Swagger 位置
Change Default Version Swagger Location
结合使用 Swashbuckle 和 c.MultipleApiVersions((apiDesc, version) =>
... 结果是我们的 swagger 文件位于例如:https://host/api/swagger/docs/{version}. I would like to actually have the swagger file at https://host/api/{version}/swagger。我可以在我的 SwaggerConfig .EnableSwagger()
中进行设置吗?
这将允许以下网址:
感谢帮助。
为此,您可以更新 swaggerconfig 文件,如下所示:
.EnableSwagger("{apiVersion}/swagger", c =>
{
c.MultipleApiVersions(
(vc) =>
{
vc.Version("v2", "Swashbuckle Dummy API V2");
vc.Version("v1", "Swashbuckle Dummy API V1");
});
});
仅供在 asp.net 核心 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
结合使用 Swashbuckle 和 c.MultipleApiVersions((apiDesc, version) =>
... 结果是我们的 swagger 文件位于例如:https://host/api/swagger/docs/{version}. I would like to actually have the swagger file at https://host/api/{version}/swagger。我可以在我的 SwaggerConfig .EnableSwagger()
中进行设置吗?
这将允许以下网址:
感谢帮助。
为此,您可以更新 swaggerconfig 文件,如下所示:
.EnableSwagger("{apiVersion}/swagger", c =>
{
c.MultipleApiVersions(
(vc) =>
{
vc.Version("v2", "Swashbuckle Dummy API V2");
vc.Version("v1", "Swashbuckle Dummy API V1");
});
});
仅供在 asp.net 核心 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