Closed vincentparrett closed 6 years ago
Would alphabetical order be clearer?
Yes, but looking at it, I suspect this is controlled by the UI. Still investigating.
Ok, please ignore, the solution is adding
tagsSorter: "alpha",
To the configuration javascript in the index.html
Since the Tags are added dynamically, I think it still might be good to have a default alphabetical order. Yeah, you can change it in the UI, but it would pretty easy to add a sort here: https://github.com/yahehe/Nancy.Swagger/blob/master/src/Nancy.Swagger/Services/SwaggerMetadataProvider.cs#L78
I actually tried that yesterday and it didn't seem to make any difference. I'll test again to be sure.
I just tried this:
foreach (var tag in RetrieveSwaggerTags().OrderBy(x => x.Name))
{
builder.Tag(tag);
}
And it seemed to work: alphabetical order (but with default
at the end)
Ok, not sure why it didn't for me. Since all my routes have tags I don't see default in the list, I guess you could always check if default is in the list and move it to the top, that would be useful as you would see the routes without tags first (I can't see why you wouldn't have tags on every route though).
I see what you're doing. You're adding Tag names to the routes, but you're not adding Tag objects to the swagger root.
tagCatalog.AddTag(new Tag()
{
Name = ServiceTagName,
Description = ServiceTagDescription
});
That's fine and it looks like Swagger UI still accepts it. But that's why your sorting didn't matter.
We could look into automatically adding tags if they are added to routes, but the logic gets tricky because of the seemingly randomized dependency injection of the modules.
Tags aren't required - so if you don't specify one (but you have others), SwaggerUI will add it to a default tag section.
I don't think default
needs to be sorted, because it's a special category. Being at the bottom is fine.
I created a PR for this simple change.
Expected Behavior
Output of Tags should be sorted in some manner
Actual Behavior
Seemingly random, most likely in order of discovery.
Not sure how hard this one is to tackle, but it looks rather odd when the tags are not sorted.