yaml - dhall-to-yaml:表示嵌套在结构化 yaml 中的非结构化块
问题描述
我正在玩 dhall,试图代表我在 dhall 中拥有的现有大型 yaml 文件。
具体来说,我正在尝试为大厅管道定义构建 dhall 类型和助手。定义大厅管道的部分 yaml 看起来像我在这里编写的 yaml。我列表中的每个资源都包含一个名称、一个类型和一个源,其结构完全取决于资源的类型。
没有详尽的资源列表供我定义,因为明天有人可能会创建一个新的资源,而且我不想每次第三方创建新的源类型时都更新我的类型。
我为此拥有的 dhall 也在这里,但我不确定我该如何代表source
。我曾考虑在我的类型中省略该字段并指示消费者使用 dhall 的//
运算符添加源,但随后很难将resource
s 嵌入 a[resource]
并仍然进行类型检查。
如何为包含非结构化字段的资源定义 dhall 类型。
resources:
- name: my-repo
type: git
source:
$some_unstructured_yaml
{ name : Text
, type : Text
, source : Optional ???
}
解决方案
这将在dhall-json
.
例如,给定这个模式:
-- This will become: https://prelude.dhall-lang.org/JSON/Type
let JSON = https://raw.githubusercontent.com/dhall-lang/dhall-lang/40c3e57a4f09448b5a7c9d203a81b64f50ed30bd/Prelude/JSON/Type
in { name : Text
, type : Text
, source : Optional JSON
}
...以及此 YAML 配置:
name: my-repo
type: git
source:
foo:
- 1
- bar: true
baz: null
...它将产生这个 Dhall 表达式:
$ yaml-to-dhall ./schema.dhall < example.yml
{ name =
"my-repo"
, source =
Some
( λ(JSON : Type)
→ λ ( json
: { array :
List JSON → JSON
, bool :
Bool → JSON
, null :
JSON
, number :
Double → JSON
, object :
List { mapKey : Text, mapValue : JSON } → JSON
, string :
Text → JSON
}
)
→ json.object
[ { mapKey =
"foo"
, mapValue =
json.array
[ json.number 1.0
, json.object [ { mapKey = "bar", mapValue = json.bool True } ]
]
}
, { mapKey = "baz", mapValue = json.null }
]
)
, type =
"git"
}
有关更多详细信息,请参阅对标准的以下更改:
...以及对dhall-json
包的以下更改:
推荐阅读
- android - CountDownTimer 在移动到下一个活动后没有停止 - 测验应用程序
- java - 类之间的值 - null
- angular - Angular FormControl:如何将类或属性应用于底层 DOM 元素?
- database - 我是否需要担心对主数据集使用存储过程的 SSRS 报告的 SQL 注入?
- linux - Yocto:为什么在构建外部内核模块期间未定义结构模块
- python - 字典理解:更改列表值中的最后一项
- hadoop - 如何通过HIVE从txt文件中的行中删除重复项
- mysql - MySQL:如何在 SELECT cluase 中使用 Multi-SELECT?
- ios - 此应用包含一个应用扩展,该扩展指定了此 iOS 版本不支持的扩展点标识符
- swift - Swift 参数标签 '(_:, destination:)' 不匹配任何可用的重载