-
Notifications
You must be signed in to change notification settings - Fork 317
Fix duplicate entity groups in Swagger UI when entities have descriptions #3099
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
base: main
Are you sure you want to change the base?
Changes from all commits
2d3defc
aafb946
db2d784
9d7ece7
46f6a5b
0044782
7eb7844
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -149,6 +149,43 @@ public void OpenApiDocumentor_TagsIncludeEntityDescription() | |
| $"Expected tag for '{entityName}' with description '{expectedDescription}' not found."); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Integration test validating that there are no duplicate tags in the OpenAPI document. | ||
| /// This test ensures that tags created in CreateDocument are reused in BuildPaths, | ||
| /// preventing Swagger UI from showing duplicate entity groups. | ||
| /// </summary> | ||
| [TestMethod] | ||
| public void OpenApiDocumentor_NoDuplicateTags() | ||
| { | ||
| // Act: Get the tags from the OpenAPI document | ||
| IList<OpenApiTag> tags = _openApiDocument.Tags; | ||
|
|
||
| // Get all tag names | ||
| List<string> tagNames = tags.Select(t => t.Name).ToList(); | ||
|
|
||
| // Get distinct tag names | ||
| List<string> distinctTagNames = tagNames.Distinct().ToList(); | ||
|
|
||
| // Assert: The number of tags should equal the number of distinct tag names (no duplicates) | ||
| Assert.AreEqual(distinctTagNames.Count, tagNames.Count, | ||
| $"Duplicate tags found in OpenAPI document. Tags: {string.Join(", ", tagNames)}"); | ||
|
Comment on lines
+158
to
+171
|
||
|
|
||
| // Additionally, verify that each operation references tags that are in the global tags list | ||
| foreach (KeyValuePair<string, OpenApiPathItem> path in _openApiDocument.Paths) | ||
| { | ||
| foreach (KeyValuePair<OperationType, OpenApiOperation> operation in path.Value.Operations) | ||
| { | ||
| foreach (OpenApiTag operationTag in operation.Value.Tags) | ||
| { | ||
| // Verify that the operation's tag is the same instance as one in the global tags | ||
| bool foundMatchingTag = tags.Any(globalTag => ReferenceEquals(globalTag, operationTag)); | ||
| Assert.IsTrue(foundMatchingTag, | ||
| $"Operation tag '{operationTag.Name}' at path '{path.Key}' is not the same instance as the global tag"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Validates that the provided OpenApiReference object has the expected schema reference id | ||
| /// and that that id is present in the list of component schema in the OpenApi document. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BuildPathslogs a warning andcontinues when the tag isn’t found inglobalTags. This can happen in normal, non-mismatch scenarios for role-filtered documents:BuildOpenApiDocumentonly adds tags whenHasAnyAvailableOperations(entity, role)is true, butBuildPathsiterates all REST-enabled entities from metadata and attempts the tag lookup before checkingconfiguredRestOperations. This can produce noisy warnings and also couples path generation to tag presence. Consider moving the permission/operation filtering (e.g.,HasAnyAvailableOperationsorconfiguredRestOperations.ContainsValue(true)) before the tag lookup, and only warn/throw when an entity should be included but the tag key is still missing.