How can I expression an optional record with required fields

Hi there

I am trying to write a tool where a record describes one of the inputs and the input itself is optional but if it is there then all parts of the input (all fields in the record) must be there. Here is a non-working example:

class: CommandLineTool
cwlVersion: v1.1
baseCommand:
  - echo
inputs:
  one:
    type:
      - 'null'
      - type: record
        fields:
          - name: one
            type: string
            inputBinding:
              position: 1
          - name: two
            type: string
            inputBinding:
              position: 2
  two:
    type: string
outputs:
  output_one:
    type: stdout
stdout: output.txt

This example does not work because one.one and one.two are required arguments. What I intend to express is that one is optional but if it is there then one.one and one.two are required. If I make the fields optional (i.e. type string?) then each of them can be provided or not, independently. That is also not correct.

I hope my question is clear.

2 Likes

This sounds like a hole in the spec/implementation. As a developer I would interpret this code exactly as your use case. I would request you open an issue on the CWL website. Currently we have different websites for different versions: the best would likely be open it on the main one (https://github.com/common-workflow-language/common-workflow-language)

Hey Peter, nice to see you here.

This appears to be a bug with the CWL reference runner, so please file an issue at https://github.com/common-workflow-language/cwltool

Specifically, it works with a YAML/JSON input object, but not via the cwltool command line specification trick:

$ cat optional-record.yaml 
two: FOO
$ cwltool optional_record.cwl optional-record.yaml 
INFO /home/michael/user_guide/env2.7/bin/cwltool 1.0.20191022103248
INFO Resolved 'optional_record.cwl' to 'file:///home/michael/cwltool/optional_record.cwl'
INFO [job optional_record.cwl] /tmp/8mcr3z$ echo > /tmp/8mcr3z/output.txt
INFO [job optional_record.cwl] completed success
{
    "output_one": {
        "checksum": "sha1$adc83b19e793491b1c6ea0fd8b46cd9f32e592fc", 
        "basename": "output.txt", 
        "location": "file:///home/michael/cwltool/output.txt", 
        "path": "/home/michael/cwltool/output.txt", 
        "class": "File", 
        "size": 1
    }
}
INFO Final process status is success

1 Like