dotnet / dotnet/aspnetcore

Add appsettings.json JSON schemas for areas that aren't already in the schema store

Open
#53,737 1 comment 13 reactions 0 assignees View on GitHub
area-networking
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [X] 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:

```xml



```
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:

```json
{
"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 https://github.com/dotnet/aspire/pull/1383 and https://github.com/dotnet/aspire/tree/main/src/Tools/ConfigurationSchemaGenerator.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.