我正在编写一个收集三个输入的动作。第一个是必需的,但是第二个和第三个是可选的。由于第二个和第三个选项的类型相似,因此有时填充第三个类型而第二个不填充。
即我想传递一本书,或书+页,或书+页+行号
我显然可以通过执行多个(几乎相同的)动作或在端点本身中来处理此问题,但是是否可以使单个动作输入的依赖关系取决于另一个输入的存在?
操作当前看起来像...
collect {
input (book) {
type (String)
min (Required) max (One)
}
input (page) {
type (Integer)
min (Optional) max (One)
}
input (line) {
type (Integer)
min (Optional) max (One)
}
}
答案 0 :(得分:0)
鉴于您的用例,按以下方式使用default-init
是有意义的:
collect {
input (book) {
type (String)
min (Required) max (One)
}
input (page) {
type (Integer)
min (Optional) max (One)
default-init {
if (!exists(page)) {
intent {
goal: YOUR ACTION HERE
value: Integer (1)
}
}
}
}
input (line) {
type (Integer)
min (Optional) max (One)
default-init {
if (!exists(line)) {
intent {
goal: YOUR ACTION HERE
value: Integer (1)
}
}
}
}
}
如果用户未提供页面和行号,则默认为1。
答案 1 :(得分:0)
看起来最好的选择(到目前为止,只有我能找到)是创建修改原始文件,然后添加第二个文件。最后,将新的action-endpoint
添加到endpoints
。
ReadBook 删除可选行
action (ReadBook) {
description ("Read a page from a book (first if page isn't provided)."")
type (Calculation)
collect {
input (book) {
type (Book)
min (Required) max (One)
}
input (page) {
type (PageNum)
min (Optional) max (One)
}
}
output (Passage)
}
ReadBookLine 使所有输入成为必需
action (ReadBookLine) {
description (Read a line from a book.)
type (Calculation)
collect {
input (book) {
type (Book)
min (Required) max (One)
}
input (page) {
type (PageNum)
min (Required) max (One)
}
input (line) {
type (LineNum)
min (Required) max (One)
}
}
output (Passage)
}
端点
endpoints {
action-endpoint (ReadBook) {
accepted-inputs (book, page)
remote-endpoint ("https://.../read_book) {
method (POST)
}
}
action-endpoint (ReadBookLine) {
accepted-inputs (book, page, line)
remote-endpoint ("https://.../read_book") {
method (POST)
}
}
}
}