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


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.


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:

The second example in the original post can be validly written as:

default_items: &default
  one: two
  foo: bar
  <<:  *default
  one: override

and the attached sample real-world use-case can also be validly written as:

- &default
  port:   53000
  user:   my_user
  passwd: S3kr1t
  db:     my_db
- &secondary
  <<:     *default
- <<:     *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?


Add a comment

Modify Ticket

Change Properties
<Author field>
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'

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

Note: See TracTickets for help on using tickets.