How to order/sort paths in NSwag swagger.json by controller name

有些话、适合烂在心里 提交于 2021-01-27 20:46:46

问题


I am using NSwag to generate swagger for my .NET Core api and everything works great, except the fact that paths are rendered in order that reflection seems to pickup Controllers from project.

So if I do have hierarchy - some controllers at root level (Controllers folder) and some in subfolder (Controllers\Subfolder folder) then the order gets messed up.

Is it possible to somehow tell NSwag to generate resulting swagger.json showing operations in alphabetical order?


回答1:


There is option within UI configuration. All you need is utilize OperationsSorter and TagsSorter, within your Startup.Configure method like:

app.UseSwaggerUi3(a => {
    a.OperationsSorter = "alpha";
    a.TagsSorter = "alpha";
});


来源:https://stackoverflow.com/questions/59060563/how-to-order-sort-paths-in-nswag-swagger-json-by-controller-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!