How to change base url of Swagger in ASP.NET core

后端 未结 5 800
孤街浪徒
孤街浪徒 2020-12-14 07:18

By default when you enable swagger in ASP.NET Core project it\'s available on url:

http://localhost:/swagger/ui

I would

5条回答
  •  既然无缘
    2020-12-14 07:47

    The UseSwaggerUi() extension method to enable the middleware in the Configure method of the StartUp class takes two variables. A baseRoute which is on swagger/ui by default, and swaggerUrl which is on swagger/v1/swagger.json by default. Simply provide a different baseRoute.

    //Swagger will be available under '/api' url
    app.UseSwaggerUi("api");
    

    If people would like to learn more about configuring Swagger for ASP.NET Core, I've written a blogpost to get started: https://dannyvanderkraan.wordpress.com/2016/09/09/asp-net-core-1-0-web-api-automatic-documentation-with-swagger-and-swashbuckle/

提交回复
热议问题