Camel provides possibilities to define Integrations using Yaml language. It is the language often used for people dealing with Kubernetes/OpenShift. This language doesn’t have the same maturity than xml or java but there are tooling that can help a lot. Given that yaml specification doesn’t allow self-described yaml metadata, several conventions are introduced to provide edition support of Yaml files. This article will focus on Camel Yaml files, both plain Yaml and Custom Resource Definitions (CRD) inside VS Code. Most of it can be transposed to other IDEs and other Yaml file types, see this other article.

Editing support

Textual editing support of yaml files is provided by VS Code Yaml. It provides syntaxic check for conformance with Yaml specification. More specific to our Camel use case, it can leverage Yaml schemas to provide completion and validation support. The binding of Yaml schema to the Yaml file can be done in various different ways. These various ways are explained in this article, describing their advantages and drawbacks.

Plain Camel Yaml files

Plain Camel Yaml files are available for Camel K and Camel standalone, for instance it is looking this way:

- from:
    uri: "timer:yaml"
    parameters:
      period: "1000"
    steps:
      - set-body:
          constant: "Hello Camel K from yaml"
      - to: "log:info"

Yaml schema

The Camel Yaml schema is available in Camel GitHub repository at the following URL https://raw.githubusercontent.com/apache/camel/main/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/camel-yaml-dsl.json

This Yaml schema is the basis for all following solutions.

It is registered in Json Schema Store.

File name pattern

VS Code Yaml is automatically resolving the schema when the file is named following one of these 2 patterns, :

  • *.camel.yaml
  • *.camelk.yaml

completion with resolved schema when using filename pattern

In the screenshot, please notice the file name visible in the editor title, the Codelens mentioning the Camel YAML DSL as resolved schema and the completion which is based on the schema.

The advantages are that the content of the file is left untouched. It is also working in all editors/IDEs relying on the Json schema store. For instance IntelliJ or editors/IDEs based on the Yaml Language server (Eclipse Desktop, Eclipse Che, Atom and more).

The drawbacks are that it doesn’t allow to have a versioning. It means that you will always have to follow the latest released version.

Inlined schema

It is possible to use inline metadata to specify the schema corresponding to the file with the VS Code Yaml. The following modeline-like format must be used:

# yaml-language-server: $schema=https://raw.githubusercontent.com/apache/camel/main/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/camel-yaml-dsl.json

No need to remember this line, on an empty file, you can call 2 completions to access it: Inlined schema and then Camel YAML DSL.

Calling completion 2 times on empty file to insert Camel K Yaml DSL

Note that after, you need to provide the first - yourself until this enhancement in Yaml Language Server has been implemented.

Defining inlined schema has the advantage to provide a self-described yaml file. It means that it allows to define the Camel/Camel K version used and consequently manage versioning. It is also working in all editors/IDEs based on the Yaml Language server (Eclipse Desktop, Eclipse Che, Atom and more).

Camel K modeline

In case, the yaml file is a Camel K one using the plain Yaml DSL and defining camel-k modeline, a schema is automatically applied by VS Code Tooling for Apache Camel K. This schema, especially the version of it, can be changed in File -> Preferences -> Settings -> Extensions -> Apache Camel K Tooling -> Camelk -> Yaml: Schema

no specific filename but the modeline # camel-k: is starting the file and that completion is available

In the screenshot, please notice that there is no specific filename but the modeline # camel-k: is starting the file and that completion is available.

The modeline is provided by default when creating the Integration file from Command palette Create a new Apache Camel K Integration file or via command-line kamel init my.yaml.

Association in VS Code Yaml settings

VS Code Yaml provides settings to map specific files from the workspace to specific schemas.

File -> Preferences -> Settings -> Extensions -> Yaml -> Yaml: Schemas -> Edit in settings.json and then insert something like:

{
	"yaml.schemas": {
		"https://raw.githubusercontent.com/apache/camel/main/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/camel-yaml-dsl.json" : "/pattern-defined-in-settings*.yaml"
	}
}

Completion on a file matching pattern provided in settings

Notice that the file is named following the specific pattern provided in code snippet example provided above. It doesn’t have any modelines and do not match JSon schema store file name pattern.

Camel CRD files

Edition support for Camel CRD files is available for a part of the Yaml attributes.

An automatic schema association is available with the following conditions:

Completion for a Kamelet CRD

Please note that it is missing several subcomponents; notably missing Flow/steps schema definitions, please vote for the support of it.

What’s next

Submit your enhancement requests! Given that several extensions are involved, feel free to report in the one that you want and you will be redirected. In case of doubt, I suggest to submit in the VS Code Language support for Apache Camel issue tracker.

Vote or provide Pull Requests for enhancement requests and issues to imrpove user experience for Camel Yaml development in VS Code, for instance:

More tooling to play with Camel Yaml in VS Code: