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

JsonSchema support for YARP configuration #1350

Open
NikiforovAll opened this issue Nov 5, 2021 · 8 comments
Open

JsonSchema support for YARP configuration #1350

NikiforovAll opened this issue Nov 5, 2021 · 8 comments
Labels
Type: Idea This issue is a high-level idea for discussion.
Milestone

Comments

@NikiforovAll
Copy link

NikiforovAll commented Nov 5, 2021

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 NikiforovAll added the Type: Idea This issue is a high-level idea for discussion. label Nov 5, 2021
@karelz
Copy link
Member

karelz commented Nov 5, 2021

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

@NikiforovAll
Copy link
Author

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.

@karelz
Copy link
Member

karelz commented Nov 5, 2021

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 karelz added this to the YARP 1.1.0 milestone Nov 11, 2021
@karelz
Copy link
Member

karelz commented Nov 11, 2021

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

@samsp-msft
Copy link
Contributor

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 samsp-msft moved this to 📋 Backlog in YARP 2.x Jun 9, 2022
@ghost
Copy link

ghost commented Jun 16, 2022

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

@karelz karelz moved this from 📋 Backlog to 🔖 Ready in YARP 2.x Jun 16, 2022
@samsp-msft samsp-msft moved this from 🔖 Ready to 📋 Backlog in YARP 2.x Jan 9, 2023
@karelz karelz modified the milestones: YARP 2.0.0, Backlog Jan 9, 2023
@Arcalise08
Copy link

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

@samsp-msft
Copy link
Contributor

samsp-msft commented Nov 17, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Idea This issue is a high-level idea for discussion.
Projects
Status: 📋 Backlog
Development

No branches or pull requests

6 participants