JSON schema is a standardized way to describe the content of JSON documents. Since YAML is a superset of JSON, it can also be used to describe YAML so long as advanced YAML functionality is not used. The standard for JSON schemas is defined in this document.
he Adapter can generate schemas describing all of its configuration files. To generate a schema, use the
-s argument of the CLI. There is one schema for the root-level configuration, and a schema for each plugin that needs a separate configuration file. For example:
Visual Studio Code provides excellent support for editing YAML documents constrained by a JSON schema.
To ease the editing of configuration files, here's the suggested setup:
- Generate all the schemas needed by your configurations using the OpenFMB CLI.
- Download and install Visual Studio Code
- Install the Red Hat YAML extension
- In a file named
.vscode/settings.jsoninside your working directory, add the following items:
YYou can customize the configuration here to your particular setup. The first argument (e.g.,
schemas/schema.json) points to a schema file. It is associated with a list of files for which this schema is applied. If you have multiple configuration files using the same schema, you can list them here. Or, as shown in the example, you can use the wildcard character * to match multiple files that follow the same pattern.
Then, you can open a configuration file in VS Code and have the following features:
Missing field highlighting
Validation of field values
Auto-complete of missing fields by pressing CTRL-SPACE
Auto-complete enum variants by pressing CTRL-SPACE
Auto-create an item of an array by writing an hyphen then pressing TAB
A breadcrumb to show you where your cursor is positioned in the file's hierarchy
Inline description of fields on mouse hovering