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?
Launch the app, and navigate to http://localhost:<port>/swagger/v1/swagger.json . The generated document describing the endpoints appears as shown in Swagger specification (swagger. json). The Swagger UI can be found at http://localhost:<port>/swagger .
Swashbuckle is an open source project for generating Swagger documents for Web APIs that are built with ASP.NET Core. There are three core components: AspNetCore. SwaggerGen - provides the functionality to generate JSON Swagger documents that describe the objects, methods, return types, etc.
json file. The Swagger specification of the REST API consists of a file of JSON data called swagger. json. This schema file includes endpoint URLs, descriptions, request parameters and response structures for the entire API.
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"; });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With