Skip to content
Anton Bozhanov edited this page May 24, 2023 · 6 revisions

This document explains how to allow an automatic binding of template files with their corresponding Laboperator Workflow Schema and enable your editor to provide code completion, documentation on hover, and validation of the entire template.

JSON schemas and settings

Language servers provide language-specific smarts for editing, validating and understanding JSON documents. VS Code supports all JSON draft versions from Draft 4 to JSON Schema Draft 2020-12 out of the box. Servers like JSON Schema Store provide schemas for most of the common JSON-based configuration files. However, custom schemas can also be used.

Custom schemas can be associated directly with a schema file, the workspace settings, as well as the user settings. VS Code does not have built-in support for YAML, so you will have to install an extension in order to enable comprehensive language support. The examples in this document assume you are using the YAML Language Support by Red Hat.

Mapping in template files

The association of a file to a JSON schema can be done in the file itself using the $schema keyword. It declares which dialect of JSON Schema the schema was written for and applies to the entire document.

JSON
{
  "$schema": "https://raw.githubusercontent.com/labforward/laboperator-workflow-schema/develop/dist/workflow-template-schema.json",
  "schema_version": "1.0.1",
  "info": {
    "version": "1.0.0",
    "uuid": "8fc60467-f93a-4d2c-b6f3-84ec6e053496",
    "title": "My Workflow Template"
  }
}
YAML
# yaml-language-server: \\$schema=https://raw.githubusercontent.com/labforward/laboperator-workflow-schema/develop/dist/workflow-template-schema.json
schema_version: '1.0.1'
info:
  version: '1.0.0'
  uuid: 8fc60467-f93a-4d2c-b6f3-84ec6e053496,
  title: My Workflow Template

You may want to configure a snippet for these repeating code patterns, in order to make use of IntelliSense suggestions.

snippet example
"Laboperator Workflow Template schema": {
  "prefix": "$schema-laboperator",
  "body": [
    "# yaml-language-server: $schema=https://raw.githubusercontent.com/labforward/laboperator-workflow-schema/develop/dist/workflow-template-schema.json"
  ],
  "description": "Laboperator Workflow Template schema"
}

Mapping in User and Workspace Settings

User Settings apply globally to any instance of VS Code you open. Workspace settings are specific to a project and can be shared across developers on a project. The following example shows how to map both JSON and YAML files to the Workflow (Step) Template schema.

"json.schemas": [
  {
    "fileMatch": ["/*.template.json", "/template.json"],
    "url": "https://raw.githubusercontent.com/labforward/laboperator-workflow-schema/develop/dist/workflow-template-schema.json"
  },
  {
    "fileMatch": ["/*.step-template.json", "/step-template.json"],
    "url": "https://raw.githubusercontent.com/labforward/laboperator-workflow-schema/develop/dist/workflow-step-template-schema.json"
  }
],
"yaml.schemas": {
  "https://raw.githubusercontent.com/labforward/laboperator-workflow-schema/develop/dist/workflow-template-schema.json": [
    "/*.template.yml",
    "/template.yml"
  ],
  "https://raw.githubusercontent.com/labforward/laboperator-workflow-schema/develop/dist/workflow-step-template-schema.json": [
    "/*.step-template.yml",
    "/step-template.yml"
  ]
}

You will find such a schema mapping applied in the workspace settings for this repository. Likewise, you can configure this for specific projects of your choice with your own glob patterns for matching files.

JetBrains family

Long story short. .json and .yml files can be associated with any schema via GUI schema selector or in preferences/settings. The route in preferences is Languages & Frameworks > Schemas and DTDs > JSON Schema Mappings. These settings are project scoped.

longer story.

Workflow template schema
https://raw.githubusercontent.com/labforward/laboperator-workflow-schema/develop/dist/workflow-template-schema.json
Workflow step template schema
https://raw.githubusercontent.com/labforward/laboperator-workflow-schema/develop/dist/workflow-step-template-schema.json