-
Notifications
You must be signed in to change notification settings - Fork 10.5k
OpenAPI: Fix duplicate xml documentation ids for Generic properties and references #64404
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
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 |
|---|---|---|
|
|
@@ -110,7 +110,7 @@ internal static string NormalizeDocId(string docId) | |
| return comments; | ||
| } | ||
|
|
||
| internal static IEnumerable<(string, XmlComment?)> ParseComments( | ||
| internal static IEnumerable<(string, XmlComment?)> ParseCommentsApplicationAssembly( | ||
| (List<(string, string)> RawComments, Compilation Compilation) input, | ||
| CancellationToken cancellationToken) | ||
| { | ||
|
|
@@ -136,6 +136,31 @@ internal static string NormalizeDocId(string docId) | |
| return comments; | ||
| } | ||
|
|
||
| internal static IEnumerable<(string, XmlComment?)> ParseCommentsReference( | ||
| (List<(string, string)> RawComments, Compilation Compilation) input, | ||
| CancellationToken cancellationToken) | ||
| { | ||
| var compilation = input.Compilation; | ||
| var comments = new List<(string, XmlComment?)>(); | ||
| foreach (var (name, value) in input.RawComments) | ||
| { | ||
| if (DocumentationCommentId.GetFirstSymbolForDeclarationId(name, compilation) is ISymbol symbol && | ||
| // Only include symbols that are accessible from the application assembly. | ||
| symbol.IsAccessibleType() && | ||
|
Comment on lines
+148
to
+149
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @desjoerd this seems okay, but should this PR also revisit the use of Specifically, it seems like this source generator should default to excluding types marked with (e.g. thinking about this from the aot perspective where I don't want paragraphs and paragraphs xml docs from internal/dev-time-only marker attributes getting baked into the executable)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the application assembly types with [Embedded] are accessible and could even be used within your Api I think. For referenced assemblies they will be already excluded as it will only emit xml comments for types marked as |
||
| // Skip static classes that are just containers for members with annotations | ||
| // since they cannot be instantiated. | ||
| symbol is not INamedTypeSymbol { TypeKind: TypeKind.Class, IsStatic: true }) | ||
| { | ||
| var parsedComment = XmlComment.Parse(symbol, compilation, value, cancellationToken); | ||
| if (parsedComment is not null) | ||
| { | ||
| comments.Add((name, parsedComment)); | ||
| } | ||
| } | ||
| } | ||
| return comments; | ||
| } | ||
|
|
||
| internal static bool FilterInvocations(SyntaxNode node, CancellationToken _) | ||
| => node is InvocationExpressionSyntax { Expression: MemberAccessExpressionSyntax { Name.Identifier.ValueText: "AddOpenApi" } }; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,10 +24,10 @@ public void Initialize(IncrementalGeneratorInitializationContext context) | |
| // and the target assembly. | ||
| var parsedCommentsFromXmlFile = commentsFromXmlFile | ||
| .Combine(context.CompilationProvider) | ||
| .Select(ParseComments); | ||
| .Select(ParseCommentsReference); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm...is this change related to the fix for generic types?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one is to fix the comments coming from a documentation file when a type also exists in the main compilation. When an internal type with the same namespace and class name exists in the Application assembly. In the unit tests it's the I duplicated the |
||
| var parsedCommentsFromCompilation = commentsFromTargetAssembly | ||
| .Combine(context.CompilationProvider) | ||
| .Select(ParseComments); | ||
| .Select(ParseCommentsApplicationAssembly); | ||
| // Discover AddOpenApi invocations so that we can intercept them with an implicit | ||
| // registration of the transformers for mapping XML doc comments to the OpenAPI file. | ||
| var groupedAddOpenApiInvocations = context.SyntaxProvider | ||
|
|
||
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.
If someone has a better idea for this, let me know. The main difference compared to
ParseCommentsApplicationAssemblyis that it only allows "accessible" types