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-09-17 21:15:46.779 | DEBUG | cwl_loader:load_cwl_from_location:220 - Loading CWL document from https://raw.githubusercontent.com/eoap/cwl2ogc/refs/heads/develop/tests/artifacts/cwl-types/string-formats.cwl...
2025-09-17 21:15:46.817 | DEBUG | cwl_loader:_load_cwl_from_stream:223 - Reading stream from https://raw.githubusercontent.com/eoap/cwl2ogc/refs/heads/develop/tests/artifacts/cwl-types/string-formats.cwl...
2025-09-17 21:15:46.830 | DEBUG | cwl_loader:load_cwl_from_stream:197 - CWL data of type <class 'ruamel.yaml.comments.CommentedMap'> successfully loaded from stream
2025-09-17 21:15:46.830 | DEBUG | cwl_loader:load_cwl_from_yaml:141 - Updating the model of type 'CommentedMap' to version 'v1.2'...
2025-09-17 21:15:46.835 | DEBUG | cwl_loader:load_cwl_from_yaml:152 - Raw CWL document successfully updated to v1.2! Now converting to the CWL model...
2025-09-17 21:15:47.378 | DEBUG | cwl_loader:load_cwl_from_yaml:160 - Raw CWL document successfully updated to v1.2! Now dereferencing the steps[].run...
2025-09-17 21:15:47.378 | DEBUG | cwl_loader:load_cwl_from_yaml:170 - steps[].run successfully dereferenced! Now dereferencing the FQNs...
2025-09-17 21:15:47.379 | DEBUG | cwl_loader:_clean_process:90 - Cleaning CommandLineTool main...
2025-09-17 21:15:47.379 | DEBUG | cwl_loader:load_cwl_from_yaml:175 - CWL document successfully dereferenced!
2025-09-17 21:15:47.379 | DEBUG | cwl_loader:_load_cwl_from_stream:231 - 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"
}
]
}
}