Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes and enhancements in JSON Configuration schema generator (#4441)
* Add tests to identify the current behavior (all tests are green). * Fix: respect [ConfigurationKeyName] override for property names This initially broke the integration test, which loads reference assemblies from the 'refs' subdirectory. But Microsoft.Extensions.Configuration.Abstractions.dll (which contains ConfigurationKeyNameAttribute) isn't copied there during build, which is why I changed the test to not use the refs subdirectory. * Ignore leading/trailing whitespace and line breaks in doc-comments, because they have no semantic meaning. IDEs auto-break lines when rendering the text, depending on screen space. However, do convert <br/> and <para/> tags into visible line breaks. While this doesn't have much effect on Aspire itself, it matters greatly to my team because we have configured Resharper to auto-format doc-comments, which takes the configured maximum line length into account. So it merges and breaks lines in doc-comments all the time. The changes on Aspire .json files are the following, which can be seen after replacing all \n with a single space in the diff. - ` ,` becomes `,` - `( 'SomeType' )` becomes `('SomeType')` - `Some. Other` becomes `Some. Other` - `Some. Other` becomes `Some.\n\nOther` (because of <para> usage) - `"Some ."` becomes `"Some."` * Fix crash on property of type byte[]. The ConfigurationBinder supports an array of numbers, as well as a base64-encoded string. See dotnet/runtime#43150. * Allow settings to appear top-level * Add support for using <inheritdoc /> in code and external assemblies. Because roslyn provides no public API to expand inherited doc-comments (see dotnet/csharplang#313), I'm using the internal Microsoft.CodeAnalysis.Shared.Extensions.ISymbolExtensions.GetDocumentationComment method. The method is made accessible by using reflection. This method behaves a bit odd though: If there's no doc-comment on a member, it internally assumes that the member contains "<doc><inheritdoc/></doc>" (which is completely invalid) and feeds that to itself. As a consequence, the method may return something wrapped in <doc>, instead of the expected <member> element. I didn't want to write a test for this undocumented behavior, but it explains the fallback to <doc> when <member> does not exist. * Refactor recursion to support collections and recursive/circular types, allow all types as component, preserve existing JSON structure on empty nodes. Note this commit includes a fix in the RuntimeSource directory to prevent a StackOverflowException. * Fix broken build after rebase on latest main * Review feedback: use Queue instead of ImmutableQueue * Preserve blank lines in doc-comments * Remove IgnoresAccessChecksToGenerator usage and just use normal reflection to reduce dependencies. * Remove unnecessary #ifs * Add explaining comments for node backup strategy * Fix normalization of whitespace characters, such as tabs * Add explaining comments for line break handling in doc-comments * Rename GenerateComponent to GeneratePathSegment * Provide compiled sample usage instead of appsettings.json comment * Replace minimal assertions with full JSON comparison * PR feedback - rename variables to remove "component" --------- Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
- Loading branch information