简体   繁体   中英

Sort on controller name or tag with NSwag and C#

I'm having a ASP.Net Core solution for which I want to use Swagger. For this I use the Nuget package NSwag (Assembly NSwag.AspNetCore, Version=11.20.1.0). In my Configuration of the app I have the following:

public void Configure(IApplicationBuilder app) {
    app..UseSwaggerUi3WithApiExplorer(settings =>
        {
            settings.GeneratorSettings.DefaultPropertyNameHandling = PropertyNameHandling.CamelCase;
            settings.PostProcess = document =>
            {
                document.Info.Version = $"v{typeof(Startup).Assembly.GetName().Version.Major}";
                document.Info.Title = "Test Api";
                document.Info.Description = "Sample API";
                document.Info.TermsOfService = "None";
                document.Info.Contact = new NSwag.SwaggerContact
                {
                    Name = "Person",
                    Email = "Email"
                };
            };
        });
}

When I run this, I see correctly all controllers and corresponding methods, but it is not sorted alphabetically.

I already tried the following:

  • Add TagSorter to settings:

     app.UseSwaggerUi3WithApiExplorer(settings => { ... settings.TagSorter = "alpha"; ... }); 
  • Add ApisSorter to settings:

     app.UseSwaggerUi3WithApiExplorer(settings => { ... settings.ApisSorter = "alpha"; ... }); 

But these changes result in the same output. How can I achieve the sorting?

I had the same issue. But after upgrading NSwag.AspNetCore -> 12.0.8 (latest version at time of writing) and replacing the methods that are now Obsolete it worked with

s.TagsSorter = "alpha";
s.OperationsSorter = "alpha";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM