Wiki

Clone wiki

snakeyaml / Variable substitution

Your configuration options can contain environment variables. SnakeYAML implements Variable substitution similar to how it works in docker-compose.

Only ${VARIABLE} syntax is supported.

it is possible to provide inline default values using typical shell syntax (exactly as for docker-compose):

  • ${VARIABLE:-default} evaluates to default if VARIABLE is unset or empty in the environment.
  • ${VARIABLE-default} evaluates to default only if VARIABLE is unset in the environment.
  • ${VARIABLE:?err} exits with an error message containing err if VARIABLE is unset or empty in the environment.
  • ${VARIABLE?err} exits with an error message containing err if VARIABLE is unset in the environment.

If variable is not set, the empty value is used. Except when it is explicitly instructed to fail.

Since SnakeYAML is no template engine, it does not substitute parts of scalar, only the whole scalar. For instance this stays as it is because template is just a part of the scalar:

    environment:
      - DEBUG=${DEBUG}
      - "DIR=${DATA_DIR}"
This is substituted:
    environment:
      DEBUG: ${DEBUG}
      DIR: ${DATA_DIR}

An example of the implementation can be found in tests.

An an example with Lombok can also be found in tests.

Updated