【问题标题】:Change location of swagger JSON using Swashbuckle使用 Swashbuckle 更改招摇 JSON 的位置
【发布时间】:2016-12-07 16:43:12
【问题描述】:

我正在尝试配置 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”不同的路径访问它 - 最好是应用程序的根目录?

【问题讨论】:

  • 你找到答案了吗?

标签: swagger swagger-ui swashbuckle


【解决方案1】:

如果有人还在寻找:

this approach 为我工作:

app.UseSwagger() 变化:

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

app.UseSwaggerUI() 更改:

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

【讨论】:

    猜你喜欢
    • 2017-12-19
    • 2017-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-03
    • 1970-01-01
    • 2017-10-06
    相关资源
    最近更新 更多