nikib3ro
nikib3ro

Reputation: 20606

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

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?

Upvotes: 5

Views: 2818

Answers (1)

nikib3ro
nikib3ro

Reputation: 20606

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";
});

Upvotes: 7

Related Questions