question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OrderActionsBy doesn't work correctly

See original GitHub issue

Cannot get OrderActionsBy working correctly. I need to order actions based on HTTP methods used so that GET methods come first (then POST, PUT, DELETE etc.). I have a few API controllers with some actions (using different HTTP methods). So I tried something very simple as shown below.

This is not working (order doesn’t change at all):

config.OrderActionsBy(apiDesc =>
{
    return apiDesc.HttpMethod == "GET" ? "1" : "2";
});

This is working (but obviously it doesn’t order actions as I want):

config.OrderActionsBy(apiDesc =>
{
    return apiDesc.HttpMethod;
});

Am I doing something wrong or misunderstood something or is this a bug in Swashbuckle?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

12reactions
ktownsend-cbrecommented, Mar 12, 2019

If there is some requirement that paths be sorted within a group and the OrderActionsBy sorting override can’t change that, I wish that fact was more discoverable in the intellisense for the method in Visual Studio. It would have saved me many hours trying to figure out why sorting was broken.

Frankly, a sorting override like this should truly override the sorting. Setting a sort override only to have it changed by internal sorting is confusing and unexpected.

9reactions
efirdmancommented, Oct 18, 2017

I do not think its working

Trying to set in the following order within the same Controller

GET - POST - PUT - DELETE

            // Define order of the Actions on the page
            Func<ApiDescription, string> sortKeySelector = (x =>
            {
                return
                    x.HttpMethod.Equals("GET", StringComparison.InvariantCultureIgnoreCase)
                    ? "0"
                        : x.HttpMethod.Equals("POST", StringComparison.InvariantCultureIgnoreCase)
                        ? "1"
                            : x.HttpMethod.Equals("PUT", StringComparison.InvariantCultureIgnoreCase)
                            ? "2"
                                : x.HttpMethod.Equals("DELETE", StringComparison.InvariantCultureIgnoreCase)
                                ? "3"
                                : "4";
            });
            options.OrderActionsBy(sortKeySelector);

*I wish I can disable Ordering in the first place and just load the way its in the controller

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - How can I change order the operations are listed in a ...
I've found how to implement document filters and I can get and order ApiDescriptions by HttpMethod , but changing the order in ApiDescriptions ......
Read more >
Swashbuckle.AspNetCore
This won't work if your app is hosted on an IIS virtual directory or behind a proxy that trims the request path before...
Read more >
Swashbuckle Custom Ordering of Controllers - Terence Golla
With OrderActionsBy you use a lambda expression to alter the sort key string used to order (group) API calls. By default, the sort...
Read more >
肖红军/Swashbuckle.AspNetCore
Open the Properties dialog for your project, click the "Build" tab and ensure that "XML documentation file" is checked. · Configure Swashbuckle to...
Read more >
Swashbuckle.AspNetCore
When you have multiple Swagger pages open, it can be difficult to tell them apart. You can alter this when enabling the SwaggerUi...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found