Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ private IList<string> DefaultTagsSelector(ApiDescription apiDescription)

private string DefaultSortKeySelector(ApiDescription apiDescription)
{
return TagsSelector(apiDescription).First();
return TagsSelector(apiDescription).FirstOrDefault()
?? apiDescription.RelativePath
?? apiDescription.ActionDescriptor?.DisplayName
?? string.Empty;
}

private static string DefaultPathGroupSelector(ApiDescription apiDescription)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,32 @@ public void GetSwagger_CanReadTagsFromMetadata()
Assert.Equal(["Some", "Tags", "Here"], [.. document.Paths["/resource"].Operations[HttpMethod.Post].Tags?.Select(t => t.Reference.Id)]);
}

[Fact]
public void GetSwagger_DoesNotThrow_WhenTagsMetadataIsEmpty()
{
var methodInfo = typeof(FakeController).GetMethod(nameof(FakeController.ActionWithParameter));
var actionDescriptor = new ActionDescriptor
{
EndpointMetadata = [new TagsAttribute()],
RouteValues = new Dictionary<string, string>
{
["controller"] = methodInfo.DeclaringType.Name.Replace("Controller", string.Empty)
}
};
var subject = Subject(
apiDescriptions:
[
ApiDescriptionFactory.Create(actionDescriptor, methodInfo, groupName: "v1", httpMethod: "POST", relativePath: "resource"),
]
);

var document = subject.GetSwagger("v1");

Assert.Equal(["/resource"], [.. document.Paths.Keys]);
Assert.Single(document.Paths["/resource"].Operations);
Assert.Empty(document.Paths["/resource"].Operations[HttpMethod.Post].Tags);
}

[Fact]
public void GetSwagger_CanReadEndpointSummaryFromMetadata()
{
Expand Down