-
-
Notifications
You must be signed in to change notification settings - Fork 533
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
Docs: ApiDocsGenerator for API documentation from XML comments #5846
Conversation
This is something that we will need to handle from the code side. We need to rewrite comments so that they are properly formated and dramatically correct. Most comments are quite old and are not as good as they could be.
I see. Some defaults are only set in the code further. We have two options. Define default on the property, or mention it in the comment.
The real type should be correct, so
Makes sense: Question! Does this new generator need to be referenced as part of the nuget once we publish blazorise?
I think whichever
|
Option 1 sounds better - one source of truth. If not doable by property we can agree on some format for handling it from comment. Like:
Should be handled by
This gonna be more complicated, Extensions are wild. We don't want just the |
I focused on default values. From what I have checked, they should all work. Default values[Parameter] public string SomeValue { get; set; } = "some string value"; It also handles cases where the default value is not a constant. [Parameter] public TimeSpan Interval { get; set; } = TimeSpan.FromSeconds(10); Additionally, it works when the default value is set by a backing field. private string _backingField = "backed value";
[Parameter] public string BackedValue
{
get => _backingField;
set => _backingField = value;
} Moreover, it preserves the exact expression of default values, not just the computed result. [Parameter] public int ComplexValue { get; set; } = 20 * 200; // Output: "20 * 200", not "4000" Enum values for Blazorise enums..I added the listing of blazorise enums: the text I didn't persuade further, because I figured there is this Docs pages can handle multiple components..Component and its related components: <ComponentApiDocs ComponentTypes="[typeof(Accordion), typeof(AccordionToggle), typeof(AccordionItem), typeof(AccordionHeader), typeof(AccordionBody)]" /> Will focus on methods now. |
I have noticed we will have some edge cases with inherited parameters. For example TextEdit is inherited from For |
…' into sup/rel-1.7/xml-comments-autogen
What about just bringing it within the list: <ComponentApiDocs ComponentTypes="[typeof(TextEdit), typeof(BaseTextInput)]" /> It will be separated from each other... Or we I can do something like: <ComponentApiDocs JoinedComponentTypes=[ [typeof(TextEdit), typeof(BaseTextInput)] ] />
I agree. We can create the page manually and add the link to the I just need to add base class to the sg. |
Having them separate is not good because user should not care how it is structured internally. They only care that TextEdi has the parameters needed. And TextEdit can only be used as an external API. The second option with |
Agree. I can define these "joins" in the SG. "Every component that inherits from Are there any other such "joins" or "exception" to what we already have? |
I would join everything that goes up to BaseComponent. Everything in BaseComponent should be excluded and optionally documented somewhere else. |
"Issues" with inheritance
So question is "How to deal with the inheritance of methods and their comments"? Also you mention some black-listed methods, what are those? |
Any public method that is only meant to be used internally. For example BeginAnimation on Modal. Or, SetValue on NumericPicker. As mentioned before, we could remove it by adding the "Should only be used internally" comment. Which lead us to the second problem.
I can only think that we need to read XML comments file to get this information. |
BTW, my original idea was to generate API docs source code as a By generating it directly into the razor files, we can immediately see what is being generated. And we don't need to run the application to see the changes. Making it easier to review what needs to be omitted by extra rules. |
What about What about the "duplicates" like |
|
||
## System.Runtime | ||
|
||
Retrieving XML comments from the `System.Runtime` assembly can be problematic, particularly for the `IDisposable` interface. |
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.
Have you tried this library to read XML comments? Maybe they have already solved this kind of problems?
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.
The issue I am facing with System.Runtime
is that it doesn't appear to the analyzer that IDispose
is from System.Runtime
. Somehow, it's blind to this assembly, so it "doesn't know which XML to load".
We define every API docs explicitly by
Possibly and overlook from our side.
This should be same as my previous comment.
We should fix this kind of problem. But in another PR. Once we merger this PR. We are going to improve comments. You can just make a list in an issue so that we know what to do.
Same, we will fix it later.
Because Icon cannot be used without an extension, just define |
For options classes, ie |
Make a list of methods to ignore methods, and add Dispose onto it. The user should not be aware of it. |
@tesar-tech you can also ignore all internal components. Every component that starts with |
Just the generic type were not handled correctly. Fixed.
What about displaying just first 5 values and then button
I moved the code little bit ahead, so it doesn't get processed at all. Also all the conditions are now on one place within one switch expression. ( bool continueProcessing, bool skipParamAndComponentCheck ) = type switch
{
_ when type.TypeKind != TypeKind.Class || type.DeclaredAccessibility != Accessibility.Public => (false, false),
_ when type.Name.StartsWith( '_' ) => ( false, false ),
_ when type.Name.EndsWith( "Options" ) => ( true, true ),
_ when type.Name.EndsWith( "RouterTabsPageAttribute" ) => ( true, true ),
_ when !type.AllInterfaces.Any( i => i.Name == "IComponent" ) => ( false, false ),
_ => ( true, false )
}; Which also solves the
It would be maybe worth it to add them under
Little bit hacky, but fixed. |
It might work but don't worry about it now. We can also make an exception and add a URL to the Icons page
Nice :) We are about done for now. I want to move from this to other tasks. We can always improve documentation later. If anything goes wrong, we will fix it. Just to have a note for later. Instead of generating |
Description
ApiDocsGenerator
, to automatically extract public properties with the[Parameter]
attribute from Blazorise components.ComponentsApiDocsSource
) containing a dictionary to retrieve all parameters for a given component.ButtonPage.razor
:This single line will generate the API documentation at the bottom of the page, populated with XML comments.
TODOs
Verify XML Comments:
Ensure the XML comments accurately represent what we want to display publicly. While this is generally true, there are discrepancies—for example, the comments for the
Button
component differ a bit (parameterActive
)Default Values Handling:
[Parameter] public int SomeParam { get; set; } = 5;
are not respected yet.Type Differences:
Button.Clicked
is nowEventCallback<MouseEventArgs>
but was previously justEventCallback
.Adding Extensions:
.csproj
file individually.Handling Special Cases:
DataGrid
includesDataGridColumn
. Currently, column properties appear in theDataGrid
API page.Clean up the actual source generator