Ticket #206 (new enhancement)
Need ability to reuse and expand on defined lists and mappings.
| Reported by: | philip@… | Owned by: | xi |
|---|---|---|---|
| Priority: | normal | Component: | libyaml |
| Severity: | normal | Keywords: | anchor reference expansion |
| Cc: |
Description
Every yaml file I've created requires some form of data reuse. YAML should support list and mapping expansions using existing anchor and reference syntax.
default_items: &default - item one - item two - item three my_items: *default - additional item
default_items: &default one: two foo: bar my_items: *default one: override
Having this ability would be valuable, and appears clean and logical in terms of the existing syntax. Submitting for consideration.
Attachments
Change History
Changed 20 months ago by philip@…
-
attachment
sample_expansion_syntax.yml
added
comment:1 Changed 18 months ago by Philip Douglass <philip@…>
More research on my part uncovered a partial solution using the merge key described here: http://yaml.org/type/merge.html
The second example in the original post can be validly written as:
default_items: &default one: two foo: bar my_items: <<: *default one: override
and the attached sample real-world use-case can also be validly written as:
database_pool: - &default host: 10.10.10.1 port: 53000 user: my_user passwd: S3kr1t db: my_db - &secondary <<: *default host: 10.10.10.2 - <<: *secondary port: 53001
However, the first example in the original post cannot be solved with the merge key, since it is only useful for mappings. Why isn't there a similar feature available for merging sequences?

Sample real-world use-case