-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Description
Is there an existing issue for this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
When editing appsettings.json files, we get intellisense for core configuration sections like "ConnectionStrings", "Logging", "Kestrel", and "AllowedHosts". This comes from https://json.schemastore.org/appsettings.json.
However, there are plenty more areas in ASP.NET Core that read from a config section than what is described in the schema store document - for example, Auth sections. In the past we haven't added these to the schema store. I assume this is because these other areas are optional, and might not be respected in your app.
While developing .NET Aspire, we have introduced a new feature that allows NuGet packages to bring in fragments of JSON schema into a project. VS will aggregate all the fragments into a composite JSON schema and use that in the editor. (Note there is work to get this experience outside of VS as well, for example VS Code.) This feature works even outside of .NET Aspire.
Describe the solution you'd like
We should use this new JSON schema fragment feature in all the places in ASP.NET Core that reads configuration sections. That way users can tell what config settings are available, and what the format should be.
Additional context
To use this feature, add some MSBuild logic to the nuget package of the form:
<Project>
<ItemGroup>
<JsonSchemaSegment Include="$(MSBuildThisFileDirectory)..\..\ConfigurationSchema.json"
FilePathPattern="appsettings\..*json" />
</ItemGroup>
</Project>where JsonSchemaSegment Include is the path to the JSON schema fragment file and FilePathPattern is a Regex for the file names this schema segment applies to.
Then you can write a JSON schema that looks like:
{
"properties": {
"SectionName": {
"type": "object",
"properties": {
"Property1": {
"type": "boolean",
"description": "Gets or sets a value that describes Property1."
}
}
}
},
"type": "object"
}To assist in creating these schema fragments, we've developed a source generator that can generate the JSON schema given a .NET type. See microsoft/aspire#1383 and https://github.com/dotnet/aspire/tree/main/src/Tools/ConfigurationSchemaGenerator.