Skip to content

YAML Usage

Micci - Luiz Miccieli edited this page Jan 30, 2025 · 5 revisions

This guide explains how to configure Templify for YAML files, allowing for the substitution of specific fields with defined placeholders, simplifying the setup of project-specific values.

YAML File Configuration

Templify uses a YAML configuration file with the structure below to enable replacement of specific values in the project’s YAML files.

steps:
  - kind: YmlHandler
    apiVersion: v1
    spec:
      - files:
          - yamls/generic1.yml
        placeholders:
          - match: mappings[0].file
            replace: newFile
          - match: mappings[0].placeholders[0].query
            replace: templify.query.project.groupId
          - match: mappings[0].placeholders[0].name
            replace: templify.replace.map.groupId
          - match: mappings[0].placeholders[1].query
            replace: templify.match.project.artifactId
          - match: mappings[0].placeholders[1].name
            replace: templify.replace.map.artifactId

Explanation of Key Sections

1. steps:

Defines a list of steps for Templify to execute. Each step specifies the handler type for a specific file (in this case, YmlHandler).

2. kind: YmlHandler

Specifies the handler type that will process the file.

3. apiVersion: v1

Indicates the version of the API for handling XML configurations. Ensure compatibility by matching the correct API version.

4. spec

The element in the spec array defines a set of files to be processed along with specific placeholders. Each spec item contains:

  • files: Specifies the Yaml files in which replacements will occur. The paths are relative to the root of the project.
  • placeholders: Defines the placeholder operations within each file, where:
    • match: The YAML path to be located in the file. We use the YAMLPath project structure.
    • replace: Specifies the placeholder value that will substitute the matched content. This value can reference an item in the templify configuration, providing flexibility to customize the output.

Example project

You can see this example working here