reverse-proxy icon indicating copy to clipboard operation
reverse-proxy copied to clipboard

JsonSchema support for YARP configuration

Open NikiforovAll opened this issue 3 years ago • 8 comments

Hi,

I've created a separate configuration file that looks something like this:

$ cat src/Gateway/routes.conf.json

{
  "ReverseProxy": {
    "Clusters": {
      "BackendApi": {
        "Destinations": {
          "Server1": {
            "Address": "http://localhost:5000"
          }
        }
      }
    },
    "Routes": {
      "ServerRoute1": {
        "ClusterId": "BackendApi",
        "Match": {
          "Path": "{**catch-all}"
        }
      }
    }
  }
}

I'm new to YARP, so I don't know the configuration of my head. It would be awesome to have suggestions based on JSON schema support.

e.g: "$schema": "http://https://microsoft.github.io/reverse-proxy/schemas/routes.conf.json",

NikiforovAll avatar Nov 05 '21 10:11 NikiforovAll

I wasn't aware of any json schema. It seems to be still in draft.

I wonder if the docs may be sufficient in the meantime - especially https://microsoft.github.io/reverse-proxy/articles/config-files.html#all-config-properties

karelz avatar Nov 05 '21 10:11 karelz

Thank you for the docs. They are very useful.

I guess my idea is to enable autocompletion and validation based on "$schema".

So the developer workflow might look like this:

  1. dotnet new yarp-config
  2. open any IDE. Most of the modern IDEs/editors automatically pick up "$schema"
  3. start typing and see suggestions.

Please feel free to close the issue if you don't find the proposal useful or valuable for overall developer experience.

NikiforovAll avatar Nov 05 '21 11:11 NikiforovAll

If IDEs support it widely, I think it would be worth adding. I was just not aware of such feature. Thanks for the tip!

karelz avatar Nov 05 '21 11:11 karelz

Triage: AppSettings.json already has this. It should be extension of that.

karelz avatar Nov 11 '21 18:11 karelz

We need to extend schemastore/appsettings.json. I would suggest that we use a $ref to a separate schema file as the appsettings schema seems to be getting unwieldy with non-inbox extensions (of which YARP would be one) and so we should set a precedent for how to do it cleanly. The format is defined at https://json-schema.org/draft/2020-12/json-schema-core.html.

samsp-msft avatar Jan 27 '22 21:01 samsp-msft

Hi @samsp-msft, @adityamandaleeka and @NikiforovAll,

Why extend appsettings.json schema? I happily would use a schema for YARP, so that generic application settings is separated from the YARP settings. In this case, I would recommend the configuration suggestion given by #NikiforovAll as a good candidate for the yarp specific schema.

Thanks

ghost avatar Jun 16 '22 05:06 ghost

I went ahead and wrote the spec up if anyone wants it. Feel free to use it

https://github.com/Arcalise08/YarpJsonSchema/blob/main/yarp.schema.json

Arcalise08 avatar Sep 22 '23 16:09 Arcalise08

VS has a new feature for Aspire where components can supply config schema files, so it doesn't need to have one big uber schema.

Notes from a chat with Eric on how this works in Aspire:

[12:51 PM] Eric Erhardt

[2:50 PM] Sam Spencer What exactly do we need to do? And will this work for any nuget package? you need to ship a .targets file in your buildTransitive folder of the nuget package that includes this: https://github.com/dotnet/aspire/blob/main/src/Components/Common/Package.targets#L1-L6 and then you write the ConfigurationSchema.json, like this example: https://github.com/dotnet/aspire/blob/main/src/Components/Aspire.Npgsql/ConfigurationSchema.json checkout the buildtranstiive folder in https://nuget.info/packages/Aspire.Npgsql/8.0.0-preview.1.23557.2

samsp-msft avatar Nov 17 '23 21:11 samsp-msft