gpt4 book ai didi

swagger - 使用 Swashbuckle 更改 swagger JSON 的位置

转载 作者:行者123 更新时间:2023-12-01 00:36:14 25 4
gpt4 key购买 nike

我正在尝试配置 Swashbuckle,以便可以使用 URL {root}/swagger.json 访问生成的 JSON 文件。

我已经操纵了许多设置,但一直无法让它工作。这里有些例子:

// This works!  JSON file is located at http://{root}/swagger/docs/v1
this.EnableSwagger(c =>
{
c.RootUrl(x => baseUrl);
c.SingleApiVersion("v1", title);
}).EnableSwaggerUi();

This works! JSON file is located at http://{root}/swagger/docs/swagger
this.EnableSwagger(c =>
{
c.RootUrl(x => baseUrl);
c.SingleApiVersion("swagger", title);
}).EnableSwaggerUi();

// This does not work. JSON file is located at http://{root}/swagger
this.EnableSwagger("{apiVersion}", c =>
{
c.RootUrl(x => baseUrl);
c.SingleApiVersion("swagger", title);
}).EnableSwaggerUi();

// This does not work. JSON file is located at http://{root}/foo/swagger
this.EnableSwagger("foo/{apiVersion}", c =>
{
c.RootUrl(x => baseUrl);
c.SingleApiVersion("swagger", title);
}).EnableSwaggerUi();

我们如何配置 Swashbuckle 以便文件名为“swagger.json”,并且可以从与“/swagger/docs”不同的路径访问它——最好是应用程序的根目录?

最佳答案

如果有人还在寻找:

this approach为我工作:

app.UseSwagger() changes:

 app.UseSwagger(c =>
{
c.RouteTemplate = "SampleApi/swagger/{documentName}/swagger.json";
});

app.UseSwaggerUI() changes:

 app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/SampleApi/swagger/v1/swagger.json", "Sample API");
c.RoutePrefix = "SampleApi/swagger";
});

关于swagger - 使用 Swashbuckle 更改 swagger JSON 的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41022875/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com