我正在尝试配置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”不同的路径(最好是应用程序的根目录)访问它?
发布于 2018-06-23 03:05:44
以防有人还在寻找:
这种方法为我工作:
app.UseSwagger()更改: "SampleApi/swagger/{documentName}/swagger.json";(c => { c.RouteTemplate =c.RouteTemplate }); app.UseSwaggerUI()更改: c.SwaggerEndpoint("/SampleApi/swagger/v1/swagger.json",app.UseSwaggerUI(c => {=> "Sample API");c.RoutePrefix = "SampleApi/swagger";};
https://stackoverflow.com/questions/41022875
复制相似问题