【发布时间】:2020-03-18 22:56:08
【问题描述】:
是否可以在 YAML 文件中引用父键的名称?
例如,如果我有以下 YAML 结构:
properties:
ServicecA:
storage: 100
ServicecB:
storage: 200
MyConfiguration:
ServiceA:
storage: ${self:properties.ServicecA.storage}
ServiceB:
storage: ${self:properties.ServiceB.storage}
我很不高兴我不得不在storage 值中再次输入ServiceA 和ServiceB。我想知道我是否可以实际将该部分引用为具有其父键名称的变量。像这样的:
properties:
ServicecA:
storage: 100
ServicecB:
storage: 200
MyConfiguration:
ServiceA:
storage: ${self:properties.${parent:keyName}.storage}
ServiceB:
storage: ${self:properties.${parent:keyName}.storage}
${parent:keyName} 应该引用其父项的键名。
这可以在常规 YAML 文件中实现吗?
【问题讨论】:
-
YAML 中的
${self:properties.ServiceA.storage}只是一个将作为字符串加载的标量。它没有引用任何东西。您可能正在使用一些为其赋予不同含义的库或应用程序,但如果不告诉我们它是哪一个,我们将无能为力。
标签: node.js yaml serverless-framework