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
(pattern
could 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 cwl2ogc import load_converter_from_location
cwl_coverter = load_converter_from_location('https://raw.githubusercontent.com/eoap/cwl2ogc/refs/heads/develop/tests/artifacts/cwl-types/string-formats.cwl')
from cwl2ogc import load_converter_from_location
cwl_coverter = load_converter_from_location('https://raw.githubusercontent.com/eoap/cwl2ogc/refs/heads/develop/tests/artifacts/cwl-types/string-formats.cwl')
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_coverter.dump_inputs(stream=sys.stdout, pretty_print=True)
import sys
cwl_coverter.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_coverter.dump_outputs(stream=sys.stdout, pretty_print=True)
cwl_coverter.dump_outputs(stream=sys.stdout, pretty_print=True)
{ "echo_output": { "schema": { "type": "string" }, "metadata": [ { "title": "cwl:type", "value": "stdout" } ] } }