Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OrderActionGroupsBy not working #567

Closed
nastassiar opened this issue Nov 12, 2015 · 3 comments
Closed

OrderActionGroupsBy not working #567

nastassiar opened this issue Nov 12, 2015 · 3 comments

Comments

@nastassiar
Copy link

I'm trying to use OrderActionGroupsBy to order my actions, but it always defaults to alphabetical order.

This is setting the configurations

   config.EnableSwagger(c =>
   {
        ...
        c.MultipleApiVersions(
           (apiDesc, targetApiVersion) => ResolveVersionSupportByRouteConstraint(apiDesc, targetApiVersion), 
           (vc) =>
            {
                        vc.Version("v2", "Swagger API V2");
                        vc.Version("v1", "Swagger API V1");
               });
        c.OrderActionGroupsBy(new CustomStringComparer());
        c.GroupActionsBy(apiDesc => GroupBy(apiDesc));
        ...
    }

This is grouping the actions by type instead of controllerName.

    private static string GroupBy(ApiDescription apiDesc)
    {
        var controllerName = apiDesc.ActionDescriptor.ControllerDescriptor.ControllerName;
        var path = apiDesc.RelativePath;

        if (controllerName.Contains("Original"))
        {
            controllerName = controllerName.Replace("Original", "");
        }
        // Check if it is one of the entities if so group by that
        // Otherwise group by controller
        var entities = new List<string>() { "Users", "Apps", "Groups" };


        var e = entities.Where(x => attr.Contains(x.ToLower())).FirstOrDefault();
        if (e != null)
        {
            return e;
        }
        return controllerName;
    }

This is my attempt at an IComparer I want Users first and then after that alphabetical

    public class CustomStringComparer : IComparer<string>
    {
        public int Compare(string x, string y)
        {
            if (x.CompareTo(y) == 0)
                return 0;

            if (x.CompareTo("Users") == 0)
                return -1;
            if (y.CompareTo("Users") == 0)
                return 1;

             return x.CompareTo(y);
        }
    }
}

This isn't working it always defaults to alphabetical no matter what I do.

@nastassiar
Copy link
Author

It looks like swagger ui is defaulting to alphabetical ordering (i.e. apisSorter: "alpha") even though the documentation says it is supposed to default to the servers ordering. Is this a bug? My Json file is properly sorted.

Based off of the documentation it seems like it should default to server order, but in swagger-ui apisSorter is set to 'alpha':

Apply a sort to the API/tags list. It can be 'alpha' (sort by name) or a function (see
Array.prototype.sort() to know how sort function works). Default is the order returned by the server
unchanged.

@nastassiar
Copy link
Author

So it seems like the swagger-ui documentation was not updated with the upgrade to 2.0 but I'm still wondering if there is a way in swashbuckle to override this to use the server order. It doesn't seem like Swashbuckle's OrderActionGroupsBy isn't functional at all.

@domaindrivendev
Copy link
Owner

See 5.3.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants