By default when you enable swagger in ASP.NET Core project it's available on url:
http://localhost:<random_port>/swagger/ui
I would like to use a different base url instead of /swagger/ui
. How/where can i configure that?
I found that for older versions you can configure the RootUrl
but there aren't similiar method in ASP.NET Core:
.EnableSwagger(c => { c.RootUrl(req => myCustomBasePath); });
In OpenAPI 3.0, you can use an array of server elements to specify one or more base URLs for your API. You can register the servers using the annotation @Server: in @OpenAPIDefinition (for all operations) in @Operation (for a single operation)
Add and configure Swagger middleware Launch the app and navigate to https://localhost:<port>/swagger/v1/swagger.json . The generated document describing the endpoints appears as shown in OpenAPI specification (openapi. json). The Swagger UI can be found at https://localhost:<port>/swagger .
By default when you enable swagger in ASP.NET Core project it's available on url: http://localhost:<random_port>/swagger/ui. I would like to use a different base url instead of /swagger/ui.
In this article, you will learn about swagger in .NET Core. Open Visual Studio and select “Create new project. Select ASP.Net Core Web Application from the templates displayed.
To add a route prefix to swagger and swagger ui is a pretty quick code change. To get a ASP.Net Core Web Api up and running, create a new project and select ASP.Net Core Web Application (.Net Core). Once the project is created you will nuget in Swashbuckle.AspNetCore:
Press F5 to run the API locally and to launch the Swagger UI just hit the http://localhost:<port_number>/swagger/index.html URL in the browser. The Swagger UI for above controller looks as follows, Hit the http://localhost:<port_number>/swagger/v1/swagger.json URL in the browser. We can see the OpenAPI specification (openapi.json).
The new swagger version provides you with a property called RoutePrefix.
app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); c.RoutePrefix = "docs"; });
Should work for .net core
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