Modify

Ticket #206 (new enhancement)

Opened 3 years ago

Last modified 2 years ago

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

sample_expansion_syntax.yml Download (972 bytes) - added by philip@… 3 years ago.
Sample real-world use-case

Change History

Changed 3 years ago by philip@…

Sample real-world use-case

comment:1 Changed 2 years 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?

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as new
as The resolution will be set. Next status will be 'closed'
to The owner will be changed from xi. Next status will be 'new'
The owner will be changed from xi to anonymous. Next status will be 'assigned'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.