Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby Kwalify YAML验证-在键名中使用正则表达式?_Ruby_Validation_Yaml - Fatal编程技术网

Ruby Kwalify YAML验证-在键名中使用正则表达式?

Ruby Kwalify YAML验证-在键名中使用正则表达式?,ruby,validation,yaml,Ruby,Validation,Yaml,我正在使用Kwalify进行模式验证。YAML文档的一部分实际上希望在映射中允许某种类型的键名 我看到Kwalify对映射中的值支持正则表达式,但我没有看到对映射中的键使用正则表达式的支持。以下是我想要支持的验证: test-element: sub-element-1: test sub-element-2: element-with-pattern-1: test1 element-with-pattern-2: test2 所以我不知道一些键名会是什么(在这里显示

我正在使用Kwalify进行模式验证。YAML文档的一部分实际上希望在映射中允许某种类型的键名

我看到Kwalify对映射中的值支持正则表达式,但我没有看到对映射中的键使用正则表达式的支持。以下是我想要支持的验证:

test-element:
  sub-element-1: test
  sub-element-2:
    element-with-pattern-1: test1
    element-with-pattern-2: test2
所以我不知道一些键名会是什么(在这里显示为假名称“element with pattern-*”),但我知道它们应该对应于正则表达式定义的模式


这是否可以使用Kwalify进行验证?

鉴于代码的当前状态,我认为这是不可能的

事实上,我也遇到了类似的情况,我发现(艰难的方式)在Kwalify上下文中不适合验证。我已经开始从灵活的键名迁移到一个可以专门定义模式的范例中

例如,我迁移了以下内容:

parent_key:
  random_key1: url1
  random_key2: url2
致:

使用后一种语法,可以进行如下验证:

"parent_key":
  type: seq
  sequence:
    - type: map
      mapping:
        "name":
          type: str
          required: yes
        "url":
          type: str
          required: yes
在该上下文中,您可以向
name
url
添加
模式
regex验证器,以实现您的目标。

要检查此项:

parent_key:
  random_key1: url1
  random_key2: url2
您应该使用“映射的默认值”,以下是模式示例:

type: map
mapping:
  "parent_key":
    type: map
    mapping:
      "=":
        type: str

type: map
mapping:
  "parent_key":
    type: map
    mapping:
      "=":
        type: str