Archimedes Trajano
Archimedes Trajano

Reputation: 41560

How do I merge multiple lists using JSON ref?

I have the following YAML

- name: Core
  description: Core functionality
- name: Artifact
  description: Artifact management

# - $ref: "v1/publications.yml#/tags/"

v1/publications.yml has

tags:
  - name: Publication
    description: |
      This defines the publication API.

I sort of want the result to be I have the following YAML

- name: Core
  description: Core functionality
- name: Artifact
  description: Artifact management
- name: Publication
  description: |
    This defines the publication API.

# - $ref: "v1/publications.yml#/tags/"

I can do it one at a time like this...

- name: Core
  description: Core functionality
- name: Artifact
  description: Artifact management
- $ref: "v1/publications.yml#/tags/0"

But I want it to add multiple without updating my source.

Upvotes: 1

Views: 227

Answers (1)

flyx
flyx

Reputation: 39768

This is not possible with the technologies you tagged. $ref is exactly that, a reference to an external subtree. You need sequence concatenation, which is something neither nor plain YAML or JSON provide.

You may be able to do this using some templating technology, which many YAML-based utilities provide. If you are in control of the loading code, you can also implement custom tags to do something like

- name: Core
  description: Core functionality
- name: Artifact
  description: Artifact management
- !append {$ref: "v1/publications.yml#/tags"}

Upvotes: 1

Related Questions