common-workflow-language / common-workflow-language/schema_salad

Undocumented behavior in the case of unions of typeDSL-ed optional types

Open
#626 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
86
Forks
64
Avg merge
19h 24m
Merged PRs (30d)
19

Description

Here is a type definition of `SaladRecordField#jsonldPredicate`.

https://github.com/common-workflow-language/schema_salad/blob/7662c7f16b1642bcc267ff8f9095c4c5220c329f/schema_salad/metaschema/metaschema.yml#L284-L287

According to the spec of SALAD, `string?` and `JsonldPredicate?` are expanded with the [typeDSL](https://www.commonwl.org/v1.2/SchemaSalad.html#Domain_Specific_Language_for_types) rule.
It says:
> If the type ends with a question mark `?`, the question mark is stripped off and the type is expanded to a union with `null`

The definition of union types are in the [spec of Apache Avro](https://avro.apache.org/docs/1.11.1/specification/#unions).
It says:
> Unions, as mentioned above, are represented using JSON arrays.

By naively interpreting the descriptions, the above type definition is processed to the following:
```yaml
- name: jsonldPredicate
type:
- ["null", "string"]
- ["null", "JsonldPredicate"]
```

However, it violates the definition of [`SaladRecordField#type`](https://www.commonwl.org/v1.2/SchemaSalad.html#SaladRecordField).

`schema-salad-tool` processes the above example to the following but this behavior is not documented in the spec of SALAD and Avro.
```yaml
- name: jsonldPredicate
type:
- "null"
- string
- JsonldPredicate
```

If it is correct, it would be nice if there is a description of this behavior.

---
IMO, the current behavior causes extra complexity to the parsers (especially the case of combining with [`$import` that is replaced in the array node](https://github.com/common-workflow-language/schema_salad/issues/478)) while it only provides a tiny syntax sugar :-(.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.