如果存在另一个可选输入,我可以将可选输入设为必需吗?

Can I make an optional input required, if another optional input is present?

我正在编写一个收集三个输入的动作。第一个是必需的,但第二个和第三个是可选的。由于第二个和第三个选项的类型相似,有时第三个类型被填充而第二个未填充。

即我要传入一本书,或者书+页,或者书+页+行号

显然,我可以通过执行多个(几乎相同的)操作或在端点本身中来处理这个问题,但是是否可以通过另一个输入的存在来确定单个操作输入的依赖性?

操作目前看起来像...

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)
  }
}

鉴于您的用例,按以下方式使用 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。

看起来最好的选择(目前只有我能找到)是创建修改原始文件,然后添加第二个。最后,添加一个新的action-endpointendpoints

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)
      }
    }
  }
}