Skip to content
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

Define a JSON schema for appsettings.json #2867

Closed
natemcmaster opened this issue Feb 10, 2018 · 18 comments
Closed

Define a JSON schema for appsettings.json #2867

natemcmaster opened this issue Feb 10, 2018 · 18 comments
Assignees
Labels
affected-most This issue impacts most of the customers area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions enhancement This issue represents an ask for new feature or an enhancement to an existing one severity-minor This label is used by an internal tool
Milestone

Comments

@natemcmaster
Copy link
Contributor

As we start to write more config binders for framework components, it becomes increasingly difficult for developers to discover settings that can be set in static config files. Documentation helps, but it would be even better if we could provide intellisense in the editor. Although config can be loaded from JSON, INI, XML, environment vars, and more, our new project templates and many apps use "appsettings.json" as a convention. It would be nice to provide a JSON schema file that includes common aspnetcore settings.

Usage
Users can reference a schema by adding the $schema property to their JSON file.

{
    "$schema": "https://somethingofficial.com/appsettings.schema.json"
    // the rest of the config there
}

Autocomplete
VS Code and VS already provide autocomplete and doc tooltips for JSON schema.
image

@Eilon
Copy link
Member

Eilon commented Apr 5, 2018

@shirhatti - as the proud owner of config, I've assigned this to you.

@Eilon
Copy link
Member

Eilon commented Jul 12, 2018

@shirhatti - any plans for this issue?

@shirhatti
Copy link
Contributor

Thanks for pinging me on this. It had slipped my radar.

@KevinMarquette
Copy link

@shirhatti I have a basic schema for appconfigs that could be used as a starting point. I'm not sure where the best place would be to add it. Any suggestions on where this should live?

@vindicatorr
Copy link

I peek in at dotnet every now and again to see where things stand and one great thing about it is the ability to change the appsettings.json and have it reload after the change.
It's much better than hardcoding little parameter/argument/value changes and rebuilding.

With that said, yes, the lack of intellisense/auto-completion for the csproj and json files are the absolute killer for me.
It's bad when I look at the documentation for Kestrel, where it shows an example appsettings.json, and not know where those settings/keys even come from, or how it has to be structured, or what other options I may have available to me.
A specific example IN that kestrel example is the "HttpsInlineCertStore" section which cannot be found if I try to look it up in the ".NET API Browser".

Another example is the "UserSecretsId" in the "PropertyGroup" of the csproj. I would only know how to use it solely by the example given.
I wouldn't know if the "UserSecretsId" is meant to be used in that PropertyGroup as opposed to somewhere else, or if it would need more structure like "<Microsoft.Extensions.Configuration.UserSecrets.UserSecretsId>" or

<Microsoft>
    <Extensions>
...
        ...<UserSecretsId>

As an aside, while that ".NET API Browser" is absolutely fantastic, it would truly be wonderful if we could do it offline with the libraries that already exist on our system.
For example, I'd love to be able to use the "Outline" in Visual Studio Code to browse through external references like System.
If that's something I can post about somewhere more applicable, do let me know.

@shirhatti
Copy link
Contributor

@vindicatorr Can you please open a new issue for what you're requesting? Completions in your csproj is orthogonal to what is being discussed here, but a valuable feature in it's own right.

@vindicatorr
Copy link

It doesn't look like a new issue is needed for the csproj auto-completions in general.

I see it has already been brought up in various places like dotnet/msbuild#2787

I also found https://github.com/tintoy/msbuild-project-tools-vscode in the marketplace (note "msbuild" referenced in both locations, showing it isn't an aspnet issue). And while there was A LOT of intellisense stuff going on in the csproj after installing it, the "UserSecretsId" never showed up and the closest thing was "GenerateUserSecretsAttribute" which didn't do anything.

@sliekens
Copy link

On topic: json schema doesn't work well with the way settings are merged. I found it's impossible to make a property required in appsettings.json but optional in appsettings.Development.json or vice versa.

@analogrelay
Copy link
Contributor

I don't think we'd make any properties required in our schema. It's just for discoverability. appsettings.json is just one of many possible ways to specify config and it's totally viable to have some settings in appsettings.json, some in appsettings.Development.json, some in environment variables, etc.

@masaeedu
Copy link

masaeedu commented May 29, 2019

While this is still being designed, I just wanted to say I actually do want to use it to make settings required. The problem right now is that we have a sprawling system of docker microservices with parameters being set through env vars, appsettings files, etc. This means there's a great deal of diligence required when adding to or modifying the configuration a service depends on; checking whether you're actually passing the right things to all services is hard to automate.

I would ideally like to be able to specify the complete set of inputs, required and optional, for a service as a appSettings.schema.json or whatever, and then be able to calculate whether the combination of:

  • the environment
  • the appSettings.json file
  • any applicable appSettings.whatever.json files

actually ends up satisfying the schema.

If this overall set of provided values doesn't satisfy the schema (including missing values for required properties), I want to be able to tell at an early stage, ideally as a linter over our deployment configs. At the least it should be possible to get the service to refuse to start if the provided configuration doesn't match the schema, so you can detect problems as dead containers.

@masaeedu
Copy link

I might have misunderstood the comment above though; if you're saying all the built in settings would be optional, that makes sense. 👍

@analogrelay
Copy link
Contributor

analogrelay commented May 29, 2019

I'm just talking about how we'd structure a JSON schema file. The schema file is just designed for IntelliSense in this case and we'd only put our "built-in" settings in it. Config validation in general, would be a separate feature.

@sliekens
Copy link

sliekens commented May 30, 2019

If the issue is discoverability of settings, didn't NuGet already solve that problem with config transformations? Having both would still be better of course. 😉

@tdreid
Copy link

tdreid commented Nov 13, 2019

It becomes increasingly difficult for developers to discover settings that can be set in static config files.

Indeed. Several hours deep on this for Kestrel here. Partial examples are fairly easy to find. Some further settings can be intuited from the shape/documentation of the configuration providers. But that just as often leads me astray

Documentation helps

@natemcmaster @shirhatti Until the schema(s) are in place to improve discoverability what's currently the most comprehensive source to determine settings that can (or can't) be set in static config files for kestrel?

So far the following seems to be the best resource. But I'm not confident that it covers everything that can be set, nor every way that any particular setting might be set. I could be wrong.

Thanks!

@0xced
Copy link
Contributor

0xced commented Apr 1, 2020

I just lost so much time because I tried to configure the urls with an array instead of a semicolon-separated string in my appsettings.json file.

❌ Don't use an array for the urls key:

{
  "urls": [ "http://localhost:4999" ]
}

✅ Use a (semicolon-separated) string for the urls key:

{
  "urls": "http://localhost:4999"
}

A json schema would certainly have prevented this error!

(Also, no error and not even a warning log for using the wrong type, the server just started on the default http://localhost:5000 address!)

@0xced
Copy link
Contributor

0xced commented Aug 11, 2020

Apparently, there's some effort to create a JSON schema for appsettings.json at https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/appsettings.json but it currently lacks ASP.NET Core standard configuration keys such as urls.

@Tratcher Tratcher added affected-most This issue impacts most of the customers enhancement This issue represents an ask for new feature or an enhancement to an existing one severity-minor This label is used by an internal tool labels Oct 12, 2020 — with ASP.NET Core Issue Ranking
@BrennanConroy BrennanConroy removed this from the Backlog milestone Nov 4, 2020
@BrennanConroy BrennanConroy added this to the Next sprint planning milestone Nov 4, 2020
@ghost
Copy link

ghost commented Nov 4, 2020

Thanks for contacting us.
We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. We will evaluate the request when we are planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@BrennanConroy BrennanConroy assigned jkotalik and unassigned shirhatti Nov 4, 2020
@jkotalik jkotalik assigned JamesNK and unassigned jkotalik Dec 10, 2020
@JamesNK
Copy link
Member

JamesNK commented Jan 5, 2021

Done 💪

https://twitter.com/JamesNK/status/1346253986647588864

@JamesNK JamesNK closed this as completed Jan 5, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Feb 4, 2021
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affected-most This issue impacts most of the customers area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions enhancement This issue represents an ask for new feature or an enhancement to an existing one severity-minor This label is used by an internal tool
Projects
None yet
Development

No branches or pull requests