简体   繁体   中英

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.

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"}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM