我正在尝试配置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"的不同路径访问。 - 最好是申请的根源?
答案 0 :(得分:3)
万一有人还在寻找:
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"; });