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

generic: add schema for config.yml #1353

Merged
merged 3 commits into from
Feb 20, 2023
Merged

Conversation

ltalirz
Copy link
Contributor

@ltalirz ltalirz commented Feb 19, 2023

Add JSON schema for validating config.yml

The config.yml is automatically validated against the schema when running build.sh. A "modeline" is added to the config.tpl.yml, which points to the schema and provides automatic validation in VSCode with the "YAML" extension by RedHat.

@ltalirz
Copy link
Contributor Author

ltalirz commented Feb 19, 2023

Hey @xpillons , here is a draft for validating the config.yml via a JSON schema
It works directly in VSCode with the YAML extension, just try it on the config.tpl.yml.

Couple of points to decide/fix

  • validation currently fails (largeviz3d is actually too long a name)
  • is JSON schema OK or do you prefer to go with a YAML schema (to my understanding, YAML schema is a bit less widely used + not sure whether VSCode will support it)
  • should the schema go in the top level or, e.g. under /toolset? Putting it in a subfolder helps to unclutter the top level, but might make it less obvious for developers that the schema needs to be updated alongside the config.tpl.yml
  • the schema currently contains a few fields specific to our setup (e.g. workstation VMs). I can remove this

cc @matt-chan

@ltalirz ltalirz force-pushed the fix/validate-config branch from 3187a88 to dc65e3e Compare February 19, 2023 15:46
@xpillons
Copy link
Collaborator

@ltalirz this is a great start.

  • unfortunately largeviz3d is used in several places and changing it will introduce breaking changes. Is there a way to have av exception in the schema ?
  • JSON schema is perfect
  • It's fine having the schema at the root in the same place that the config.tpl.yml file

I would add an option in the build.sh to skip schema validation, I'm sure there are several cases we haven't think of, and this would be useful.

@xpillons xpillons added kind/feature New feature request do-not-merge labels Feb 20, 2023
@ltalirz ltalirz force-pushed the fix/validate-config branch from dc65e3e to 2e3bdf4 Compare February 20, 2023 17:40
Add JSON schema for validating config.yml

The confing.yml is automatically validated against the schema when running `build.sh`.
A "mode key" is added to the `config.tpl.yml`, which points to the schema and provides
automatic validation in VSCode with the "YAML" extension by RedHat.
@ltalirz ltalirz force-pushed the fix/validate-config branch from 2e3bdf4 to c12ddb9 Compare February 20, 2023 17:41
@ltalirz
Copy link
Contributor Author

ltalirz commented Feb 20, 2023

Hi @xpillons, thanks for the quick review; I've addressed your comments, the remaining question would be whether to remove any mention of workstation from the schema (just let me know).

@xpillons
Copy link
Collaborator

@ltalirz please build the schema based strictly on config.tpl.yml as it will be confusing otherwise.

@ltalirz ltalirz force-pushed the fix/validate-config branch from e6f579d to 80cfad4 Compare February 20, 2023 18:01
@ltalirz ltalirz marked this pull request as ready for review February 20, 2023 18:02
@ltalirz ltalirz requested a review from xpillons February 20, 2023 18:02
@xpillons
Copy link
Collaborator

@ltalirz what would be the process to update the schema ? is there a tool to do this ? if so can instructions be added ?

@ltalirz
Copy link
Contributor Author

ltalirz commented Feb 20, 2023

@ltalirz what would be the process to update the schema ?

For the first draft I programmatically inferred the schema from the existing yml file and then manually added descriptions, constraints, etc.

I believe for minor changes to the config.tpl.yml it would be easiest to just edit the schema manually, it's quite straightforward and VS Code already knows all the allowed fields in JSON Schema, which makes it even easier.

One aspect you may want to think about is whether the in-line documentation can eventually be removed from the config.tpl.yml since it is present in the schema and is accessible via mouse hover in VS Code:

image

Having it in the schema seems important to be able to provide good error messages; this should also make it straightforward to reuse in a GUI on the Azure Marketplace.

At the moment this information is somewhat duplicated (but maybe ok for the time being).

is there a tool to do this ? if so can instructions be added ?

I guess this would call for a new section of the az-hop documentation aimed at developers rather than admins?

@ltalirz
Copy link
Contributor Author

ltalirz commented Feb 20, 2023

P.S. The schema can also be used to define default values transparently. I've not yet started doing that.

@xpillons
Copy link
Collaborator

ok, got it. In fact not all customers are using VSCode, hence docs in the template file directly. And yes we should have a developer section in the doc.

Copy link
Collaborator

@xpillons xpillons left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I approve this first release, we can work on adding more constraints in the future

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature New feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants