Swagger UI Sort

Hello,

We use the Swagger UI quite a bit when testing our REST interfaces. It’s an excellent tool!

One source of frustration I have is that the sort order of the APIs listed in Swagger seems arbitrary.

Is there any way to force the Swagger interface to list interfaces alphabetically by path?

Thanks,

-Z

Are you using SwaggerFeature plugin or OpenApiFeature plugin? And what version of ServiceStack are you using? In recent version 4.5.13 which is available on MyGet Apis are sorted in alphabetical order.

We’re using the OpenApiFeature with ServiceStack 4.5.13.0.

Is OpenApiFeature plugin to use here?

Thanks,

-Z

Yes, this is the version of OpenApiFeature plugin where operation paths are sorted alphabetically by default. If you didn’t redefine serialization routine for OrderedDictionary you should get similar picture.

Can you provide a stand-alone sample which demonstates non-alphabetically sort order so we can look into it?

I have multiple services, and the order in the Swagger ui is not alphabetical. I am on the latest 5.9.3 release

All of the services are in the same namespace, but defined across numerous files.

Any way to influence the sorting would be appreciated.

The Swagger UI controls the ordering which does initially group by path segment which is why you’re seeing all your APIs under the api group, but doesn’t appear they order within that group.

You can create your own custom groups with the [Tag] attribute which should help with discovery, these also allow you to group APIs in the metadata page as well.

You could try reordering the APIs in the ApiDeclarationFilter where you can try reordering the Paths OrderedDictionary where your APIs are defined which may have an effect in Swaggers UI.

I added the [TAG] attribute to partition my endpoints, and then the ordering was sufficient for my needs.

At a latter date I will investigate how to order by entity first and HttpMethod second.

Thank you.

1 Like