【问题标题】:Making reference to the key name of parent in a YAML file?在 YAML 文件中引用父项的键名?
【发布时间】: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


【解决方案1】:

此功能需要能够检查结构中的当前路径。此外,由于源键是ServiceA,而目标键是ServicecA,因此需要进行字符串操作。

The docs 既没有提到检查当前路径的能力,也没有提到将c 插入给定字符串的任何功能。所以这似乎是不可能做到的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-05
    • 2020-01-25
    • 2016-01-09
    • 2020-09-23
    • 2017-12-08
    • 1970-01-01
    • 2019-01-08
    相关资源
    最近更新 更多