0

.NET Web APi, .NET Framework 4.8, Nswag 12.3 Instead of random order of web api endpoints, or alphabetical - my customer would like them ordered in a specific order.
For example, the first thing a user does is Login. So customer would like Login endpoint listed first. Then Client endpoints, Disaster endpoints, Project endpoints, Disaster Client endpoints, etc. So not alphabetical.

I saw this: https://github.com/RicoSuter/NSwag/issues/2879 ((In PostProcess you reorder the Paths collection of the document))

I started by putting the endpoint names in a list - in the order the customer wants them. Then when document is generated - I create a new list of document.Paths - in the correct order. I was going to set documents.Paths to my new list of paths but document.Paths is read only.

Any ideas? Thanks

Bubba
  • 192
  • 1
  • 3
  • 14

1 Answers1

0

You could do something like this:

var orderedPaths = document.Paths.OrderBy(p => p.Key).ToArray();
document.Paths.Clear();
foreach (var p in orderedPaths)
{
    document.Paths.Add(p.Key, p.Value);
}
harmen
  • 163
  • 2
  • 8