$base: "https://w3id.org/cwl/cwl#"

$namespaces:
  cwl: "https://w3id.org/cwl/cwl#"
  sld: "https://w3id.org/cwl/salad#"
  rdfs: "http://www.w3.org/2000/01/rdf-schema#"

$graph:

- name: "Common Workflow Language, Draft 3"
  type: documentation
  doc: {$include: concepts.md}

- $import: "salad/schema_salad/metaschema/metaschema.yml"

- name: BaseTypesDoc
  type: documentation
  doc: |
    ## Base types
  docChild:
    - "#CWLType"
    - "#Process"

- type: enum
  name: CWLVersions
  doc: "Version symbols for published CWL document versions."
  symbols:
    - cwl:draft-2
    - cwl:draft-3.dev1
    - cwl:draft-3.dev2
    - cwl:draft-3.dev3
    - cwl:draft-3.dev4
    - cwl:draft-3.dev5
    - cwl:draft-3

- name: CWLType
  type: enum
  extends: "sld:PrimitiveType"
  symbols:
    - cwl:File
  doc:
    - "Extends primitive types with the concept of a file as a first class type."
    - "File: A File object"

- name: File
  type: record
  docParent: "#CWLType"
  doc: |
    Represents a file (or group of files if `secondaryFiles` is specified) that
    must be accessible by tools using standard POSIX file system call API such as
    open(2) and read(2).
  fields:
    - name: class
      type:
        type: enum
        name: File_class
        symbols:
          - cwl:File
      jsonldPredicate:
        "_id": "@type"
        "_type": "@vocab"
      doc: Must be `File` to indicate this object describes a file.
    - name: path
      type: string
      doc: The path to the file.
      jsonldPredicate:
        "_id": "cwl:path"
        "_type": "@id"
    - name: checksum
      type: ["null", string]
      doc: |
        Optional hash code for validating file integrity.  Currently must be in the form
        "sha1$ + hexidecimal string" using the SHA-1 algorithm.
    - name: size
      type: ["null", long]
      doc: Optional file size.
    - name: "secondaryFiles"
      type:
        - "null"
        - type: array
          items: "#File"
      jsonldPredicate: "cwl:secondaryFiles"
      doc: |
        A list of additional files that are associated with the primary file
        and must be transferred alongside the primary file.  Examples include
        indexes of the primary file, or external references which must be
        included when loading primary document.  A file object listed in
        `secondaryFiles` may itself include `secondaryFiles` for which the same
        rules apply.
    - name: format
      type: ["null", string]
      jsonldPredicate:
        _id: cwl:format
        _type: "@id"
        identity: true
      doc: |
        The format of the file.  This must be a URI of a concept node that
        represents the file format, preferrably defined within an ontology.
        If no ontology is available, file formats may be tested by exact match.

        Reasoning about format compatability must be done by checking that an
        input file format is the same, `owl:equivalentClass` or
        `rdfs:subClassOf` the format required by the input parameter.
        `owl:equivalentClass` is transitive with `rdfs:subClassOf`, e.g. if
        `<B> owl:equivalentClass <C>` and `<B> owl:subclassOf <A>` then infer
        `<C> owl:subclassOf <A>`.

        File format ontologies may be provided in the "$schema" metadata at the
        root of the document.  If no ontologies are specified in `$schema`, the
        runtime may perform exact file format matches.


- name: SchemaBase
  type: record
  abstract: true
  fields:
    - name: secondaryFiles
      type:
        - "null"
        - "string"
        - "#Expression"
        - type: "array"
          items: ["string", "#Expression"]
      jsonldPredicate: "cwl:secondaryFiles"
      doc: |
        Only valid when `type: File` or is an array of `items: File`.

        Describes files that must be included alongside the primary file(s).

        If the value is an expression, the value of `self` in the expression
        must be the primary input or output File to which this binding applies.

        If the value is a string, it specifies that the following pattern
        should be applied to the primary file:

          1. If string begins with one or more caret `^` characters, for each
            caret, remove the last file extension from the path (the last
            period `.` and all following characters).  If there are no file
            extensions, the path is unchanged.
          2. Append the remainder of the string to the end of the file path.

    - name: format
      type:
        - "null"
        - string
        - type: array
          items: string
        - "#Expression"
      jsonldPredicate:
        _id: cwl:format
        _type: "@id"
        identity: true
      doc: |
        Only valid when `type: File` or is an array of `items: File`.

        For input parameters, this must be one or more URIs of a concept nodes
        that represents file formats which are allowed as input to this
        parameter, preferrably defined within an ontology.  If no ontology is
        available, file formats may be tested by exact match.

        For output parameters, this is the file format that will be assigned to
        the output parameter.

    - name: streamable
      type: ["null", "boolean"]
      doc: |
        Only valid when `type: File` or is an array of `items: File`.

        A value of `true` indicates that the file is read or written
        sequentially without seeking.  An implementation may use this flag to
        indicate whether it is valid to stream file contents using a named
        pipe.  Default: `false`.


- name: Parameter
  type: record
  extends: "#SchemaBase"
  abstract: true
  doc: |
    Define an input or output parameter to a process.

  fields:
    - name: type
      type:
        - "null"
        - "#CWLType"
        - "sld:RecordSchema"
        - "sld:EnumSchema"
        - "sld:ArraySchema"
        - string
        - type: array
          items:
            - "#CWLType"
            - "sld:RecordSchema"
            - "sld:EnumSchema"
            - "sld:ArraySchema"
            - string
      jsonldPredicate:
        "_id": "sld:type"
        "_type": "@vocab"
      doc: |
        Specify valid types of data that may be assigned to this parameter.

    - name: label
      type:
        - "null"
        - string
      jsonldPredicate: "rdfs:label"
      doc: "A short, human-readable label of this parameter object."

    - name: description
      type:
        - "null"
        - string
      jsonldPredicate: "rdfs:comment"
      doc: "A long, human-readable description of this parameter object."


- type: enum
  name: Expression
  doc: |
    Not a real type.  Indicates that a field must allow runtime parameter
    references.  If [InlineJavascriptRequirement](#InlineJavascriptRequirement)
    is declared and supported by the platform, the field must also allow
    Javascript expressions.
  symbols:
    - cwl:ExpressionPlaceholder


- name: InputBinding
  type: record
  abstract: true
  fields:
    - name: loadContents
      type:
        - "null"
        - boolean
      jsonldPredicate: "cwl:loadContents"
      doc: |
        Only valid when `type: File` or is an array of `items: File`.

        Read up to the first 64 KiB of text from the file and place it in the
        "contents" field of the file object for use by expressions.


- name: OutputBinding
  type: record
  abstract: true


- name: InputSchema
  extends: "#SchemaBase"
  type: record
  abstract: true


- name: OutputSchema
  extends: "#SchemaBase"
  type: record
  abstract: true


- name: InputRecordField
  type: record
  extends: "sld:RecordField"
  specialize:
    - specializeFrom: "sld:RecordSchema"
      specializeTo: "#InputRecordSchema"
    - specializeFrom: "sld:EnumSchema"
      specializeTo: "#InputEnumSchema"
    - specializeFrom: "sld:ArraySchema"
      specializeTo: "#InputArraySchema"
  fields:
    - name: inputBinding
      type: [ "null", "#InputBinding" ]
      jsonldPredicate: "cwl:inputBinding"


- name: InputRecordSchema
  type: record
  extends: ["sld:RecordSchema", "#InputSchema"]
  specialize:
    - specializeFrom: "sld:RecordField"
      specializeTo: "#InputRecordField"


- name: InputEnumSchema
  type: record
  extends: ["sld:EnumSchema", "#InputSchema"]
  fields:
    - name: inputBinding
      type: [ "null", "#InputBinding" ]
      jsonldPredicate: "cwl:inputBinding"


- name: InputArraySchema
  type: record
  extends: ["sld:ArraySchema", "#InputSchema"]
  specialize:
    - specializeFrom: "sld:RecordSchema"
      specializeTo: "#InputRecordSchema"
    - specializeFrom: "sld:EnumSchema"
      specializeTo: "#InputEnumSchema"
    - specializeFrom: "sld:ArraySchema"
      specializeTo: "#InputArraySchema"
  fields:
    - name: inputBinding
      type: [ "null", "#InputBinding" ]
      jsonldPredicate: "cwl:inputBinding"


- name: OutputRecordField
  type: record
  extends: "sld:RecordField"
  specialize:
    - specializeFrom: "sld:RecordSchema"
      specializeTo: "#OutputRecordSchema"
    - specializeFrom: "sld:EnumSchema"
      specializeTo: "#OutputEnumSchema"
    - specializeFrom: "sld:ArraySchema"
      specializeTo: "#OutputArraySchema"
  fields:
    - name: outputBinding
      type: [ "null", "#OutputBinding" ]
      jsonldPredicate: "cwl:outputBinding"


- name: OutputRecordSchema
  type: record
  extends: ["sld:RecordSchema", "#OutputSchema"]
  docParent: "#OutputParameter"
  specialize:
    - specializeFrom: "sld:RecordField"
      specializeTo: "#OutputRecordField"


- name: OutputEnumSchema
  type: record
  extends: ["sld:EnumSchema", "#OutputSchema"]
  docParent: "#OutputParameter"
  fields:
    - name: outputBinding
      type: [ "null", "#OutputBinding" ]
      jsonldPredicate: "cwl:outputBinding"

- name: OutputArraySchema
  type: record
  extends: ["sld:ArraySchema", "#OutputSchema"]
  docParent: "#OutputParameter"
  specialize:
    - specializeFrom: "sld:RecordSchema"
      specializeTo: "#OutputRecordSchema"
    - specializeFrom: "sld:EnumSchema"
      specializeTo: "#OutputEnumSchema"
    - specializeFrom: "sld:ArraySchema"
      specializeTo: "#OutputArraySchema"
  fields:
    - name: outputBinding
      type: [ "null", "#OutputBinding" ]
      jsonldPredicate: "cwl:outputBinding"


- name: InputParameter
  type: record
  extends: "#Parameter"
  specialize:
    - specializeFrom: "sld:RecordSchema"
      specializeTo: "#InputRecordSchema"
    - specializeFrom: "sld:EnumSchema"
      specializeTo: "#InputEnumSchema"
    - specializeFrom: "sld:ArraySchema"
      specializeTo: "#InputArraySchema"
  fields:
    - name: id
      type: string
      jsonldPredicate: "@id"
      doc: "The unique identifier for this parameter object."

    - name: "inputBinding"
      type: [ "null", "#InputBinding" ]
      jsonldPredicate: "cwl:inputBinding"
      doc: |
        Describes how to handle the inputs of a process and convert them
        into a concrete form for execution, such as command line parameters.

    - name: default
      type: ["null", "Any"]
      jsonldPredicate: "cwl:default"
      doc: |
        The default value for this parameter if not provided in the input
        object.


- name: OutputParameter
  type: record
  extends: "#Parameter"
  specialize:
    - specializeFrom: "sld:RecordSchema"
      specializeTo: "#OutputRecordSchema"
    - specializeFrom: "sld:EnumSchema"
      specializeTo: "#OutputEnumSchema"
    - specializeFrom: "sld:ArraySchema"
      specializeTo: "#OutputArraySchema"
  fields:
    - name: id
      type: string
      jsonldPredicate: "@id"
      doc: "The unique identifier for this parameter object."
    - name: "outputBinding"
      type: [ "null", "#OutputBinding" ]
      jsonldPredicate: "cwl:outputBinding"
      doc: |
        Describes how to handle the outputs of a process.


- type: record
  name: ProcessRequirement
  abstract: true
  doc: |
    A process requirement declares a prerequisite that may or must be fulfilled
    before executing a process.  See [`Process.hints`](#process) and
    [`Process.requirements`](#process).

    Process requirements are the primary mechanism for specifying extensions to
    the CWL core specification.

  fields:
    - name: "class"
      type: "string"
      doc: "The specific requirement type."
      jsonldPredicate:
        "_id": "@type"
        "_type": "@vocab"


- type: record
  name: Process
  abstract: true
  doc: |

    The base executable type in CWL is the `Process` object defined by the
    document.  Note that the `Process` object is abstract and cannot be
    directly executed.

  fields:
    - name: id
      type: ["null", string]
      jsonldPredicate: "@id"
      doc: "The unique identifier for this process object."
    - name: inputs
      type:
        type: array
        items: "#InputParameter"
      jsonldPredicate: "cwl:inputs"
      doc: |
        Defines the input parameters of the process.  The process is ready to
        run when all required input parameters are associated with concrete
        values.  Input parameters include a schema for each parameter which is
        used to validate the input object.  It may also be used to build a user
        interface for constructing the input object.
    - name: outputs
      type:
        type: array
        items: "#OutputParameter"
      jsonldPredicate: "cwl:outputs"
      doc: |
        Defines the parameters representing the output of the process.  May be
        used to generate and/or validate the output object.
    - name: requirements
      type:
        - "null"
        - type: array
          items: "#ProcessRequirement"
      jsonldPredicate: "cwl:requirements"
      doc: |
        Declares requirements that apply to either the runtime environment or the
        workflow engine that must be met in order to execute this process.  If
        an implementation cannot satisfy all requirements, or a requirement is
        listed which is not recognized by the implementation, it is a fatal
        error and the implementation must not attempt to run the process,
        unless overridden at user option.
    - name: hints
      type:
        - "null"
        - type: array
          items: Any
      jsonldPredicate: "cwl:hints"
      doc: |
        Declares hints applying to either the runtime environment or the
        workflow engine that may be helpful in executing this process.  It is
        not an error if an implementation cannot satisfy all hints, however
        the implementation may report a warning.
      jsonldPredicate:
        _id: cwl:hints
        noLinkCheck: true
    - name: label
      type:
        - "null"
        - string
      jsonldPredicate: "rdfs:label"
      doc: "A short, human-readable label of this process object."
    - name: description
      type:
        - "null"
        - string
      jsonldPredicate: "rdfs:comment"
      doc: "A long, human-readable description of this process object."
    - name: cwlVersion
      type:
        - "null"
        - "#CWLVersions"
      doc: "CWL document version"
      jsonldPredicate:
        "_id": "cwl:cwlVersion"
        "_type": "@vocab"

- name: InlineJavascriptRequirement
  type: record
  extends: "#ProcessRequirement"
  doc: |
    Indicates that the workflow platform must support inline Javascript expressions.
    If this requirement is not present, the workflow platform must not perform expression
    interpolatation.
  fields:
    - name: expressionLib
      type:
        - "null"
        - type: array
          items: string
      doc: |
        Additional code fragments that will also be inserted
        before executing the expression code.  Allows for function definitions that may
        be called from CWL expressions.


- name: SchemaDefRequirement
  type: record
  extends: "#ProcessRequirement"
  doc: |
    This field consists of an array of type definitions which must be used when
    interpreting the `inputs` and `outputs` fields.  When a `type` field
    contain a URI, the implementation must check if the type is defined in
    `schemaDefs` and use that definition.  If the type is not found in
    `schemaDefs`, it is an error.  The entries in `schemaDefs` must be
    processed in the order listed such that later schema definitions may refer
    to earlier schema definitions.
  fields:
    - name: types
      type:
        type: array
        items: "#InputSchema"
      doc: The list of type definitions.
