10

I am trying to configure Swashbuckle so the generated JSON file can be accessed using the URL {root}/swagger.json.

I've manipulated a number of settings but have been unable to get it to work. Here are some examples:

// 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();

How can we configure Swashbuckle so the file is named "swagger.json" and it is accessed from a different path from "/swagger/docs" - preferably the root of the application?

SonOfPirate
  • 5,642
  • 3
  • 41
  • 97

1 Answers1

16

In case anyone is still looking:

this approach worked for me:

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";
 });
Nandun
  • 1,802
  • 2
  • 20
  • 35