我正在尝试向ytt中的映射数组添加映射,以修改YAML文档。
我尝试了下面的方法,但它出错了,它说它需要一个map,但得到了一个数组。
https://gist.github.com/amalagaura/c8b5c7c92402120ed76dec95dfafb276
---
id: 1
type: book
awards:
books:
- id: 1
title: International Botev
reviewers:
- id: 2
name: PersonB
- id: 2
title: Dayton Literary Peace Prize
reviewers:
- id: 3
name: PersonC
#! How do I add a map to an array of maps?#@ load("@ytt:overlay", "overlay")
#@overlay/match by=overlay.all
---
awards:
books:
#@overlay/match by=overlay.all, expects="1+"
#@overlay/match missing_ok=True
reviewers:
#@overlay/append
- id: 1
name: PersonA发布于 2020-10-24 05:32:43
#@ load("@ytt:overlay", "overlay")
#! Add a map to an array of maps:
#@overlay/match by=overlay.all
---
awards:
books:
#@overlay/match by=overlay.all, expects="1+"
- reviewers:
#@overlay/append
- id: 1
name: Person A你的解决方案已经很接近了,你真正需要的就是让reviewers成为一个数组项。如果您希望能够将审阅者添加到没有该键的图书中,则必须在数组项和映射项上添加一个匹配器;下面包含了一个要点,以查看此行为的实际覆盖情况。如果同一项目上有多个#@overlay/match注释,则最后一个将获胜。有计划改善这种行为:https://github.com/k14s/ytt/issues/114。
https://get-ytt.io/#gist:https://gist.github.com/gcheadle-vmware/a6243ee73fa5cc139dba870690eb15c5
https://stackoverflow.com/questions/64504795
复制相似问题