You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Today, each Aspire Component has a ConfigurationSchema.json file that is added to the nupkg to provide JSON intellisense in appsettings.json files in the IDE:
"description": "The options relevant to a set of redis connections.",
"properties": {
"AbortOnConnectFail": {
"type": "boolean",
"description": "Gets or sets whether connect/configuration timeouts should be explicitly notified via a TimeoutException."
},
"AllowAdmin": {
"type": "boolean",
"description": "Indicates whether admin operations should be allowed."
},
Currently these .json files are hand-crafted. We should be able to generate them. My high-level thinking is:
Add a "post-compile" task to the build that uses Roslyn APIs to inspect and generate these .json files based on a supplied set of Types and config paths.
The ConfigurationSchema.json files stay checked into source control
This allows us to inspect, link to, and see the history of the file over time.
If the generated file is different than the checked-in file, fail the build.
The generator has an MSBuild option to overwrite the file, so when it needs to be updated you can simply dotnet build /p:UpdateConfigurationSchema=true and produce the new file
The text was updated successfully, but these errors were encountered:
Another reason this tool can't be a Roslyn source generator is because it needs to read XML docs for referenced assemblies. For example, the ConfigurationOptions.AllowAdmin property above gets its description from the XML docs on the StackExchange.Redis ConfigurationOptions type. A Roslyn source generator can't get this information due to dotnet/roslyn#51769.
Adds a tool that automatically generates ConfigurationSchema.json files for components.
To use the tool, a component adds an assembly attribute. For example:
```C#
[assembly: ConfigurationSchema("Aspire:Azure:Storage:Blobs", typeof(AzureStorageBlobsSettings))]
[assembly: ConfigurationSchema("Aspire:Azure:Storage:Blobs:ClientOptions", typeof(BlobClientOptions), exclusionPaths: ["Default"])]
[assembly: LoggingCategories("Azure", "Azure.Core", "Azure.Identity")]
```
### ConfigurationSchemaAttribute
* The first parameter is the config section path where the type is loaded from.
* The second parameter is the Type that is bound at that path.
* ExclusionPaths - (optional) The config sections to exclude from the ConfigurationSchema. This is useful if there are properties you don't want to publicize in the config schema.
### LoggingCategoriesAttribute
* The list of log categories produced by the component. These categories will show up under the `Logging` section in appsettings.json
This tool works after compilation by scanning the assembly for `ConfigurationSchema` and `LoggingCategories` attributes, and uses Roslyn APIs to inspect all properties of the types. It reuses all the parsing logic from https://github.com/dotnet/runtime/tree/main/src/libraries/Microsoft.Extensions.Configuration.Binder/gen, and using the underlying model objects, generates a JSON schema using System.Text.Json.Nodes APIs.
I've copied the necessary code from dotnet/runtime into the `RuntimeSource` folder for now. This code doesn't need to be reviewed since it is a straight copy from dotnet/runtime. After this PR goes through, we will set up an automatic "sync" action that will update this code anytime changes in the dotnet/runtime code is updated.
Fix#1146
Today, each Aspire Component has a ConfigurationSchema.json file that is added to the nupkg to provide JSON intellisense in appsettings.json files in the IDE:
aspire/src/Components/Aspire.StackExchange.Redis/ConfigurationSchema.json
Lines 21 to 32 in a3f058c
Currently these .json files are hand-crafted. We should be able to generate them. My high-level thinking is:
dotnet build /p:UpdateConfigurationSchema=true
and produce the new fileThe text was updated successfully, but these errors were encountered: