← All recipes
Open source

Merge YAML snippet

Recipe IDorg.openrewrite.yaml.MergeYaml
Artifactorg.openrewrite:rewrite-yaml

Merge a YAML snippet with an existing YAML document.

Single recipeApache 2.0

Usage

You’ll need the Moderne CLI configured before running the command below.

mod run . --recipe org.openrewrite.yaml.MergeYaml --recipe-option "key=$.metadata" --recipe-option "yaml=labels:
  label-one: "value-one""

If the recipe isn’t available locally, install it with:

mod config recipes jar install org.openrewrite:rewrite-yaml:8.88.0

Options

NameTypeDescription
keyrequiredStringA JsonPath expression used to find matching keys.
e.g. $.metadata
yamlrequiredStringThe YAML snippet to insert. The snippet will be indented to match the style of its surroundings.
e.g. labels: label-one: "value-one"
acceptTheirsBooleanWhen the YAML snippet to insert conflicts with an existing key value pair and an existing key has a different value, prefer the original value.
objectIdentifyingPropertyStringName of a property which will be used to identify objects (mapping). This serves as the key to match on when merging entries of a sequence.
e.g. name
filePatternStringA glob expression representing a file path to search for (relative to the project root). Blank/null matches all.
e.g. .github/workflows/*.yml
insertModeInsertModeChoose an insertion point when multiple mappings exist. Default is Last.
insertPropertyStringDefine the key for the insertion mode. Takes the key JsonPath into account. Only useful when insert mode is either Before or After.
e.g. some-key
createNewKeysBooleanWhen the key path does _not_ match any keys, create new keys on the spot. Default is true.

Data tables

Structured output this recipe can produce.

  • Source files that had resultsSource files that were modified by the recipe run.org.openrewrite.table.SourcesFileResults
  • Source files that had search resultsSearch results that were found during the recipe run.org.openrewrite.table.SearchResults
  • Source files that errored on a recipeThe details of all errors produced by a recipe run.org.openrewrite.table.SourcesFileErrors
  • Recipe performanceStatistics used in analyzing the performance of recipes.org.openrewrite.table.RecipeRunStats