Skip to content

Examples

This page provides complex examples showing how multiple fyaml concepts work together. For basic examples and detailed documentation, see the Usage Guide.

All examples shown here correspond to runnable examples in the examples directory in the repository.

Combining Multiple Concepts

This example demonstrates how root-level files, @ files, and deep nesting work together:

Directory Structure

config/
  defaults.yml
  entities/
    @shared.yml
    item1/
      config.yml
      metadata.yml
    item2/
      settings.yml
  category1/
    item3.yml
    item4.yml

Input Files

defaults.yml:

project: example
version: 1.0.0

entities/@shared.yml:

environment: production
region: us-east-1

entities/item1/config.yml:

entity:
  id: example1
  attributes:
    name: sample name
    tags: []

entities/item1/metadata.yml:

related:
  - id: example2
    attributes:
      name: related item
      tags:
        - tag1

entities/item2/settings.yml:

entity:
  id: example2
  attributes:
    name: another item
    tags:
      - tag2

category1/item3.yml:

entity:
  id: example3
  attributes:
    name: third item
    tags: []

category1/item4.yml:

entity:
  id: example4
  attributes:
    name: fourth item
    tags: []

Command

fyaml config/

Output

category1:
  item3:
    entity:
      id: example3
      attributes:
        name: third item
        tags: []
  item4:
    entity:
      id: example4
      attributes:
        name: fourth item
        tags: []
entities:
  environment: production
  item1:
    config:
      entity:
        id: example1
        attributes:
          name: sample name
          tags: []
    metadata:
      related:
        - attributes:
            name: related item
            tags:
              - tag1
          id: example2
  item2:
    settings:
      entity:
        id: example2
        attributes:
          name: another item
          tags:
            - tag2
  region: us-east-1
project: example
version: 1.0.0

Key points:

  • defaults.yml at root merges project and version into the top level (root-level files merge directly)
  • entities/@shared.yml merges environment and region into the entities map (uses @ to merge into parent directory)
  • Deep nesting (3 levels: entities/item1/config.yml) works naturally
  • All concepts work together in a single structure

Runnable Examples

The following examples demonstrate individual concepts. Each has a corresponding runnable example in the repository:

See the examples directory for all available examples.