reverse-proxy
reverse-proxy copied to clipboard
JsonSchema support for YARP configuration
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",
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
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:
-
dotnet new yarp-config
- open any IDE. Most of the modern IDEs/editors automatically pick up "$schema"
- 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.
If IDEs support it widely, I think it would be worth adding. I was just not aware of such feature. Thanks for the tip!
Triage: AppSettings.json already has this. It should be extension of that.
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.
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
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
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