String formats¶
Follow below an example to demonstrate how the library handles and convert a an almost complete subset of all supported string formats by OpenAPI/JSON Schema, initial schema implementation in https://raw.githubusercontent.com/eoap/schemas/main/string_format.yaml
What's out of the scope:
binary;byte;regex(patterncould be computed at runtime only, no way to specify it in the schema).
1. Parsing¶
In this sample we'll show the access from a remote public URL.
In [1]:
Copied!
from cwl_loader import load_cwl_from_location
from cwl2ogc import BaseCWLtypes2OGCConverter
cwl_document = load_cwl_from_location('https://raw.githubusercontent.com/eoap/cwl2ogc/refs/heads/develop/tests/artifacts/cwl-types/string-formats.cwl')
cwl_converter = BaseCWLtypes2OGCConverter(cwl_document)
from cwl_loader import load_cwl_from_location
from cwl2ogc import BaseCWLtypes2OGCConverter
cwl_document = load_cwl_from_location('https://raw.githubusercontent.com/eoap/cwl2ogc/refs/heads/develop/tests/artifacts/cwl-types/string-formats.cwl')
cwl_converter = BaseCWLtypes2OGCConverter(cwl_document)
2025-11-06 22:55:18.170 | DEBUG | cwl_loader:load_cwl_from_location:228 - Loading CWL document from https://raw.githubusercontent.com/eoap/cwl2ogc/refs/heads/develop/tests/artifacts/cwl-types/string-formats.cwl...
2025-11-06 22:55:18.305 | DEBUG | cwl_loader:_load_cwl_from_stream:231 - Reading stream from https://raw.githubusercontent.com/eoap/cwl2ogc/refs/heads/develop/tests/artifacts/cwl-types/string-formats.cwl...
2025-11-06 22:55:18.317 | DEBUG | cwl_loader:load_cwl_from_stream:203 - CWL data of type <class 'ruamel.yaml.comments.CommentedMap'> successfully loaded from stream
2025-11-06 22:55:18.318 | DEBUG | cwl_loader:load_cwl_from_yaml:143 - No needs to update the Raw CWL document since it targets already the v1.2
2025-11-06 22:55:18.319 | DEBUG | cwl_loader:load_cwl_from_yaml:145 - Parsing the raw CWL document to the CWL Utils DOM...
2025-11-06 22:55:19.363 | DEBUG | cwl_loader:load_cwl_from_yaml:158 - Raw CWL document successfully parsed to the CWL Utils DOM!
2025-11-06 22:55:19.364 | DEBUG | cwl_loader:load_cwl_from_yaml:160 - Dereferencing the steps[].run...
2025-11-06 22:55:19.364 | DEBUG | cwl_loader:load_cwl_from_yaml:167 - steps[].run successfully dereferenced! Dereferencing the FQNs...
2025-11-06 22:55:19.365 | DEBUG | cwl_loader:load_cwl_from_yaml:171 - CWL document successfully dereferenced! Now verifying steps[].run integrity...
2025-11-06 22:55:19.365 | DEBUG | cwl_loader:load_cwl_from_yaml:175 - All steps[].run link are resolvable!
2025-11-06 22:55:19.366 | DEBUG | cwl_loader:load_cwl_from_yaml:178 - Sorting Process instances by dependencies....
2025-11-06 22:55:19.366 | DEBUG | cwl_loader:load_cwl_from_yaml:180 - Sorting process is over.
2025-11-06 22:55:19.367 | DEBUG | cwl_loader:_load_cwl_from_stream:240 - Stream from https://raw.githubusercontent.com/eoap/cwl2ogc/refs/heads/develop/tests/artifacts/cwl-types/string-formats.cwl successfully load!
3. Inputs conversion¶
Once the document is parsed, invoke the cwl2ogc APIs to convert the CWL inputs to the OGC JSON format:
In [2]:
Copied!
import sys
cwl_converter.dump_inputs(stream=sys.stdout, pretty_print=True)
import sys
cwl_converter.dump_inputs(stream=sys.stdout, pretty_print=True)
{
"date_input": {
"schema": {
"type": "string",
"format": "date"
},
"metadata": [
{
"title": "cwl:type",
"value": "https://raw.githubusercontent.com/eoap/schemas/main/string_format.yaml#Date"
}
],
"minOccurs": 1,
"maxOccurs": 1,
"valuePassing": "byValue",
"title": "Expected schema serialization: { \"type\": \"string\", \"format\": \"\"date\" }"
},
"date-time_input": {
"schema": {
"type": "string",
"format": "date-time"
},
"metadata": [
{
"title": "cwl:type",
"value": "https://raw.githubusercontent.com/eoap/schemas/main/string_format.yaml#DateTime"
}
],
"minOccurs": 1,
"maxOccurs": 1,
"valuePassing": "byValue",
"title": "Expected schema serialization: { \"type\": \"string\", \"format\": \"date-time\" }"
},
"duration_input": {
"schema": {
"type": "string",
"format": "duration"
},
"metadata": [
{
"title": "cwl:type",
"value": "https://raw.githubusercontent.com/eoap/schemas/main/string_format.yaml#Duration"
}
],
"minOccurs": 1,
"maxOccurs": 1,
"valuePassing": "byValue",
"title": "Expected schema serialization: { \"type\": \"string\", \"format\": \"duration\" }"
},
"email_input": {
"schema": {
"type": "string",
"format": "email"
},
"metadata": [
{
"title": "cwl:type",
"value": "https://raw.githubusercontent.com/eoap/schemas/main/string_format.yaml#Email"
}
],
"minOccurs": 1,
"maxOccurs": 1,
"valuePassing": "byValue",
"title": "Expected schema serialization: { \"type\": \"string\", \"format\": \"email\" }"
},
"hostname_input": {
"schema": {
"type": "string",
"format": "hostname"
},
"metadata": [
{
"title": "cwl:type",
"value": "https://raw.githubusercontent.com/eoap/schemas/main/string_format.yaml#Hostname"
}
],
"minOccurs": 1,
"maxOccurs": 1,
"valuePassing": "byValue",
"title": "Expected schema serialization: { \"type\": \"string\", \"format\": \"hostname\" }"
},
"idn-email_input": {
"schema": {
"type": "string",
"format": "idn-email"
},
"metadata": [
{
"title": "cwl:type",
"value": "https://raw.githubusercontent.com/eoap/schemas/main/string_format.yaml#IDNEmail"
}
],
"minOccurs": 1,
"maxOccurs": 1,
"valuePassing": "byValue",
"title": "Expected schema serialization: { \"type\": \"string\", \"format\": \"idn-email\" }"
},
"idn-hostname_input": {
"schema": {
"type": "string",
"format": "idn-hostname"
},
"metadata": [
{
"title": "cwl:type",
"value": "https://raw.githubusercontent.com/eoap/schemas/main/string_format.yaml#IDNHostname"
}
],
"minOccurs": 1,
"maxOccurs": 1,
"valuePassing": "byValue",
"title": "Expected schema serialization: { \"type\": \"string\", \"format\": \"idn-hostname\" }"
},
"ipv4_input": {
"schema": {
"type": "string",
"format": "ipv4"
},
"metadata": [
{
"title": "cwl:type",
"value": "https://raw.githubusercontent.com/eoap/schemas/main/string_format.yaml#IPv4"
}
],
"minOccurs": 1,
"maxOccurs": 1,
"valuePassing": "byValue",
"title": "Expected schema serialization: { \"type\": \"string\", \"format\": \"ipv4\" }"
},
"ipv6_input": {
"schema": {
"type": "string",
"format": "ipv6"
},
"metadata": [
{
"title": "cwl:type",
"value": "https://raw.githubusercontent.com/eoap/schemas/main/string_format.yaml#IPv6"
}
],
"minOccurs": 1,
"maxOccurs": 1,
"valuePassing": "byValue",
"title": "Expected schema serialization: { \"type\": \"string\", \"format\": \"ipv6\" }"
},
"iri_input": {
"schema": {
"type": "string",
"format": "iri"
},
"metadata": [
{
"title": "cwl:type",
"value": "https://raw.githubusercontent.com/eoap/schemas/main/string_format.yaml#IRI"
}
],
"minOccurs": 1,
"maxOccurs": 1,
"valuePassing": "byValue",
"title": "Expected schema serialization: { \"type\": \"string\", \"format\": \"iri\" }"
},
"iri-reference_input": {
"schema": {
"type": "string",
"format": "iri-reference"
},
"metadata": [
{
"title": "cwl:type",
"value": "https://raw.githubusercontent.com/eoap/schemas/main/string_format.yaml#IRIReference"
}
],
"minOccurs": 1,
"maxOccurs": 1,
"valuePassing": "byValue",
"title": "Expected schema serialization: { \"type\": \"string\", \"format\": \"iri-reference\" }"
},
"json-pointer_input": {
"schema": {
"type": "string",
"format": "json-pointer"
},
"metadata": [
{
"title": "cwl:type",
"value": "https://raw.githubusercontent.com/eoap/schemas/main/string_format.yaml#JsonPointer"
}
],
"minOccurs": 1,
"maxOccurs": 1,
"valuePassing": "byValue",
"title": "Expected schema serialization: { \"type\": \"string\", \"format\": \"json-pointer\" }"
},
"password_input": {
"schema": {
"type": "string",
"format": "password"
},
"metadata": [
{
"title": "cwl:type",
"value": "https://raw.githubusercontent.com/eoap/schemas/main/string_format.yaml#Password"
}
],
"minOccurs": 1,
"maxOccurs": 1,
"valuePassing": "byValue",
"title": "Expected schema serialization: { \"type\": \"string\", \"format\": \"password\" }"
},
"relative-json-pointer_input": {
"schema": {
"type": "string",
"format": "relative-json-pointer"
},
"metadata": [
{
"title": "cwl:type",
"value": "https://raw.githubusercontent.com/eoap/schemas/main/string_format.yaml#RelativeJsonPointer"
}
],
"minOccurs": 1,
"maxOccurs": 1,
"valuePassing": "byValue",
"title": "Expected schema serialization: { \"type\": \"string\", \"format\": \"relative-json-pointer\" }"
},
"uuid_input": {
"schema": {
"type": "string",
"format": "uuid"
},
"metadata": [
{
"title": "cwl:type",
"value": "https://raw.githubusercontent.com/eoap/schemas/main/string_format.yaml#UUID"
}
],
"minOccurs": 1,
"maxOccurs": 1,
"valuePassing": "byValue",
"title": "Expected schema serialization: { \"type\": \"string\", \"format\": \"uuid\" }"
},
"uri_input": {
"schema": {
"type": "string",
"format": "uri"
},
"metadata": [
{
"title": "cwl:type",
"value": "https://raw.githubusercontent.com/eoap/schemas/main/string_format.yaml#URI"
}
],
"minOccurs": 1,
"maxOccurs": 1,
"valuePassing": "byValue",
"title": "Expected schema serialization: { \"type\": \"string\", \"format\": \"uri\" }"
},
"uri-reference_input": {
"schema": {
"type": "string",
"format": "uri-reference"
},
"metadata": [
{
"title": "cwl:type",
"value": "https://raw.githubusercontent.com/eoap/schemas/main/string_format.yaml#URIReference"
}
],
"minOccurs": 1,
"maxOccurs": 1,
"valuePassing": "byValue",
"title": "Expected schema serialization: { \"type\": \"string\", \"format\": \"uri-reference\" }"
},
"uri-template_input": {
"schema": {
"type": "string",
"format": "uri-template"
},
"metadata": [
{
"title": "cwl:type",
"value": "https://raw.githubusercontent.com/eoap/schemas/main/string_format.yaml#URITemplate"
}
],
"minOccurs": 1,
"maxOccurs": 1,
"valuePassing": "byValue",
"title": "Expected schema serialization: { \"type\": \"string\", \"format\": \"uri-template\" }"
},
"time_input": {
"schema": {
"type": "string",
"format": "time"
},
"metadata": [
{
"title": "cwl:type",
"value": "https://raw.githubusercontent.com/eoap/schemas/main/string_format.yaml#Time"
}
],
"minOccurs": 1,
"maxOccurs": 1,
"valuePassing": "byValue",
"title": "Expected schema serialization: { \"type\": \"string\", \"format\": \"time\" }"
}
}
2. Outputs conversion¶
Users can reuse the BaseCWLtypes2OGCConverter instance to convert the CWL outputs to the OGC JSON format:
In [3]:
Copied!
cwl_converter.dump_outputs(stream=sys.stdout, pretty_print=True)
cwl_converter.dump_outputs(stream=sys.stdout, pretty_print=True)
{
"echo_output": {
"schema": {
"type": "string"
},
"metadata": [
{
"title": "cwl:type",
"value": "stdout"
}
]
}
}