From ec338d9e258361bd80b748ba81b7be0db233f0c9 Mon Sep 17 00:00:00 2001 From: mark Date: Wed, 8 Jun 2022 16:25:39 +0100 Subject: [PATCH 01/20] First attempt at translation --- common.json | 7 + core.json | 558 +++++++++++++++++++++++++++++++++++++++++++++++ etsi103280.json | 11 + test.py | 189 ++++++++++++++++ test_doc.json | 8 + test_json.py | 18 ++ test_schema.json | 38 ++++ 7 files changed, 829 insertions(+) create mode 100644 common.json create mode 100644 core.json create mode 100644 etsi103280.json create mode 100644 test.py create mode 100644 test_doc.json create mode 100644 test_json.py create mode 100644 test_schema.json diff --git a/common.json b/common.json new file mode 100644 index 0000000..b32e709 --- /dev/null +++ b/common.json @@ -0,0 +1,7 @@ +{ + "$id" : "130120/common", + "$defs" : { + "ObjectIdentifier" : { "$ref" : "#/$defs/ObjectRoot"}, + "ObjectRoot" : {"type" : "integer"} + } +} \ No newline at end of file diff --git a/core.json b/core.json new file mode 100644 index 0000000..1ad2f40 --- /dev/null +++ b/core.json @@ -0,0 +1,558 @@ +{ + "$id": "core", + "oneOf": [ + { + "$ref": "#/$defs/HI1Message" + } + ], + "$defs": { + "ObjectIdentifier": { + "$ref": "etsi103280.json#/$defs/UUID" + }, + "HI1Message": { + "type": "object", + "properties": { + "Header": { + "$ref": "#/$defs/MessageHeader" + }, + "Payload": { + "$ref": "#/$defs/MessagePayload" + }, + "Signature": { + "$ref": "xmldsig.json#/$defs/SignatureType" + } + }, + "required": [ + "Header", + "Payload" + ] + }, + "MessageHeader": { + "type": "object", + "properties": { + "SenderIdentifier": { + "$ref": "#/$defs/EndpointID" + }, + "ReceiverIdentifier": { + "$ref": "#/$defs/EndpointID" + }, + "TransactionIdentifier": { + "$ref": "etsi103280.json#/$defs/UUID" + }, + "Timestamp": { + "$ref": "etsi103280.json#/$defs/QualifiedMicrosecondDateTime" + }, + "Version": { + "$ref": "#/$defs/Version" + } + }, + "required": [ + "SenderIdentifier", + "ReceiverIdentifier", + "TransactionIdentifier", + "Timestamp", + "Version" + ] + }, + "Version": { + "type": "object", + "properties": { + "ETSIVersion": { + "$ref": "common.json#/$defs/ETSIVersion" + }, + "NationalProfileOwner": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "NationalProfileVersion": { + "$ref": "etsi103280.json#/$defs/ShortString" + } + }, + "required": [ + "ETSIVersion", + "NationalProfileOwner", + "NationalProfileVersion" + ] + }, + "EndpointID": { + "type": "object", + "properties": { + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + }, + "UniqueIdentifier": { + "$ref": "etsi103280.json#/$defs/LongString" + } + }, + "required": [ + "CountryCode", + "UniqueIdentifier" + ] + }, + "MessagePayload": { + "oneOf": [ + { + "type": "object", + "properties": { + "RequestPayload": { + "$ref": "#/$defs/RequestPayload" + } + }, + "required": [ + "RequestPayload" + ] + }, + { + "type": "object", + "properties": { + "ResponsePayload": { + "$ref": "#/$defs/ResponsePayload" + } + }, + "required": [ + "ResponsePayload" + ] + } + ] + }, + "RequestPayload": { + "type": "object", + "properties": { + "ActionRequests": { + "$ref": "#/$defs/ActionRequests" + } + }, + "required": [ + "ActionRequests" + ] + }, + "ActionRequests": { + "type": "object", + "properties": { + "ActionRequest": { + "$ref": "#/$defs/ActionRequest" + } + }, + "required": [ + "ActionRequest" + ] + }, + "ResponsePayload": { + "oneOf": [ + { + "type": "object", + "properties": { + "ActionResponses": { + "$ref": "#/$defs/ActionResponses" + } + }, + "required": [ + "ActionResponses" + ] + }, + { + "type": "object", + "properties": { + "ErrorInformation": { + "$ref": "#/$defs/ActionUnsuccesfulInformation" + } + }, + "required": [ + "ErrorInformation" + ] + } + ] + }, + "ActionResponses": { + "type": "object", + "properties": { + "ActionResponse": { + "$ref": "#/$defs/ActionResponse" + } + }, + "required": [ + "ActionResponse" + ] + }, + "ActionRequest": { + "allOf": [ + { + "type": "object", + "properties": { + "ActionIdentifier": { + "type": "integer", + "minimum": 0 + } + }, + "required": [ + "ActionIdentifier" + ] + }, + { + "oneOf": [ + { + "type": "object", + "properties": { + "GET": { + "$ref": "#/$defs/GETRequest" + } + }, + "required": [ + "GET" + ] + }, + { + "type": "object", + "properties": { + "CREATE": { + "$ref": "#/$defs/CREATERequest" + } + }, + "required": [ + "CREATE" + ] + }, + { + "type": "object", + "properties": { + "UPDATE": { + "$ref": "#/$defs/UPDATERequest" + } + }, + "required": [ + "UPDATE" + ] + }, + { + "type": "object", + "properties": { + "LIST": { + "$ref": "#/$defs/LISTRequest" + } + }, + "required": [ + "LIST" + ] + }, + { + "type": "object", + "properties": { + "DELIVER": { + "$ref": "#/$defs/DELIVERRequest" + } + }, + "required": [ + "DELIVER" + ] + } + ] + } + ] + }, + "ActionResponse": { + "allOf": [ + { + "type": "object", + "properties": { + "ActionIdentifier": { + "type": "integer", + "minimum": 0 + } + }, + "required": [ + "ActionIdentifier" + ] + }, + { + "oneOf": [ + { + "type": "object", + "properties": { + "GETResponse": { + "$ref": "#/$defs/GETResponse" + } + }, + "required": [ + "GETResponse" + ] + }, + { + "type": "object", + "properties": { + "CREATEResponse": { + "$ref": "#/$defs/CREATEResponse" + } + }, + "required": [ + "CREATEResponse" + ] + }, + { + "type": "object", + "properties": { + "UPDATEResponse": { + "$ref": "#/$defs/UPDATEResponse" + } + }, + "required": [ + "UPDATEResponse" + ] + }, + { + "type": "object", + "properties": { + "LISTResponse": { + "$ref": "#/$defs/LISTResponse" + } + }, + "required": [ + "LISTResponse" + ] + }, + { + "type": "object", + "properties": { + "ErrorInformation": { + "$ref": "#/$defs/ActionUnsuccesfulInformation" + } + }, + "required": [ + "ErrorInformation" + ] + }, + { + "type": "object", + "properties": { + "DELIVERResponse": { + "$ref": "#/$defs/DELIVERResponse" + } + }, + "required": [ + "DELIVERResponse" + ] + } + ] + } + ] + }, + "GETRequest": { + "type": "object", + "properties": { + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + } + }, + "required": [ + "Identifier" + ] + }, + "GETResponse": { + "type": "object", + "properties": { + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "HI1Object" + ] + }, + "CREATERequest": { + "type": "object", + "properties": { + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "HI1Object" + ] + }, + "CREATEResponse": { + "type": "object", + "properties": { + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + }, + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "Identifier" + ] + }, + "UPDATERequest": { + "type": "object", + "properties": { + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "HI1Object" + ] + }, + "UPDATEResponse": { + "type": "object", + "properties": { + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + }, + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "Identifier" + ] + }, + "LISTRequest": { + "type": "object", + "properties": { + "ObjectType": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "LastChanged": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + } + }, + "required": [] + }, + "LISTResponse": { + "type": "object", + "properties": { + "ListResponseRecord": { + "$ref": "#/$defs/ListResponseRecord" + } + }, + "required": [] + }, + "ListResponseRecord": { + "type": "object", + "properties": { + "ObjectType": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + }, + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + }, + "OwnerIdentifier": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "Generation": { + "type": "integer", + "minimum": 0 + }, + "ExternalIdentifier": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "LastChanged": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + } + }, + "required": [ + "ObjectType", + "Identifier", + "Generation" + ] + }, + "ActionUnsuccesfulInformation": { + "type": "object", + "properties": { + "ErrorCode": { + "type": "integer", + "minimum": 0 + }, + "ErrorDescription": { + "$ref": "etsi103280.json#/$defs/LongString" + } + }, + "required": [ + "ErrorCode", + "ErrorDescription" + ] + }, + "DELIVERRequest": { + "type": "object", + "properties": { + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + }, + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "Identifier", + "HI1Object" + ] + }, + "DELIVERResponse": { + "type": "object", + "properties": { + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + } + }, + "required": [ + "Identifier" + ] + }, + "HI1Object": { + "type": "object", + "properties": { + "ObjectIdentifier": { + "$ref": "#/$defs/ObjectIdentifier" + }, + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + }, + "OwnerIdentifier": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "Generation": { + "type": "integer", + "minimum": 0 + }, + "ExternalIdentifier": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "AssociatedObjects": { + "$ref": "#/$defs/AssociatedObjects" + }, + "LastChanged": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "NationalHandlingParameters": { + "$ref": "#/$defs/NationalHandlingParameters" + } + }, + "required": [ + "ObjectIdentifier" + ] + }, + "AssociatedObjects": { + "type": "object", + "properties": { + "AssociatedObject": { + "$ref": "#/$defs/ObjectIdentifier" + } + }, + "required": [] + }, + "NationalHandlingParameters": { + "type": "object", + "properties": { + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + } + }, + "required": [ + "CountryCode" + ] + } + } +} \ No newline at end of file diff --git a/etsi103280.json b/etsi103280.json new file mode 100644 index 0000000..b6bd0ad --- /dev/null +++ b/etsi103280.json @@ -0,0 +1,11 @@ +{ + "$id" : "130120/common", + "$defs" : { + "ObjectIdentifier" : { "$ref" : "#/$defs/ObjectRoot"}, + "ObjectRoot" : {"type" : "integer"}, + "UUID" : { + "type" : "string", + "pattern" : "^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$" + } + } +} \ No newline at end of file diff --git a/test.py b/test.py new file mode 100644 index 0000000..a6b12b2 --- /dev/null +++ b/test.py @@ -0,0 +1,189 @@ +import json +import logging +from pathlib import Path +from pprint import pprint + +from xmlschema import * +from xmlschema.validators.complex_types import XsdComplexType +from xmlschema.validators.simple_types import XsdAtomicRestriction, XsdAtomicBuiltin +from xmlschema.validators.groups import * + +schemas = [ "103120/schema/ts_103120_Authorisation.xsd", + "103120/schema/ts_103120_Common.xsd", + "103120/schema/ts_103120_Delivery.xsd", + "103120/schema/ts_103120_Document.xsd", + "103120/schema/ts_103120_Notification.xsd", + "103120/schema/ts_103120_Task.xsd", + "103280/TS_103_280.xsd", + "testing/deps/xmldsig/xmldsig-core-schema.xsd"] + +schemaLocations = [] +for schemaFile in schemas: + try: + xs = XMLSchema(schemaFile, validation='skip') + schemaLocations.append((xs.target_namespace, str(Path(schemaFile).resolve()))) + print (" [ {0} -> {1} ]".format(xs.target_namespace, schemaFile)) + except XMLSchemaParseError as ex: + print (" [ {0} failed to parse: {1} ]".format(schemaFile, ex)) + +coreSchema = XMLSchema('103120/schema/ts_103120_Core.xsd', locations = schemaLocations) + +js = { + "$id" : "core", + "oneOf" : [], + "$defs" : {} +} + +ns_mappings = { + 'http://uri.etsi.org/03120/common/2019/10/Core' : 'core', + 'http://uri.etsi.org/03120/common/2016/02/Common' : 'common', + 'http://uri.etsi.org/03280/common/2017/07' : 'etsi103280', + 'http://www.w3.org/2000/09/xmldsig#' : 'xmldsig' +} + +primitive_type_mappings = { + "token" : { "type" : "string"}, + "string" : { "type" : "string"}, + "nonNegativeInteger" : { "type" : "integer", "minimum" : 0}, + "anyType" : {} +} + +def process_qname(qname): + namespace = qname[1:qname.find('}')] + token = qname[qname.find('}')+1:] + return token, namespace + +def get_type_from_elem(elem: XsdElement, local_id): + t = elem.type + ns = t.name[1:t.name.find('}')] + if (ns == "http://www.w3.org/2001/XMLSchema"): + # this should be an XSD primitive type + mapped_type = primitive_type_mappings[t.local_name] + return mapped_type + else: + # this needs to be a type in a namespace we know about + mapped_ns = ns_mappings[ns] + if (mapped_ns == local_id): + return { "$ref" : f"#/$defs/{elem.type.local_name}"} + else: + return {"$ref" : f"{mapped_ns}.json#/$defs/{elem.type.local_name}"} + +def get_ref(token, ns, context): + mapped_ns = ns_mappings[ns] + if (mapped_ns == context): + return f"#/$defs/{token}" + else: + return f"{mapped_ns}.json#/$defs/{token}" + + +for elementName, element in coreSchema.elements.items(): + print (f"Root element: {elementName} = {element}") + token, ns = process_qname(element.type.name) + js["oneOf"].append({ + '$ref' : get_ref(token, ns, 'core') + }) + + +def process_choice(choice: XsdGroup): + if choice.model != 'choice': + raise Exception(f"Wrong group type: {c.model}") + oneOf = [] + for c in choice.iter_model(): + if not (type(c) is XsdElement): + raise Exception (f"Non-element {c} encountered in choice {choice}") + t = get_type_from_elem(c, 'core') + oneOf.append({ + "type" : "object", + "properties" : { + c.local_name : t + }, + "required" : [c.local_name] + }) + return oneOf + + +def process_atomic_restriction (sctype): + r = {} + print (f" Atomic restriction: {sctype}") + token, ns = process_qname(sctype.name) + print (f" [{ns}] {token}") + print (f" Root type {sctype.root_type}") + print (f" Base type {sctype.base_type}") + print (" Facets....") + for k, f in sctype.facets.items(): + print (f" facet {k} = {f}") + print (" Validators....") + for v in list(sctype.validators): + print (f" validator {v}") + mappedType = primitive_type_mappings.get(sctype.base_type.name) + if mappedType: + r = mappedType + print (f" Found primitive mapping to {mappedType}") + if len(sctype.facets) > 0: + raise Exception("Too many facets in primitive type") + firstKey = sctype.facets.keys[0] + if (firstKey != '{http://www.w3.org/2001/XMLSchema}pattern'): + raise Exception (f"Unhandled facet {firstKey}") + pattern = sctype.facets[firstKey] + r['pattern'] = pattern.pattern + if len(sctype.validators) > 0: + raise Exception("Too many validators in primitive type") + return token, r + else: + base_token, base_ns = process_qname(sctype.base_type.name) + return token, { '$ref' : get_ref(base_token, base_ns, 'core')} + + +for typeName, sctype in coreSchema.types.items(): + print (f"Type: {typeName} = {type} ({type(sctype)}") + if type(sctype) is XsdAtomicRestriction: + token, typeDef = process_atomic_restriction(sctype) + js["$defs"][token] = typeDef + #print (dir(sctype)) + if type(sctype) is XsdComplexType: + content = sctype.content + print(f" Content {content}") + d = {} + if type(content) is XsdGroup: + if content.model == "sequence": + print (" SEQUENCE!") + d = { + 'type' : 'object', + 'properties' : {}, + 'required' : [] + } + innerChoice = None + for c in list(content.iter_model()): + print (f" > {c}") + if type(c) is XsdElement: + d['properties'][c.local_name] = get_type_from_elem(c, 'core') + if c.effective_min_occurs == 1: + d['required'].append(c.local_name) + elif type(c) is XsdGroup: + if innerChoice: + raise Exception ("Second group encountered") + if c.model != "choice": + raise Exception (f"Don't know what to do with inner {c}") + innerChoice = process_choice(c) + else: + raise Exception(f"Unknown element type {c}") + if (innerChoice): + js["$defs"][sctype.local_name] = { + 'allOf' : [ + d, + {'oneOf' : innerChoice} + ] + } + else: + js["$defs"][sctype.local_name] = d + elif content.model =="choice": + print (" CHOICE!") + oneOf = process_choice(content) + js["$defs"][sctype.local_name] = {'oneOf' : oneOf} + + else: + raise Exception(f"Unknown content type {content}") + + +pprint(js) +Path('./core.json').write_text(json.dumps(js, indent=2)) \ No newline at end of file diff --git a/test_doc.json b/test_doc.json new file mode 100644 index 0000000..846a011 --- /dev/null +++ b/test_doc.json @@ -0,0 +1,8 @@ +{ + "HI1Message" : { + "Header" : 45, + "Payload" : { + "RequestPayload" : "oops" + } + } +} \ No newline at end of file diff --git a/test_json.py b/test_json.py new file mode 100644 index 0000000..6d0cb70 --- /dev/null +++ b/test_json.py @@ -0,0 +1,18 @@ +import jsonschema +import json + +def getJson(filename): + with open(filename) as f: + j = json.load(f) + return j + + +schema = getJson('test_schema.json') +instance = getJson('test_doc.json') + +store = { + "core" : schema, + "common.json" : getJson('common.json') +} +resolver = jsonschema.RefResolver("", "", store) +jsonschema.validate(instance, schema, resolver=resolver) \ No newline at end of file diff --git a/test_schema.json b/test_schema.json new file mode 100644 index 0000000..b2ed4f7 --- /dev/null +++ b/test_schema.json @@ -0,0 +1,38 @@ +{ + "$id" : "core", + + "oneOf" : [ + { + "type" : "object", + "properties": { + "HI1Message": { "$ref": "#/$defs/HI1Message" } + }, + "required": ["HI1Message"] + } + ], + + "$defs": { + "HI1Message" : { + "type" : "object", + "properties" : { + "Header" : { "$ref" : "./common.json#/$defs/ObjectIdentifier"}, + "Payload" : { "$ref" : "#/$defs/MessagePayload"} + }, + "required" : ["Header", "Payload"] + }, + "MessagePayload" : { + "oneOf" : [ + { + "type" : "object", + "properties" : { "RequestPayload" : { "type" : "integer"} }, + "required" : ["RequestPayload"] + }, + { + "type" : "object", + "properties" : { "ResponsePayload" : { "type" : "string"} }, + "required" : ["ResponsePayload"] + } + ] + } + } +} \ No newline at end of file -- GitLab From c6d8e230649e0fd667653471317e61cf53cd3ebf Mon Sep 17 00:00:00 2001 From: mark Date: Thu, 9 Jun 2022 13:33:30 +0100 Subject: [PATCH 02/20] Refactoring and making per-file --- translate.py | 14 +++ translate_schema/__init__.py | 42 +++++++ translate_schema/type_mapping.py | 185 +++++++++++++++++++++++++++++++ translate_schema/util.py | 24 ++++ 4 files changed, 265 insertions(+) create mode 100644 translate.py create mode 100644 translate_schema/__init__.py create mode 100644 translate_schema/type_mapping.py create mode 100644 translate_schema/util.py diff --git a/translate.py b/translate.py new file mode 100644 index 0000000..3891030 --- /dev/null +++ b/translate.py @@ -0,0 +1,14 @@ +import json +import logging +from pathlib import Path + +from xmlschema import * + +from translate_schema import * + +logging.basicConfig(level = logging.DEBUG) + +if __name__ == "__main__": + js = translate_schema("103280/TS_103_280.xsd", "103120.json") + print(json.dumps(js, indent=2)) + diff --git a/translate_schema/__init__.py b/translate_schema/__init__.py new file mode 100644 index 0000000..6a67a5f --- /dev/null +++ b/translate_schema/__init__.py @@ -0,0 +1,42 @@ +import logging +from numbers import Complex +from pathlib import Path + +from xmlschema import * + +from .type_mapping import * + +log = logging.getLogger() + +mappings = [ + XSDNativeSimpleTypeMapping(), + ChoiceMapping(), + SequenceMapping(), +] + +def translate_schema (schema_path, schema_id): + js = { + "$id" : schema_id, + "$defs" : {} + } + + logging.info(f"Translating schema {schema_path}") + xs = XMLSchema(schema_path, validation='lax') + logging.info(f"Schema namespace: {xs.target_namespace}" ) + + for type_name, xsd_type in xs.types.items(): + logging.info(f"Processing {type_name} : {xsd_type}") + + j = None + for mapping in mappings: + log.debug("\n----------------------------------------") + j = mapping.map(xsd_type) + if j is None: + continue + else: + break + if j is None: + raise Exception(f"Unmapped type {type_name} ({xsd_type})") + js["$defs"][xsd_type.local_name] = j + logging.debug (f"Mapped {type_name} to {j}") + return js \ No newline at end of file diff --git a/translate_schema/type_mapping.py b/translate_schema/type_mapping.py new file mode 100644 index 0000000..46c5989 --- /dev/null +++ b/translate_schema/type_mapping.py @@ -0,0 +1,185 @@ +from copy import deepcopy +import logging +from abc import ABC, abstractmethod + +from xmlschema.validators.simple_types import * +from xmlschema.validators.complex_types import * +from xmlschema.validators.groups import * +from xmlschema.validators.facets import * + +from .util import * + +log = logging.getLogger() + +class TypeMapping(ABC): + @abstractmethod + def map(self, xst : BaseXsdType): + return None + +class SimpleTypeMapping(TypeMapping): + def map(self, xst: BaseXsdType): + log.debug(f"Attempting mapping of {xst} to simple type") + if not (type(xst) is XsdAtomicRestriction): + log.debug("Type is not an XsdAtomicRestriction, giving up") + return None + return { + "$ref" : xst.base_type.name + } + +class XSDNativeSimpleTypeMapping(SimpleTypeMapping): + XSD_NS = "http://www.w3.org/2001/XMLSchema" + + XSD_TYPE_MAP = { + "string" : { "type" : "string" }, + "normalizedString" : { "type" : "string", "pattern" : "^[^\r\n\t]*$"}, + "dateTime" : { "type" : "string"}, + "token" : { "type" : "string", "pattern" : "^[^\r\n\t]*$"}, + "anyURI" : { "type" : "string" }, + + "integer" : { "type" : "integer"}, + + "hexBinary" : { "type" : "string", "pattern" : "^([a-fA-F0-9]{2})*$"} + } + + def map(self, xst: BaseXsdType): + log.debug(f"Attempting mapping of {xst} to XSD native type") + j = super().map(xst) + if j is None: + log.debug("Not a simple type, giving up") + return None + + + mapped_type = XSDNativeSimpleTypeMapping.XSD_TYPE_MAP.get(xst.base_type.local_name) + parent_type = None + if mapped_type is None: + ns = extract_namespace(xst.base_type.name) + if ns == XSDNativeSimpleTypeMapping.XSD_NS: + raise Exception (f"No mapping for xs:{xst.base_type.local_name}") + parent_type = get_ref_for(xst.base_type, xst.namespaces['']) + mapped_type = XSDNativeSimpleTypeMapping.XSD_TYPE_MAP.get(xst.root_type.local_name) + if mapped_type is None: + raise Exception (f"Could not find mapping for root type xs:{xst.root_type.local_name}") + + mapped_type = dict(mapped_type) + + for k, v in xst.facets.items(): + log.debug(f"Mapping facet {v}") + if type(v) is XsdMaxLengthFacet: + mapped_type['maxLength'] = v.value + continue + if type(v) is XsdMinLengthFacet: + mapped_type['minLength'] = v.value + continue + if type(v) is XsdPatternFacets: + if len(v.regexps) > 1: + raise Exception (f"Multiple patterns given in facet {v} of {xst}") + p = v.regexps[0] + if (not p.startswith('^')) and (not p.endswith('$')): + p = f"^{p}$" + mapped_type['pattern'] = p + continue + if type (v) is XsdMinInclusiveFacet: + mapped_type['minimum'] = v.value + continue + if type (v) is XsdMaxInclusiveFacet: + mapped_type['maximum'] = v.value + continue + if type (v) is XsdMinExclusiveFacet: + mapped_type['exclusiveMinimum'] = v.value + continue + if type (v) is XsdMaxExclusiveFacet: + mapped_type['exclusiveMaximum'] = v.value + continue + raise Exception (f"Unhandled facet {v}") + if parent_type: + return { 'allOf' : [parent_type, mapped_type] } + return mapped_type + + +class ComplexTypeMapping(TypeMapping): + def map(self, xst: BaseXsdType): + if not (type(xst) is XsdComplexType): + return None + return { + "type" : "object" + } + +def get_type_from_elem(elem: XsdElement, current_ns : str): + ns = extract_namespace(elem.type.name) + if (ns == "http://www.w3.org/2001/XMLSchema"): + # this should be an XSD primitive type + return dict(XSDNativeSimpleTypeMapping.XSD_TYPE_MAP[elem.type.local_name]) + else: + return get_ref_for(elem.type, current_ns) + + +def process_choice(choice: XsdGroup, current_ns : str): + if choice.model != 'choice': + raise Exception(f"Wrong group type: {c.model}") + oneOf = [] + for c in choice.iter_model(): + if not (type(c) is XsdElement): + raise Exception (f"Non-element {c} encountered in choice {choice}") + t = get_type_from_elem(c, current_ns) + oneOf.append({ + "type" : "object", + "properties" : { + c.local_name : t + }, + "required" : [c.local_name] + }) + return oneOf + +class ChoiceMapping(ComplexTypeMapping): + def map(self, xst : BaseXsdType): + log.debug(f"Attempting mapping of {xst} to sequence") + j = super().map(xst) + if j is None: + log.debug("Not a complex type, giving up") + return None + content = xst.content + if (content.model != 'choice'): + log.debug("Not a sequence, giving up") + return None + return { 'oneOf' : process_choice(content, xst.namespaces[''])} + +class SequenceMapping(ComplexTypeMapping): + def map(self, xst: BaseXsdType): + log.debug(f"Attempting mapping of {xst} to sequence") + j = super().map(xst) + if j is None: + log.debug("Not a complex type, giving up") + return None + content = xst.content + if (content.model != 'sequence'): + log.debug("Not a sequence, giving up") + return None + mapped_type = { + 'type' : 'object', + 'properties' : {}, + 'required' : [] + } + inner_choice = None + for c in list(content.iter_model()): + log.debug(f"Processing model item {c}") + if type(c) is XsdElement: + mapped_type['properties'][c.local_name] = get_type_from_elem(c, xst.namespaces['']) + if c.effective_min_occurs == 1: + mapped_type['required'].append(c.local_name) + elif type(c) is XsdGroup: + if inner_choice: + raise Exception (f"Second group '{c.local_name}' encountered in {xst}") + if c.model != "choice": + raise Exception (f"Don't know what to do with inner group {c} in {xst} - not a choice") + inner_choice = process_choice(c) + else: + raise Exception(f"Unknown element type {c}") + if (inner_choice): + return { + 'allOf' : [ + mapped_type, + {'oneOf' : inner_choice} + ] + } + else: + return mapped_type diff --git a/translate_schema/util.py b/translate_schema/util.py new file mode 100644 index 0000000..ce22cf3 --- /dev/null +++ b/translate_schema/util.py @@ -0,0 +1,24 @@ +import re + +from xmlschema import * + +def extract_namespace(qname: str): + match = re.search(r'^\{([^\{\}]+)\}(([^\{\}]+))$', qname) + if match is None: + return None + return match.group(1) + +NS_MAP = { + 'http://uri.etsi.org/03120/common/2019/10/Core' : 'core.json', + 'http://uri.etsi.org/03120/common/2016/02/Common' : 'common.json', + 'http://uri.etsi.org/03280/common/2017/07' : 'etsi103280.json', + 'http://www.w3.org/2000/09/xmldsig#' : 'xmldsig', +} + +def get_ref_for(xsd_type: XsdType, current_ns : str): + ns = extract_namespace(xsd_type.name) + if ns == current_ns: + return { "$ref" : f"#/$defs/{xsd_type.local_name}" } + else: + mapped_id = NS_MAP[ns] + return { "$ref" : f"{mapped_id}#/$defs/{xsd_type.local_name}"} \ No newline at end of file -- GitLab From 3487c507bc77b7dea8b0cb527f7e2e9d35a8a184 Mon Sep 17 00:00:00 2001 From: mark Date: Fri, 10 Jun 2022 10:54:58 +0100 Subject: [PATCH 03/20] Extending mapping --- translate.py | 23 +++++++++++++++++++++-- translate_schema/__init__.py | 4 ++-- translate_schema/type_mapping.py | 25 +++++++++++++++++-------- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/translate.py b/translate.py index 3891030..7b62565 100644 --- a/translate.py +++ b/translate.py @@ -9,6 +9,25 @@ from translate_schema import * logging.basicConfig(level = logging.DEBUG) if __name__ == "__main__": - js = translate_schema("103280/TS_103_280.xsd", "103120.json") - print(json.dumps(js, indent=2)) + # js = translate_schema("103280/TS_103_280.xsd", "103120.json") + # print(json.dumps(js, indent=2)) + schemas = [ "103120/schema/ts_103120_Authorisation.xsd", + "103120/schema/ts_103120_Common.xsd", + "103120/schema/ts_103120_Delivery.xsd", + "103120/schema/ts_103120_Document.xsd", + "103120/schema/ts_103120_Notification.xsd", + "103120/schema/ts_103120_Task.xsd", + "103280/TS_103_280.xsd", + "testing/deps/xmldsig/xmldsig-core-schema.xsd"] + + schema_locations = [] + for schemaFile in schemas: + try: + xs = XMLSchema(schemaFile, validation='skip') + schema_locations.append((xs.target_namespace, str(Path(schemaFile).resolve()))) + print (" [ {0} -> {1} ]".format(xs.target_namespace, schemaFile)) + except XMLSchemaParseError as ex: + print (" [ {0} failed to parse: {1} ]".format(schemaFile, ex)) + js = translate_schema("103120/schema/ts_103120_core.xsd", "core.json", schema_locations) + print(json.dumps(js, indent=2)) diff --git a/translate_schema/__init__.py b/translate_schema/__init__.py index 6a67a5f..a4ddb4b 100644 --- a/translate_schema/__init__.py +++ b/translate_schema/__init__.py @@ -14,14 +14,14 @@ mappings = [ SequenceMapping(), ] -def translate_schema (schema_path, schema_id): +def translate_schema (schema_path, schema_id, schema_locations = []): js = { "$id" : schema_id, "$defs" : {} } logging.info(f"Translating schema {schema_path}") - xs = XMLSchema(schema_path, validation='lax') + xs = XMLSchema(schema_path, validation='lax', locations=schema_locations) logging.info(f"Schema namespace: {xs.target_namespace}" ) for type_name, xsd_type in xs.types.items(): diff --git a/translate_schema/type_mapping.py b/translate_schema/type_mapping.py index 46c5989..582e1c4 100644 --- a/translate_schema/type_mapping.py +++ b/translate_schema/type_mapping.py @@ -37,8 +37,11 @@ class XSDNativeSimpleTypeMapping(SimpleTypeMapping): "anyURI" : { "type" : "string" }, "integer" : { "type" : "integer"}, + "nonNegativeInteger" : { "type" : "integer", "minimum" : 0}, - "hexBinary" : { "type" : "string", "pattern" : "^([a-fA-F0-9]{2})*$"} + "hexBinary" : { "type" : "string", "pattern" : "^([a-fA-F0-9]{2})*$"}, + + "anyType" : {} } def map(self, xst: BaseXsdType): @@ -51,14 +54,20 @@ class XSDNativeSimpleTypeMapping(SimpleTypeMapping): mapped_type = XSDNativeSimpleTypeMapping.XSD_TYPE_MAP.get(xst.base_type.local_name) parent_type = None + if mapped_type is None: ns = extract_namespace(xst.base_type.name) if ns == XSDNativeSimpleTypeMapping.XSD_NS: + print (xst) + print (xst.base_type) raise Exception (f"No mapping for xs:{xst.base_type.local_name}") - parent_type = get_ref_for(xst.base_type, xst.namespaces['']) - mapped_type = XSDNativeSimpleTypeMapping.XSD_TYPE_MAP.get(xst.root_type.local_name) - if mapped_type is None: - raise Exception (f"Could not find mapping for root type xs:{xst.root_type.local_name}") + if len(xst.facets) == 0: + mapped_type = get_ref_for(xst.base_type, xst.namespaces['']) + else: + parent_type = get_ref_for(xst.base_type, xst.namespaces['']) + mapped_type = XSDNativeSimpleTypeMapping.XSD_TYPE_MAP.get(xst.root_type.local_name) + if mapped_type is None: + raise Exception (f"Could not find mapping for root type xs:{xst.root_type.local_name}") mapped_type = dict(mapped_type) @@ -132,14 +141,14 @@ def process_choice(choice: XsdGroup, current_ns : str): class ChoiceMapping(ComplexTypeMapping): def map(self, xst : BaseXsdType): - log.debug(f"Attempting mapping of {xst} to sequence") + log.debug(f"Attempting mapping of {xst} to choice") j = super().map(xst) if j is None: log.debug("Not a complex type, giving up") return None content = xst.content if (content.model != 'choice'): - log.debug("Not a sequence, giving up") + log.debug("Not a choice, giving up") return None return { 'oneOf' : process_choice(content, xst.namespaces[''])} @@ -171,7 +180,7 @@ class SequenceMapping(ComplexTypeMapping): raise Exception (f"Second group '{c.local_name}' encountered in {xst}") if c.model != "choice": raise Exception (f"Don't know what to do with inner group {c} in {xst} - not a choice") - inner_choice = process_choice(c) + inner_choice = process_choice(c, xst.namespaces['']) else: raise Exception(f"Unknown element type {c}") if (inner_choice): -- GitLab From 88bf00f48ee85e329e02aadc38954b8a17b47d46 Mon Sep 17 00:00:00 2001 From: mark Date: Fri, 10 Jun 2022 15:51:43 +0100 Subject: [PATCH 04/20] First working auto-translation --- 120.json | 31 ++ json/authorisation.json | 126 +++++++ json/common.json | 161 +++++++++ json/core.json | 551 ++++++++++++++++++++++++++++++ json/delivery.json | 204 ++++++++++++ json/document.json | 137 ++++++++ json/etsi103280.json | 384 +++++++++++++++++++++ json/notification.json | 64 ++++ json/task.json | 499 ++++++++++++++++++++++++++++ json/xmldsig.json | 553 +++++++++++++++++++++++++++++++ translate.py | 80 ++++- translate_schema/__init__.py | 18 +- translate_schema/type_mapping.py | 87 +++-- translate_schema/util.py | 20 -- 14 files changed, 2847 insertions(+), 68 deletions(-) create mode 100644 120.json create mode 100644 json/authorisation.json create mode 100644 json/common.json create mode 100644 json/core.json create mode 100644 json/delivery.json create mode 100644 json/document.json create mode 100644 json/etsi103280.json create mode 100644 json/notification.json create mode 100644 json/task.json create mode 100644 json/xmldsig.json diff --git a/120.json b/120.json new file mode 100644 index 0000000..9a4e178 --- /dev/null +++ b/120.json @@ -0,0 +1,31 @@ +{ + "Header" : { + "SenderIdentifier" : { + "CountryCode" : "XX", + "UniqueIdentifier" : "ACTOR01" + }, + "ReceiverIdentifier" : { + "CountryCode" : "YY", + "UniqueIdentifier" : "ACTOR02" + }, + "TransactionIdentifier" : "c4a09046-61da-485b-83f2-ca12caebf40b", + "Timestamp" : "2022-06-10T15:50:00.000000Z", + "Version" : { + "ETSIVersion" : "V1.11.2", + "NationalProfileOwner" : "NA", + "NationalProfileVersion" : "NA" + } + }, + "Payload" : { + "ResponsePayload" : { + "ActionResponses" : { + "ActionResponse" : { + "ActionIdentifier" : 0, + "CREATEResponse" : { + "Identifier" : "f25dec16-927c-433b-959c-1886182cac58" + } + } + } + } + } +} \ No newline at end of file diff --git a/json/authorisation.json b/json/authorisation.json new file mode 100644 index 0000000..8b1facb --- /dev/null +++ b/json/authorisation.json @@ -0,0 +1,126 @@ +{ + "$id": "authorisation.json", + "$defs": { + "AuthorisationObject": { + "type": "object", + "properties": { + "ObjectIdentifier": { + "$ref": "core.json#/$defs/ObjectIdentifier" + }, + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + }, + "OwnerIdentifier": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "Generation": { + "type": "integer", + "minimum": 0 + }, + "ExternalIdentifier": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "AssociatedObjects": { + "$ref": "core.json#/$defs/AssociatedObjects" + }, + "LastChanged": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "NationalHandlingParameters": { + "$ref": "core.json#/$defs/NationalHandlingParameters" + }, + "AuthorisationReference": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "AuthorisationLegalType": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "AuthorisationPriority": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "AuthorisationStatus": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "AuthorisationDesiredStatus": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "AuthorisationTimespan": { + "$ref": "#/$defs/AuthorisationTimespan" + }, + "AuthorisationCSPID": { + "$ref": "#/$defs/AuthorisationCSPID" + }, + "AuthorisationCreationTimestamp": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "AuthorisationServedTimestamp": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "AuthorisationTerminationTimestamp": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "AuthorisationApprovalDetails": { + "$ref": "common.json#/$defs/ApprovalDetails" + }, + "AuthorisationInvalidReason": { + "$ref": "core.json#/$defs/ActionUnsuccesfulInformation" + }, + "AuthorisationFlags": { + "$ref": "#/$defs/AuthorisationFlags" + }, + "AuthorisationManualInformation": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "NationalAuthorisationParameters": { + "$ref": "#/$defs/NationalAuthorisationParameters" + } + }, + "required": [ + "ObjectIdentifier" + ] + }, + "AuthorisationFlags": { + "type": "object", + "properties": { + "AuthorisationFlag": { + "$ref": "common.json#/$defs/DictionaryEntry" + } + }, + "required": [] + }, + "AuthorisationTimespan": { + "type": "object", + "properties": { + "StartTime": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "EndTime": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + } + }, + "required": [] + }, + "AuthorisationCSPID": { + "type": "object", + "properties": { + "CSPID": { + "$ref": "core.json#/$defs/EndpointID" + } + }, + "required": [ + "CSPID" + ] + }, + "NationalAuthorisationParameters": { + "type": "object", + "properties": { + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + } + }, + "required": [ + "CountryCode" + ] + } + } +} \ No newline at end of file diff --git a/json/common.json b/json/common.json new file mode 100644 index 0000000..00a7c13 --- /dev/null +++ b/json/common.json @@ -0,0 +1,161 @@ +{ + "$id": "common.json", + "$defs": { + "ETSIVersion": { + "allOf": [ + { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + { + "type": "string", + "pattern": "^V\\d+\\.\\d+\\.\\d+$" + } + ] + }, + "DictionaryEntry": { + "type": "object", + "properties": { + "Owner": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "Name": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "Value": { + "$ref": "etsi103280.json#/$defs/ShortString" + } + }, + "required": [ + "Owner", + "Name", + "Value" + ] + }, + "ApprovalDetails": { + "type": "object", + "properties": { + "ApprovalType": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "ApprovalDescription": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "ApprovalReference": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "ApproverDetails": { + "$ref": "#/$defs/ApproverDetails" + }, + "ApprovalTimestamp": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "ApprovalIsEmergency": { + "type": "boolean" + }, + "ApprovalDigitalSignature": { + "$ref": "#/$defs/ApprovalDigitalSignature" + }, + "ApprovalNationalDetails": { + "$ref": "#/$defs/ApprovalNationalDetails" + } + }, + "required": [] + }, + "ApproverDetails": { + "type": "object", + "properties": { + "ApproverName": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "ApproverRole": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "ApproverIdentity": { + "$ref": "#/$defs/ApproverIdentity" + }, + "ApproverContactDetails": { + "$ref": "#/$defs/ApproverContactDetails" + } + }, + "required": [] + }, + "ApproverIdentity": { + "oneOf": [ + { + "type": "object", + "properties": { + "NationalApproverIdentity": { + "$ref": "#/$defs/NationalApproverIdentity" + } + }, + "required": [ + "NationalApproverIdentity" + ] + } + ] + }, + "ApproverContactDetails": { + "type": "object", + "properties": { + "ApproverAlternateName": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "ApproverEmailAddress": { + "$ref": "etsi103280.json#/$defs/InternationalizedEmailAddress" + }, + "ApproverPhoneNumber": { + "$ref": "etsi103280.json#/$defs/InternationalE164" + } + }, + "required": [] + }, + "NationalApproverIdentity": { + "type": "object", + "properties": { + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + } + }, + "required": [ + "CountryCode" + ] + }, + "ApprovalDigitalSignature": { + "oneOf": [ + { + "type": "object", + "properties": { + "NationalDigitalSignature": { + "$ref": "#/$defs/NationalDigitalSignature" + } + }, + "required": [ + "NationalDigitalSignature" + ] + } + ] + }, + "ApprovalNationalDetails": { + "type": "object", + "properties": { + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + } + }, + "required": [ + "CountryCode" + ] + }, + "NationalDigitalSignature": { + "type": "object", + "properties": { + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + } + }, + "required": [ + "CountryCode" + ] + } + } +} \ No newline at end of file diff --git a/json/core.json b/json/core.json new file mode 100644 index 0000000..67e1ca3 --- /dev/null +++ b/json/core.json @@ -0,0 +1,551 @@ +{ + "$id": "core.json", + "$defs": { + "ObjectIdentifier": { + "$ref": "etsi103280.json#/$defs/UUID" + }, + "HI1Message": { + "type": "object", + "properties": { + "Header": { + "$ref": "#/$defs/MessageHeader" + }, + "Payload": { + "$ref": "#/$defs/MessagePayload" + } + }, + "required": [ + "Header", + "Payload" + ] + }, + "MessageHeader": { + "type": "object", + "properties": { + "SenderIdentifier": { + "$ref": "#/$defs/EndpointID" + }, + "ReceiverIdentifier": { + "$ref": "#/$defs/EndpointID" + }, + "TransactionIdentifier": { + "$ref": "etsi103280.json#/$defs/UUID" + }, + "Timestamp": { + "$ref": "etsi103280.json#/$defs/QualifiedMicrosecondDateTime" + }, + "Version": { + "$ref": "#/$defs/Version" + } + }, + "required": [ + "SenderIdentifier", + "ReceiverIdentifier", + "TransactionIdentifier", + "Timestamp", + "Version" + ] + }, + "Version": { + "type": "object", + "properties": { + "ETSIVersion": { + "$ref": "common.json#/$defs/ETSIVersion" + }, + "NationalProfileOwner": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "NationalProfileVersion": { + "$ref": "etsi103280.json#/$defs/ShortString" + } + }, + "required": [ + "ETSIVersion", + "NationalProfileOwner", + "NationalProfileVersion" + ] + }, + "EndpointID": { + "type": "object", + "properties": { + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + }, + "UniqueIdentifier": { + "$ref": "etsi103280.json#/$defs/LongString" + } + }, + "required": [ + "CountryCode", + "UniqueIdentifier" + ] + }, + "MessagePayload": { + "oneOf": [ + { + "type": "object", + "properties": { + "RequestPayload": { + "$ref": "#/$defs/RequestPayload" + } + }, + "required": [ + "RequestPayload" + ] + }, + { + "type": "object", + "properties": { + "ResponsePayload": { + "$ref": "#/$defs/ResponsePayload" + } + }, + "required": [ + "ResponsePayload" + ] + } + ] + }, + "RequestPayload": { + "type": "object", + "properties": { + "ActionRequests": { + "$ref": "#/$defs/ActionRequests" + } + }, + "required": [ + "ActionRequests" + ] + }, + "ActionRequests": { + "type": "object", + "properties": { + "ActionRequest": { + "$ref": "#/$defs/ActionRequest" + } + }, + "required": [ + "ActionRequest" + ] + }, + "ResponsePayload": { + "oneOf": [ + { + "type": "object", + "properties": { + "ActionResponses": { + "$ref": "#/$defs/ActionResponses" + } + }, + "required": [ + "ActionResponses" + ] + }, + { + "type": "object", + "properties": { + "ErrorInformation": { + "$ref": "#/$defs/ActionUnsuccesfulInformation" + } + }, + "required": [ + "ErrorInformation" + ] + } + ] + }, + "ActionResponses": { + "type": "object", + "properties": { + "ActionResponse": { + "$ref": "#/$defs/ActionResponse" + } + }, + "required": [ + "ActionResponse" + ] + }, + "ActionRequest": { + "allOf": [ + { + "type": "object", + "properties": { + "ActionIdentifier": { + "type": "integer", + "minimum": 0 + } + }, + "required": [ + "ActionIdentifier" + ] + }, + { + "oneOf": [ + { + "type": "object", + "properties": { + "GET": { + "$ref": "#/$defs/GETRequest" + } + }, + "required": [ + "GET" + ] + }, + { + "type": "object", + "properties": { + "CREATE": { + "$ref": "#/$defs/CREATERequest" + } + }, + "required": [ + "CREATE" + ] + }, + { + "type": "object", + "properties": { + "UPDATE": { + "$ref": "#/$defs/UPDATERequest" + } + }, + "required": [ + "UPDATE" + ] + }, + { + "type": "object", + "properties": { + "LIST": { + "$ref": "#/$defs/LISTRequest" + } + }, + "required": [ + "LIST" + ] + }, + { + "type": "object", + "properties": { + "DELIVER": { + "$ref": "#/$defs/DELIVERRequest" + } + }, + "required": [ + "DELIVER" + ] + } + ] + } + ] + }, + "ActionResponse": { + "allOf": [ + { + "type": "object", + "properties": { + "ActionIdentifier": { + "type": "integer", + "minimum": 0 + } + }, + "required": [ + "ActionIdentifier" + ] + }, + { + "oneOf": [ + { + "type": "object", + "properties": { + "GETResponse": { + "$ref": "#/$defs/GETResponse" + } + }, + "required": [ + "GETResponse" + ] + }, + { + "type": "object", + "properties": { + "CREATEResponse": { + "$ref": "#/$defs/CREATEResponse" + } + }, + "required": [ + "CREATEResponse" + ] + }, + { + "type": "object", + "properties": { + "UPDATEResponse": { + "$ref": "#/$defs/UPDATEResponse" + } + }, + "required": [ + "UPDATEResponse" + ] + }, + { + "type": "object", + "properties": { + "LISTResponse": { + "$ref": "#/$defs/LISTResponse" + } + }, + "required": [ + "LISTResponse" + ] + }, + { + "type": "object", + "properties": { + "ErrorInformation": { + "$ref": "#/$defs/ActionUnsuccesfulInformation" + } + }, + "required": [ + "ErrorInformation" + ] + }, + { + "type": "object", + "properties": { + "DELIVERResponse": { + "$ref": "#/$defs/DELIVERResponse" + } + }, + "required": [ + "DELIVERResponse" + ] + } + ] + } + ] + }, + "GETRequest": { + "type": "object", + "properties": { + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + } + }, + "required": [ + "Identifier" + ] + }, + "GETResponse": { + "type": "object", + "properties": { + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "HI1Object" + ] + }, + "CREATERequest": { + "type": "object", + "properties": { + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "HI1Object" + ] + }, + "CREATEResponse": { + "type": "object", + "properties": { + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + }, + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "Identifier" + ] + }, + "UPDATERequest": { + "type": "object", + "properties": { + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "HI1Object" + ] + }, + "UPDATEResponse": { + "type": "object", + "properties": { + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + }, + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "Identifier" + ] + }, + "LISTRequest": { + "type": "object", + "properties": { + "ObjectType": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "LastChanged": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + } + }, + "required": [] + }, + "LISTResponse": { + "type": "object", + "properties": { + "ListResponseRecord": { + "$ref": "#/$defs/ListResponseRecord" + } + }, + "required": [] + }, + "ListResponseRecord": { + "type": "object", + "properties": { + "ObjectType": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + }, + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + }, + "OwnerIdentifier": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "Generation": { + "type": "integer", + "minimum": 0 + }, + "ExternalIdentifier": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "LastChanged": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + } + }, + "required": [ + "ObjectType", + "Identifier", + "Generation" + ] + }, + "ActionUnsuccesfulInformation": { + "type": "object", + "properties": { + "ErrorCode": { + "type": "integer", + "minimum": 0 + }, + "ErrorDescription": { + "$ref": "etsi103280.json#/$defs/LongString" + } + }, + "required": [ + "ErrorCode", + "ErrorDescription" + ] + }, + "DELIVERRequest": { + "type": "object", + "properties": { + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + }, + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "Identifier", + "HI1Object" + ] + }, + "DELIVERResponse": { + "type": "object", + "properties": { + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + } + }, + "required": [ + "Identifier" + ] + }, + "HI1Object": { + "type": "object", + "properties": { + "ObjectIdentifier": { + "$ref": "#/$defs/ObjectIdentifier" + }, + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + }, + "OwnerIdentifier": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "Generation": { + "type": "integer", + "minimum": 0 + }, + "ExternalIdentifier": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "AssociatedObjects": { + "$ref": "#/$defs/AssociatedObjects" + }, + "LastChanged": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "NationalHandlingParameters": { + "$ref": "#/$defs/NationalHandlingParameters" + } + }, + "required": [ + "ObjectIdentifier" + ] + }, + "AssociatedObjects": { + "type": "object", + "properties": { + "AssociatedObject": { + "$ref": "#/$defs/ObjectIdentifier" + } + }, + "required": [] + }, + "NationalHandlingParameters": { + "type": "object", + "properties": { + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + } + }, + "required": [ + "CountryCode" + ] + } + }, + "$ref": "#/$defs/HI1Message" +} \ No newline at end of file diff --git a/json/delivery.json b/json/delivery.json new file mode 100644 index 0000000..7aef09a --- /dev/null +++ b/json/delivery.json @@ -0,0 +1,204 @@ +{ + "$id": "delivery.json", + "$defs": { + "DeliveryObject": { + "type": "object", + "properties": { + "ObjectIdentifier": { + "$ref": "core.json#/$defs/ObjectIdentifier" + }, + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + }, + "OwnerIdentifier": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "Generation": { + "type": "integer", + "minimum": 0 + }, + "ExternalIdentifier": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "AssociatedObjects": { + "$ref": "core.json#/$defs/AssociatedObjects" + }, + "LastChanged": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "NationalHandlingParameters": { + "$ref": "core.json#/$defs/NationalHandlingParameters" + }, + "Reference": { + "$ref": "#/$defs/Reference" + }, + "DeliveryID": { + "$ref": "etsi103280.json#/$defs/UUID" + }, + "SequenceNumber": { + "type": "integer", + "minimum": 0 + }, + "LastSequence": { + "type": "boolean" + }, + "Manifest": { + "$ref": "#/$defs/Manifest" + }, + "Delivery": { + "$ref": "#/$defs/Delivery" + } + }, + "required": [ + "ObjectIdentifier" + ] + }, + "Reference": { + "oneOf": [ + { + "type": "object", + "properties": { + "LDID": { + "$ref": "etsi103280.json#/$defs/LDID" + } + }, + "required": [ + "LDID" + ] + }, + { + "type": "object", + "properties": { + "LIID": { + "$ref": "etsi103280.json#/$defs/LIID" + } + }, + "required": [ + "LIID" + ] + } + ] + }, + "Manifest": { + "oneOf": [ + { + "type": "object", + "properties": { + "Specification": { + "$ref": "common.json#/$defs/DictionaryEntry" + } + }, + "required": [ + "Specification" + ] + }, + { + "type": "object", + "properties": { + "ExternalSchema": { + "$ref": "#/$defs/ExternalSchema" + } + }, + "required": [ + "ExternalSchema" + ] + } + ] + }, + "ExternalSchema": { + "type": "object", + "properties": { + "ManifestID": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "ManifestContents": { + "$ref": "#/$defs/ManifestContents" + } + }, + "required": [] + }, + "ManifestContents": { + "oneOf": [ + { + "type": "object", + "properties": { + "BinaryData": { + "$ref": "#/$defs/EmbeddedBinaryData" + } + }, + "required": [ + "BinaryData" + ] + }, + { + "type": "object", + "properties": { + "XMLSchema": { + "$ref": "#/$defs/SchemaContent" + } + }, + "required": [ + "XMLSchema" + ] + } + ] + }, + "SchemaContent": { + "type": "object", + "properties": { + "schema": {} + }, + "required": [ + "schema" + ] + }, + "Delivery": { + "oneOf": [ + { + "type": "object", + "properties": { + "BinaryData": { + "$ref": "#/$defs/EmbeddedBinaryData" + } + }, + "required": [ + "BinaryData" + ] + }, + { + "type": "object", + "properties": { + "XMLData": { + "$ref": "#/$defs/EmbeddedXMLData" + } + }, + "required": [ + "XMLData" + ] + } + ] + }, + "EmbeddedBinaryData": { + "type": "object", + "properties": { + "Data": { + "type": "string", + "pattern": "^[-A-Za-z0-9+/]*={0,3}$" + }, + "ContentType": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "Checksum": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "ChecksumType": { + "$ref": "etsi103280.json#/$defs/ShortString" + } + }, + "required": [ + "Data" + ] + }, + "EmbeddedXMLData": {} + } +} \ No newline at end of file diff --git a/json/document.json b/json/document.json new file mode 100644 index 0000000..6f6f493 --- /dev/null +++ b/json/document.json @@ -0,0 +1,137 @@ +{ + "$id": "document.json", + "$defs": { + "DocumentObject": { + "type": "object", + "properties": { + "ObjectIdentifier": { + "$ref": "core.json#/$defs/ObjectIdentifier" + }, + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + }, + "OwnerIdentifier": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "Generation": { + "type": "integer", + "minimum": 0 + }, + "ExternalIdentifier": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "AssociatedObjects": { + "$ref": "core.json#/$defs/AssociatedObjects" + }, + "LastChanged": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "NationalHandlingParameters": { + "$ref": "core.json#/$defs/NationalHandlingParameters" + }, + "DocumentReference": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "DocumentName": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "DocumentStatus": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "DocumentDesiredStatus": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "DocumentTimespan": { + "$ref": "#/$defs/DocumentTimespan" + }, + "DocumentType": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "DocumentProperties": { + "$ref": "#/$defs/DocumentProperties" + }, + "DocumentBody": { + "$ref": "#/$defs/DocumentBody" + }, + "DocumentSignature": { + "$ref": "common.json#/$defs/ApprovalDetails" + }, + "DocumentInvalidReason": { + "$ref": "core.json#/$defs/ActionUnsuccesfulInformation" + }, + "NationalDocumentParameters": { + "$ref": "#/$defs/NationalDocumentParameters" + } + }, + "required": [ + "ObjectIdentifier" + ] + }, + "DocumentTimespan": { + "type": "object", + "properties": { + "StartTime": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "EndTime": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + } + }, + "required": [] + }, + "DocumentProperties": { + "type": "object", + "properties": { + "DocumentProperty": { + "$ref": "#/$defs/DocumentProperty" + } + }, + "required": [] + }, + "DocumentProperty": { + "type": "object", + "properties": { + "PropertyType": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "PropertyValue": { + "$ref": "etsi103280.json#/$defs/LongString" + } + }, + "required": [ + "PropertyType", + "PropertyValue" + ] + }, + "DocumentBody": { + "type": "object", + "properties": { + "Contents": { + "type": "string", + "pattern": "^[-A-Za-z0-9+/]*={0,3}$" + }, + "ContentType": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "Checksum": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "ChecksumType": { + "$ref": "etsi103280.json#/$defs/ShortString" + } + }, + "required": [] + }, + "NationalDocumentParameters": { + "type": "object", + "properties": { + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + } + }, + "required": [ + "CountryCode" + ] + } + } +} \ No newline at end of file diff --git a/json/etsi103280.json b/json/etsi103280.json new file mode 100644 index 0000000..09457bd --- /dev/null +++ b/json/etsi103280.json @@ -0,0 +1,384 @@ +{ + "$id": "etsi103280.json", + "$defs": { + "ShortString": { + "type": "string", + "maxLength": 255 + }, + "LongString": { + "type": "string", + "maxLength": 65535 + }, + "LIID": { + "type": "string", + "pattern": "^([!-~]{1,25})|([0-9a-f]{26,50})$" + }, + "UTCDateTime": { + "type": "string", + "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$" + }, + "UTCMicrosecondDateTime": { + "type": "string", + "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{6}Z$" + }, + "QualifiedDateTime": { + "type": "string", + "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(Z|[+-][0-9]{2}:[0-9]{2})$" + }, + "QualifiedMicrosecondDateTime": { + "type": "string", + "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{6}(Z|[+-][0-9]{2}:[0-9]{2})$" + }, + "InternationalE164": { + "type": "string", + "pattern": "^[0-9]{1,15}$" + }, + "IMSI": { + "type": "string", + "pattern": "^[0-9]{6,15}$" + }, + "IMEI": { + "type": "string", + "pattern": "^[0-9]{14}$" + }, + "IMEICheckDigit": { + "type": "string", + "pattern": "^[0-9]{15}$" + }, + "IMEISV": { + "type": "string", + "pattern": "^[0-9]{16}$" + }, + "IPv4Address": { + "type": "string", + "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])$" + }, + "IPv4CIDR": { + "type": "string", + "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])/([1-2]?[0-9]|3[0-2])$" + }, + "IPv6Address": { + "type": "string", + "pattern": "^([0-9a-f]{4}:){7}([0-9a-f]{4})$" + }, + "IPv6CIDR": { + "type": "string", + "pattern": "^([0-9a-f]{4}:){7}([0-9a-f]{4})/(([1-9][0-9]?)|(1[0-1][0-9])|(12[0-8]))$" + }, + "TCPPort": { + "type": "integer", + "exclusiveMinimum": 1, + "maximum": 65535 + }, + "UDPPort": { + "type": "integer", + "minimum": 0, + "maximum": 65535 + }, + "MACAddress": { + "type": "string", + "pattern": "^([a-f0-9]{2}:){5}[a-f0-9]{2}$" + }, + "EmailAddress": { + "allOf": [ + { + "$ref": "#/$defs/ShortString" + }, + { + "type": "string", + "pattern": "^[a-zA-Z0-9\\.!#$%&'\\*\\+\\\\/=\\?\\^_`\\{\\|\\}~\\-]+@[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$" + } + ] + }, + "UUID": { + "type": "string", + "pattern": "^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$" + }, + "ISOCountryCode": { + "type": "string", + "pattern": "^[A-Z]{2}$" + }, + "SIPURI": { + "type": "string", + "pattern": "^sips?:[a-zA-Z0-9!#$&-;=?-\\[\\]_~%]+$" + }, + "TELURI": { + "type": "string", + "pattern": "^tel:[a-zA-Z0-9!#$&-;=?-\\[\\]_~%]+$" + }, + "WGS84LatitudeDecimal": { + "type": "string", + "pattern": "^[NS][0-9]{2}\\.[0-9]{6}$" + }, + "WGS84LongitudeDecimal": { + "type": "string", + "pattern": "^[EW][0-9]{3}\\.[0-9]{6}$" + }, + "WGS84LatitudeAngular": { + "type": "string", + "pattern": "^[NS][0-9]{6}\\.[0-9]{2}$" + }, + "WGS84LongitudeAngular": { + "type": "string", + "pattern": "^[EW][0-9]{7}\\.[0-9]{2}$" + }, + "SUPIIMSI": { + "$ref": "#/$defs/IMSI" + }, + "SUPINAI": { + "$ref": "#/$defs/NAI" + }, + "SUCI": { + "type": "string", + "pattern": "^([a-fA-F0-9]{2})*$" + }, + "PEIIMEI": { + "$ref": "#/$defs/IMEI" + }, + "PEIIMEICheckDigit": { + "$ref": "#/$defs/IMEICheckDigit" + }, + "PEIIMEISV": { + "$ref": "#/$defs/IMEISV" + }, + "GPSIMSISDN": { + "type": "string", + "pattern": "^[0-9]{1,15}$" + }, + "GPSINAI": { + "$ref": "#/$defs/NAI" + }, + "NAI": { + "type": "string" + }, + "LDID": { + "type": "string", + "pattern": "^([A-Z]{2}-.+-.+)$" + }, + "InternationalizedEmailAddress": { + "allOf": [ + { + "$ref": "#/$defs/ShortString" + }, + { + "type": "string", + "pattern": "^.+@.+$" + } + ] + }, + "EUI64": { + "type": "string", + "pattern": "^([a-f0-9]{2}:){7}[a-f0-9]{2}$" + }, + "CGI": { + "type": "string", + "pattern": "^[0-9]{3}-[0-9]{2,3}-[a-f0-9]{4}-[a-f0-9]{4}$" + }, + "ECGI": { + "type": "string", + "pattern": "^[0-9]{3}-[0-9]{2,3}-[a-f0-9]{7}$" + }, + "NCGI": { + "type": "string", + "pattern": "^[0-9]{3}-[0-9]{2,3}-[a-f0-9]{9}$" + }, + "ICCID": { + "type": "string", + "pattern": "^[0-9]{19,20}$" + }, + "IPAddress": { + "oneOf": [ + { + "type": "object", + "properties": { + "IPv4Address": { + "$ref": "#/$defs/IPv4Address" + } + }, + "required": [ + "IPv4Address" + ] + }, + { + "type": "object", + "properties": { + "IPv6Address": { + "$ref": "#/$defs/IPv6Address" + } + }, + "required": [ + "IPv6Address" + ] + } + ] + }, + "IPCIDR": { + "oneOf": [ + { + "type": "object", + "properties": { + "IPv4CIDR": { + "$ref": "#/$defs/IPv4CIDR" + } + }, + "required": [ + "IPv4CIDR" + ] + }, + { + "type": "object", + "properties": { + "IPv6CIDR": { + "$ref": "#/$defs/IPv6CIDR" + } + }, + "required": [ + "IPv6CIDR" + ] + } + ] + }, + "TCPPortRange": { + "type": "object", + "properties": { + "start": { + "$ref": "#/$defs/TCPPort" + }, + "end": { + "$ref": "#/$defs/TCPPort" + } + }, + "required": [ + "start", + "end" + ] + }, + "UDPPortRange": { + "type": "object", + "properties": { + "start": { + "$ref": "#/$defs/UDPPort" + }, + "end": { + "$ref": "#/$defs/UDPPort" + } + }, + "required": [ + "start", + "end" + ] + }, + "Port": { + "oneOf": [ + { + "type": "object", + "properties": { + "TCPPort": { + "$ref": "#/$defs/TCPPort" + } + }, + "required": [ + "TCPPort" + ] + }, + { + "type": "object", + "properties": { + "UDPPort": { + "$ref": "#/$defs/UDPPort" + } + }, + "required": [ + "UDPPort" + ] + } + ] + }, + "PortRange": { + "oneOf": [ + { + "type": "object", + "properties": { + "TCPPortRange": { + "$ref": "#/$defs/TCPPortRange" + } + }, + "required": [ + "TCPPortRange" + ] + }, + { + "type": "object", + "properties": { + "UDPPortRange": { + "$ref": "#/$defs/UDPPortRange" + } + }, + "required": [ + "UDPPortRange" + ] + } + ] + }, + "IPAddressPort": { + "type": "object", + "properties": { + "address": { + "$ref": "#/$defs/IPAddress" + }, + "port": { + "$ref": "#/$defs/Port" + } + }, + "required": [ + "address", + "port" + ] + }, + "IPAddressPortRange": { + "type": "object", + "properties": { + "address": { + "$ref": "#/$defs/IPAddress" + }, + "portRange": { + "$ref": "#/$defs/PortRange" + } + }, + "required": [ + "address", + "portRange" + ] + }, + "WGS84CoordinateDecimal": { + "type": "object", + "properties": { + "latitude": { + "$ref": "#/$defs/WGS84LatitudeDecimal" + }, + "longitude": { + "$ref": "#/$defs/WGS84LongitudeDecimal" + } + }, + "required": [ + "latitude", + "longitude" + ] + }, + "WGS84CoordinateAngular": { + "type": "object", + "properties": { + "latitude": { + "$ref": "#/$defs/WGS84LatitudeAngular" + }, + "longitude": { + "$ref": "#/$defs/WGS84LongitudeAngular" + } + }, + "required": [ + "latitude", + "longitude" + ] + } + } +} \ No newline at end of file diff --git a/json/notification.json b/json/notification.json new file mode 100644 index 0000000..e9805f5 --- /dev/null +++ b/json/notification.json @@ -0,0 +1,64 @@ +{ + "$id": "notification.json", + "$defs": { + "NotificationObject": { + "type": "object", + "properties": { + "ObjectIdentifier": { + "$ref": "core.json#/$defs/ObjectIdentifier" + }, + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + }, + "OwnerIdentifier": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "Generation": { + "type": "integer", + "minimum": 0 + }, + "ExternalIdentifier": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "AssociatedObjects": { + "$ref": "core.json#/$defs/AssociatedObjects" + }, + "LastChanged": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "NationalHandlingParameters": { + "$ref": "core.json#/$defs/NationalHandlingParameters" + }, + "NotificationDetails": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "NotificationType": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "NewNotification": { + "type": "boolean" + }, + "NotificationTimestamp": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "NationalNotificationParameters": { + "$ref": "#/$defs/NationalNotificationParameters" + } + }, + "required": [ + "ObjectIdentifier" + ] + }, + "NationalNotificationParameters": { + "type": "object", + "properties": { + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + } + }, + "required": [ + "CountryCode" + ] + } + } +} \ No newline at end of file diff --git a/json/task.json b/json/task.json new file mode 100644 index 0000000..f945d95 --- /dev/null +++ b/json/task.json @@ -0,0 +1,499 @@ +{ + "$id": "task.json", + "$defs": { + "LITaskObject": { + "type": "object", + "properties": { + "ObjectIdentifier": { + "$ref": "core.json#/$defs/ObjectIdentifier" + }, + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + }, + "OwnerIdentifier": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "Generation": { + "type": "integer", + "minimum": 0 + }, + "ExternalIdentifier": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "AssociatedObjects": { + "$ref": "core.json#/$defs/AssociatedObjects" + }, + "LastChanged": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "NationalHandlingParameters": { + "$ref": "core.json#/$defs/NationalHandlingParameters" + }, + "Reference": { + "$ref": "etsi103280.json#/$defs/LIID" + }, + "Status": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "DesiredStatus": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "Timespan": { + "$ref": "#/$defs/TaskTimespan" + }, + "TargetIdentifier": { + "$ref": "#/$defs/TargetIdentifier" + }, + "DeliveryType": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "DeliveryDetails": { + "$ref": "#/$defs/TaskDeliveryDetails" + }, + "ApprovalDetails": { + "$ref": "common.json#/$defs/ApprovalDetails" + }, + "CSPID": { + "$ref": "core.json#/$defs/EndpointID" + }, + "HandlingProfile": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "InvalidReason": { + "$ref": "core.json#/$defs/ActionUnsuccesfulInformation" + }, + "Flags": { + "$ref": "#/$defs/TaskFlags" + }, + "NationalLITaskingParameters": { + "$ref": "#/$defs/NationalLITaskingParameters" + } + }, + "required": [ + "ObjectIdentifier" + ] + }, + "TaskTimespan": { + "type": "object", + "properties": { + "StartTime": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "EndTime": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "TerminationTime": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "ProvisioningTime": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "DeprovisioningTime": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + } + }, + "required": [] + }, + "TargetIdentifier": { + "type": "object", + "properties": { + "TargetIdentifierValues": { + "$ref": "#/$defs/TargetIdentifierValues" + }, + "ServiceType": { + "$ref": "common.json#/$defs/DictionaryEntry" + } + }, + "required": [] + }, + "TargetIdentifierValues": { + "type": "object", + "properties": { + "TargetIdentifierValue": { + "$ref": "#/$defs/TargetIdentifierValue" + } + }, + "required": [ + "TargetIdentifierValue" + ] + }, + "TargetIdentifierValue": { + "type": "object", + "properties": { + "FormatType": { + "$ref": "#/$defs/FormatType" + }, + "Value": { + "$ref": "etsi103280.json#/$defs/LongString" + } + }, + "required": [ + "FormatType", + "Value" + ] + }, + "FormatType": { + "type": "object", + "properties": { + "FormatOwner": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "FormatName": { + "$ref": "etsi103280.json#/$defs/ShortString" + } + }, + "required": [ + "FormatOwner", + "FormatName" + ] + }, + "TaskDeliveryDetails": { + "type": "object", + "properties": { + "DeliveryDestination": { + "$ref": "#/$defs/DeliveryDestination" + } + }, + "required": [ + "DeliveryDestination" + ] + }, + "DeliveryDestination": { + "type": "object", + "properties": { + "DeliveryAddress": { + "$ref": "#/$defs/DeliveryAddress" + }, + "EncryptionDetails": { + "$ref": "#/$defs/NationalEncryptionDetails" + }, + "IRIorCC": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "HandoverFormat": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "DeliveryProfile": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "NationalDeliveryParameters": { + "$ref": "#/$defs/NationalDeliveryParameters" + } + }, + "required": [] + }, + "DeliveryAddress": { + "oneOf": [ + { + "type": "object", + "properties": { + "IPv4Address": { + "$ref": "etsi103280.json#/$defs/IPv4Address" + } + }, + "required": [ + "IPv4Address" + ] + }, + { + "type": "object", + "properties": { + "IPv6Address": { + "$ref": "etsi103280.json#/$defs/IPv6Address" + } + }, + "required": [ + "IPv6Address" + ] + }, + { + "type": "object", + "properties": { + "IPAddressPort": { + "$ref": "etsi103280.json#/$defs/IPAddressPort" + } + }, + "required": [ + "IPAddressPort" + ] + }, + { + "type": "object", + "properties": { + "IPAddressPortRange": { + "$ref": "etsi103280.json#/$defs/IPAddressPortRange" + } + }, + "required": [ + "IPAddressPortRange" + ] + }, + { + "type": "object", + "properties": { + "E164Number": { + "$ref": "etsi103280.json#/$defs/InternationalE164" + } + }, + "required": [ + "E164Number" + ] + }, + { + "type": "object", + "properties": { + "FTPAddress": { + "type": "string" + } + }, + "required": [ + "FTPAddress" + ] + }, + { + "type": "object", + "properties": { + "URL": { + "type": "string" + } + }, + "required": [ + "URL" + ] + }, + { + "type": "object", + "properties": { + "FQDN": { + "$ref": "etsi103280.json#/$defs/LongString" + } + }, + "required": [ + "FQDN" + ] + }, + { + "type": "object", + "properties": { + "EmailAddress": { + "$ref": "etsi103280.json#/$defs/EmailAddress" + } + }, + "required": [ + "EmailAddress" + ] + } + ] + }, + "TaskFlags": { + "type": "object", + "properties": { + "TaskFlag": { + "$ref": "common.json#/$defs/DictionaryEntry" + } + }, + "required": [] + }, + "NationalLITaskingParameters": { + "type": "object", + "properties": { + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + } + }, + "required": [ + "CountryCode" + ] + }, + "NationalDeliveryParameters": { + "type": "object", + "properties": { + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + } + }, + "required": [ + "CountryCode" + ] + }, + "NationalEncryptionDetails": { + "type": "object", + "properties": { + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + } + }, + "required": [ + "CountryCode" + ] + }, + "LDTaskObject": { + "type": "object", + "properties": { + "ObjectIdentifier": { + "$ref": "core.json#/$defs/ObjectIdentifier" + }, + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + }, + "OwnerIdentifier": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "Generation": { + "type": "integer", + "minimum": 0 + }, + "ExternalIdentifier": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "AssociatedObjects": { + "$ref": "core.json#/$defs/AssociatedObjects" + }, + "LastChanged": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "NationalHandlingParameters": { + "$ref": "core.json#/$defs/NationalHandlingParameters" + }, + "Reference": { + "$ref": "etsi103280.json#/$defs/LDID" + }, + "Status": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "StatusReason": { + "$ref": "core.json#/$defs/ActionUnsuccesfulInformation" + }, + "DesiredStatus": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "RequestDetails": { + "$ref": "#/$defs/RequestDetails" + }, + "DeliveryDetails": { + "$ref": "#/$defs/LDDeliveryDetails" + }, + "ApprovalDetails": { + "$ref": "common.json#/$defs/ApprovalDetails" + }, + "CSPID": { + "$ref": "core.json#/$defs/EndpointID" + }, + "HandlingProfile": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "Flags": { + "$ref": "#/$defs/LDTaskFlags" + }, + "NationalLDTaskingParameters": { + "$ref": "#/$defs/NationalLDTaskingParameters" + } + }, + "required": [ + "ObjectIdentifier" + ] + }, + "RequestDetails": { + "type": "object", + "properties": { + "Type": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "StartTime": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "EndTime": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "ObservedTime": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "ObservedTimes": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "RequestValues": { + "$ref": "#/$defs/RequestValues" + } + }, + "required": [] + }, + "RequestValues": { + "type": "object", + "properties": { + "RequestValue": { + "$ref": "#/$defs/RequestValue" + } + }, + "required": [ + "RequestValue" + ] + }, + "RequestValue": { + "type": "object", + "properties": { + "FormatType": { + "$ref": "#/$defs/FormatType" + }, + "Value": { + "$ref": "etsi103280.json#/$defs/LongString" + } + }, + "required": [ + "FormatType", + "Value" + ] + }, + "LDDeliveryDetails": { + "type": "object", + "properties": { + "LDDeliveryDestination": { + "$ref": "#/$defs/LDDeliveryDestination" + } + }, + "required": [ + "LDDeliveryDestination" + ] + }, + "LDDeliveryDestination": { + "type": "object", + "properties": { + "DeliveryAddress": { + "$ref": "#/$defs/DeliveryAddress" + }, + "EncryptionDetails": { + "$ref": "#/$defs/NationalEncryptionDetails" + }, + "LDHandoverFormat": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "LDDeliveryProfile": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "NationalDeliveryParameters": { + "$ref": "#/$defs/NationalDeliveryParameters" + } + }, + "required": [] + }, + "LDTaskFlags": { + "type": "object", + "properties": { + "LDTaskFlag": { + "$ref": "common.json#/$defs/DictionaryEntry" + } + }, + "required": [] + }, + "NationalLDTaskingParameters": { + "type": "object", + "properties": { + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + } + }, + "required": [ + "CountryCode" + ] + } + } +} \ No newline at end of file diff --git a/json/xmldsig.json b/json/xmldsig.json new file mode 100644 index 0000000..dde4cb0 --- /dev/null +++ b/json/xmldsig.json @@ -0,0 +1,553 @@ +{ + "$id": "core.json", + "$defs": { + "ObjectIdentifier": { + "$ref": "etsi103280.json#/$defs/UUID" + }, + "HI1Message": { + "type": "object", + "properties": { + "Header": { + "$ref": "#/$defs/MessageHeader" + }, + "Payload": { + "$ref": "#/$defs/MessagePayload" + }, + "Signature": { + "$ref": "xmldsig.json#/$defs/SignatureType" + } + }, + "required": [ + "Header", + "Payload" + ] + }, + "MessageHeader": { + "type": "object", + "properties": { + "SenderIdentifier": { + "$ref": "#/$defs/EndpointID" + }, + "ReceiverIdentifier": { + "$ref": "#/$defs/EndpointID" + }, + "TransactionIdentifier": { + "$ref": "etsi103280.json#/$defs/UUID" + }, + "Timestamp": { + "$ref": "etsi103280.json#/$defs/QualifiedMicrosecondDateTime" + }, + "Version": { + "$ref": "#/$defs/Version" + } + }, + "required": [ + "SenderIdentifier", + "ReceiverIdentifier", + "TransactionIdentifier", + "Timestamp", + "Version" + ] + }, + "Version": { + "type": "object", + "properties": { + "ETSIVersion": { + "$ref": "common.json#/$defs/ETSIVersion" + }, + "NationalProfileOwner": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "NationalProfileVersion": { + "$ref": "etsi103280.json#/$defs/ShortString" + } + }, + "required": [ + "ETSIVersion", + "NationalProfileOwner", + "NationalProfileVersion" + ] + }, + "EndpointID": { + "type": "object", + "properties": { + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + }, + "UniqueIdentifier": { + "$ref": "etsi103280.json#/$defs/LongString" + } + }, + "required": [ + "CountryCode", + "UniqueIdentifier" + ] + }, + "MessagePayload": { + "oneOf": [ + { + "type": "object", + "properties": { + "RequestPayload": { + "$ref": "#/$defs/RequestPayload" + } + }, + "required": [ + "RequestPayload" + ] + }, + { + "type": "object", + "properties": { + "ResponsePayload": { + "$ref": "#/$defs/ResponsePayload" + } + }, + "required": [ + "ResponsePayload" + ] + } + ] + }, + "RequestPayload": { + "type": "object", + "properties": { + "ActionRequests": { + "$ref": "#/$defs/ActionRequests" + } + }, + "required": [ + "ActionRequests" + ] + }, + "ActionRequests": { + "type": "object", + "properties": { + "ActionRequest": { + "$ref": "#/$defs/ActionRequest" + } + }, + "required": [ + "ActionRequest" + ] + }, + "ResponsePayload": { + "oneOf": [ + { + "type": "object", + "properties": { + "ActionResponses": { + "$ref": "#/$defs/ActionResponses" + } + }, + "required": [ + "ActionResponses" + ] + }, + { + "type": "object", + "properties": { + "ErrorInformation": { + "$ref": "#/$defs/ActionUnsuccesfulInformation" + } + }, + "required": [ + "ErrorInformation" + ] + } + ] + }, + "ActionResponses": { + "type": "object", + "properties": { + "ActionResponse": { + "$ref": "#/$defs/ActionResponse" + } + }, + "required": [ + "ActionResponse" + ] + }, + "ActionRequest": { + "allOf": [ + { + "type": "object", + "properties": { + "ActionIdentifier": { + "type": "integer", + "minimum": 0 + } + }, + "required": [ + "ActionIdentifier" + ] + }, + { + "oneOf": [ + { + "type": "object", + "properties": { + "GET": { + "$ref": "#/$defs/GETRequest" + } + }, + "required": [ + "GET" + ] + }, + { + "type": "object", + "properties": { + "CREATE": { + "$ref": "#/$defs/CREATERequest" + } + }, + "required": [ + "CREATE" + ] + }, + { + "type": "object", + "properties": { + "UPDATE": { + "$ref": "#/$defs/UPDATERequest" + } + }, + "required": [ + "UPDATE" + ] + }, + { + "type": "object", + "properties": { + "LIST": { + "$ref": "#/$defs/LISTRequest" + } + }, + "required": [ + "LIST" + ] + }, + { + "type": "object", + "properties": { + "DELIVER": { + "$ref": "#/$defs/DELIVERRequest" + } + }, + "required": [ + "DELIVER" + ] + } + ] + } + ] + }, + "ActionResponse": { + "allOf": [ + { + "type": "object", + "properties": { + "ActionIdentifier": { + "type": "integer", + "minimum": 0 + } + }, + "required": [ + "ActionIdentifier" + ] + }, + { + "oneOf": [ + { + "type": "object", + "properties": { + "GETResponse": { + "$ref": "#/$defs/GETResponse" + } + }, + "required": [ + "GETResponse" + ] + }, + { + "type": "object", + "properties": { + "CREATEResponse": { + "$ref": "#/$defs/CREATEResponse" + } + }, + "required": [ + "CREATEResponse" + ] + }, + { + "type": "object", + "properties": { + "UPDATEResponse": { + "$ref": "#/$defs/UPDATEResponse" + } + }, + "required": [ + "UPDATEResponse" + ] + }, + { + "type": "object", + "properties": { + "LISTResponse": { + "$ref": "#/$defs/LISTResponse" + } + }, + "required": [ + "LISTResponse" + ] + }, + { + "type": "object", + "properties": { + "ErrorInformation": { + "$ref": "#/$defs/ActionUnsuccesfulInformation" + } + }, + "required": [ + "ErrorInformation" + ] + }, + { + "type": "object", + "properties": { + "DELIVERResponse": { + "$ref": "#/$defs/DELIVERResponse" + } + }, + "required": [ + "DELIVERResponse" + ] + } + ] + } + ] + }, + "GETRequest": { + "type": "object", + "properties": { + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + } + }, + "required": [ + "Identifier" + ] + }, + "GETResponse": { + "type": "object", + "properties": { + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "HI1Object" + ] + }, + "CREATERequest": { + "type": "object", + "properties": { + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "HI1Object" + ] + }, + "CREATEResponse": { + "type": "object", + "properties": { + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + }, + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "Identifier" + ] + }, + "UPDATERequest": { + "type": "object", + "properties": { + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "HI1Object" + ] + }, + "UPDATEResponse": { + "type": "object", + "properties": { + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + }, + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "Identifier" + ] + }, + "LISTRequest": { + "type": "object", + "properties": { + "ObjectType": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "LastChanged": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + } + }, + "required": [] + }, + "LISTResponse": { + "type": "object", + "properties": { + "ListResponseRecord": { + "$ref": "#/$defs/ListResponseRecord" + } + }, + "required": [] + }, + "ListResponseRecord": { + "type": "object", + "properties": { + "ObjectType": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + }, + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + }, + "OwnerIdentifier": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "Generation": { + "type": "integer", + "minimum": 0 + }, + "ExternalIdentifier": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "LastChanged": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + } + }, + "required": [ + "ObjectType", + "Identifier", + "Generation" + ] + }, + "ActionUnsuccesfulInformation": { + "type": "object", + "properties": { + "ErrorCode": { + "type": "integer", + "minimum": 0 + }, + "ErrorDescription": { + "$ref": "etsi103280.json#/$defs/LongString" + } + }, + "required": [ + "ErrorCode", + "ErrorDescription" + ] + }, + "DELIVERRequest": { + "type": "object", + "properties": { + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + }, + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "Identifier", + "HI1Object" + ] + }, + "DELIVERResponse": { + "type": "object", + "properties": { + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + } + }, + "required": [ + "Identifier" + ] + }, + "HI1Object": { + "type": "object", + "properties": { + "ObjectIdentifier": { + "$ref": "#/$defs/ObjectIdentifier" + }, + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + }, + "OwnerIdentifier": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "Generation": { + "type": "integer", + "minimum": 0 + }, + "ExternalIdentifier": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "AssociatedObjects": { + "$ref": "#/$defs/AssociatedObjects" + }, + "LastChanged": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "NationalHandlingParameters": { + "$ref": "#/$defs/NationalHandlingParameters" + } + }, + "required": [ + "ObjectIdentifier" + ] + }, + "AssociatedObjects": { + "type": "object", + "properties": { + "AssociatedObject": { + "$ref": "#/$defs/ObjectIdentifier" + } + }, + "required": [] + }, + "NationalHandlingParameters": { + "type": "object", + "properties": { + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + } + }, + "required": [ + "CountryCode" + ] + } + } +} \ No newline at end of file diff --git a/translate.py b/translate.py index 7b62565..35a1a3b 100644 --- a/translate.py +++ b/translate.py @@ -1,33 +1,83 @@ import json import logging +import os from pathlib import Path +import sys from xmlschema import * from translate_schema import * -logging.basicConfig(level = logging.DEBUG) +import jsonschema -if __name__ == "__main__": - # js = translate_schema("103280/TS_103_280.xsd", "103120.json") - # print(json.dumps(js, indent=2)) - schemas = [ "103120/schema/ts_103120_Authorisation.xsd", - "103120/schema/ts_103120_Common.xsd", - "103120/schema/ts_103120_Delivery.xsd", - "103120/schema/ts_103120_Document.xsd", - "103120/schema/ts_103120_Notification.xsd", - "103120/schema/ts_103120_Task.xsd", - "103280/TS_103_280.xsd", - "testing/deps/xmldsig/xmldsig-core-schema.xsd"] +logging.basicConfig(level = logging.DEBUG) +def build_schema_locations (paths): schema_locations = [] - for schemaFile in schemas: + for schemaFile in paths: try: xs = XMLSchema(schemaFile, validation='skip') schema_locations.append((xs.target_namespace, str(Path(schemaFile).resolve()))) print (" [ {0} -> {1} ]".format(xs.target_namespace, schemaFile)) except XMLSchemaParseError as ex: print (" [ {0} failed to parse: {1} ]".format(schemaFile, ex)) + return schema_locations + +def get_json(filename): + with open(filename) as f: + j = json.load(f) + return j + +if __name__ == "__main__": + if len(sys.argv) > 1 and sys.argv[1] == "rebuild": + schema_paths = [ "103120/schema/ts_103120_Authorisation.xsd", + "103120/schema/ts_103120_Common.xsd", + "103120/schema/ts_103120_Core.xsd", + "103120/schema/ts_103120_Delivery.xsd", + "103120/schema/ts_103120_Document.xsd", + "103120/schema/ts_103120_Notification.xsd", + "103120/schema/ts_103120_Task.xsd", + "103280/TS_103_280.xsd", + "testing/deps/xmldsig/xmldsig-core-schema.xsd"] - js = translate_schema("103120/schema/ts_103120_core.xsd", "core.json", schema_locations) - print(json.dumps(js, indent=2)) + schema_locations = build_schema_locations(schema_paths) + + ns_to_id_map = { + schema[0]: schema[0].split('/')[-1].lower() + ".json" + for schema in schema_locations if '03120' in schema[0] + } | { + 'http://uri.etsi.org/03280/common/2017/07' : 'etsi103280.json', + 'http://www.w3.org/2000/09/xmldsig#' : 'xmldsig.json', + } + + # js = translate_schema("103280/TS_103_280.xsd", "103120.json") + # print(json.dumps(js, indent=2)) + + output_path = Path('json/') + if not output_path.exists(): + os.mkdir(str(output_path)) + + json_schemas = {} + for schema_tuple in schema_locations: + if 'xmldsig' in (schema_tuple[1]): + continue + js = translate_schema(schema_tuple[1], ns_to_id_map, schema_locations) + if ns_to_id_map[schema_tuple[0]] == 'core.json': + js['$defs']['HI1Message']['properties'].pop('Signature') + js_path = output_path / ns_to_id_map[schema_tuple[0]] + with open(str(js_path), 'w') as f: + f.write(json.dumps(js, indent=2)) + json_schemas[js['$id']] = js + else: + json_schemas = {} + json_path = Path('json/') + for json_file in json_path.glob("*.json"): + json_schemas[json_file.name] = get_json(json_file) + + resolver = jsonschema.RefResolver("", "", json_schemas) + + instance = get_json("120.json") + schema = json_schemas['core.json'] + jsonschema.validate(instance, schema, resolver=resolver) + + # print(json.dumps(js, indent=2)) diff --git a/translate_schema/__init__.py b/translate_schema/__init__.py index a4ddb4b..cf6b3f8 100644 --- a/translate_schema/__init__.py +++ b/translate_schema/__init__.py @@ -14,9 +14,9 @@ mappings = [ SequenceMapping(), ] -def translate_schema (schema_path, schema_id, schema_locations = []): +def translate_schema (schema_path: str, ns_to_id_map: dict, schema_locations = []): js = { - "$id" : schema_id, + "$id" : "?", "$defs" : {} } @@ -24,6 +24,20 @@ def translate_schema (schema_path, schema_id, schema_locations = []): xs = XMLSchema(schema_path, validation='lax', locations=schema_locations) logging.info(f"Schema namespace: {xs.target_namespace}" ) + schema_id = ns_to_id_map[xs.target_namespace] + js['$id'] = schema_id + + TypeMapping.ns_to_id_map = ns_to_id_map + + elementList = [] + for elementName, element in xs.elements.items(): + logging.info(f"Processing element {elementName} : {element}") + elementList.append(TypeMapping.get_ref_for(element.type, element.namespaces[''])) + if len(elementList) == 1: + js['$ref'] = elementList[0]['$ref'] + elif len(elementList) > 1: + js['oneOf'] = elementList + for type_name, xsd_type in xs.types.items(): logging.info(f"Processing {type_name} : {xsd_type}") diff --git a/translate_schema/type_mapping.py b/translate_schema/type_mapping.py index 582e1c4..a7bf7f6 100644 --- a/translate_schema/type_mapping.py +++ b/translate_schema/type_mapping.py @@ -12,10 +12,37 @@ from .util import * log = logging.getLogger() class TypeMapping(ABC): + ns_to_id_map = {} + @abstractmethod def map(self, xst : BaseXsdType): return None + @classmethod + def extract_namespace(cls, qname: str): + match = re.search(r'^\{([^\{\}]+)\}(([^\{\}]+))$', qname) + if match is None: + return None + return match.group(1) + + @classmethod + def get_ref_for(cls, xsd_type: XsdType, current_ns : str): + ns = cls.extract_namespace(xsd_type.name) + if ns == current_ns: + return { "$ref" : f"#/$defs/{xsd_type.local_name}" } + else: + mapped_id = cls.ns_to_id_map[ns] + return { "$ref" : f"{mapped_id}#/$defs/{xsd_type.local_name}"} + + @classmethod + def get_type_from_elem(cls, elem: XsdElement, current_ns : str): + ns = cls.extract_namespace(elem.type.name) + if (ns == "http://www.w3.org/2001/XMLSchema"): + # this should be an XSD primitive type + return dict(XSDNativeSimpleTypeMapping.XSD_TYPE_MAP[elem.type.local_name]) + else: + return cls.get_ref_for(elem.type, current_ns) + class SimpleTypeMapping(TypeMapping): def map(self, xst: BaseXsdType): log.debug(f"Attempting mapping of {xst} to simple type") @@ -39,7 +66,10 @@ class XSDNativeSimpleTypeMapping(SimpleTypeMapping): "integer" : { "type" : "integer"}, "nonNegativeInteger" : { "type" : "integer", "minimum" : 0}, + "boolean" : { "type" : "boolean" }, + "hexBinary" : { "type" : "string", "pattern" : "^([a-fA-F0-9]{2})*$"}, + "base64Binary" : { "type" : "string", "pattern" : "^[-A-Za-z0-9+/]*={0,3}$"}, "anyType" : {} } @@ -56,15 +86,15 @@ class XSDNativeSimpleTypeMapping(SimpleTypeMapping): parent_type = None if mapped_type is None: - ns = extract_namespace(xst.base_type.name) + ns = TypeMapping.extract_namespace(xst.base_type.name) if ns == XSDNativeSimpleTypeMapping.XSD_NS: print (xst) print (xst.base_type) raise Exception (f"No mapping for xs:{xst.base_type.local_name}") if len(xst.facets) == 0: - mapped_type = get_ref_for(xst.base_type, xst.namespaces['']) + mapped_type = TypeMapping.get_ref_for(xst.base_type, xst.namespaces['']) else: - parent_type = get_ref_for(xst.base_type, xst.namespaces['']) + parent_type = TypeMapping.get_ref_for(xst.base_type, xst.namespaces['']) mapped_type = XSDNativeSimpleTypeMapping.XSD_TYPE_MAP.get(xst.root_type.local_name) if mapped_type is None: raise Exception (f"Could not find mapping for root type xs:{xst.root_type.local_name}") @@ -113,33 +143,26 @@ class ComplexTypeMapping(TypeMapping): "type" : "object" } -def get_type_from_elem(elem: XsdElement, current_ns : str): - ns = extract_namespace(elem.type.name) - if (ns == "http://www.w3.org/2001/XMLSchema"): - # this should be an XSD primitive type - return dict(XSDNativeSimpleTypeMapping.XSD_TYPE_MAP[elem.type.local_name]) - else: - return get_ref_for(elem.type, current_ns) - - -def process_choice(choice: XsdGroup, current_ns : str): - if choice.model != 'choice': - raise Exception(f"Wrong group type: {c.model}") - oneOf = [] - for c in choice.iter_model(): - if not (type(c) is XsdElement): - raise Exception (f"Non-element {c} encountered in choice {choice}") - t = get_type_from_elem(c, current_ns) - oneOf.append({ - "type" : "object", - "properties" : { - c.local_name : t - }, - "required" : [c.local_name] - }) - return oneOf class ChoiceMapping(ComplexTypeMapping): + @classmethod + def process_choice(cls, choice: XsdGroup, current_ns : str): + if choice.model != 'choice': + raise Exception(f"Wrong group type: {c.model}") + oneOf = [] + for c in choice.iter_model(): + if not (type(c) is XsdElement): + raise Exception (f"Non-element {c} encountered in choice {choice}") + t = TypeMapping.get_type_from_elem(c, current_ns) + oneOf.append({ + "type" : "object", + "properties" : { + c.local_name : t + }, + "required" : [c.local_name] + }) + return oneOf + def map(self, xst : BaseXsdType): log.debug(f"Attempting mapping of {xst} to choice") j = super().map(xst) @@ -150,7 +173,7 @@ class ChoiceMapping(ComplexTypeMapping): if (content.model != 'choice'): log.debug("Not a choice, giving up") return None - return { 'oneOf' : process_choice(content, xst.namespaces[''])} + return { 'oneOf' : ChoiceMapping.process_choice(content, xst.namespaces[''])} class SequenceMapping(ComplexTypeMapping): def map(self, xst: BaseXsdType): @@ -172,7 +195,7 @@ class SequenceMapping(ComplexTypeMapping): for c in list(content.iter_model()): log.debug(f"Processing model item {c}") if type(c) is XsdElement: - mapped_type['properties'][c.local_name] = get_type_from_elem(c, xst.namespaces['']) + mapped_type['properties'][c.local_name] = TypeMapping.get_type_from_elem(c, xst.namespaces['']) if c.effective_min_occurs == 1: mapped_type['required'].append(c.local_name) elif type(c) is XsdGroup: @@ -180,7 +203,9 @@ class SequenceMapping(ComplexTypeMapping): raise Exception (f"Second group '{c.local_name}' encountered in {xst}") if c.model != "choice": raise Exception (f"Don't know what to do with inner group {c} in {xst} - not a choice") - inner_choice = process_choice(c, xst.namespaces['']) + inner_choice = ChoiceMapping.process_choice(c, xst.namespaces['']) + elif type(c) is XsdAnyElement: + mapped_type = {} else: raise Exception(f"Unknown element type {c}") if (inner_choice): diff --git a/translate_schema/util.py b/translate_schema/util.py index ce22cf3..f7f67b3 100644 --- a/translate_schema/util.py +++ b/translate_schema/util.py @@ -2,23 +2,3 @@ import re from xmlschema import * -def extract_namespace(qname: str): - match = re.search(r'^\{([^\{\}]+)\}(([^\{\}]+))$', qname) - if match is None: - return None - return match.group(1) - -NS_MAP = { - 'http://uri.etsi.org/03120/common/2019/10/Core' : 'core.json', - 'http://uri.etsi.org/03120/common/2016/02/Common' : 'common.json', - 'http://uri.etsi.org/03280/common/2017/07' : 'etsi103280.json', - 'http://www.w3.org/2000/09/xmldsig#' : 'xmldsig', -} - -def get_ref_for(xsd_type: XsdType, current_ns : str): - ns = extract_namespace(xsd_type.name) - if ns == current_ns: - return { "$ref" : f"#/$defs/{xsd_type.local_name}" } - else: - mapped_id = NS_MAP[ns] - return { "$ref" : f"{mapped_id}#/$defs/{xsd_type.local_name}"} \ No newline at end of file -- GitLab From f3b148282075570c9c6fe0b6ffaa56035b7a2851 Mon Sep 17 00:00:00 2001 From: mark Date: Mon, 13 Jun 2022 09:37:29 +0100 Subject: [PATCH 05/20] Refactor --- translate_schema/ChoiceMapping.py | 42 ++++ translate_schema/ComplexTypeMapping.py | 11 + translate_schema/SequenceMapping.py | 56 +++++ translate_schema/SimpleTypeMapping.py | 18 ++ translate_schema/TypeMapping.py | 69 ++++++ .../XSDNativeSimpleTypeMapping.py | 72 ++++++ translate_schema/__init__.py | 6 +- translate_schema/type_mapping.py | 219 ------------------ 8 files changed, 273 insertions(+), 220 deletions(-) create mode 100644 translate_schema/ChoiceMapping.py create mode 100644 translate_schema/ComplexTypeMapping.py create mode 100644 translate_schema/SequenceMapping.py create mode 100644 translate_schema/SimpleTypeMapping.py create mode 100644 translate_schema/TypeMapping.py create mode 100644 translate_schema/XSDNativeSimpleTypeMapping.py delete mode 100644 translate_schema/type_mapping.py diff --git a/translate_schema/ChoiceMapping.py b/translate_schema/ChoiceMapping.py new file mode 100644 index 0000000..fecadf8 --- /dev/null +++ b/translate_schema/ChoiceMapping.py @@ -0,0 +1,42 @@ +import logging + +from xmlschema.validators.simple_types import * +from xmlschema.validators.complex_types import * +from xmlschema.validators.groups import * +from xmlschema.validators.facets import * + +from .TypeMapping import TypeMapping +from .ComplexTypeMapping import ComplexTypeMapping + +log = logging.getLogger() + +class ChoiceMapping(ComplexTypeMapping): + @classmethod + def process_choice(cls, choice: XsdGroup, current_ns : str): + if choice.model != 'choice': + raise Exception(f"Wrong group type: {c.model}") + oneOf = [] + for c in choice.iter_model(): + if not (type(c) is XsdElement): + raise Exception (f"Non-element {c} encountered in choice {choice}") + t = TypeMapping.get_type_from_elem(c, current_ns) + oneOf.append({ + "type" : "object", + "properties" : { + c.local_name : t + }, + "required" : [c.local_name] + }) + return oneOf + + def map(self, xst : BaseXsdType): + log.debug(f"Attempting mapping of {xst} to choice") + j = super().map(xst) + if j is None: + log.debug("Not a complex type, giving up") + return None + content = xst.content + if (content.model != 'choice'): + log.debug("Not a choice, giving up") + return None + return { 'oneOf' : ChoiceMapping.process_choice(content, xst.namespaces[''])} diff --git a/translate_schema/ComplexTypeMapping.py b/translate_schema/ComplexTypeMapping.py new file mode 100644 index 0000000..e181909 --- /dev/null +++ b/translate_schema/ComplexTypeMapping.py @@ -0,0 +1,11 @@ +from xmlschema.validators.complex_types import * + +from .TypeMapping import TypeMapping + +class ComplexTypeMapping(TypeMapping): + def map(self, xst: BaseXsdType): + if not (type(xst) is XsdComplexType): + return None + return { + "type" : "object" + } diff --git a/translate_schema/SequenceMapping.py b/translate_schema/SequenceMapping.py new file mode 100644 index 0000000..9999df8 --- /dev/null +++ b/translate_schema/SequenceMapping.py @@ -0,0 +1,56 @@ +import logging + +from xmlschema.validators.simple_types import * +from xmlschema.validators.complex_types import * +from xmlschema.validators.groups import * +from xmlschema.validators.facets import * + +from .TypeMapping import TypeMapping +from .ChoiceMapping import ChoiceMapping +from .ComplexTypeMapping import ComplexTypeMapping + +log = logging.getLogger() + + +class SequenceMapping(ComplexTypeMapping): + def map(self, xst: BaseXsdType): + log.debug(f"Attempting mapping of {xst} to sequence") + j = super().map(xst) + if j is None: + log.debug("Not a complex type, giving up") + return None + content = xst.content + if (content.model != 'sequence'): + log.debug("Not a sequence, giving up") + return None + mapped_type = { + 'type' : 'object', + 'properties' : {}, + 'required' : [] + } + inner_choice = None + for c in list(content.iter_model()): + log.debug(f"Processing model item {c}") + if type(c) is XsdElement: + mapped_type['properties'][c.local_name] = TypeMapping.get_type_from_elem(c, xst.namespaces['']) + if c.effective_min_occurs == 1: + mapped_type['required'].append(c.local_name) + elif type(c) is XsdGroup: + if inner_choice: + raise Exception (f"Second group '{c.local_name}' encountered in {xst}") + if c.model != "choice": + raise Exception (f"Don't know what to do with inner group {c} in {xst} - not a choice") + inner_choice = ChoiceMapping.process_choice(c, xst.namespaces['']) + elif type(c) is XsdAnyElement: + mapped_type = {} + else: + raise Exception(f"Unknown element type {c}") + if (inner_choice): + return { + 'allOf' : [ + mapped_type, + {'oneOf' : inner_choice} + ] + } + else: + return mapped_type diff --git a/translate_schema/SimpleTypeMapping.py b/translate_schema/SimpleTypeMapping.py new file mode 100644 index 0000000..2e60f9c --- /dev/null +++ b/translate_schema/SimpleTypeMapping.py @@ -0,0 +1,18 @@ +import logging + +from xmlschema.validators.complex_types import * +from xmlschema.validators.simple_types import XsdAtomicRestriction + +from .TypeMapping import TypeMapping + +log = logging.getLogger() + +class SimpleTypeMapping(TypeMapping): + def map(self, xst: BaseXsdType): + log.debug(f"Attempting mapping of {xst} to simple type") + if not (type(xst) is XsdAtomicRestriction): + log.debug("Type is not an XsdAtomicRestriction, giving up") + return None + return { + "$ref" : xst.base_type.name + } \ No newline at end of file diff --git a/translate_schema/TypeMapping.py b/translate_schema/TypeMapping.py new file mode 100644 index 0000000..57fa0ed --- /dev/null +++ b/translate_schema/TypeMapping.py @@ -0,0 +1,69 @@ +import logging +from abc import ABC, abstractmethod + +from xmlschema.validators.simple_types import * +from xmlschema.validators.complex_types import * +from xmlschema.validators.groups import * +from xmlschema.validators.facets import * + +log = logging.getLogger() + +class TypeMapping(ABC): + ns_to_id_map = {} + + XSD_NS = "http://www.w3.org/2001/XMLSchema" + + XSD_TYPE_MAP = { + "string" : { "type" : "string" }, + "normalizedString" : { "type" : "string", "pattern" : "^[^\r\n\t]*$"}, + "dateTime" : { "type" : "string"}, + "token" : { "type" : "string", "pattern" : "^[^\r\n\t]*$"}, + "anyURI" : { "type" : "string" }, + + "integer" : { "type" : "integer"}, + "nonNegativeInteger" : { "type" : "integer", "minimum" : 0}, + + "boolean" : { "type" : "boolean" }, + + "hexBinary" : { "type" : "string", "pattern" : "^([a-fA-F0-9]{2})*$"}, + "base64Binary" : { "type" : "string", "pattern" : "^[-A-Za-z0-9+/]*={0,3}$"}, + + "anyType" : {} + } + + @abstractmethod + def map(self, xst : BaseXsdType): + return None + + @classmethod + def extract_namespace(cls, qname: str): + match = re.search(r'^\{([^\{\}]+)\}(([^\{\}]+))$', qname) + if match is None: + return None + return match.group(1) + + @classmethod + def get_ref_for(cls, xsd_type: XsdType, current_ns : str): + ns = cls.extract_namespace(xsd_type.name) + if ns == current_ns: + return { "$ref" : f"#/$defs/{xsd_type.local_name}" } + else: + mapped_id = cls.ns_to_id_map[ns] + return { "$ref" : f"{mapped_id}#/$defs/{xsd_type.local_name}"} + + @classmethod + def get_type_from_elem(cls, elem: XsdElement, current_ns : str): + ns = cls.extract_namespace(elem.type.name) + if (ns == TypeMapping.XSD_NS): + # this should be an XSD primitive type + return dict(TypeMapping.XSD_TYPE_MAP[elem.type.local_name]) + else: + return cls.get_ref_for(elem.type, current_ns) + + + + + + + + diff --git a/translate_schema/XSDNativeSimpleTypeMapping.py b/translate_schema/XSDNativeSimpleTypeMapping.py new file mode 100644 index 0000000..772ac10 --- /dev/null +++ b/translate_schema/XSDNativeSimpleTypeMapping.py @@ -0,0 +1,72 @@ +import logging + +from xmlschema.validators.simple_types import * +from xmlschema.validators.complex_types import * +from xmlschema.validators.groups import * +from xmlschema.validators.facets import * + +from .TypeMapping import TypeMapping +from .SimpleTypeMapping import SimpleTypeMapping + +log = logging.getLogger() + +class XSDNativeSimpleTypeMapping(SimpleTypeMapping): + + def map(self, xst: BaseXsdType): + log.debug(f"Attempting mapping of {xst} to XSD native type") + j = super().map(xst) + if j is None: + log.debug("Not a simple type, giving up") + return None + + mapped_type = TypeMapping.XSD_TYPE_MAP.get(xst.base_type.local_name) + parent_type = None + + if mapped_type is None: + ns = TypeMapping.extract_namespace(xst.base_type.name) + if ns == XSDNativeSimpleTypeMapping.XSD_NS: + print (xst) + print (xst.base_type) + raise Exception (f"No mapping for xs:{xst.base_type.local_name}") + if len(xst.facets) == 0: + mapped_type = TypeMapping.get_ref_for(xst.base_type, xst.namespaces['']) + else: + parent_type = TypeMapping.get_ref_for(xst.base_type, xst.namespaces['']) + mapped_type = TypeMapping.XSD_TYPE_MAP.get(xst.root_type.local_name) + if mapped_type is None: + raise Exception (f"Could not find mapping for root type xs:{xst.root_type.local_name}") + + mapped_type = dict(mapped_type) + + for k, v in xst.facets.items(): + log.debug(f"Mapping facet {v}") + if type(v) is XsdMaxLengthFacet: + mapped_type['maxLength'] = v.value + continue + if type(v) is XsdMinLengthFacet: + mapped_type['minLength'] = v.value + continue + if type(v) is XsdPatternFacets: + if len(v.regexps) > 1: + raise Exception (f"Multiple patterns given in facet {v} of {xst}") + p = v.regexps[0] + if (not p.startswith('^')) and (not p.endswith('$')): + p = f"^{p}$" + mapped_type['pattern'] = p + continue + if type (v) is XsdMinInclusiveFacet: + mapped_type['minimum'] = v.value + continue + if type (v) is XsdMaxInclusiveFacet: + mapped_type['maximum'] = v.value + continue + if type (v) is XsdMinExclusiveFacet: + mapped_type['exclusiveMinimum'] = v.value + continue + if type (v) is XsdMaxExclusiveFacet: + mapped_type['exclusiveMaximum'] = v.value + continue + raise Exception (f"Unhandled facet {v}") + if parent_type: + return { 'allOf' : [parent_type, mapped_type] } + return mapped_type diff --git a/translate_schema/__init__.py b/translate_schema/__init__.py index cf6b3f8..c1719ca 100644 --- a/translate_schema/__init__.py +++ b/translate_schema/__init__.py @@ -4,7 +4,11 @@ from pathlib import Path from xmlschema import * -from .type_mapping import * +from .TypeMapping import * +from .XSDNativeSimpleTypeMapping import XSDNativeSimpleTypeMapping +from .ChoiceMapping import ChoiceMapping +from .SequenceMapping import SequenceMapping + log = logging.getLogger() diff --git a/translate_schema/type_mapping.py b/translate_schema/type_mapping.py deleted file mode 100644 index a7bf7f6..0000000 --- a/translate_schema/type_mapping.py +++ /dev/null @@ -1,219 +0,0 @@ -from copy import deepcopy -import logging -from abc import ABC, abstractmethod - -from xmlschema.validators.simple_types import * -from xmlschema.validators.complex_types import * -from xmlschema.validators.groups import * -from xmlschema.validators.facets import * - -from .util import * - -log = logging.getLogger() - -class TypeMapping(ABC): - ns_to_id_map = {} - - @abstractmethod - def map(self, xst : BaseXsdType): - return None - - @classmethod - def extract_namespace(cls, qname: str): - match = re.search(r'^\{([^\{\}]+)\}(([^\{\}]+))$', qname) - if match is None: - return None - return match.group(1) - - @classmethod - def get_ref_for(cls, xsd_type: XsdType, current_ns : str): - ns = cls.extract_namespace(xsd_type.name) - if ns == current_ns: - return { "$ref" : f"#/$defs/{xsd_type.local_name}" } - else: - mapped_id = cls.ns_to_id_map[ns] - return { "$ref" : f"{mapped_id}#/$defs/{xsd_type.local_name}"} - - @classmethod - def get_type_from_elem(cls, elem: XsdElement, current_ns : str): - ns = cls.extract_namespace(elem.type.name) - if (ns == "http://www.w3.org/2001/XMLSchema"): - # this should be an XSD primitive type - return dict(XSDNativeSimpleTypeMapping.XSD_TYPE_MAP[elem.type.local_name]) - else: - return cls.get_ref_for(elem.type, current_ns) - -class SimpleTypeMapping(TypeMapping): - def map(self, xst: BaseXsdType): - log.debug(f"Attempting mapping of {xst} to simple type") - if not (type(xst) is XsdAtomicRestriction): - log.debug("Type is not an XsdAtomicRestriction, giving up") - return None - return { - "$ref" : xst.base_type.name - } - -class XSDNativeSimpleTypeMapping(SimpleTypeMapping): - XSD_NS = "http://www.w3.org/2001/XMLSchema" - - XSD_TYPE_MAP = { - "string" : { "type" : "string" }, - "normalizedString" : { "type" : "string", "pattern" : "^[^\r\n\t]*$"}, - "dateTime" : { "type" : "string"}, - "token" : { "type" : "string", "pattern" : "^[^\r\n\t]*$"}, - "anyURI" : { "type" : "string" }, - - "integer" : { "type" : "integer"}, - "nonNegativeInteger" : { "type" : "integer", "minimum" : 0}, - - "boolean" : { "type" : "boolean" }, - - "hexBinary" : { "type" : "string", "pattern" : "^([a-fA-F0-9]{2})*$"}, - "base64Binary" : { "type" : "string", "pattern" : "^[-A-Za-z0-9+/]*={0,3}$"}, - - "anyType" : {} - } - - def map(self, xst: BaseXsdType): - log.debug(f"Attempting mapping of {xst} to XSD native type") - j = super().map(xst) - if j is None: - log.debug("Not a simple type, giving up") - return None - - - mapped_type = XSDNativeSimpleTypeMapping.XSD_TYPE_MAP.get(xst.base_type.local_name) - parent_type = None - - if mapped_type is None: - ns = TypeMapping.extract_namespace(xst.base_type.name) - if ns == XSDNativeSimpleTypeMapping.XSD_NS: - print (xst) - print (xst.base_type) - raise Exception (f"No mapping for xs:{xst.base_type.local_name}") - if len(xst.facets) == 0: - mapped_type = TypeMapping.get_ref_for(xst.base_type, xst.namespaces['']) - else: - parent_type = TypeMapping.get_ref_for(xst.base_type, xst.namespaces['']) - mapped_type = XSDNativeSimpleTypeMapping.XSD_TYPE_MAP.get(xst.root_type.local_name) - if mapped_type is None: - raise Exception (f"Could not find mapping for root type xs:{xst.root_type.local_name}") - - mapped_type = dict(mapped_type) - - for k, v in xst.facets.items(): - log.debug(f"Mapping facet {v}") - if type(v) is XsdMaxLengthFacet: - mapped_type['maxLength'] = v.value - continue - if type(v) is XsdMinLengthFacet: - mapped_type['minLength'] = v.value - continue - if type(v) is XsdPatternFacets: - if len(v.regexps) > 1: - raise Exception (f"Multiple patterns given in facet {v} of {xst}") - p = v.regexps[0] - if (not p.startswith('^')) and (not p.endswith('$')): - p = f"^{p}$" - mapped_type['pattern'] = p - continue - if type (v) is XsdMinInclusiveFacet: - mapped_type['minimum'] = v.value - continue - if type (v) is XsdMaxInclusiveFacet: - mapped_type['maximum'] = v.value - continue - if type (v) is XsdMinExclusiveFacet: - mapped_type['exclusiveMinimum'] = v.value - continue - if type (v) is XsdMaxExclusiveFacet: - mapped_type['exclusiveMaximum'] = v.value - continue - raise Exception (f"Unhandled facet {v}") - if parent_type: - return { 'allOf' : [parent_type, mapped_type] } - return mapped_type - - -class ComplexTypeMapping(TypeMapping): - def map(self, xst: BaseXsdType): - if not (type(xst) is XsdComplexType): - return None - return { - "type" : "object" - } - - -class ChoiceMapping(ComplexTypeMapping): - @classmethod - def process_choice(cls, choice: XsdGroup, current_ns : str): - if choice.model != 'choice': - raise Exception(f"Wrong group type: {c.model}") - oneOf = [] - for c in choice.iter_model(): - if not (type(c) is XsdElement): - raise Exception (f"Non-element {c} encountered in choice {choice}") - t = TypeMapping.get_type_from_elem(c, current_ns) - oneOf.append({ - "type" : "object", - "properties" : { - c.local_name : t - }, - "required" : [c.local_name] - }) - return oneOf - - def map(self, xst : BaseXsdType): - log.debug(f"Attempting mapping of {xst} to choice") - j = super().map(xst) - if j is None: - log.debug("Not a complex type, giving up") - return None - content = xst.content - if (content.model != 'choice'): - log.debug("Not a choice, giving up") - return None - return { 'oneOf' : ChoiceMapping.process_choice(content, xst.namespaces[''])} - -class SequenceMapping(ComplexTypeMapping): - def map(self, xst: BaseXsdType): - log.debug(f"Attempting mapping of {xst} to sequence") - j = super().map(xst) - if j is None: - log.debug("Not a complex type, giving up") - return None - content = xst.content - if (content.model != 'sequence'): - log.debug("Not a sequence, giving up") - return None - mapped_type = { - 'type' : 'object', - 'properties' : {}, - 'required' : [] - } - inner_choice = None - for c in list(content.iter_model()): - log.debug(f"Processing model item {c}") - if type(c) is XsdElement: - mapped_type['properties'][c.local_name] = TypeMapping.get_type_from_elem(c, xst.namespaces['']) - if c.effective_min_occurs == 1: - mapped_type['required'].append(c.local_name) - elif type(c) is XsdGroup: - if inner_choice: - raise Exception (f"Second group '{c.local_name}' encountered in {xst}") - if c.model != "choice": - raise Exception (f"Don't know what to do with inner group {c} in {xst} - not a choice") - inner_choice = ChoiceMapping.process_choice(c, xst.namespaces['']) - elif type(c) is XsdAnyElement: - mapped_type = {} - else: - raise Exception(f"Unknown element type {c}") - if (inner_choice): - return { - 'allOf' : [ - mapped_type, - {'oneOf' : inner_choice} - ] - } - else: - return mapped_type -- GitLab From 4a558c8995c6aa71589a7aafde12bbed5b649711 Mon Sep 17 00:00:00 2001 From: mark Date: Mon, 13 Jun 2022 12:44:20 +0100 Subject: [PATCH 06/20] Adding arrays --- 120.json | 14 ++++-- json/authorisation.json | 25 +++++++--- json/common.json | 5 +- json/core.json | 61 +++++++++++++++++------ json/delivery.json | 5 ++ json/document.json | 15 +++++- json/notification.json | 5 ++ json/task.json | 75 +++++++++++++++++++++-------- translate.py | 23 +++++++-- translate_schema/SequenceMapping.py | 30 ++++++++++-- translate_schema/__init__.py | 3 ++ translate_schema/util.py | 4 -- 12 files changed, 206 insertions(+), 59 deletions(-) delete mode 100644 translate_schema/util.py diff --git a/120.json b/120.json index 9a4e178..56e1266 100644 --- a/120.json +++ b/120.json @@ -19,12 +19,20 @@ "Payload" : { "ResponsePayload" : { "ActionResponses" : { - "ActionResponse" : { + "ActionResponse" : [{ "ActionIdentifier" : 0, "CREATEResponse" : { - "Identifier" : "f25dec16-927c-433b-959c-1886182cac58" + "Identifier" : "f25dec16-927c-433b-959c-1886182cac58", + "HI1Object" : { + "xsiType" : "{http://uri.etsi.org/03120/common/2020/09/Task}LITaskObject", + "ObjectIdentifier" : "d980e335-d17a-471f-bb40-cddf4457fd6b", + "Reference" : "LIID", + "TargetIdentifier" : { + + } + } } - } + }] } } } diff --git a/json/authorisation.json b/json/authorisation.json index 8b1facb..2b70572 100644 --- a/json/authorisation.json +++ b/json/authorisation.json @@ -4,6 +4,10 @@ "AuthorisationObject": { "type": "object", "properties": { + "xsiType": { + "type": "string", + "enum": "{http://uri.etsi.org/03120/common/2020/09/Authorisation}AuthorisationObject" + }, "ObjectIdentifier": { "$ref": "core.json#/$defs/ObjectIdentifier" }, @@ -60,7 +64,10 @@ "$ref": "etsi103280.json#/$defs/QualifiedDateTime" }, "AuthorisationApprovalDetails": { - "$ref": "common.json#/$defs/ApprovalDetails" + "type": "array", + "items": { + "$ref": "common.json#/$defs/ApprovalDetails" + } }, "AuthorisationInvalidReason": { "$ref": "core.json#/$defs/ActionUnsuccesfulInformation" @@ -76,6 +83,7 @@ } }, "required": [ + "xsiType", "ObjectIdentifier" ] }, @@ -83,7 +91,10 @@ "type": "object", "properties": { "AuthorisationFlag": { - "$ref": "common.json#/$defs/DictionaryEntry" + "type": "array", + "items": { + "$ref": "common.json#/$defs/DictionaryEntry" + } } }, "required": [] @@ -104,12 +115,14 @@ "type": "object", "properties": { "CSPID": { - "$ref": "core.json#/$defs/EndpointID" + "type": "array", + "items": { + "$ref": "core.json#/$defs/EndpointID" + }, + "minContains": 1 } }, - "required": [ - "CSPID" - ] + "required": [] }, "NationalAuthorisationParameters": { "type": "object", diff --git a/json/common.json b/json/common.json index 00a7c13..0d899af 100644 --- a/json/common.json +++ b/json/common.json @@ -74,7 +74,10 @@ "$ref": "#/$defs/ApproverIdentity" }, "ApproverContactDetails": { - "$ref": "#/$defs/ApproverContactDetails" + "type": "array", + "items": { + "$ref": "#/$defs/ApproverContactDetails" + } } }, "required": [] diff --git a/json/core.json b/json/core.json index 67e1ca3..1f41359 100644 --- a/json/core.json +++ b/json/core.json @@ -121,12 +121,14 @@ "type": "object", "properties": { "ActionRequest": { - "$ref": "#/$defs/ActionRequest" + "type": "array", + "items": { + "$ref": "#/$defs/ActionRequest" + }, + "minContains": 1 } }, - "required": [ - "ActionRequest" - ] + "required": [] }, "ResponsePayload": { "oneOf": [ @@ -158,12 +160,14 @@ "type": "object", "properties": { "ActionResponse": { - "$ref": "#/$defs/ActionResponse" + "type": "array", + "items": { + "$ref": "#/$defs/ActionResponse" + }, + "minContains": 1 } }, - "required": [ - "ActionResponse" - ] + "required": [] }, "ActionRequest": { "allOf": [ @@ -341,7 +345,7 @@ "type": "object", "properties": { "HI1Object": { - "$ref": "#/$defs/HI1Object" + "$ref": "#/$defs/OneOfHI1Object" } }, "required": [ @@ -352,7 +356,7 @@ "type": "object", "properties": { "HI1Object": { - "$ref": "#/$defs/HI1Object" + "$ref": "#/$defs/OneOfHI1Object" } }, "required": [ @@ -366,7 +370,7 @@ "$ref": "#/$defs/ObjectIdentifier" }, "HI1Object": { - "$ref": "#/$defs/HI1Object" + "$ref": "#/$defs/OneOfHI1Object" } }, "required": [ @@ -377,7 +381,7 @@ "type": "object", "properties": { "HI1Object": { - "$ref": "#/$defs/HI1Object" + "$ref": "#/$defs/OneOfHI1Object" } }, "required": [ @@ -391,7 +395,7 @@ "$ref": "#/$defs/ObjectIdentifier" }, "HI1Object": { - "$ref": "#/$defs/HI1Object" + "$ref": "#/$defs/OneOfHI1Object" } }, "required": [ @@ -414,7 +418,10 @@ "type": "object", "properties": { "ListResponseRecord": { - "$ref": "#/$defs/ListResponseRecord" + "type": "array", + "items": { + "$ref": "#/$defs/ListResponseRecord" + } } }, "required": [] @@ -474,7 +481,7 @@ "$ref": "#/$defs/ObjectIdentifier" }, "HI1Object": { - "$ref": "#/$defs/HI1Object" + "$ref": "#/$defs/OneOfHI1Object" } }, "required": [ @@ -530,7 +537,10 @@ "type": "object", "properties": { "AssociatedObject": { - "$ref": "#/$defs/ObjectIdentifier" + "type": "array", + "items": { + "$ref": "#/$defs/ObjectIdentifier" + } } }, "required": [] @@ -545,6 +555,25 @@ "required": [ "CountryCode" ] + }, + "OneOfHI1Object": { + "oneOf": [ + { + "$ref": "authorisation.json#/$defs/AuthorisationObject" + }, + { + "$ref": "task.json#/$defs/LITaskObject" + }, + { + "$ref": "task.json#/$defs/LDTaskObject" + }, + { + "$ref": "document.json#/$defs/DocumentObject" + }, + { + "$ref": "notification.json#/$defs/NotificationObject" + } + ] } }, "$ref": "#/$defs/HI1Message" diff --git a/json/delivery.json b/json/delivery.json index 7aef09a..f82e84e 100644 --- a/json/delivery.json +++ b/json/delivery.json @@ -4,6 +4,10 @@ "DeliveryObject": { "type": "object", "properties": { + "xsiType": { + "type": "string", + "enum": "{http://uri.etsi.org/03120/common/2019/10/Delivery}DeliveryObject" + }, "ObjectIdentifier": { "$ref": "core.json#/$defs/ObjectIdentifier" }, @@ -50,6 +54,7 @@ } }, "required": [ + "xsiType", "ObjectIdentifier" ] }, diff --git a/json/document.json b/json/document.json index 6f6f493..f255164 100644 --- a/json/document.json +++ b/json/document.json @@ -4,6 +4,10 @@ "DocumentObject": { "type": "object", "properties": { + "xsiType": { + "type": "string", + "enum": "{http://uri.etsi.org/03120/common/2020/09/Document}DocumentObject" + }, "ObjectIdentifier": { "$ref": "core.json#/$defs/ObjectIdentifier" }, @@ -54,7 +58,10 @@ "$ref": "#/$defs/DocumentBody" }, "DocumentSignature": { - "$ref": "common.json#/$defs/ApprovalDetails" + "type": "array", + "items": { + "$ref": "common.json#/$defs/ApprovalDetails" + } }, "DocumentInvalidReason": { "$ref": "core.json#/$defs/ActionUnsuccesfulInformation" @@ -64,6 +71,7 @@ } }, "required": [ + "xsiType", "ObjectIdentifier" ] }, @@ -83,7 +91,10 @@ "type": "object", "properties": { "DocumentProperty": { - "$ref": "#/$defs/DocumentProperty" + "type": "array", + "items": { + "$ref": "#/$defs/DocumentProperty" + } } }, "required": [] diff --git a/json/notification.json b/json/notification.json index e9805f5..41f2dd7 100644 --- a/json/notification.json +++ b/json/notification.json @@ -4,6 +4,10 @@ "NotificationObject": { "type": "object", "properties": { + "xsiType": { + "type": "string", + "enum": "{http://uri.etsi.org/03120/common/2016/02/Notification}NotificationObject" + }, "ObjectIdentifier": { "$ref": "core.json#/$defs/ObjectIdentifier" }, @@ -46,6 +50,7 @@ } }, "required": [ + "xsiType", "ObjectIdentifier" ] }, diff --git a/json/task.json b/json/task.json index f945d95..debdece 100644 --- a/json/task.json +++ b/json/task.json @@ -4,6 +4,10 @@ "LITaskObject": { "type": "object", "properties": { + "xsiType": { + "type": "string", + "enum": "{http://uri.etsi.org/03120/common/2020/09/Task}LITaskObject" + }, "ObjectIdentifier": { "$ref": "core.json#/$defs/ObjectIdentifier" }, @@ -51,7 +55,10 @@ "$ref": "#/$defs/TaskDeliveryDetails" }, "ApprovalDetails": { - "$ref": "common.json#/$defs/ApprovalDetails" + "type": "array", + "items": { + "$ref": "common.json#/$defs/ApprovalDetails" + } }, "CSPID": { "$ref": "core.json#/$defs/EndpointID" @@ -70,6 +77,7 @@ } }, "required": [ + "xsiType", "ObjectIdentifier" ] }, @@ -110,12 +118,14 @@ "type": "object", "properties": { "TargetIdentifierValue": { - "$ref": "#/$defs/TargetIdentifierValue" + "type": "array", + "items": { + "$ref": "#/$defs/TargetIdentifierValue" + }, + "minContains": 1 } }, - "required": [ - "TargetIdentifierValue" - ] + "required": [] }, "TargetIdentifierValue": { "type": "object", @@ -151,12 +161,14 @@ "type": "object", "properties": { "DeliveryDestination": { - "$ref": "#/$defs/DeliveryDestination" + "type": "array", + "items": { + "$ref": "#/$defs/DeliveryDestination" + }, + "minContains": 1 } }, - "required": [ - "DeliveryDestination" - ] + "required": [] }, "DeliveryDestination": { "type": "object", @@ -289,7 +301,10 @@ "type": "object", "properties": { "TaskFlag": { - "$ref": "common.json#/$defs/DictionaryEntry" + "type": "array", + "items": { + "$ref": "common.json#/$defs/DictionaryEntry" + } } }, "required": [] @@ -330,6 +345,10 @@ "LDTaskObject": { "type": "object", "properties": { + "xsiType": { + "type": "string", + "enum": "{http://uri.etsi.org/03120/common/2020/09/Task}LDTaskObject" + }, "ObjectIdentifier": { "$ref": "core.json#/$defs/ObjectIdentifier" }, @@ -374,7 +393,10 @@ "$ref": "#/$defs/LDDeliveryDetails" }, "ApprovalDetails": { - "$ref": "common.json#/$defs/ApprovalDetails" + "type": "array", + "items": { + "$ref": "common.json#/$defs/ApprovalDetails" + } }, "CSPID": { "$ref": "core.json#/$defs/EndpointID" @@ -390,6 +412,7 @@ } }, "required": [ + "xsiType", "ObjectIdentifier" ] }, @@ -409,7 +432,10 @@ "$ref": "etsi103280.json#/$defs/QualifiedDateTime" }, "ObservedTimes": { - "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + "type": "array", + "items": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + } }, "RequestValues": { "$ref": "#/$defs/RequestValues" @@ -421,12 +447,14 @@ "type": "object", "properties": { "RequestValue": { - "$ref": "#/$defs/RequestValue" + "type": "array", + "items": { + "$ref": "#/$defs/RequestValue" + }, + "minContains": 1 } }, - "required": [ - "RequestValue" - ] + "required": [] }, "RequestValue": { "type": "object", @@ -447,12 +475,14 @@ "type": "object", "properties": { "LDDeliveryDestination": { - "$ref": "#/$defs/LDDeliveryDestination" + "type": "array", + "items": { + "$ref": "#/$defs/LDDeliveryDestination" + }, + "minContains": 1 } }, - "required": [ - "LDDeliveryDestination" - ] + "required": [] }, "LDDeliveryDestination": { "type": "object", @@ -479,7 +509,10 @@ "type": "object", "properties": { "LDTaskFlag": { - "$ref": "common.json#/$defs/DictionaryEntry" + "type": "array", + "items": { + "$ref": "common.json#/$defs/DictionaryEntry" + } } }, "required": [] diff --git a/translate.py b/translate.py index 35a1a3b..a08854c 100644 --- a/translate.py +++ b/translate.py @@ -10,7 +10,7 @@ from translate_schema import * import jsonschema -logging.basicConfig(level = logging.DEBUG) +logging.basicConfig(level = logging.INFO) def build_schema_locations (paths): schema_locations = [] @@ -65,9 +65,26 @@ if __name__ == "__main__": if ns_to_id_map[schema_tuple[0]] == 'core.json': js['$defs']['HI1Message']['properties'].pop('Signature') js_path = output_path / ns_to_id_map[schema_tuple[0]] + + if "Core" in schema_tuple[1]: + js["$defs"]['OneOfHI1Object'] = { + 'oneOf' : [ + {'$ref' : 'authorisation.json#/$defs/AuthorisationObject'}, + {'$ref' : 'task.json#/$defs/LITaskObject'}, + {'$ref' : 'task.json#/$defs/LDTaskObject'}, + {'$ref' : 'document.json#/$defs/DocumentObject'}, + {'$ref' : 'notification.json#/$defs/NotificationObject'}, + ] + } + + json_string = json.dumps(js, indent=2) + + if "Core" in schema_tuple[1]: + json_string = json_string.replace('"$ref": "#/$defs/HI1Object"', '"$ref": "#/$defs/OneOfHI1Object"') + with open(str(js_path), 'w') as f: - f.write(json.dumps(js, indent=2)) - json_schemas[js['$id']] = js + f.write(json_string) + json_schemas[js['$id']] = json.loads(json_string) else: json_schemas = {} json_path = Path('json/') diff --git a/translate_schema/SequenceMapping.py b/translate_schema/SequenceMapping.py index 9999df8..bd3bb79 100644 --- a/translate_schema/SequenceMapping.py +++ b/translate_schema/SequenceMapping.py @@ -28,13 +28,37 @@ class SequenceMapping(ComplexTypeMapping): 'properties' : {}, 'required' : [] } + + # Not going to try and do all of this automatically for now + # Only make insert the xsiType parameter + if (xst.base_type): + # mapped_type['__DESCENDENT_OF__'] = TypeMapping.get_ref_for(xst.base_type, xst.namespaces['']) + mapped_type['properties']['xsiType'] = { + "type" : "string", + "enum" : xst.name + } + mapped_type['required'].append('xsiType') + # if xst.abstract: + # mapped_type['__ABSTRACT__'] = True + # pass + inner_choice = None for c in list(content.iter_model()): log.debug(f"Processing model item {c}") if type(c) is XsdElement: - mapped_type['properties'][c.local_name] = TypeMapping.get_type_from_elem(c, xst.namespaces['']) - if c.effective_min_occurs == 1: - mapped_type['required'].append(c.local_name) + if c.effective_max_occurs != 1: + mapped_type['properties'][c.local_name] = { + "type" : "array", + "items" : TypeMapping.get_type_from_elem(c, xst.namespaces['']) + } + if c.effective_max_occurs: + mapped_type['properties'][c.local_name]['maxContains'] = c.effective_max_occurs + if c.effective_min_occurs > 0: + mapped_type['properties'][c.local_name]['minContains'] = c.effective_min_occurs + else: + mapped_type['properties'][c.local_name] = TypeMapping.get_type_from_elem(c, xst.namespaces['']) + if c.effective_min_occurs == 1: + mapped_type['required'].append(c.local_name) elif type(c) is XsdGroup: if inner_choice: raise Exception (f"Second group '{c.local_name}' encountered in {xst}") diff --git a/translate_schema/__init__.py b/translate_schema/__init__.py index c1719ca..b56a382 100644 --- a/translate_schema/__init__.py +++ b/translate_schema/__init__.py @@ -42,6 +42,7 @@ def translate_schema (schema_path: str, ns_to_id_map: dict, schema_locations = [ elif len(elementList) > 1: js['oneOf'] = elementList + descendent_types = {} for type_name, xsd_type in xs.types.items(): logging.info(f"Processing {type_name} : {xsd_type}") @@ -57,4 +58,6 @@ def translate_schema (schema_path: str, ns_to_id_map: dict, schema_locations = [ raise Exception(f"Unmapped type {type_name} ({xsd_type})") js["$defs"][xsd_type.local_name] = j logging.debug (f"Mapped {type_name} to {j}") + + print (descendent_types) return js \ No newline at end of file diff --git a/translate_schema/util.py b/translate_schema/util.py deleted file mode 100644 index f7f67b3..0000000 --- a/translate_schema/util.py +++ /dev/null @@ -1,4 +0,0 @@ -import re - -from xmlschema import * - -- GitLab From 5337a2cc9f288c66df25f9edea159e0811b4e722 Mon Sep 17 00:00:00 2001 From: mark Date: Mon, 13 Jun 2022 13:56:33 +0100 Subject: [PATCH 07/20] Fixing mxxContains -> mxxItems --- 120.json | 10 +++++++++- json/authorisation.json | 2 +- json/core.json | 4 ++-- json/task.json | 8 ++++---- translate_schema/SequenceMapping.py | 4 ++-- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/120.json b/120.json index 56e1266..f0e1df4 100644 --- a/120.json +++ b/120.json @@ -28,7 +28,15 @@ "ObjectIdentifier" : "d980e335-d17a-471f-bb40-cddf4457fd6b", "Reference" : "LIID", "TargetIdentifier" : { - + "TargetIdentifierValues" : { + "TargetIdentifierValue" : [ { + "FormatType" : { + "FormatOwner" : "ETSI", + "FormatName" : "InternationalE164" + }, + "Value" : "447700900123" + } ] + } } } } diff --git a/json/authorisation.json b/json/authorisation.json index 2b70572..e8b4a52 100644 --- a/json/authorisation.json +++ b/json/authorisation.json @@ -119,7 +119,7 @@ "items": { "$ref": "core.json#/$defs/EndpointID" }, - "minContains": 1 + "minItems": 1 } }, "required": [] diff --git a/json/core.json b/json/core.json index 1f41359..d87aac2 100644 --- a/json/core.json +++ b/json/core.json @@ -125,7 +125,7 @@ "items": { "$ref": "#/$defs/ActionRequest" }, - "minContains": 1 + "minItems": 1 } }, "required": [] @@ -164,7 +164,7 @@ "items": { "$ref": "#/$defs/ActionResponse" }, - "minContains": 1 + "minItems": 1 } }, "required": [] diff --git a/json/task.json b/json/task.json index debdece..1de702a 100644 --- a/json/task.json +++ b/json/task.json @@ -122,7 +122,7 @@ "items": { "$ref": "#/$defs/TargetIdentifierValue" }, - "minContains": 1 + "minItems": 1 } }, "required": [] @@ -165,7 +165,7 @@ "items": { "$ref": "#/$defs/DeliveryDestination" }, - "minContains": 1 + "minItems": 1 } }, "required": [] @@ -451,7 +451,7 @@ "items": { "$ref": "#/$defs/RequestValue" }, - "minContains": 1 + "minItems": 1 } }, "required": [] @@ -479,7 +479,7 @@ "items": { "$ref": "#/$defs/LDDeliveryDestination" }, - "minContains": 1 + "minItems": 1 } }, "required": [] diff --git a/translate_schema/SequenceMapping.py b/translate_schema/SequenceMapping.py index bd3bb79..6bb4ca3 100644 --- a/translate_schema/SequenceMapping.py +++ b/translate_schema/SequenceMapping.py @@ -52,9 +52,9 @@ class SequenceMapping(ComplexTypeMapping): "items" : TypeMapping.get_type_from_elem(c, xst.namespaces['']) } if c.effective_max_occurs: - mapped_type['properties'][c.local_name]['maxContains'] = c.effective_max_occurs + mapped_type['properties'][c.local_name]['maxItems'] = c.effective_max_occurs if c.effective_min_occurs > 0: - mapped_type['properties'][c.local_name]['minContains'] = c.effective_min_occurs + mapped_type['properties'][c.local_name]['minItems'] = c.effective_min_occurs else: mapped_type['properties'][c.local_name] = TypeMapping.get_type_from_elem(c, xst.namespaces['']) if c.effective_min_occurs == 1: -- GitLab From 510c5b280a3f4b745cff5c9d804252d99f7a0ceb Mon Sep 17 00:00:00 2001 From: mark Date: Wed, 15 Jun 2022 16:30:21 +0100 Subject: [PATCH 08/20] Moving files --- 120.json => translation/120.json | 0 README.md => translation/README.md | 0 common.json => translation/common.json | 0 core.json => translation/core.json | 0 etsi103280.json => translation/etsi103280.json | 0 test.py => translation/test.py | 0 test_doc.json => translation/test_doc.json | 0 test_json.py => translation/test_json.py | 0 test_schema.json => translation/test_schema.json | 0 {translate_schema => translation/translate}/ChoiceMapping.py | 0 .../translate}/ComplexTypeMapping.py | 0 {translate_schema => translation/translate}/SequenceMapping.py | 0 .../translate}/SimpleTypeMapping.py | 0 {translate_schema => translation/translate}/TypeMapping.py | 0 .../translate}/XSDNativeSimpleTypeMapping.py | 0 {translate_schema => translation/translate}/__init__.py | 0 translate.py => translation/translate_120.py | 2 +- 17 files changed, 1 insertion(+), 1 deletion(-) rename 120.json => translation/120.json (100%) rename README.md => translation/README.md (100%) rename common.json => translation/common.json (100%) rename core.json => translation/core.json (100%) rename etsi103280.json => translation/etsi103280.json (100%) rename test.py => translation/test.py (100%) rename test_doc.json => translation/test_doc.json (100%) rename test_json.py => translation/test_json.py (100%) rename test_schema.json => translation/test_schema.json (100%) rename {translate_schema => translation/translate}/ChoiceMapping.py (100%) rename {translate_schema => translation/translate}/ComplexTypeMapping.py (100%) rename {translate_schema => translation/translate}/SequenceMapping.py (100%) rename {translate_schema => translation/translate}/SimpleTypeMapping.py (100%) rename {translate_schema => translation/translate}/TypeMapping.py (100%) rename {translate_schema => translation/translate}/XSDNativeSimpleTypeMapping.py (100%) rename {translate_schema => translation/translate}/__init__.py (100%) rename translate.py => translation/translate_120.py (99%) diff --git a/120.json b/translation/120.json similarity index 100% rename from 120.json rename to translation/120.json diff --git a/README.md b/translation/README.md similarity index 100% rename from README.md rename to translation/README.md diff --git a/common.json b/translation/common.json similarity index 100% rename from common.json rename to translation/common.json diff --git a/core.json b/translation/core.json similarity index 100% rename from core.json rename to translation/core.json diff --git a/etsi103280.json b/translation/etsi103280.json similarity index 100% rename from etsi103280.json rename to translation/etsi103280.json diff --git a/test.py b/translation/test.py similarity index 100% rename from test.py rename to translation/test.py diff --git a/test_doc.json b/translation/test_doc.json similarity index 100% rename from test_doc.json rename to translation/test_doc.json diff --git a/test_json.py b/translation/test_json.py similarity index 100% rename from test_json.py rename to translation/test_json.py diff --git a/test_schema.json b/translation/test_schema.json similarity index 100% rename from test_schema.json rename to translation/test_schema.json diff --git a/translate_schema/ChoiceMapping.py b/translation/translate/ChoiceMapping.py similarity index 100% rename from translate_schema/ChoiceMapping.py rename to translation/translate/ChoiceMapping.py diff --git a/translate_schema/ComplexTypeMapping.py b/translation/translate/ComplexTypeMapping.py similarity index 100% rename from translate_schema/ComplexTypeMapping.py rename to translation/translate/ComplexTypeMapping.py diff --git a/translate_schema/SequenceMapping.py b/translation/translate/SequenceMapping.py similarity index 100% rename from translate_schema/SequenceMapping.py rename to translation/translate/SequenceMapping.py diff --git a/translate_schema/SimpleTypeMapping.py b/translation/translate/SimpleTypeMapping.py similarity index 100% rename from translate_schema/SimpleTypeMapping.py rename to translation/translate/SimpleTypeMapping.py diff --git a/translate_schema/TypeMapping.py b/translation/translate/TypeMapping.py similarity index 100% rename from translate_schema/TypeMapping.py rename to translation/translate/TypeMapping.py diff --git a/translate_schema/XSDNativeSimpleTypeMapping.py b/translation/translate/XSDNativeSimpleTypeMapping.py similarity index 100% rename from translate_schema/XSDNativeSimpleTypeMapping.py rename to translation/translate/XSDNativeSimpleTypeMapping.py diff --git a/translate_schema/__init__.py b/translation/translate/__init__.py similarity index 100% rename from translate_schema/__init__.py rename to translation/translate/__init__.py diff --git a/translate.py b/translation/translate_120.py similarity index 99% rename from translate.py rename to translation/translate_120.py index a08854c..9f74378 100644 --- a/translate.py +++ b/translation/translate_120.py @@ -6,7 +6,7 @@ import sys from xmlschema import * -from translate_schema import * +from translate import * import jsonschema -- GitLab From 0fc32c7c9a58cf55e6d82eacc2a30d45c5dfcefe Mon Sep 17 00:00:00 2001 From: mark Date: Wed, 15 Jun 2022 16:32:30 +0100 Subject: [PATCH 09/20] Adding schema (translation code will be left in cr/103120/025 for now) --- 103280/TS_103_280.json | 384 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 384 insertions(+) create mode 100644 103280/TS_103_280.json diff --git a/103280/TS_103_280.json b/103280/TS_103_280.json new file mode 100644 index 0000000..09457bd --- /dev/null +++ b/103280/TS_103_280.json @@ -0,0 +1,384 @@ +{ + "$id": "etsi103280.json", + "$defs": { + "ShortString": { + "type": "string", + "maxLength": 255 + }, + "LongString": { + "type": "string", + "maxLength": 65535 + }, + "LIID": { + "type": "string", + "pattern": "^([!-~]{1,25})|([0-9a-f]{26,50})$" + }, + "UTCDateTime": { + "type": "string", + "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$" + }, + "UTCMicrosecondDateTime": { + "type": "string", + "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{6}Z$" + }, + "QualifiedDateTime": { + "type": "string", + "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(Z|[+-][0-9]{2}:[0-9]{2})$" + }, + "QualifiedMicrosecondDateTime": { + "type": "string", + "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{6}(Z|[+-][0-9]{2}:[0-9]{2})$" + }, + "InternationalE164": { + "type": "string", + "pattern": "^[0-9]{1,15}$" + }, + "IMSI": { + "type": "string", + "pattern": "^[0-9]{6,15}$" + }, + "IMEI": { + "type": "string", + "pattern": "^[0-9]{14}$" + }, + "IMEICheckDigit": { + "type": "string", + "pattern": "^[0-9]{15}$" + }, + "IMEISV": { + "type": "string", + "pattern": "^[0-9]{16}$" + }, + "IPv4Address": { + "type": "string", + "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])$" + }, + "IPv4CIDR": { + "type": "string", + "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])/([1-2]?[0-9]|3[0-2])$" + }, + "IPv6Address": { + "type": "string", + "pattern": "^([0-9a-f]{4}:){7}([0-9a-f]{4})$" + }, + "IPv6CIDR": { + "type": "string", + "pattern": "^([0-9a-f]{4}:){7}([0-9a-f]{4})/(([1-9][0-9]?)|(1[0-1][0-9])|(12[0-8]))$" + }, + "TCPPort": { + "type": "integer", + "exclusiveMinimum": 1, + "maximum": 65535 + }, + "UDPPort": { + "type": "integer", + "minimum": 0, + "maximum": 65535 + }, + "MACAddress": { + "type": "string", + "pattern": "^([a-f0-9]{2}:){5}[a-f0-9]{2}$" + }, + "EmailAddress": { + "allOf": [ + { + "$ref": "#/$defs/ShortString" + }, + { + "type": "string", + "pattern": "^[a-zA-Z0-9\\.!#$%&'\\*\\+\\\\/=\\?\\^_`\\{\\|\\}~\\-]+@[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$" + } + ] + }, + "UUID": { + "type": "string", + "pattern": "^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$" + }, + "ISOCountryCode": { + "type": "string", + "pattern": "^[A-Z]{2}$" + }, + "SIPURI": { + "type": "string", + "pattern": "^sips?:[a-zA-Z0-9!#$&-;=?-\\[\\]_~%]+$" + }, + "TELURI": { + "type": "string", + "pattern": "^tel:[a-zA-Z0-9!#$&-;=?-\\[\\]_~%]+$" + }, + "WGS84LatitudeDecimal": { + "type": "string", + "pattern": "^[NS][0-9]{2}\\.[0-9]{6}$" + }, + "WGS84LongitudeDecimal": { + "type": "string", + "pattern": "^[EW][0-9]{3}\\.[0-9]{6}$" + }, + "WGS84LatitudeAngular": { + "type": "string", + "pattern": "^[NS][0-9]{6}\\.[0-9]{2}$" + }, + "WGS84LongitudeAngular": { + "type": "string", + "pattern": "^[EW][0-9]{7}\\.[0-9]{2}$" + }, + "SUPIIMSI": { + "$ref": "#/$defs/IMSI" + }, + "SUPINAI": { + "$ref": "#/$defs/NAI" + }, + "SUCI": { + "type": "string", + "pattern": "^([a-fA-F0-9]{2})*$" + }, + "PEIIMEI": { + "$ref": "#/$defs/IMEI" + }, + "PEIIMEICheckDigit": { + "$ref": "#/$defs/IMEICheckDigit" + }, + "PEIIMEISV": { + "$ref": "#/$defs/IMEISV" + }, + "GPSIMSISDN": { + "type": "string", + "pattern": "^[0-9]{1,15}$" + }, + "GPSINAI": { + "$ref": "#/$defs/NAI" + }, + "NAI": { + "type": "string" + }, + "LDID": { + "type": "string", + "pattern": "^([A-Z]{2}-.+-.+)$" + }, + "InternationalizedEmailAddress": { + "allOf": [ + { + "$ref": "#/$defs/ShortString" + }, + { + "type": "string", + "pattern": "^.+@.+$" + } + ] + }, + "EUI64": { + "type": "string", + "pattern": "^([a-f0-9]{2}:){7}[a-f0-9]{2}$" + }, + "CGI": { + "type": "string", + "pattern": "^[0-9]{3}-[0-9]{2,3}-[a-f0-9]{4}-[a-f0-9]{4}$" + }, + "ECGI": { + "type": "string", + "pattern": "^[0-9]{3}-[0-9]{2,3}-[a-f0-9]{7}$" + }, + "NCGI": { + "type": "string", + "pattern": "^[0-9]{3}-[0-9]{2,3}-[a-f0-9]{9}$" + }, + "ICCID": { + "type": "string", + "pattern": "^[0-9]{19,20}$" + }, + "IPAddress": { + "oneOf": [ + { + "type": "object", + "properties": { + "IPv4Address": { + "$ref": "#/$defs/IPv4Address" + } + }, + "required": [ + "IPv4Address" + ] + }, + { + "type": "object", + "properties": { + "IPv6Address": { + "$ref": "#/$defs/IPv6Address" + } + }, + "required": [ + "IPv6Address" + ] + } + ] + }, + "IPCIDR": { + "oneOf": [ + { + "type": "object", + "properties": { + "IPv4CIDR": { + "$ref": "#/$defs/IPv4CIDR" + } + }, + "required": [ + "IPv4CIDR" + ] + }, + { + "type": "object", + "properties": { + "IPv6CIDR": { + "$ref": "#/$defs/IPv6CIDR" + } + }, + "required": [ + "IPv6CIDR" + ] + } + ] + }, + "TCPPortRange": { + "type": "object", + "properties": { + "start": { + "$ref": "#/$defs/TCPPort" + }, + "end": { + "$ref": "#/$defs/TCPPort" + } + }, + "required": [ + "start", + "end" + ] + }, + "UDPPortRange": { + "type": "object", + "properties": { + "start": { + "$ref": "#/$defs/UDPPort" + }, + "end": { + "$ref": "#/$defs/UDPPort" + } + }, + "required": [ + "start", + "end" + ] + }, + "Port": { + "oneOf": [ + { + "type": "object", + "properties": { + "TCPPort": { + "$ref": "#/$defs/TCPPort" + } + }, + "required": [ + "TCPPort" + ] + }, + { + "type": "object", + "properties": { + "UDPPort": { + "$ref": "#/$defs/UDPPort" + } + }, + "required": [ + "UDPPort" + ] + } + ] + }, + "PortRange": { + "oneOf": [ + { + "type": "object", + "properties": { + "TCPPortRange": { + "$ref": "#/$defs/TCPPortRange" + } + }, + "required": [ + "TCPPortRange" + ] + }, + { + "type": "object", + "properties": { + "UDPPortRange": { + "$ref": "#/$defs/UDPPortRange" + } + }, + "required": [ + "UDPPortRange" + ] + } + ] + }, + "IPAddressPort": { + "type": "object", + "properties": { + "address": { + "$ref": "#/$defs/IPAddress" + }, + "port": { + "$ref": "#/$defs/Port" + } + }, + "required": [ + "address", + "port" + ] + }, + "IPAddressPortRange": { + "type": "object", + "properties": { + "address": { + "$ref": "#/$defs/IPAddress" + }, + "portRange": { + "$ref": "#/$defs/PortRange" + } + }, + "required": [ + "address", + "portRange" + ] + }, + "WGS84CoordinateDecimal": { + "type": "object", + "properties": { + "latitude": { + "$ref": "#/$defs/WGS84LatitudeDecimal" + }, + "longitude": { + "$ref": "#/$defs/WGS84LongitudeDecimal" + } + }, + "required": [ + "latitude", + "longitude" + ] + }, + "WGS84CoordinateAngular": { + "type": "object", + "properties": { + "latitude": { + "$ref": "#/$defs/WGS84LatitudeAngular" + }, + "longitude": { + "$ref": "#/$defs/WGS84LongitudeAngular" + } + }, + "required": [ + "latitude", + "longitude" + ] + } + } +} \ No newline at end of file -- GitLab From 53112d6e3110ec6310dddf1ec967437b863418ad Mon Sep 17 00:00:00 2001 From: mark Date: Thu, 16 Jun 2022 07:27:35 +0100 Subject: [PATCH 10/20] Fixing refs --- .../json_examples/example1_test.json | 0 .../json_schema/TS_103_120_authorisation.json | 24 +- .../json_schema/TS_103_120_common.json | 2 +- .../json_schema/TS_103_120_core.json | 21 +- .../json_schema/TS_103_120_delivery.json | 10 +- .../json_schema/TS_103_120_document.json | 20 +- .../json_schema/TS_103_120_notification.json | 10 +- .../json_schema/TS_103_120_task.json | 58 +- translation/README.md => README.md | 0 json/etsi103280.json | 384 ------------ json/xmldsig.json | 553 ----------------- testing/json_compile_targets.json | 20 + testing/json_process.py | 43 ++ translation/common.json | 7 - translation/core.json | 558 ------------------ translation/etsi103280.json | 11 - translation/test.py | 189 ------ translation/test_doc.json | 8 - translation/test_json.py | 18 - translation/test_schema.json | 38 -- translation/translate_120.py | 131 ++-- 21 files changed, 201 insertions(+), 1904 deletions(-) rename translation/120.json => 103120/json_examples/example1_test.json (100%) rename json/authorisation.json => 103120/json_schema/TS_103_120_authorisation.json (80%) rename json/common.json => 103120/json_schema/TS_103_120_common.json (99%) rename json/core.json => 103120/json_schema/TS_103_120_core.json (95%) rename json/delivery.json => 103120/json_schema/TS_103_120_delivery.json (93%) rename json/document.json => 103120/json_schema/TS_103_120_document.json (83%) rename json/notification.json => 103120/json_schema/TS_103_120_notification.json (83%) rename json/task.json => 103120/json_schema/TS_103_120_task.json (85%) rename translation/README.md => README.md (100%) delete mode 100644 json/etsi103280.json delete mode 100644 json/xmldsig.json create mode 100644 testing/json_compile_targets.json create mode 100644 testing/json_process.py delete mode 100644 translation/common.json delete mode 100644 translation/core.json delete mode 100644 translation/etsi103280.json delete mode 100644 translation/test.py delete mode 100644 translation/test_doc.json delete mode 100644 translation/test_json.py delete mode 100644 translation/test_schema.json diff --git a/translation/120.json b/103120/json_examples/example1_test.json similarity index 100% rename from translation/120.json rename to 103120/json_examples/example1_test.json diff --git a/json/authorisation.json b/103120/json_schema/TS_103_120_authorisation.json similarity index 80% rename from json/authorisation.json rename to 103120/json_schema/TS_103_120_authorisation.json index e8b4a52..3591164 100644 --- a/json/authorisation.json +++ b/103120/json_schema/TS_103_120_authorisation.json @@ -1,5 +1,5 @@ { - "$id": "authorisation.json", + "$id": "TS_103_120_authorisation.json", "$defs": { "AuthorisationObject": { "type": "object", @@ -9,7 +9,7 @@ "enum": "{http://uri.etsi.org/03120/common/2020/09/Authorisation}AuthorisationObject" }, "ObjectIdentifier": { - "$ref": "core.json#/$defs/ObjectIdentifier" + "$ref": "TS_103_120_core.json#/$defs/ObjectIdentifier" }, "CountryCode": { "$ref": "etsi103280.json#/$defs/ISOCountryCode" @@ -25,28 +25,28 @@ "$ref": "etsi103280.json#/$defs/LongString" }, "AssociatedObjects": { - "$ref": "core.json#/$defs/AssociatedObjects" + "$ref": "TS_103_120_core.json#/$defs/AssociatedObjects" }, "LastChanged": { "$ref": "etsi103280.json#/$defs/QualifiedDateTime" }, "NationalHandlingParameters": { - "$ref": "core.json#/$defs/NationalHandlingParameters" + "$ref": "TS_103_120_core.json#/$defs/NationalHandlingParameters" }, "AuthorisationReference": { "$ref": "etsi103280.json#/$defs/LongString" }, "AuthorisationLegalType": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "AuthorisationPriority": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "AuthorisationStatus": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "AuthorisationDesiredStatus": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "AuthorisationTimespan": { "$ref": "#/$defs/AuthorisationTimespan" @@ -66,11 +66,11 @@ "AuthorisationApprovalDetails": { "type": "array", "items": { - "$ref": "common.json#/$defs/ApprovalDetails" + "$ref": "TS_103_120_common.json#/$defs/ApprovalDetails" } }, "AuthorisationInvalidReason": { - "$ref": "core.json#/$defs/ActionUnsuccesfulInformation" + "$ref": "TS_103_120_core.json#/$defs/ActionUnsuccesfulInformation" }, "AuthorisationFlags": { "$ref": "#/$defs/AuthorisationFlags" @@ -93,7 +93,7 @@ "AuthorisationFlag": { "type": "array", "items": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" } } }, @@ -117,7 +117,7 @@ "CSPID": { "type": "array", "items": { - "$ref": "core.json#/$defs/EndpointID" + "$ref": "TS_103_120_core.json#/$defs/EndpointID" }, "minItems": 1 } diff --git a/json/common.json b/103120/json_schema/TS_103_120_common.json similarity index 99% rename from json/common.json rename to 103120/json_schema/TS_103_120_common.json index 0d899af..34ffdc4 100644 --- a/json/common.json +++ b/103120/json_schema/TS_103_120_common.json @@ -1,5 +1,5 @@ { - "$id": "common.json", + "$id": "TS_103_120_common.json", "$defs": { "ETSIVersion": { "allOf": [ diff --git a/json/core.json b/103120/json_schema/TS_103_120_core.json similarity index 95% rename from json/core.json rename to 103120/json_schema/TS_103_120_core.json index d87aac2..44adf1d 100644 --- a/json/core.json +++ b/103120/json_schema/TS_103_120_core.json @@ -1,5 +1,5 @@ { - "$id": "core.json", + "$id": "TS_103_120_core.json", "$defs": { "ObjectIdentifier": { "$ref": "etsi103280.json#/$defs/UUID" @@ -12,6 +12,9 @@ }, "Payload": { "$ref": "#/$defs/MessagePayload" + }, + "Signature": { + "$ref": "xmldsig.json#/$defs/SignatureType" } }, "required": [ @@ -50,7 +53,7 @@ "type": "object", "properties": { "ETSIVersion": { - "$ref": "common.json#/$defs/ETSIVersion" + "$ref": "TS_103_120_common.json#/$defs/ETSIVersion" }, "NationalProfileOwner": { "$ref": "etsi103280.json#/$defs/ShortString" @@ -406,7 +409,7 @@ "type": "object", "properties": { "ObjectType": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "LastChanged": { "$ref": "etsi103280.json#/$defs/QualifiedDateTime" @@ -430,7 +433,7 @@ "type": "object", "properties": { "ObjectType": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "Identifier": { "$ref": "#/$defs/ObjectIdentifier" @@ -559,19 +562,19 @@ "OneOfHI1Object": { "oneOf": [ { - "$ref": "authorisation.json#/$defs/AuthorisationObject" + "$ref": "TS_103_120_authorisation.json#/$defs/AuthorisationObject" }, { - "$ref": "task.json#/$defs/LITaskObject" + "$ref": "TS_103_120_task.json#/$defs/LITaskObject" }, { - "$ref": "task.json#/$defs/LDTaskObject" + "$ref": "TS_103_120_task.json#/$defs/LDTaskObject" }, { - "$ref": "document.json#/$defs/DocumentObject" + "$ref": "TS_103_120_document.json#/$defs/DocumentObject" }, { - "$ref": "notification.json#/$defs/NotificationObject" + "$ref": "TS_103_120_notification.json#/$defs/NotificationObject" } ] } diff --git a/json/delivery.json b/103120/json_schema/TS_103_120_delivery.json similarity index 93% rename from json/delivery.json rename to 103120/json_schema/TS_103_120_delivery.json index f82e84e..6e6b4c1 100644 --- a/json/delivery.json +++ b/103120/json_schema/TS_103_120_delivery.json @@ -1,5 +1,5 @@ { - "$id": "delivery.json", + "$id": "TS_103_120_delivery.json", "$defs": { "DeliveryObject": { "type": "object", @@ -9,7 +9,7 @@ "enum": "{http://uri.etsi.org/03120/common/2019/10/Delivery}DeliveryObject" }, "ObjectIdentifier": { - "$ref": "core.json#/$defs/ObjectIdentifier" + "$ref": "TS_103_120_core.json#/$defs/ObjectIdentifier" }, "CountryCode": { "$ref": "etsi103280.json#/$defs/ISOCountryCode" @@ -25,13 +25,13 @@ "$ref": "etsi103280.json#/$defs/LongString" }, "AssociatedObjects": { - "$ref": "core.json#/$defs/AssociatedObjects" + "$ref": "TS_103_120_core.json#/$defs/AssociatedObjects" }, "LastChanged": { "$ref": "etsi103280.json#/$defs/QualifiedDateTime" }, "NationalHandlingParameters": { - "$ref": "core.json#/$defs/NationalHandlingParameters" + "$ref": "TS_103_120_core.json#/$defs/NationalHandlingParameters" }, "Reference": { "$ref": "#/$defs/Reference" @@ -90,7 +90,7 @@ "type": "object", "properties": { "Specification": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" } }, "required": [ diff --git a/json/document.json b/103120/json_schema/TS_103_120_document.json similarity index 83% rename from json/document.json rename to 103120/json_schema/TS_103_120_document.json index f255164..ca04c04 100644 --- a/json/document.json +++ b/103120/json_schema/TS_103_120_document.json @@ -1,5 +1,5 @@ { - "$id": "document.json", + "$id": "TS_103_120_document.json", "$defs": { "DocumentObject": { "type": "object", @@ -9,7 +9,7 @@ "enum": "{http://uri.etsi.org/03120/common/2020/09/Document}DocumentObject" }, "ObjectIdentifier": { - "$ref": "core.json#/$defs/ObjectIdentifier" + "$ref": "TS_103_120_core.json#/$defs/ObjectIdentifier" }, "CountryCode": { "$ref": "etsi103280.json#/$defs/ISOCountryCode" @@ -25,13 +25,13 @@ "$ref": "etsi103280.json#/$defs/LongString" }, "AssociatedObjects": { - "$ref": "core.json#/$defs/AssociatedObjects" + "$ref": "TS_103_120_core.json#/$defs/AssociatedObjects" }, "LastChanged": { "$ref": "etsi103280.json#/$defs/QualifiedDateTime" }, "NationalHandlingParameters": { - "$ref": "core.json#/$defs/NationalHandlingParameters" + "$ref": "TS_103_120_core.json#/$defs/NationalHandlingParameters" }, "DocumentReference": { "$ref": "etsi103280.json#/$defs/LongString" @@ -40,16 +40,16 @@ "$ref": "etsi103280.json#/$defs/LongString" }, "DocumentStatus": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "DocumentDesiredStatus": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "DocumentTimespan": { "$ref": "#/$defs/DocumentTimespan" }, "DocumentType": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "DocumentProperties": { "$ref": "#/$defs/DocumentProperties" @@ -60,11 +60,11 @@ "DocumentSignature": { "type": "array", "items": { - "$ref": "common.json#/$defs/ApprovalDetails" + "$ref": "TS_103_120_common.json#/$defs/ApprovalDetails" } }, "DocumentInvalidReason": { - "$ref": "core.json#/$defs/ActionUnsuccesfulInformation" + "$ref": "TS_103_120_core.json#/$defs/ActionUnsuccesfulInformation" }, "NationalDocumentParameters": { "$ref": "#/$defs/NationalDocumentParameters" @@ -103,7 +103,7 @@ "type": "object", "properties": { "PropertyType": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "PropertyValue": { "$ref": "etsi103280.json#/$defs/LongString" diff --git a/json/notification.json b/103120/json_schema/TS_103_120_notification.json similarity index 83% rename from json/notification.json rename to 103120/json_schema/TS_103_120_notification.json index 41f2dd7..76f549e 100644 --- a/json/notification.json +++ b/103120/json_schema/TS_103_120_notification.json @@ -1,5 +1,5 @@ { - "$id": "notification.json", + "$id": "TS_103_120_notification.json", "$defs": { "NotificationObject": { "type": "object", @@ -9,7 +9,7 @@ "enum": "{http://uri.etsi.org/03120/common/2016/02/Notification}NotificationObject" }, "ObjectIdentifier": { - "$ref": "core.json#/$defs/ObjectIdentifier" + "$ref": "TS_103_120_core.json#/$defs/ObjectIdentifier" }, "CountryCode": { "$ref": "etsi103280.json#/$defs/ISOCountryCode" @@ -25,19 +25,19 @@ "$ref": "etsi103280.json#/$defs/LongString" }, "AssociatedObjects": { - "$ref": "core.json#/$defs/AssociatedObjects" + "$ref": "TS_103_120_core.json#/$defs/AssociatedObjects" }, "LastChanged": { "$ref": "etsi103280.json#/$defs/QualifiedDateTime" }, "NationalHandlingParameters": { - "$ref": "core.json#/$defs/NationalHandlingParameters" + "$ref": "TS_103_120_core.json#/$defs/NationalHandlingParameters" }, "NotificationDetails": { "$ref": "etsi103280.json#/$defs/LongString" }, "NotificationType": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "NewNotification": { "type": "boolean" diff --git a/json/task.json b/103120/json_schema/TS_103_120_task.json similarity index 85% rename from json/task.json rename to 103120/json_schema/TS_103_120_task.json index 1de702a..9145098 100644 --- a/json/task.json +++ b/103120/json_schema/TS_103_120_task.json @@ -1,5 +1,5 @@ { - "$id": "task.json", + "$id": "TS_103_120_task.json", "$defs": { "LITaskObject": { "type": "object", @@ -9,7 +9,7 @@ "enum": "{http://uri.etsi.org/03120/common/2020/09/Task}LITaskObject" }, "ObjectIdentifier": { - "$ref": "core.json#/$defs/ObjectIdentifier" + "$ref": "TS_103_120_core.json#/$defs/ObjectIdentifier" }, "CountryCode": { "$ref": "etsi103280.json#/$defs/ISOCountryCode" @@ -25,22 +25,22 @@ "$ref": "etsi103280.json#/$defs/LongString" }, "AssociatedObjects": { - "$ref": "core.json#/$defs/AssociatedObjects" + "$ref": "TS_103_120_core.json#/$defs/AssociatedObjects" }, "LastChanged": { "$ref": "etsi103280.json#/$defs/QualifiedDateTime" }, "NationalHandlingParameters": { - "$ref": "core.json#/$defs/NationalHandlingParameters" + "$ref": "TS_103_120_core.json#/$defs/NationalHandlingParameters" }, "Reference": { "$ref": "etsi103280.json#/$defs/LIID" }, "Status": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "DesiredStatus": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "Timespan": { "$ref": "#/$defs/TaskTimespan" @@ -49,7 +49,7 @@ "$ref": "#/$defs/TargetIdentifier" }, "DeliveryType": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "DeliveryDetails": { "$ref": "#/$defs/TaskDeliveryDetails" @@ -57,17 +57,17 @@ "ApprovalDetails": { "type": "array", "items": { - "$ref": "common.json#/$defs/ApprovalDetails" + "$ref": "TS_103_120_common.json#/$defs/ApprovalDetails" } }, "CSPID": { - "$ref": "core.json#/$defs/EndpointID" + "$ref": "TS_103_120_core.json#/$defs/EndpointID" }, "HandlingProfile": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "InvalidReason": { - "$ref": "core.json#/$defs/ActionUnsuccesfulInformation" + "$ref": "TS_103_120_core.json#/$defs/ActionUnsuccesfulInformation" }, "Flags": { "$ref": "#/$defs/TaskFlags" @@ -109,7 +109,7 @@ "$ref": "#/$defs/TargetIdentifierValues" }, "ServiceType": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" } }, "required": [] @@ -180,13 +180,13 @@ "$ref": "#/$defs/NationalEncryptionDetails" }, "IRIorCC": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "HandoverFormat": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "DeliveryProfile": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "NationalDeliveryParameters": { "$ref": "#/$defs/NationalDeliveryParameters" @@ -303,7 +303,7 @@ "TaskFlag": { "type": "array", "items": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" } } }, @@ -350,7 +350,7 @@ "enum": "{http://uri.etsi.org/03120/common/2020/09/Task}LDTaskObject" }, "ObjectIdentifier": { - "$ref": "core.json#/$defs/ObjectIdentifier" + "$ref": "TS_103_120_core.json#/$defs/ObjectIdentifier" }, "CountryCode": { "$ref": "etsi103280.json#/$defs/ISOCountryCode" @@ -366,25 +366,25 @@ "$ref": "etsi103280.json#/$defs/LongString" }, "AssociatedObjects": { - "$ref": "core.json#/$defs/AssociatedObjects" + "$ref": "TS_103_120_core.json#/$defs/AssociatedObjects" }, "LastChanged": { "$ref": "etsi103280.json#/$defs/QualifiedDateTime" }, "NationalHandlingParameters": { - "$ref": "core.json#/$defs/NationalHandlingParameters" + "$ref": "TS_103_120_core.json#/$defs/NationalHandlingParameters" }, "Reference": { "$ref": "etsi103280.json#/$defs/LDID" }, "Status": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "StatusReason": { - "$ref": "core.json#/$defs/ActionUnsuccesfulInformation" + "$ref": "TS_103_120_core.json#/$defs/ActionUnsuccesfulInformation" }, "DesiredStatus": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "RequestDetails": { "$ref": "#/$defs/RequestDetails" @@ -395,14 +395,14 @@ "ApprovalDetails": { "type": "array", "items": { - "$ref": "common.json#/$defs/ApprovalDetails" + "$ref": "TS_103_120_common.json#/$defs/ApprovalDetails" } }, "CSPID": { - "$ref": "core.json#/$defs/EndpointID" + "$ref": "TS_103_120_core.json#/$defs/EndpointID" }, "HandlingProfile": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "Flags": { "$ref": "#/$defs/LDTaskFlags" @@ -420,7 +420,7 @@ "type": "object", "properties": { "Type": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "StartTime": { "$ref": "etsi103280.json#/$defs/QualifiedDateTime" @@ -494,10 +494,10 @@ "$ref": "#/$defs/NationalEncryptionDetails" }, "LDHandoverFormat": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "LDDeliveryProfile": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "NationalDeliveryParameters": { "$ref": "#/$defs/NationalDeliveryParameters" @@ -511,7 +511,7 @@ "LDTaskFlag": { "type": "array", "items": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" } } }, diff --git a/translation/README.md b/README.md similarity index 100% rename from translation/README.md rename to README.md diff --git a/json/etsi103280.json b/json/etsi103280.json deleted file mode 100644 index 09457bd..0000000 --- a/json/etsi103280.json +++ /dev/null @@ -1,384 +0,0 @@ -{ - "$id": "etsi103280.json", - "$defs": { - "ShortString": { - "type": "string", - "maxLength": 255 - }, - "LongString": { - "type": "string", - "maxLength": 65535 - }, - "LIID": { - "type": "string", - "pattern": "^([!-~]{1,25})|([0-9a-f]{26,50})$" - }, - "UTCDateTime": { - "type": "string", - "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$" - }, - "UTCMicrosecondDateTime": { - "type": "string", - "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{6}Z$" - }, - "QualifiedDateTime": { - "type": "string", - "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(Z|[+-][0-9]{2}:[0-9]{2})$" - }, - "QualifiedMicrosecondDateTime": { - "type": "string", - "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{6}(Z|[+-][0-9]{2}:[0-9]{2})$" - }, - "InternationalE164": { - "type": "string", - "pattern": "^[0-9]{1,15}$" - }, - "IMSI": { - "type": "string", - "pattern": "^[0-9]{6,15}$" - }, - "IMEI": { - "type": "string", - "pattern": "^[0-9]{14}$" - }, - "IMEICheckDigit": { - "type": "string", - "pattern": "^[0-9]{15}$" - }, - "IMEISV": { - "type": "string", - "pattern": "^[0-9]{16}$" - }, - "IPv4Address": { - "type": "string", - "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])$" - }, - "IPv4CIDR": { - "type": "string", - "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])/([1-2]?[0-9]|3[0-2])$" - }, - "IPv6Address": { - "type": "string", - "pattern": "^([0-9a-f]{4}:){7}([0-9a-f]{4})$" - }, - "IPv6CIDR": { - "type": "string", - "pattern": "^([0-9a-f]{4}:){7}([0-9a-f]{4})/(([1-9][0-9]?)|(1[0-1][0-9])|(12[0-8]))$" - }, - "TCPPort": { - "type": "integer", - "exclusiveMinimum": 1, - "maximum": 65535 - }, - "UDPPort": { - "type": "integer", - "minimum": 0, - "maximum": 65535 - }, - "MACAddress": { - "type": "string", - "pattern": "^([a-f0-9]{2}:){5}[a-f0-9]{2}$" - }, - "EmailAddress": { - "allOf": [ - { - "$ref": "#/$defs/ShortString" - }, - { - "type": "string", - "pattern": "^[a-zA-Z0-9\\.!#$%&'\\*\\+\\\\/=\\?\\^_`\\{\\|\\}~\\-]+@[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$" - } - ] - }, - "UUID": { - "type": "string", - "pattern": "^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$" - }, - "ISOCountryCode": { - "type": "string", - "pattern": "^[A-Z]{2}$" - }, - "SIPURI": { - "type": "string", - "pattern": "^sips?:[a-zA-Z0-9!#$&-;=?-\\[\\]_~%]+$" - }, - "TELURI": { - "type": "string", - "pattern": "^tel:[a-zA-Z0-9!#$&-;=?-\\[\\]_~%]+$" - }, - "WGS84LatitudeDecimal": { - "type": "string", - "pattern": "^[NS][0-9]{2}\\.[0-9]{6}$" - }, - "WGS84LongitudeDecimal": { - "type": "string", - "pattern": "^[EW][0-9]{3}\\.[0-9]{6}$" - }, - "WGS84LatitudeAngular": { - "type": "string", - "pattern": "^[NS][0-9]{6}\\.[0-9]{2}$" - }, - "WGS84LongitudeAngular": { - "type": "string", - "pattern": "^[EW][0-9]{7}\\.[0-9]{2}$" - }, - "SUPIIMSI": { - "$ref": "#/$defs/IMSI" - }, - "SUPINAI": { - "$ref": "#/$defs/NAI" - }, - "SUCI": { - "type": "string", - "pattern": "^([a-fA-F0-9]{2})*$" - }, - "PEIIMEI": { - "$ref": "#/$defs/IMEI" - }, - "PEIIMEICheckDigit": { - "$ref": "#/$defs/IMEICheckDigit" - }, - "PEIIMEISV": { - "$ref": "#/$defs/IMEISV" - }, - "GPSIMSISDN": { - "type": "string", - "pattern": "^[0-9]{1,15}$" - }, - "GPSINAI": { - "$ref": "#/$defs/NAI" - }, - "NAI": { - "type": "string" - }, - "LDID": { - "type": "string", - "pattern": "^([A-Z]{2}-.+-.+)$" - }, - "InternationalizedEmailAddress": { - "allOf": [ - { - "$ref": "#/$defs/ShortString" - }, - { - "type": "string", - "pattern": "^.+@.+$" - } - ] - }, - "EUI64": { - "type": "string", - "pattern": "^([a-f0-9]{2}:){7}[a-f0-9]{2}$" - }, - "CGI": { - "type": "string", - "pattern": "^[0-9]{3}-[0-9]{2,3}-[a-f0-9]{4}-[a-f0-9]{4}$" - }, - "ECGI": { - "type": "string", - "pattern": "^[0-9]{3}-[0-9]{2,3}-[a-f0-9]{7}$" - }, - "NCGI": { - "type": "string", - "pattern": "^[0-9]{3}-[0-9]{2,3}-[a-f0-9]{9}$" - }, - "ICCID": { - "type": "string", - "pattern": "^[0-9]{19,20}$" - }, - "IPAddress": { - "oneOf": [ - { - "type": "object", - "properties": { - "IPv4Address": { - "$ref": "#/$defs/IPv4Address" - } - }, - "required": [ - "IPv4Address" - ] - }, - { - "type": "object", - "properties": { - "IPv6Address": { - "$ref": "#/$defs/IPv6Address" - } - }, - "required": [ - "IPv6Address" - ] - } - ] - }, - "IPCIDR": { - "oneOf": [ - { - "type": "object", - "properties": { - "IPv4CIDR": { - "$ref": "#/$defs/IPv4CIDR" - } - }, - "required": [ - "IPv4CIDR" - ] - }, - { - "type": "object", - "properties": { - "IPv6CIDR": { - "$ref": "#/$defs/IPv6CIDR" - } - }, - "required": [ - "IPv6CIDR" - ] - } - ] - }, - "TCPPortRange": { - "type": "object", - "properties": { - "start": { - "$ref": "#/$defs/TCPPort" - }, - "end": { - "$ref": "#/$defs/TCPPort" - } - }, - "required": [ - "start", - "end" - ] - }, - "UDPPortRange": { - "type": "object", - "properties": { - "start": { - "$ref": "#/$defs/UDPPort" - }, - "end": { - "$ref": "#/$defs/UDPPort" - } - }, - "required": [ - "start", - "end" - ] - }, - "Port": { - "oneOf": [ - { - "type": "object", - "properties": { - "TCPPort": { - "$ref": "#/$defs/TCPPort" - } - }, - "required": [ - "TCPPort" - ] - }, - { - "type": "object", - "properties": { - "UDPPort": { - "$ref": "#/$defs/UDPPort" - } - }, - "required": [ - "UDPPort" - ] - } - ] - }, - "PortRange": { - "oneOf": [ - { - "type": "object", - "properties": { - "TCPPortRange": { - "$ref": "#/$defs/TCPPortRange" - } - }, - "required": [ - "TCPPortRange" - ] - }, - { - "type": "object", - "properties": { - "UDPPortRange": { - "$ref": "#/$defs/UDPPortRange" - } - }, - "required": [ - "UDPPortRange" - ] - } - ] - }, - "IPAddressPort": { - "type": "object", - "properties": { - "address": { - "$ref": "#/$defs/IPAddress" - }, - "port": { - "$ref": "#/$defs/Port" - } - }, - "required": [ - "address", - "port" - ] - }, - "IPAddressPortRange": { - "type": "object", - "properties": { - "address": { - "$ref": "#/$defs/IPAddress" - }, - "portRange": { - "$ref": "#/$defs/PortRange" - } - }, - "required": [ - "address", - "portRange" - ] - }, - "WGS84CoordinateDecimal": { - "type": "object", - "properties": { - "latitude": { - "$ref": "#/$defs/WGS84LatitudeDecimal" - }, - "longitude": { - "$ref": "#/$defs/WGS84LongitudeDecimal" - } - }, - "required": [ - "latitude", - "longitude" - ] - }, - "WGS84CoordinateAngular": { - "type": "object", - "properties": { - "latitude": { - "$ref": "#/$defs/WGS84LatitudeAngular" - }, - "longitude": { - "$ref": "#/$defs/WGS84LongitudeAngular" - } - }, - "required": [ - "latitude", - "longitude" - ] - } - } -} \ No newline at end of file diff --git a/json/xmldsig.json b/json/xmldsig.json deleted file mode 100644 index dde4cb0..0000000 --- a/json/xmldsig.json +++ /dev/null @@ -1,553 +0,0 @@ -{ - "$id": "core.json", - "$defs": { - "ObjectIdentifier": { - "$ref": "etsi103280.json#/$defs/UUID" - }, - "HI1Message": { - "type": "object", - "properties": { - "Header": { - "$ref": "#/$defs/MessageHeader" - }, - "Payload": { - "$ref": "#/$defs/MessagePayload" - }, - "Signature": { - "$ref": "xmldsig.json#/$defs/SignatureType" - } - }, - "required": [ - "Header", - "Payload" - ] - }, - "MessageHeader": { - "type": "object", - "properties": { - "SenderIdentifier": { - "$ref": "#/$defs/EndpointID" - }, - "ReceiverIdentifier": { - "$ref": "#/$defs/EndpointID" - }, - "TransactionIdentifier": { - "$ref": "etsi103280.json#/$defs/UUID" - }, - "Timestamp": { - "$ref": "etsi103280.json#/$defs/QualifiedMicrosecondDateTime" - }, - "Version": { - "$ref": "#/$defs/Version" - } - }, - "required": [ - "SenderIdentifier", - "ReceiverIdentifier", - "TransactionIdentifier", - "Timestamp", - "Version" - ] - }, - "Version": { - "type": "object", - "properties": { - "ETSIVersion": { - "$ref": "common.json#/$defs/ETSIVersion" - }, - "NationalProfileOwner": { - "$ref": "etsi103280.json#/$defs/ShortString" - }, - "NationalProfileVersion": { - "$ref": "etsi103280.json#/$defs/ShortString" - } - }, - "required": [ - "ETSIVersion", - "NationalProfileOwner", - "NationalProfileVersion" - ] - }, - "EndpointID": { - "type": "object", - "properties": { - "CountryCode": { - "$ref": "etsi103280.json#/$defs/ISOCountryCode" - }, - "UniqueIdentifier": { - "$ref": "etsi103280.json#/$defs/LongString" - } - }, - "required": [ - "CountryCode", - "UniqueIdentifier" - ] - }, - "MessagePayload": { - "oneOf": [ - { - "type": "object", - "properties": { - "RequestPayload": { - "$ref": "#/$defs/RequestPayload" - } - }, - "required": [ - "RequestPayload" - ] - }, - { - "type": "object", - "properties": { - "ResponsePayload": { - "$ref": "#/$defs/ResponsePayload" - } - }, - "required": [ - "ResponsePayload" - ] - } - ] - }, - "RequestPayload": { - "type": "object", - "properties": { - "ActionRequests": { - "$ref": "#/$defs/ActionRequests" - } - }, - "required": [ - "ActionRequests" - ] - }, - "ActionRequests": { - "type": "object", - "properties": { - "ActionRequest": { - "$ref": "#/$defs/ActionRequest" - } - }, - "required": [ - "ActionRequest" - ] - }, - "ResponsePayload": { - "oneOf": [ - { - "type": "object", - "properties": { - "ActionResponses": { - "$ref": "#/$defs/ActionResponses" - } - }, - "required": [ - "ActionResponses" - ] - }, - { - "type": "object", - "properties": { - "ErrorInformation": { - "$ref": "#/$defs/ActionUnsuccesfulInformation" - } - }, - "required": [ - "ErrorInformation" - ] - } - ] - }, - "ActionResponses": { - "type": "object", - "properties": { - "ActionResponse": { - "$ref": "#/$defs/ActionResponse" - } - }, - "required": [ - "ActionResponse" - ] - }, - "ActionRequest": { - "allOf": [ - { - "type": "object", - "properties": { - "ActionIdentifier": { - "type": "integer", - "minimum": 0 - } - }, - "required": [ - "ActionIdentifier" - ] - }, - { - "oneOf": [ - { - "type": "object", - "properties": { - "GET": { - "$ref": "#/$defs/GETRequest" - } - }, - "required": [ - "GET" - ] - }, - { - "type": "object", - "properties": { - "CREATE": { - "$ref": "#/$defs/CREATERequest" - } - }, - "required": [ - "CREATE" - ] - }, - { - "type": "object", - "properties": { - "UPDATE": { - "$ref": "#/$defs/UPDATERequest" - } - }, - "required": [ - "UPDATE" - ] - }, - { - "type": "object", - "properties": { - "LIST": { - "$ref": "#/$defs/LISTRequest" - } - }, - "required": [ - "LIST" - ] - }, - { - "type": "object", - "properties": { - "DELIVER": { - "$ref": "#/$defs/DELIVERRequest" - } - }, - "required": [ - "DELIVER" - ] - } - ] - } - ] - }, - "ActionResponse": { - "allOf": [ - { - "type": "object", - "properties": { - "ActionIdentifier": { - "type": "integer", - "minimum": 0 - } - }, - "required": [ - "ActionIdentifier" - ] - }, - { - "oneOf": [ - { - "type": "object", - "properties": { - "GETResponse": { - "$ref": "#/$defs/GETResponse" - } - }, - "required": [ - "GETResponse" - ] - }, - { - "type": "object", - "properties": { - "CREATEResponse": { - "$ref": "#/$defs/CREATEResponse" - } - }, - "required": [ - "CREATEResponse" - ] - }, - { - "type": "object", - "properties": { - "UPDATEResponse": { - "$ref": "#/$defs/UPDATEResponse" - } - }, - "required": [ - "UPDATEResponse" - ] - }, - { - "type": "object", - "properties": { - "LISTResponse": { - "$ref": "#/$defs/LISTResponse" - } - }, - "required": [ - "LISTResponse" - ] - }, - { - "type": "object", - "properties": { - "ErrorInformation": { - "$ref": "#/$defs/ActionUnsuccesfulInformation" - } - }, - "required": [ - "ErrorInformation" - ] - }, - { - "type": "object", - "properties": { - "DELIVERResponse": { - "$ref": "#/$defs/DELIVERResponse" - } - }, - "required": [ - "DELIVERResponse" - ] - } - ] - } - ] - }, - "GETRequest": { - "type": "object", - "properties": { - "Identifier": { - "$ref": "#/$defs/ObjectIdentifier" - } - }, - "required": [ - "Identifier" - ] - }, - "GETResponse": { - "type": "object", - "properties": { - "HI1Object": { - "$ref": "#/$defs/HI1Object" - } - }, - "required": [ - "HI1Object" - ] - }, - "CREATERequest": { - "type": "object", - "properties": { - "HI1Object": { - "$ref": "#/$defs/HI1Object" - } - }, - "required": [ - "HI1Object" - ] - }, - "CREATEResponse": { - "type": "object", - "properties": { - "Identifier": { - "$ref": "#/$defs/ObjectIdentifier" - }, - "HI1Object": { - "$ref": "#/$defs/HI1Object" - } - }, - "required": [ - "Identifier" - ] - }, - "UPDATERequest": { - "type": "object", - "properties": { - "HI1Object": { - "$ref": "#/$defs/HI1Object" - } - }, - "required": [ - "HI1Object" - ] - }, - "UPDATEResponse": { - "type": "object", - "properties": { - "Identifier": { - "$ref": "#/$defs/ObjectIdentifier" - }, - "HI1Object": { - "$ref": "#/$defs/HI1Object" - } - }, - "required": [ - "Identifier" - ] - }, - "LISTRequest": { - "type": "object", - "properties": { - "ObjectType": { - "$ref": "common.json#/$defs/DictionaryEntry" - }, - "LastChanged": { - "$ref": "etsi103280.json#/$defs/QualifiedDateTime" - } - }, - "required": [] - }, - "LISTResponse": { - "type": "object", - "properties": { - "ListResponseRecord": { - "$ref": "#/$defs/ListResponseRecord" - } - }, - "required": [] - }, - "ListResponseRecord": { - "type": "object", - "properties": { - "ObjectType": { - "$ref": "common.json#/$defs/DictionaryEntry" - }, - "Identifier": { - "$ref": "#/$defs/ObjectIdentifier" - }, - "CountryCode": { - "$ref": "etsi103280.json#/$defs/ISOCountryCode" - }, - "OwnerIdentifier": { - "$ref": "etsi103280.json#/$defs/ShortString" - }, - "Generation": { - "type": "integer", - "minimum": 0 - }, - "ExternalIdentifier": { - "$ref": "etsi103280.json#/$defs/LongString" - }, - "LastChanged": { - "$ref": "etsi103280.json#/$defs/QualifiedDateTime" - } - }, - "required": [ - "ObjectType", - "Identifier", - "Generation" - ] - }, - "ActionUnsuccesfulInformation": { - "type": "object", - "properties": { - "ErrorCode": { - "type": "integer", - "minimum": 0 - }, - "ErrorDescription": { - "$ref": "etsi103280.json#/$defs/LongString" - } - }, - "required": [ - "ErrorCode", - "ErrorDescription" - ] - }, - "DELIVERRequest": { - "type": "object", - "properties": { - "Identifier": { - "$ref": "#/$defs/ObjectIdentifier" - }, - "HI1Object": { - "$ref": "#/$defs/HI1Object" - } - }, - "required": [ - "Identifier", - "HI1Object" - ] - }, - "DELIVERResponse": { - "type": "object", - "properties": { - "Identifier": { - "$ref": "#/$defs/ObjectIdentifier" - } - }, - "required": [ - "Identifier" - ] - }, - "HI1Object": { - "type": "object", - "properties": { - "ObjectIdentifier": { - "$ref": "#/$defs/ObjectIdentifier" - }, - "CountryCode": { - "$ref": "etsi103280.json#/$defs/ISOCountryCode" - }, - "OwnerIdentifier": { - "$ref": "etsi103280.json#/$defs/ShortString" - }, - "Generation": { - "type": "integer", - "minimum": 0 - }, - "ExternalIdentifier": { - "$ref": "etsi103280.json#/$defs/LongString" - }, - "AssociatedObjects": { - "$ref": "#/$defs/AssociatedObjects" - }, - "LastChanged": { - "$ref": "etsi103280.json#/$defs/QualifiedDateTime" - }, - "NationalHandlingParameters": { - "$ref": "#/$defs/NationalHandlingParameters" - } - }, - "required": [ - "ObjectIdentifier" - ] - }, - "AssociatedObjects": { - "type": "object", - "properties": { - "AssociatedObject": { - "$ref": "#/$defs/ObjectIdentifier" - } - }, - "required": [] - }, - "NationalHandlingParameters": { - "type": "object", - "properties": { - "CountryCode": { - "$ref": "etsi103280.json#/$defs/ISOCountryCode" - } - }, - "required": [ - "CountryCode" - ] - } - } -} \ No newline at end of file diff --git a/testing/json_compile_targets.json b/testing/json_compile_targets.json new file mode 100644 index 0000000..86b2d25 --- /dev/null +++ b/testing/json_compile_targets.json @@ -0,0 +1,20 @@ +[ + { + "coreSchema" : "./103280/TS_103_280.json", + "supportingSchemas" : [], + "exampleFiles" : [] + }, + { + "coreSchema" : "./103120/json_schema/TS_103_120_core.json", + "supportingSchemas" : [ + "./103120/json_schema/TS_103_120_authorisation.json", + "./103120/json_schema/TS_103_120_common.json", + "./103120/json_schema/TS_103_120_document.json", + "./103120/json_schema/TS_103_120_notification.json", + "./103120/json_schema/TS_103_120_task.json", + "./103120/json_schema/TS_103_120_delivery.json", + "./103280/TS_103_280.json" + ], + "exampleFiles" : ["./103120/json_examples/"] + } +] \ No newline at end of file diff --git a/testing/json_process.py b/testing/json_process.py new file mode 100644 index 0000000..6eaed05 --- /dev/null +++ b/testing/json_process.py @@ -0,0 +1,43 @@ +import logging +import json +from pathlib import Path + +import jsonschema + +def get_json(filename: str): + with open(filename) as f: + j = json.load(f) + return j + + +logging.basicConfig(level=logging.DEBUG) +if __name__ == "__main__": + targets = get_json("testing/json_compile_targets.json") + + resolver=None + for target in targets: + logging.info(f"Testing {target['coreSchema']}") + schema = get_json(target['coreSchema']) + + supporting_schemas = {schema['$id'] : schema} + for supporting_schema in target['supportingSchemas']: + js = get_json(supporting_schema) + supporting_schemas[js['$id']] = js + if len(supporting_schemas.keys()) > 0: + ref_resolver = jsonschema.RefResolver("", "", supporting_schemas) + print(supporting_schemas.keys()) + else: + ref_resolver = None + + # validator = jsonschema.Draft202012Validator(schema, resolver=resolver) + + for example_dir in target['exampleFiles']: + for example_file in Path(example_dir).rglob("*.json"): + instance = get_json(example_file) + jsonschema.validate(instance, schema, resolver = ref_resolver) + # for err in validator.iter_errors(instance): + # print(err.message) + logging.info("Done testing") + + +# print(json.dumps(js, indent=2)) \ No newline at end of file diff --git a/translation/common.json b/translation/common.json deleted file mode 100644 index b32e709..0000000 --- a/translation/common.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "$id" : "130120/common", - "$defs" : { - "ObjectIdentifier" : { "$ref" : "#/$defs/ObjectRoot"}, - "ObjectRoot" : {"type" : "integer"} - } -} \ No newline at end of file diff --git a/translation/core.json b/translation/core.json deleted file mode 100644 index 1ad2f40..0000000 --- a/translation/core.json +++ /dev/null @@ -1,558 +0,0 @@ -{ - "$id": "core", - "oneOf": [ - { - "$ref": "#/$defs/HI1Message" - } - ], - "$defs": { - "ObjectIdentifier": { - "$ref": "etsi103280.json#/$defs/UUID" - }, - "HI1Message": { - "type": "object", - "properties": { - "Header": { - "$ref": "#/$defs/MessageHeader" - }, - "Payload": { - "$ref": "#/$defs/MessagePayload" - }, - "Signature": { - "$ref": "xmldsig.json#/$defs/SignatureType" - } - }, - "required": [ - "Header", - "Payload" - ] - }, - "MessageHeader": { - "type": "object", - "properties": { - "SenderIdentifier": { - "$ref": "#/$defs/EndpointID" - }, - "ReceiverIdentifier": { - "$ref": "#/$defs/EndpointID" - }, - "TransactionIdentifier": { - "$ref": "etsi103280.json#/$defs/UUID" - }, - "Timestamp": { - "$ref": "etsi103280.json#/$defs/QualifiedMicrosecondDateTime" - }, - "Version": { - "$ref": "#/$defs/Version" - } - }, - "required": [ - "SenderIdentifier", - "ReceiverIdentifier", - "TransactionIdentifier", - "Timestamp", - "Version" - ] - }, - "Version": { - "type": "object", - "properties": { - "ETSIVersion": { - "$ref": "common.json#/$defs/ETSIVersion" - }, - "NationalProfileOwner": { - "$ref": "etsi103280.json#/$defs/ShortString" - }, - "NationalProfileVersion": { - "$ref": "etsi103280.json#/$defs/ShortString" - } - }, - "required": [ - "ETSIVersion", - "NationalProfileOwner", - "NationalProfileVersion" - ] - }, - "EndpointID": { - "type": "object", - "properties": { - "CountryCode": { - "$ref": "etsi103280.json#/$defs/ISOCountryCode" - }, - "UniqueIdentifier": { - "$ref": "etsi103280.json#/$defs/LongString" - } - }, - "required": [ - "CountryCode", - "UniqueIdentifier" - ] - }, - "MessagePayload": { - "oneOf": [ - { - "type": "object", - "properties": { - "RequestPayload": { - "$ref": "#/$defs/RequestPayload" - } - }, - "required": [ - "RequestPayload" - ] - }, - { - "type": "object", - "properties": { - "ResponsePayload": { - "$ref": "#/$defs/ResponsePayload" - } - }, - "required": [ - "ResponsePayload" - ] - } - ] - }, - "RequestPayload": { - "type": "object", - "properties": { - "ActionRequests": { - "$ref": "#/$defs/ActionRequests" - } - }, - "required": [ - "ActionRequests" - ] - }, - "ActionRequests": { - "type": "object", - "properties": { - "ActionRequest": { - "$ref": "#/$defs/ActionRequest" - } - }, - "required": [ - "ActionRequest" - ] - }, - "ResponsePayload": { - "oneOf": [ - { - "type": "object", - "properties": { - "ActionResponses": { - "$ref": "#/$defs/ActionResponses" - } - }, - "required": [ - "ActionResponses" - ] - }, - { - "type": "object", - "properties": { - "ErrorInformation": { - "$ref": "#/$defs/ActionUnsuccesfulInformation" - } - }, - "required": [ - "ErrorInformation" - ] - } - ] - }, - "ActionResponses": { - "type": "object", - "properties": { - "ActionResponse": { - "$ref": "#/$defs/ActionResponse" - } - }, - "required": [ - "ActionResponse" - ] - }, - "ActionRequest": { - "allOf": [ - { - "type": "object", - "properties": { - "ActionIdentifier": { - "type": "integer", - "minimum": 0 - } - }, - "required": [ - "ActionIdentifier" - ] - }, - { - "oneOf": [ - { - "type": "object", - "properties": { - "GET": { - "$ref": "#/$defs/GETRequest" - } - }, - "required": [ - "GET" - ] - }, - { - "type": "object", - "properties": { - "CREATE": { - "$ref": "#/$defs/CREATERequest" - } - }, - "required": [ - "CREATE" - ] - }, - { - "type": "object", - "properties": { - "UPDATE": { - "$ref": "#/$defs/UPDATERequest" - } - }, - "required": [ - "UPDATE" - ] - }, - { - "type": "object", - "properties": { - "LIST": { - "$ref": "#/$defs/LISTRequest" - } - }, - "required": [ - "LIST" - ] - }, - { - "type": "object", - "properties": { - "DELIVER": { - "$ref": "#/$defs/DELIVERRequest" - } - }, - "required": [ - "DELIVER" - ] - } - ] - } - ] - }, - "ActionResponse": { - "allOf": [ - { - "type": "object", - "properties": { - "ActionIdentifier": { - "type": "integer", - "minimum": 0 - } - }, - "required": [ - "ActionIdentifier" - ] - }, - { - "oneOf": [ - { - "type": "object", - "properties": { - "GETResponse": { - "$ref": "#/$defs/GETResponse" - } - }, - "required": [ - "GETResponse" - ] - }, - { - "type": "object", - "properties": { - "CREATEResponse": { - "$ref": "#/$defs/CREATEResponse" - } - }, - "required": [ - "CREATEResponse" - ] - }, - { - "type": "object", - "properties": { - "UPDATEResponse": { - "$ref": "#/$defs/UPDATEResponse" - } - }, - "required": [ - "UPDATEResponse" - ] - }, - { - "type": "object", - "properties": { - "LISTResponse": { - "$ref": "#/$defs/LISTResponse" - } - }, - "required": [ - "LISTResponse" - ] - }, - { - "type": "object", - "properties": { - "ErrorInformation": { - "$ref": "#/$defs/ActionUnsuccesfulInformation" - } - }, - "required": [ - "ErrorInformation" - ] - }, - { - "type": "object", - "properties": { - "DELIVERResponse": { - "$ref": "#/$defs/DELIVERResponse" - } - }, - "required": [ - "DELIVERResponse" - ] - } - ] - } - ] - }, - "GETRequest": { - "type": "object", - "properties": { - "Identifier": { - "$ref": "#/$defs/ObjectIdentifier" - } - }, - "required": [ - "Identifier" - ] - }, - "GETResponse": { - "type": "object", - "properties": { - "HI1Object": { - "$ref": "#/$defs/HI1Object" - } - }, - "required": [ - "HI1Object" - ] - }, - "CREATERequest": { - "type": "object", - "properties": { - "HI1Object": { - "$ref": "#/$defs/HI1Object" - } - }, - "required": [ - "HI1Object" - ] - }, - "CREATEResponse": { - "type": "object", - "properties": { - "Identifier": { - "$ref": "#/$defs/ObjectIdentifier" - }, - "HI1Object": { - "$ref": "#/$defs/HI1Object" - } - }, - "required": [ - "Identifier" - ] - }, - "UPDATERequest": { - "type": "object", - "properties": { - "HI1Object": { - "$ref": "#/$defs/HI1Object" - } - }, - "required": [ - "HI1Object" - ] - }, - "UPDATEResponse": { - "type": "object", - "properties": { - "Identifier": { - "$ref": "#/$defs/ObjectIdentifier" - }, - "HI1Object": { - "$ref": "#/$defs/HI1Object" - } - }, - "required": [ - "Identifier" - ] - }, - "LISTRequest": { - "type": "object", - "properties": { - "ObjectType": { - "$ref": "common.json#/$defs/DictionaryEntry" - }, - "LastChanged": { - "$ref": "etsi103280.json#/$defs/QualifiedDateTime" - } - }, - "required": [] - }, - "LISTResponse": { - "type": "object", - "properties": { - "ListResponseRecord": { - "$ref": "#/$defs/ListResponseRecord" - } - }, - "required": [] - }, - "ListResponseRecord": { - "type": "object", - "properties": { - "ObjectType": { - "$ref": "common.json#/$defs/DictionaryEntry" - }, - "Identifier": { - "$ref": "#/$defs/ObjectIdentifier" - }, - "CountryCode": { - "$ref": "etsi103280.json#/$defs/ISOCountryCode" - }, - "OwnerIdentifier": { - "$ref": "etsi103280.json#/$defs/ShortString" - }, - "Generation": { - "type": "integer", - "minimum": 0 - }, - "ExternalIdentifier": { - "$ref": "etsi103280.json#/$defs/LongString" - }, - "LastChanged": { - "$ref": "etsi103280.json#/$defs/QualifiedDateTime" - } - }, - "required": [ - "ObjectType", - "Identifier", - "Generation" - ] - }, - "ActionUnsuccesfulInformation": { - "type": "object", - "properties": { - "ErrorCode": { - "type": "integer", - "minimum": 0 - }, - "ErrorDescription": { - "$ref": "etsi103280.json#/$defs/LongString" - } - }, - "required": [ - "ErrorCode", - "ErrorDescription" - ] - }, - "DELIVERRequest": { - "type": "object", - "properties": { - "Identifier": { - "$ref": "#/$defs/ObjectIdentifier" - }, - "HI1Object": { - "$ref": "#/$defs/HI1Object" - } - }, - "required": [ - "Identifier", - "HI1Object" - ] - }, - "DELIVERResponse": { - "type": "object", - "properties": { - "Identifier": { - "$ref": "#/$defs/ObjectIdentifier" - } - }, - "required": [ - "Identifier" - ] - }, - "HI1Object": { - "type": "object", - "properties": { - "ObjectIdentifier": { - "$ref": "#/$defs/ObjectIdentifier" - }, - "CountryCode": { - "$ref": "etsi103280.json#/$defs/ISOCountryCode" - }, - "OwnerIdentifier": { - "$ref": "etsi103280.json#/$defs/ShortString" - }, - "Generation": { - "type": "integer", - "minimum": 0 - }, - "ExternalIdentifier": { - "$ref": "etsi103280.json#/$defs/LongString" - }, - "AssociatedObjects": { - "$ref": "#/$defs/AssociatedObjects" - }, - "LastChanged": { - "$ref": "etsi103280.json#/$defs/QualifiedDateTime" - }, - "NationalHandlingParameters": { - "$ref": "#/$defs/NationalHandlingParameters" - } - }, - "required": [ - "ObjectIdentifier" - ] - }, - "AssociatedObjects": { - "type": "object", - "properties": { - "AssociatedObject": { - "$ref": "#/$defs/ObjectIdentifier" - } - }, - "required": [] - }, - "NationalHandlingParameters": { - "type": "object", - "properties": { - "CountryCode": { - "$ref": "etsi103280.json#/$defs/ISOCountryCode" - } - }, - "required": [ - "CountryCode" - ] - } - } -} \ No newline at end of file diff --git a/translation/etsi103280.json b/translation/etsi103280.json deleted file mode 100644 index b6bd0ad..0000000 --- a/translation/etsi103280.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "$id" : "130120/common", - "$defs" : { - "ObjectIdentifier" : { "$ref" : "#/$defs/ObjectRoot"}, - "ObjectRoot" : {"type" : "integer"}, - "UUID" : { - "type" : "string", - "pattern" : "^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$" - } - } -} \ No newline at end of file diff --git a/translation/test.py b/translation/test.py deleted file mode 100644 index a6b12b2..0000000 --- a/translation/test.py +++ /dev/null @@ -1,189 +0,0 @@ -import json -import logging -from pathlib import Path -from pprint import pprint - -from xmlschema import * -from xmlschema.validators.complex_types import XsdComplexType -from xmlschema.validators.simple_types import XsdAtomicRestriction, XsdAtomicBuiltin -from xmlschema.validators.groups import * - -schemas = [ "103120/schema/ts_103120_Authorisation.xsd", - "103120/schema/ts_103120_Common.xsd", - "103120/schema/ts_103120_Delivery.xsd", - "103120/schema/ts_103120_Document.xsd", - "103120/schema/ts_103120_Notification.xsd", - "103120/schema/ts_103120_Task.xsd", - "103280/TS_103_280.xsd", - "testing/deps/xmldsig/xmldsig-core-schema.xsd"] - -schemaLocations = [] -for schemaFile in schemas: - try: - xs = XMLSchema(schemaFile, validation='skip') - schemaLocations.append((xs.target_namespace, str(Path(schemaFile).resolve()))) - print (" [ {0} -> {1} ]".format(xs.target_namespace, schemaFile)) - except XMLSchemaParseError as ex: - print (" [ {0} failed to parse: {1} ]".format(schemaFile, ex)) - -coreSchema = XMLSchema('103120/schema/ts_103120_Core.xsd', locations = schemaLocations) - -js = { - "$id" : "core", - "oneOf" : [], - "$defs" : {} -} - -ns_mappings = { - 'http://uri.etsi.org/03120/common/2019/10/Core' : 'core', - 'http://uri.etsi.org/03120/common/2016/02/Common' : 'common', - 'http://uri.etsi.org/03280/common/2017/07' : 'etsi103280', - 'http://www.w3.org/2000/09/xmldsig#' : 'xmldsig' -} - -primitive_type_mappings = { - "token" : { "type" : "string"}, - "string" : { "type" : "string"}, - "nonNegativeInteger" : { "type" : "integer", "minimum" : 0}, - "anyType" : {} -} - -def process_qname(qname): - namespace = qname[1:qname.find('}')] - token = qname[qname.find('}')+1:] - return token, namespace - -def get_type_from_elem(elem: XsdElement, local_id): - t = elem.type - ns = t.name[1:t.name.find('}')] - if (ns == "http://www.w3.org/2001/XMLSchema"): - # this should be an XSD primitive type - mapped_type = primitive_type_mappings[t.local_name] - return mapped_type - else: - # this needs to be a type in a namespace we know about - mapped_ns = ns_mappings[ns] - if (mapped_ns == local_id): - return { "$ref" : f"#/$defs/{elem.type.local_name}"} - else: - return {"$ref" : f"{mapped_ns}.json#/$defs/{elem.type.local_name}"} - -def get_ref(token, ns, context): - mapped_ns = ns_mappings[ns] - if (mapped_ns == context): - return f"#/$defs/{token}" - else: - return f"{mapped_ns}.json#/$defs/{token}" - - -for elementName, element in coreSchema.elements.items(): - print (f"Root element: {elementName} = {element}") - token, ns = process_qname(element.type.name) - js["oneOf"].append({ - '$ref' : get_ref(token, ns, 'core') - }) - - -def process_choice(choice: XsdGroup): - if choice.model != 'choice': - raise Exception(f"Wrong group type: {c.model}") - oneOf = [] - for c in choice.iter_model(): - if not (type(c) is XsdElement): - raise Exception (f"Non-element {c} encountered in choice {choice}") - t = get_type_from_elem(c, 'core') - oneOf.append({ - "type" : "object", - "properties" : { - c.local_name : t - }, - "required" : [c.local_name] - }) - return oneOf - - -def process_atomic_restriction (sctype): - r = {} - print (f" Atomic restriction: {sctype}") - token, ns = process_qname(sctype.name) - print (f" [{ns}] {token}") - print (f" Root type {sctype.root_type}") - print (f" Base type {sctype.base_type}") - print (" Facets....") - for k, f in sctype.facets.items(): - print (f" facet {k} = {f}") - print (" Validators....") - for v in list(sctype.validators): - print (f" validator {v}") - mappedType = primitive_type_mappings.get(sctype.base_type.name) - if mappedType: - r = mappedType - print (f" Found primitive mapping to {mappedType}") - if len(sctype.facets) > 0: - raise Exception("Too many facets in primitive type") - firstKey = sctype.facets.keys[0] - if (firstKey != '{http://www.w3.org/2001/XMLSchema}pattern'): - raise Exception (f"Unhandled facet {firstKey}") - pattern = sctype.facets[firstKey] - r['pattern'] = pattern.pattern - if len(sctype.validators) > 0: - raise Exception("Too many validators in primitive type") - return token, r - else: - base_token, base_ns = process_qname(sctype.base_type.name) - return token, { '$ref' : get_ref(base_token, base_ns, 'core')} - - -for typeName, sctype in coreSchema.types.items(): - print (f"Type: {typeName} = {type} ({type(sctype)}") - if type(sctype) is XsdAtomicRestriction: - token, typeDef = process_atomic_restriction(sctype) - js["$defs"][token] = typeDef - #print (dir(sctype)) - if type(sctype) is XsdComplexType: - content = sctype.content - print(f" Content {content}") - d = {} - if type(content) is XsdGroup: - if content.model == "sequence": - print (" SEQUENCE!") - d = { - 'type' : 'object', - 'properties' : {}, - 'required' : [] - } - innerChoice = None - for c in list(content.iter_model()): - print (f" > {c}") - if type(c) is XsdElement: - d['properties'][c.local_name] = get_type_from_elem(c, 'core') - if c.effective_min_occurs == 1: - d['required'].append(c.local_name) - elif type(c) is XsdGroup: - if innerChoice: - raise Exception ("Second group encountered") - if c.model != "choice": - raise Exception (f"Don't know what to do with inner {c}") - innerChoice = process_choice(c) - else: - raise Exception(f"Unknown element type {c}") - if (innerChoice): - js["$defs"][sctype.local_name] = { - 'allOf' : [ - d, - {'oneOf' : innerChoice} - ] - } - else: - js["$defs"][sctype.local_name] = d - elif content.model =="choice": - print (" CHOICE!") - oneOf = process_choice(content) - js["$defs"][sctype.local_name] = {'oneOf' : oneOf} - - else: - raise Exception(f"Unknown content type {content}") - - -pprint(js) -Path('./core.json').write_text(json.dumps(js, indent=2)) \ No newline at end of file diff --git a/translation/test_doc.json b/translation/test_doc.json deleted file mode 100644 index 846a011..0000000 --- a/translation/test_doc.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "HI1Message" : { - "Header" : 45, - "Payload" : { - "RequestPayload" : "oops" - } - } -} \ No newline at end of file diff --git a/translation/test_json.py b/translation/test_json.py deleted file mode 100644 index 6d0cb70..0000000 --- a/translation/test_json.py +++ /dev/null @@ -1,18 +0,0 @@ -import jsonschema -import json - -def getJson(filename): - with open(filename) as f: - j = json.load(f) - return j - - -schema = getJson('test_schema.json') -instance = getJson('test_doc.json') - -store = { - "core" : schema, - "common.json" : getJson('common.json') -} -resolver = jsonschema.RefResolver("", "", store) -jsonschema.validate(instance, schema, resolver=resolver) \ No newline at end of file diff --git a/translation/test_schema.json b/translation/test_schema.json deleted file mode 100644 index b2ed4f7..0000000 --- a/translation/test_schema.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "$id" : "core", - - "oneOf" : [ - { - "type" : "object", - "properties": { - "HI1Message": { "$ref": "#/$defs/HI1Message" } - }, - "required": ["HI1Message"] - } - ], - - "$defs": { - "HI1Message" : { - "type" : "object", - "properties" : { - "Header" : { "$ref" : "./common.json#/$defs/ObjectIdentifier"}, - "Payload" : { "$ref" : "#/$defs/MessagePayload"} - }, - "required" : ["Header", "Payload"] - }, - "MessagePayload" : { - "oneOf" : [ - { - "type" : "object", - "properties" : { "RequestPayload" : { "type" : "integer"} }, - "required" : ["RequestPayload"] - }, - { - "type" : "object", - "properties" : { "ResponsePayload" : { "type" : "string"} }, - "required" : ["ResponsePayload"] - } - ] - } - } -} \ No newline at end of file diff --git a/translation/translate_120.py b/translation/translate_120.py index 9f74378..5d4b2ab 100644 --- a/translation/translate_120.py +++ b/translation/translate_120.py @@ -23,78 +23,75 @@ def build_schema_locations (paths): print (" [ {0} failed to parse: {1} ]".format(schemaFile, ex)) return schema_locations -def get_json(filename): - with open(filename) as f: - j = json.load(f) - return j + if __name__ == "__main__": - if len(sys.argv) > 1 and sys.argv[1] == "rebuild": - schema_paths = [ "103120/schema/ts_103120_Authorisation.xsd", - "103120/schema/ts_103120_Common.xsd", - "103120/schema/ts_103120_Core.xsd", - "103120/schema/ts_103120_Delivery.xsd", - "103120/schema/ts_103120_Document.xsd", - "103120/schema/ts_103120_Notification.xsd", - "103120/schema/ts_103120_Task.xsd", - "103280/TS_103_280.xsd", - "testing/deps/xmldsig/xmldsig-core-schema.xsd"] - - schema_locations = build_schema_locations(schema_paths) - - ns_to_id_map = { - schema[0]: schema[0].split('/')[-1].lower() + ".json" - for schema in schema_locations if '03120' in schema[0] - } | { - 'http://uri.etsi.org/03280/common/2017/07' : 'etsi103280.json', - 'http://www.w3.org/2000/09/xmldsig#' : 'xmldsig.json', - } - - # js = translate_schema("103280/TS_103_280.xsd", "103120.json") - # print(json.dumps(js, indent=2)) - - output_path = Path('json/') - if not output_path.exists(): - os.mkdir(str(output_path)) - - json_schemas = {} - for schema_tuple in schema_locations: - if 'xmldsig' in (schema_tuple[1]): - continue - js = translate_schema(schema_tuple[1], ns_to_id_map, schema_locations) - if ns_to_id_map[schema_tuple[0]] == 'core.json': - js['$defs']['HI1Message']['properties'].pop('Signature') - js_path = output_path / ns_to_id_map[schema_tuple[0]] - - if "Core" in schema_tuple[1]: - js["$defs"]['OneOfHI1Object'] = { - 'oneOf' : [ - {'$ref' : 'authorisation.json#/$defs/AuthorisationObject'}, - {'$ref' : 'task.json#/$defs/LITaskObject'}, - {'$ref' : 'task.json#/$defs/LDTaskObject'}, - {'$ref' : 'document.json#/$defs/DocumentObject'}, - {'$ref' : 'notification.json#/$defs/NotificationObject'}, - ] - } - - json_string = json.dumps(js, indent=2) - - if "Core" in schema_tuple[1]: - json_string = json_string.replace('"$ref": "#/$defs/HI1Object"', '"$ref": "#/$defs/OneOfHI1Object"') + schema_paths = [ "103120/schema/ts_103120_Authorisation.xsd", + "103120/schema/ts_103120_Common.xsd", + "103120/schema/ts_103120_Core.xsd", + "103120/schema/ts_103120_Delivery.xsd", + "103120/schema/ts_103120_Document.xsd", + "103120/schema/ts_103120_Notification.xsd", + "103120/schema/ts_103120_Task.xsd", + "103280/TS_103_280.xsd", + "testing/deps/xmldsig/xmldsig-core-schema.xsd"] + + schema_locations = build_schema_locations(schema_paths) + + ns_to_id_map = { + schema[0]: "TS_103_120_" + schema[0].split('/')[-1].lower() + ".json" + for schema in schema_locations if '03120' in schema[0] + } | { + 'http://uri.etsi.org/03280/common/2017/07' : 'etsi103280.json', + 'http://www.w3.org/2000/09/xmldsig#' : 'xmldsig.json', + } + + # js = translate_schema("103280/TS_103_280.xsd", "103120.json") + # print(json.dumps(js, indent=2)) + output_path = Path('103120/json_schema') + if not output_path.exists(): + os.mkdir(str(output_path)) + + json_schemas = {} + for schema_tuple in schema_locations: + if 'xmldsig' in (schema_tuple[1]): + continue + js = translate_schema(schema_tuple[1], ns_to_id_map, schema_locations) + if ns_to_id_map[schema_tuple[0]] == 'core.json': + js['$defs']['HI1Message']['properties'].pop('Signature') + js_path = output_path / ns_to_id_map[schema_tuple[0]] + + if "Core" in schema_tuple[1]: + js["$defs"]['OneOfHI1Object'] = { + 'oneOf' : [ + {'$ref' : 'TS_103_120_authorisation.json#/$defs/AuthorisationObject'}, + {'$ref' : 'TS_103_120_task.json#/$defs/LITaskObject'}, + {'$ref' : 'TS_103_120_task.json#/$defs/LDTaskObject'}, + {'$ref' : 'TS_103_120_document.json#/$defs/DocumentObject'}, + {'$ref' : 'TS_103_120_notification.json#/$defs/NotificationObject'}, + ] + } + + json_string = json.dumps(js, indent=2) + + if "Core" in schema_tuple[1]: + json_string = json_string.replace('"$ref": "#/$defs/HI1Object"', '"$ref": "#/$defs/OneOfHI1Object"') + + if "TS_103_120" in str(js_path): with open(str(js_path), 'w') as f: f.write(json_string) - json_schemas[js['$id']] = json.loads(json_string) - else: - json_schemas = {} - json_path = Path('json/') - for json_file in json_path.glob("*.json"): - json_schemas[json_file.name] = get_json(json_file) + # json_schemas[js['$id']] = json.loads(json_string) + # else: + # json_schemas = {} + # json_path = Path('103120/json_schema') + # for json_file in json_path.glob("*.json"): + # json_schemas[json_file.name] = get_json(json_file) - resolver = jsonschema.RefResolver("", "", json_schemas) + # resolver = jsonschema.RefResolver("", "", json_schemas) - instance = get_json("120.json") - schema = json_schemas['core.json'] - jsonschema.validate(instance, schema, resolver=resolver) + # instance = get_json("120.json") + # schema = json_schemas['core.json'] + # jsonschema.validate(instance, schema, resolver=resolver) - # print(json.dumps(js, indent=2)) + # # print(json.dumps(js, indent=2)) -- GitLab From b64e84734d3334fd4726266aa366acef444b4655 Mon Sep 17 00:00:00 2001 From: mark Date: Wed, 15 Jun 2022 16:32:30 +0100 Subject: [PATCH 11/20] Adding schema (translation code will be left in cr/103120/025 for now) --- 103280/TS_103_280.json | 384 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 384 insertions(+) create mode 100644 103280/TS_103_280.json diff --git a/103280/TS_103_280.json b/103280/TS_103_280.json new file mode 100644 index 0000000..09457bd --- /dev/null +++ b/103280/TS_103_280.json @@ -0,0 +1,384 @@ +{ + "$id": "etsi103280.json", + "$defs": { + "ShortString": { + "type": "string", + "maxLength": 255 + }, + "LongString": { + "type": "string", + "maxLength": 65535 + }, + "LIID": { + "type": "string", + "pattern": "^([!-~]{1,25})|([0-9a-f]{26,50})$" + }, + "UTCDateTime": { + "type": "string", + "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$" + }, + "UTCMicrosecondDateTime": { + "type": "string", + "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{6}Z$" + }, + "QualifiedDateTime": { + "type": "string", + "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(Z|[+-][0-9]{2}:[0-9]{2})$" + }, + "QualifiedMicrosecondDateTime": { + "type": "string", + "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{6}(Z|[+-][0-9]{2}:[0-9]{2})$" + }, + "InternationalE164": { + "type": "string", + "pattern": "^[0-9]{1,15}$" + }, + "IMSI": { + "type": "string", + "pattern": "^[0-9]{6,15}$" + }, + "IMEI": { + "type": "string", + "pattern": "^[0-9]{14}$" + }, + "IMEICheckDigit": { + "type": "string", + "pattern": "^[0-9]{15}$" + }, + "IMEISV": { + "type": "string", + "pattern": "^[0-9]{16}$" + }, + "IPv4Address": { + "type": "string", + "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])$" + }, + "IPv4CIDR": { + "type": "string", + "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])/([1-2]?[0-9]|3[0-2])$" + }, + "IPv6Address": { + "type": "string", + "pattern": "^([0-9a-f]{4}:){7}([0-9a-f]{4})$" + }, + "IPv6CIDR": { + "type": "string", + "pattern": "^([0-9a-f]{4}:){7}([0-9a-f]{4})/(([1-9][0-9]?)|(1[0-1][0-9])|(12[0-8]))$" + }, + "TCPPort": { + "type": "integer", + "exclusiveMinimum": 1, + "maximum": 65535 + }, + "UDPPort": { + "type": "integer", + "minimum": 0, + "maximum": 65535 + }, + "MACAddress": { + "type": "string", + "pattern": "^([a-f0-9]{2}:){5}[a-f0-9]{2}$" + }, + "EmailAddress": { + "allOf": [ + { + "$ref": "#/$defs/ShortString" + }, + { + "type": "string", + "pattern": "^[a-zA-Z0-9\\.!#$%&'\\*\\+\\\\/=\\?\\^_`\\{\\|\\}~\\-]+@[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$" + } + ] + }, + "UUID": { + "type": "string", + "pattern": "^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$" + }, + "ISOCountryCode": { + "type": "string", + "pattern": "^[A-Z]{2}$" + }, + "SIPURI": { + "type": "string", + "pattern": "^sips?:[a-zA-Z0-9!#$&-;=?-\\[\\]_~%]+$" + }, + "TELURI": { + "type": "string", + "pattern": "^tel:[a-zA-Z0-9!#$&-;=?-\\[\\]_~%]+$" + }, + "WGS84LatitudeDecimal": { + "type": "string", + "pattern": "^[NS][0-9]{2}\\.[0-9]{6}$" + }, + "WGS84LongitudeDecimal": { + "type": "string", + "pattern": "^[EW][0-9]{3}\\.[0-9]{6}$" + }, + "WGS84LatitudeAngular": { + "type": "string", + "pattern": "^[NS][0-9]{6}\\.[0-9]{2}$" + }, + "WGS84LongitudeAngular": { + "type": "string", + "pattern": "^[EW][0-9]{7}\\.[0-9]{2}$" + }, + "SUPIIMSI": { + "$ref": "#/$defs/IMSI" + }, + "SUPINAI": { + "$ref": "#/$defs/NAI" + }, + "SUCI": { + "type": "string", + "pattern": "^([a-fA-F0-9]{2})*$" + }, + "PEIIMEI": { + "$ref": "#/$defs/IMEI" + }, + "PEIIMEICheckDigit": { + "$ref": "#/$defs/IMEICheckDigit" + }, + "PEIIMEISV": { + "$ref": "#/$defs/IMEISV" + }, + "GPSIMSISDN": { + "type": "string", + "pattern": "^[0-9]{1,15}$" + }, + "GPSINAI": { + "$ref": "#/$defs/NAI" + }, + "NAI": { + "type": "string" + }, + "LDID": { + "type": "string", + "pattern": "^([A-Z]{2}-.+-.+)$" + }, + "InternationalizedEmailAddress": { + "allOf": [ + { + "$ref": "#/$defs/ShortString" + }, + { + "type": "string", + "pattern": "^.+@.+$" + } + ] + }, + "EUI64": { + "type": "string", + "pattern": "^([a-f0-9]{2}:){7}[a-f0-9]{2}$" + }, + "CGI": { + "type": "string", + "pattern": "^[0-9]{3}-[0-9]{2,3}-[a-f0-9]{4}-[a-f0-9]{4}$" + }, + "ECGI": { + "type": "string", + "pattern": "^[0-9]{3}-[0-9]{2,3}-[a-f0-9]{7}$" + }, + "NCGI": { + "type": "string", + "pattern": "^[0-9]{3}-[0-9]{2,3}-[a-f0-9]{9}$" + }, + "ICCID": { + "type": "string", + "pattern": "^[0-9]{19,20}$" + }, + "IPAddress": { + "oneOf": [ + { + "type": "object", + "properties": { + "IPv4Address": { + "$ref": "#/$defs/IPv4Address" + } + }, + "required": [ + "IPv4Address" + ] + }, + { + "type": "object", + "properties": { + "IPv6Address": { + "$ref": "#/$defs/IPv6Address" + } + }, + "required": [ + "IPv6Address" + ] + } + ] + }, + "IPCIDR": { + "oneOf": [ + { + "type": "object", + "properties": { + "IPv4CIDR": { + "$ref": "#/$defs/IPv4CIDR" + } + }, + "required": [ + "IPv4CIDR" + ] + }, + { + "type": "object", + "properties": { + "IPv6CIDR": { + "$ref": "#/$defs/IPv6CIDR" + } + }, + "required": [ + "IPv6CIDR" + ] + } + ] + }, + "TCPPortRange": { + "type": "object", + "properties": { + "start": { + "$ref": "#/$defs/TCPPort" + }, + "end": { + "$ref": "#/$defs/TCPPort" + } + }, + "required": [ + "start", + "end" + ] + }, + "UDPPortRange": { + "type": "object", + "properties": { + "start": { + "$ref": "#/$defs/UDPPort" + }, + "end": { + "$ref": "#/$defs/UDPPort" + } + }, + "required": [ + "start", + "end" + ] + }, + "Port": { + "oneOf": [ + { + "type": "object", + "properties": { + "TCPPort": { + "$ref": "#/$defs/TCPPort" + } + }, + "required": [ + "TCPPort" + ] + }, + { + "type": "object", + "properties": { + "UDPPort": { + "$ref": "#/$defs/UDPPort" + } + }, + "required": [ + "UDPPort" + ] + } + ] + }, + "PortRange": { + "oneOf": [ + { + "type": "object", + "properties": { + "TCPPortRange": { + "$ref": "#/$defs/TCPPortRange" + } + }, + "required": [ + "TCPPortRange" + ] + }, + { + "type": "object", + "properties": { + "UDPPortRange": { + "$ref": "#/$defs/UDPPortRange" + } + }, + "required": [ + "UDPPortRange" + ] + } + ] + }, + "IPAddressPort": { + "type": "object", + "properties": { + "address": { + "$ref": "#/$defs/IPAddress" + }, + "port": { + "$ref": "#/$defs/Port" + } + }, + "required": [ + "address", + "port" + ] + }, + "IPAddressPortRange": { + "type": "object", + "properties": { + "address": { + "$ref": "#/$defs/IPAddress" + }, + "portRange": { + "$ref": "#/$defs/PortRange" + } + }, + "required": [ + "address", + "portRange" + ] + }, + "WGS84CoordinateDecimal": { + "type": "object", + "properties": { + "latitude": { + "$ref": "#/$defs/WGS84LatitudeDecimal" + }, + "longitude": { + "$ref": "#/$defs/WGS84LongitudeDecimal" + } + }, + "required": [ + "latitude", + "longitude" + ] + }, + "WGS84CoordinateAngular": { + "type": "object", + "properties": { + "latitude": { + "$ref": "#/$defs/WGS84LatitudeAngular" + }, + "longitude": { + "$ref": "#/$defs/WGS84LongitudeAngular" + } + }, + "required": [ + "latitude", + "longitude" + ] + } + } +} \ No newline at end of file -- GitLab From d8d745fd8999f152a2cb51cc285ad8be2ce19217 Mon Sep 17 00:00:00 2001 From: mark Date: Wed, 8 Jun 2022 16:25:39 +0100 Subject: [PATCH 12/20] First attempt at translation --- common.json | 7 + core.json | 558 +++++++++++++++++++++++++++++++++++++++++++++++ etsi103280.json | 11 + test.py | 189 ++++++++++++++++ test_doc.json | 8 + test_json.py | 18 ++ test_schema.json | 38 ++++ 7 files changed, 829 insertions(+) create mode 100644 common.json create mode 100644 core.json create mode 100644 etsi103280.json create mode 100644 test.py create mode 100644 test_doc.json create mode 100644 test_json.py create mode 100644 test_schema.json diff --git a/common.json b/common.json new file mode 100644 index 0000000..b32e709 --- /dev/null +++ b/common.json @@ -0,0 +1,7 @@ +{ + "$id" : "130120/common", + "$defs" : { + "ObjectIdentifier" : { "$ref" : "#/$defs/ObjectRoot"}, + "ObjectRoot" : {"type" : "integer"} + } +} \ No newline at end of file diff --git a/core.json b/core.json new file mode 100644 index 0000000..1ad2f40 --- /dev/null +++ b/core.json @@ -0,0 +1,558 @@ +{ + "$id": "core", + "oneOf": [ + { + "$ref": "#/$defs/HI1Message" + } + ], + "$defs": { + "ObjectIdentifier": { + "$ref": "etsi103280.json#/$defs/UUID" + }, + "HI1Message": { + "type": "object", + "properties": { + "Header": { + "$ref": "#/$defs/MessageHeader" + }, + "Payload": { + "$ref": "#/$defs/MessagePayload" + }, + "Signature": { + "$ref": "xmldsig.json#/$defs/SignatureType" + } + }, + "required": [ + "Header", + "Payload" + ] + }, + "MessageHeader": { + "type": "object", + "properties": { + "SenderIdentifier": { + "$ref": "#/$defs/EndpointID" + }, + "ReceiverIdentifier": { + "$ref": "#/$defs/EndpointID" + }, + "TransactionIdentifier": { + "$ref": "etsi103280.json#/$defs/UUID" + }, + "Timestamp": { + "$ref": "etsi103280.json#/$defs/QualifiedMicrosecondDateTime" + }, + "Version": { + "$ref": "#/$defs/Version" + } + }, + "required": [ + "SenderIdentifier", + "ReceiverIdentifier", + "TransactionIdentifier", + "Timestamp", + "Version" + ] + }, + "Version": { + "type": "object", + "properties": { + "ETSIVersion": { + "$ref": "common.json#/$defs/ETSIVersion" + }, + "NationalProfileOwner": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "NationalProfileVersion": { + "$ref": "etsi103280.json#/$defs/ShortString" + } + }, + "required": [ + "ETSIVersion", + "NationalProfileOwner", + "NationalProfileVersion" + ] + }, + "EndpointID": { + "type": "object", + "properties": { + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + }, + "UniqueIdentifier": { + "$ref": "etsi103280.json#/$defs/LongString" + } + }, + "required": [ + "CountryCode", + "UniqueIdentifier" + ] + }, + "MessagePayload": { + "oneOf": [ + { + "type": "object", + "properties": { + "RequestPayload": { + "$ref": "#/$defs/RequestPayload" + } + }, + "required": [ + "RequestPayload" + ] + }, + { + "type": "object", + "properties": { + "ResponsePayload": { + "$ref": "#/$defs/ResponsePayload" + } + }, + "required": [ + "ResponsePayload" + ] + } + ] + }, + "RequestPayload": { + "type": "object", + "properties": { + "ActionRequests": { + "$ref": "#/$defs/ActionRequests" + } + }, + "required": [ + "ActionRequests" + ] + }, + "ActionRequests": { + "type": "object", + "properties": { + "ActionRequest": { + "$ref": "#/$defs/ActionRequest" + } + }, + "required": [ + "ActionRequest" + ] + }, + "ResponsePayload": { + "oneOf": [ + { + "type": "object", + "properties": { + "ActionResponses": { + "$ref": "#/$defs/ActionResponses" + } + }, + "required": [ + "ActionResponses" + ] + }, + { + "type": "object", + "properties": { + "ErrorInformation": { + "$ref": "#/$defs/ActionUnsuccesfulInformation" + } + }, + "required": [ + "ErrorInformation" + ] + } + ] + }, + "ActionResponses": { + "type": "object", + "properties": { + "ActionResponse": { + "$ref": "#/$defs/ActionResponse" + } + }, + "required": [ + "ActionResponse" + ] + }, + "ActionRequest": { + "allOf": [ + { + "type": "object", + "properties": { + "ActionIdentifier": { + "type": "integer", + "minimum": 0 + } + }, + "required": [ + "ActionIdentifier" + ] + }, + { + "oneOf": [ + { + "type": "object", + "properties": { + "GET": { + "$ref": "#/$defs/GETRequest" + } + }, + "required": [ + "GET" + ] + }, + { + "type": "object", + "properties": { + "CREATE": { + "$ref": "#/$defs/CREATERequest" + } + }, + "required": [ + "CREATE" + ] + }, + { + "type": "object", + "properties": { + "UPDATE": { + "$ref": "#/$defs/UPDATERequest" + } + }, + "required": [ + "UPDATE" + ] + }, + { + "type": "object", + "properties": { + "LIST": { + "$ref": "#/$defs/LISTRequest" + } + }, + "required": [ + "LIST" + ] + }, + { + "type": "object", + "properties": { + "DELIVER": { + "$ref": "#/$defs/DELIVERRequest" + } + }, + "required": [ + "DELIVER" + ] + } + ] + } + ] + }, + "ActionResponse": { + "allOf": [ + { + "type": "object", + "properties": { + "ActionIdentifier": { + "type": "integer", + "minimum": 0 + } + }, + "required": [ + "ActionIdentifier" + ] + }, + { + "oneOf": [ + { + "type": "object", + "properties": { + "GETResponse": { + "$ref": "#/$defs/GETResponse" + } + }, + "required": [ + "GETResponse" + ] + }, + { + "type": "object", + "properties": { + "CREATEResponse": { + "$ref": "#/$defs/CREATEResponse" + } + }, + "required": [ + "CREATEResponse" + ] + }, + { + "type": "object", + "properties": { + "UPDATEResponse": { + "$ref": "#/$defs/UPDATEResponse" + } + }, + "required": [ + "UPDATEResponse" + ] + }, + { + "type": "object", + "properties": { + "LISTResponse": { + "$ref": "#/$defs/LISTResponse" + } + }, + "required": [ + "LISTResponse" + ] + }, + { + "type": "object", + "properties": { + "ErrorInformation": { + "$ref": "#/$defs/ActionUnsuccesfulInformation" + } + }, + "required": [ + "ErrorInformation" + ] + }, + { + "type": "object", + "properties": { + "DELIVERResponse": { + "$ref": "#/$defs/DELIVERResponse" + } + }, + "required": [ + "DELIVERResponse" + ] + } + ] + } + ] + }, + "GETRequest": { + "type": "object", + "properties": { + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + } + }, + "required": [ + "Identifier" + ] + }, + "GETResponse": { + "type": "object", + "properties": { + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "HI1Object" + ] + }, + "CREATERequest": { + "type": "object", + "properties": { + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "HI1Object" + ] + }, + "CREATEResponse": { + "type": "object", + "properties": { + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + }, + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "Identifier" + ] + }, + "UPDATERequest": { + "type": "object", + "properties": { + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "HI1Object" + ] + }, + "UPDATEResponse": { + "type": "object", + "properties": { + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + }, + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "Identifier" + ] + }, + "LISTRequest": { + "type": "object", + "properties": { + "ObjectType": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "LastChanged": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + } + }, + "required": [] + }, + "LISTResponse": { + "type": "object", + "properties": { + "ListResponseRecord": { + "$ref": "#/$defs/ListResponseRecord" + } + }, + "required": [] + }, + "ListResponseRecord": { + "type": "object", + "properties": { + "ObjectType": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + }, + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + }, + "OwnerIdentifier": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "Generation": { + "type": "integer", + "minimum": 0 + }, + "ExternalIdentifier": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "LastChanged": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + } + }, + "required": [ + "ObjectType", + "Identifier", + "Generation" + ] + }, + "ActionUnsuccesfulInformation": { + "type": "object", + "properties": { + "ErrorCode": { + "type": "integer", + "minimum": 0 + }, + "ErrorDescription": { + "$ref": "etsi103280.json#/$defs/LongString" + } + }, + "required": [ + "ErrorCode", + "ErrorDescription" + ] + }, + "DELIVERRequest": { + "type": "object", + "properties": { + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + }, + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "Identifier", + "HI1Object" + ] + }, + "DELIVERResponse": { + "type": "object", + "properties": { + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + } + }, + "required": [ + "Identifier" + ] + }, + "HI1Object": { + "type": "object", + "properties": { + "ObjectIdentifier": { + "$ref": "#/$defs/ObjectIdentifier" + }, + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + }, + "OwnerIdentifier": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "Generation": { + "type": "integer", + "minimum": 0 + }, + "ExternalIdentifier": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "AssociatedObjects": { + "$ref": "#/$defs/AssociatedObjects" + }, + "LastChanged": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "NationalHandlingParameters": { + "$ref": "#/$defs/NationalHandlingParameters" + } + }, + "required": [ + "ObjectIdentifier" + ] + }, + "AssociatedObjects": { + "type": "object", + "properties": { + "AssociatedObject": { + "$ref": "#/$defs/ObjectIdentifier" + } + }, + "required": [] + }, + "NationalHandlingParameters": { + "type": "object", + "properties": { + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + } + }, + "required": [ + "CountryCode" + ] + } + } +} \ No newline at end of file diff --git a/etsi103280.json b/etsi103280.json new file mode 100644 index 0000000..b6bd0ad --- /dev/null +++ b/etsi103280.json @@ -0,0 +1,11 @@ +{ + "$id" : "130120/common", + "$defs" : { + "ObjectIdentifier" : { "$ref" : "#/$defs/ObjectRoot"}, + "ObjectRoot" : {"type" : "integer"}, + "UUID" : { + "type" : "string", + "pattern" : "^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$" + } + } +} \ No newline at end of file diff --git a/test.py b/test.py new file mode 100644 index 0000000..a6b12b2 --- /dev/null +++ b/test.py @@ -0,0 +1,189 @@ +import json +import logging +from pathlib import Path +from pprint import pprint + +from xmlschema import * +from xmlschema.validators.complex_types import XsdComplexType +from xmlschema.validators.simple_types import XsdAtomicRestriction, XsdAtomicBuiltin +from xmlschema.validators.groups import * + +schemas = [ "103120/schema/ts_103120_Authorisation.xsd", + "103120/schema/ts_103120_Common.xsd", + "103120/schema/ts_103120_Delivery.xsd", + "103120/schema/ts_103120_Document.xsd", + "103120/schema/ts_103120_Notification.xsd", + "103120/schema/ts_103120_Task.xsd", + "103280/TS_103_280.xsd", + "testing/deps/xmldsig/xmldsig-core-schema.xsd"] + +schemaLocations = [] +for schemaFile in schemas: + try: + xs = XMLSchema(schemaFile, validation='skip') + schemaLocations.append((xs.target_namespace, str(Path(schemaFile).resolve()))) + print (" [ {0} -> {1} ]".format(xs.target_namespace, schemaFile)) + except XMLSchemaParseError as ex: + print (" [ {0} failed to parse: {1} ]".format(schemaFile, ex)) + +coreSchema = XMLSchema('103120/schema/ts_103120_Core.xsd', locations = schemaLocations) + +js = { + "$id" : "core", + "oneOf" : [], + "$defs" : {} +} + +ns_mappings = { + 'http://uri.etsi.org/03120/common/2019/10/Core' : 'core', + 'http://uri.etsi.org/03120/common/2016/02/Common' : 'common', + 'http://uri.etsi.org/03280/common/2017/07' : 'etsi103280', + 'http://www.w3.org/2000/09/xmldsig#' : 'xmldsig' +} + +primitive_type_mappings = { + "token" : { "type" : "string"}, + "string" : { "type" : "string"}, + "nonNegativeInteger" : { "type" : "integer", "minimum" : 0}, + "anyType" : {} +} + +def process_qname(qname): + namespace = qname[1:qname.find('}')] + token = qname[qname.find('}')+1:] + return token, namespace + +def get_type_from_elem(elem: XsdElement, local_id): + t = elem.type + ns = t.name[1:t.name.find('}')] + if (ns == "http://www.w3.org/2001/XMLSchema"): + # this should be an XSD primitive type + mapped_type = primitive_type_mappings[t.local_name] + return mapped_type + else: + # this needs to be a type in a namespace we know about + mapped_ns = ns_mappings[ns] + if (mapped_ns == local_id): + return { "$ref" : f"#/$defs/{elem.type.local_name}"} + else: + return {"$ref" : f"{mapped_ns}.json#/$defs/{elem.type.local_name}"} + +def get_ref(token, ns, context): + mapped_ns = ns_mappings[ns] + if (mapped_ns == context): + return f"#/$defs/{token}" + else: + return f"{mapped_ns}.json#/$defs/{token}" + + +for elementName, element in coreSchema.elements.items(): + print (f"Root element: {elementName} = {element}") + token, ns = process_qname(element.type.name) + js["oneOf"].append({ + '$ref' : get_ref(token, ns, 'core') + }) + + +def process_choice(choice: XsdGroup): + if choice.model != 'choice': + raise Exception(f"Wrong group type: {c.model}") + oneOf = [] + for c in choice.iter_model(): + if not (type(c) is XsdElement): + raise Exception (f"Non-element {c} encountered in choice {choice}") + t = get_type_from_elem(c, 'core') + oneOf.append({ + "type" : "object", + "properties" : { + c.local_name : t + }, + "required" : [c.local_name] + }) + return oneOf + + +def process_atomic_restriction (sctype): + r = {} + print (f" Atomic restriction: {sctype}") + token, ns = process_qname(sctype.name) + print (f" [{ns}] {token}") + print (f" Root type {sctype.root_type}") + print (f" Base type {sctype.base_type}") + print (" Facets....") + for k, f in sctype.facets.items(): + print (f" facet {k} = {f}") + print (" Validators....") + for v in list(sctype.validators): + print (f" validator {v}") + mappedType = primitive_type_mappings.get(sctype.base_type.name) + if mappedType: + r = mappedType + print (f" Found primitive mapping to {mappedType}") + if len(sctype.facets) > 0: + raise Exception("Too many facets in primitive type") + firstKey = sctype.facets.keys[0] + if (firstKey != '{http://www.w3.org/2001/XMLSchema}pattern'): + raise Exception (f"Unhandled facet {firstKey}") + pattern = sctype.facets[firstKey] + r['pattern'] = pattern.pattern + if len(sctype.validators) > 0: + raise Exception("Too many validators in primitive type") + return token, r + else: + base_token, base_ns = process_qname(sctype.base_type.name) + return token, { '$ref' : get_ref(base_token, base_ns, 'core')} + + +for typeName, sctype in coreSchema.types.items(): + print (f"Type: {typeName} = {type} ({type(sctype)}") + if type(sctype) is XsdAtomicRestriction: + token, typeDef = process_atomic_restriction(sctype) + js["$defs"][token] = typeDef + #print (dir(sctype)) + if type(sctype) is XsdComplexType: + content = sctype.content + print(f" Content {content}") + d = {} + if type(content) is XsdGroup: + if content.model == "sequence": + print (" SEQUENCE!") + d = { + 'type' : 'object', + 'properties' : {}, + 'required' : [] + } + innerChoice = None + for c in list(content.iter_model()): + print (f" > {c}") + if type(c) is XsdElement: + d['properties'][c.local_name] = get_type_from_elem(c, 'core') + if c.effective_min_occurs == 1: + d['required'].append(c.local_name) + elif type(c) is XsdGroup: + if innerChoice: + raise Exception ("Second group encountered") + if c.model != "choice": + raise Exception (f"Don't know what to do with inner {c}") + innerChoice = process_choice(c) + else: + raise Exception(f"Unknown element type {c}") + if (innerChoice): + js["$defs"][sctype.local_name] = { + 'allOf' : [ + d, + {'oneOf' : innerChoice} + ] + } + else: + js["$defs"][sctype.local_name] = d + elif content.model =="choice": + print (" CHOICE!") + oneOf = process_choice(content) + js["$defs"][sctype.local_name] = {'oneOf' : oneOf} + + else: + raise Exception(f"Unknown content type {content}") + + +pprint(js) +Path('./core.json').write_text(json.dumps(js, indent=2)) \ No newline at end of file diff --git a/test_doc.json b/test_doc.json new file mode 100644 index 0000000..846a011 --- /dev/null +++ b/test_doc.json @@ -0,0 +1,8 @@ +{ + "HI1Message" : { + "Header" : 45, + "Payload" : { + "RequestPayload" : "oops" + } + } +} \ No newline at end of file diff --git a/test_json.py b/test_json.py new file mode 100644 index 0000000..6d0cb70 --- /dev/null +++ b/test_json.py @@ -0,0 +1,18 @@ +import jsonschema +import json + +def getJson(filename): + with open(filename) as f: + j = json.load(f) + return j + + +schema = getJson('test_schema.json') +instance = getJson('test_doc.json') + +store = { + "core" : schema, + "common.json" : getJson('common.json') +} +resolver = jsonschema.RefResolver("", "", store) +jsonschema.validate(instance, schema, resolver=resolver) \ No newline at end of file diff --git a/test_schema.json b/test_schema.json new file mode 100644 index 0000000..b2ed4f7 --- /dev/null +++ b/test_schema.json @@ -0,0 +1,38 @@ +{ + "$id" : "core", + + "oneOf" : [ + { + "type" : "object", + "properties": { + "HI1Message": { "$ref": "#/$defs/HI1Message" } + }, + "required": ["HI1Message"] + } + ], + + "$defs": { + "HI1Message" : { + "type" : "object", + "properties" : { + "Header" : { "$ref" : "./common.json#/$defs/ObjectIdentifier"}, + "Payload" : { "$ref" : "#/$defs/MessagePayload"} + }, + "required" : ["Header", "Payload"] + }, + "MessagePayload" : { + "oneOf" : [ + { + "type" : "object", + "properties" : { "RequestPayload" : { "type" : "integer"} }, + "required" : ["RequestPayload"] + }, + { + "type" : "object", + "properties" : { "ResponsePayload" : { "type" : "string"} }, + "required" : ["ResponsePayload"] + } + ] + } + } +} \ No newline at end of file -- GitLab From f1d64166860fd3bc6884cd652411b095d1128c01 Mon Sep 17 00:00:00 2001 From: mark Date: Thu, 9 Jun 2022 13:33:30 +0100 Subject: [PATCH 13/20] Refactoring and making per-file --- translate.py | 14 +++ translate_schema/__init__.py | 42 +++++++ translate_schema/type_mapping.py | 185 +++++++++++++++++++++++++++++++ translate_schema/util.py | 24 ++++ 4 files changed, 265 insertions(+) create mode 100644 translate.py create mode 100644 translate_schema/__init__.py create mode 100644 translate_schema/type_mapping.py create mode 100644 translate_schema/util.py diff --git a/translate.py b/translate.py new file mode 100644 index 0000000..3891030 --- /dev/null +++ b/translate.py @@ -0,0 +1,14 @@ +import json +import logging +from pathlib import Path + +from xmlschema import * + +from translate_schema import * + +logging.basicConfig(level = logging.DEBUG) + +if __name__ == "__main__": + js = translate_schema("103280/TS_103_280.xsd", "103120.json") + print(json.dumps(js, indent=2)) + diff --git a/translate_schema/__init__.py b/translate_schema/__init__.py new file mode 100644 index 0000000..6a67a5f --- /dev/null +++ b/translate_schema/__init__.py @@ -0,0 +1,42 @@ +import logging +from numbers import Complex +from pathlib import Path + +from xmlschema import * + +from .type_mapping import * + +log = logging.getLogger() + +mappings = [ + XSDNativeSimpleTypeMapping(), + ChoiceMapping(), + SequenceMapping(), +] + +def translate_schema (schema_path, schema_id): + js = { + "$id" : schema_id, + "$defs" : {} + } + + logging.info(f"Translating schema {schema_path}") + xs = XMLSchema(schema_path, validation='lax') + logging.info(f"Schema namespace: {xs.target_namespace}" ) + + for type_name, xsd_type in xs.types.items(): + logging.info(f"Processing {type_name} : {xsd_type}") + + j = None + for mapping in mappings: + log.debug("\n----------------------------------------") + j = mapping.map(xsd_type) + if j is None: + continue + else: + break + if j is None: + raise Exception(f"Unmapped type {type_name} ({xsd_type})") + js["$defs"][xsd_type.local_name] = j + logging.debug (f"Mapped {type_name} to {j}") + return js \ No newline at end of file diff --git a/translate_schema/type_mapping.py b/translate_schema/type_mapping.py new file mode 100644 index 0000000..46c5989 --- /dev/null +++ b/translate_schema/type_mapping.py @@ -0,0 +1,185 @@ +from copy import deepcopy +import logging +from abc import ABC, abstractmethod + +from xmlschema.validators.simple_types import * +from xmlschema.validators.complex_types import * +from xmlschema.validators.groups import * +from xmlschema.validators.facets import * + +from .util import * + +log = logging.getLogger() + +class TypeMapping(ABC): + @abstractmethod + def map(self, xst : BaseXsdType): + return None + +class SimpleTypeMapping(TypeMapping): + def map(self, xst: BaseXsdType): + log.debug(f"Attempting mapping of {xst} to simple type") + if not (type(xst) is XsdAtomicRestriction): + log.debug("Type is not an XsdAtomicRestriction, giving up") + return None + return { + "$ref" : xst.base_type.name + } + +class XSDNativeSimpleTypeMapping(SimpleTypeMapping): + XSD_NS = "http://www.w3.org/2001/XMLSchema" + + XSD_TYPE_MAP = { + "string" : { "type" : "string" }, + "normalizedString" : { "type" : "string", "pattern" : "^[^\r\n\t]*$"}, + "dateTime" : { "type" : "string"}, + "token" : { "type" : "string", "pattern" : "^[^\r\n\t]*$"}, + "anyURI" : { "type" : "string" }, + + "integer" : { "type" : "integer"}, + + "hexBinary" : { "type" : "string", "pattern" : "^([a-fA-F0-9]{2})*$"} + } + + def map(self, xst: BaseXsdType): + log.debug(f"Attempting mapping of {xst} to XSD native type") + j = super().map(xst) + if j is None: + log.debug("Not a simple type, giving up") + return None + + + mapped_type = XSDNativeSimpleTypeMapping.XSD_TYPE_MAP.get(xst.base_type.local_name) + parent_type = None + if mapped_type is None: + ns = extract_namespace(xst.base_type.name) + if ns == XSDNativeSimpleTypeMapping.XSD_NS: + raise Exception (f"No mapping for xs:{xst.base_type.local_name}") + parent_type = get_ref_for(xst.base_type, xst.namespaces['']) + mapped_type = XSDNativeSimpleTypeMapping.XSD_TYPE_MAP.get(xst.root_type.local_name) + if mapped_type is None: + raise Exception (f"Could not find mapping for root type xs:{xst.root_type.local_name}") + + mapped_type = dict(mapped_type) + + for k, v in xst.facets.items(): + log.debug(f"Mapping facet {v}") + if type(v) is XsdMaxLengthFacet: + mapped_type['maxLength'] = v.value + continue + if type(v) is XsdMinLengthFacet: + mapped_type['minLength'] = v.value + continue + if type(v) is XsdPatternFacets: + if len(v.regexps) > 1: + raise Exception (f"Multiple patterns given in facet {v} of {xst}") + p = v.regexps[0] + if (not p.startswith('^')) and (not p.endswith('$')): + p = f"^{p}$" + mapped_type['pattern'] = p + continue + if type (v) is XsdMinInclusiveFacet: + mapped_type['minimum'] = v.value + continue + if type (v) is XsdMaxInclusiveFacet: + mapped_type['maximum'] = v.value + continue + if type (v) is XsdMinExclusiveFacet: + mapped_type['exclusiveMinimum'] = v.value + continue + if type (v) is XsdMaxExclusiveFacet: + mapped_type['exclusiveMaximum'] = v.value + continue + raise Exception (f"Unhandled facet {v}") + if parent_type: + return { 'allOf' : [parent_type, mapped_type] } + return mapped_type + + +class ComplexTypeMapping(TypeMapping): + def map(self, xst: BaseXsdType): + if not (type(xst) is XsdComplexType): + return None + return { + "type" : "object" + } + +def get_type_from_elem(elem: XsdElement, current_ns : str): + ns = extract_namespace(elem.type.name) + if (ns == "http://www.w3.org/2001/XMLSchema"): + # this should be an XSD primitive type + return dict(XSDNativeSimpleTypeMapping.XSD_TYPE_MAP[elem.type.local_name]) + else: + return get_ref_for(elem.type, current_ns) + + +def process_choice(choice: XsdGroup, current_ns : str): + if choice.model != 'choice': + raise Exception(f"Wrong group type: {c.model}") + oneOf = [] + for c in choice.iter_model(): + if not (type(c) is XsdElement): + raise Exception (f"Non-element {c} encountered in choice {choice}") + t = get_type_from_elem(c, current_ns) + oneOf.append({ + "type" : "object", + "properties" : { + c.local_name : t + }, + "required" : [c.local_name] + }) + return oneOf + +class ChoiceMapping(ComplexTypeMapping): + def map(self, xst : BaseXsdType): + log.debug(f"Attempting mapping of {xst} to sequence") + j = super().map(xst) + if j is None: + log.debug("Not a complex type, giving up") + return None + content = xst.content + if (content.model != 'choice'): + log.debug("Not a sequence, giving up") + return None + return { 'oneOf' : process_choice(content, xst.namespaces[''])} + +class SequenceMapping(ComplexTypeMapping): + def map(self, xst: BaseXsdType): + log.debug(f"Attempting mapping of {xst} to sequence") + j = super().map(xst) + if j is None: + log.debug("Not a complex type, giving up") + return None + content = xst.content + if (content.model != 'sequence'): + log.debug("Not a sequence, giving up") + return None + mapped_type = { + 'type' : 'object', + 'properties' : {}, + 'required' : [] + } + inner_choice = None + for c in list(content.iter_model()): + log.debug(f"Processing model item {c}") + if type(c) is XsdElement: + mapped_type['properties'][c.local_name] = get_type_from_elem(c, xst.namespaces['']) + if c.effective_min_occurs == 1: + mapped_type['required'].append(c.local_name) + elif type(c) is XsdGroup: + if inner_choice: + raise Exception (f"Second group '{c.local_name}' encountered in {xst}") + if c.model != "choice": + raise Exception (f"Don't know what to do with inner group {c} in {xst} - not a choice") + inner_choice = process_choice(c) + else: + raise Exception(f"Unknown element type {c}") + if (inner_choice): + return { + 'allOf' : [ + mapped_type, + {'oneOf' : inner_choice} + ] + } + else: + return mapped_type diff --git a/translate_schema/util.py b/translate_schema/util.py new file mode 100644 index 0000000..ce22cf3 --- /dev/null +++ b/translate_schema/util.py @@ -0,0 +1,24 @@ +import re + +from xmlschema import * + +def extract_namespace(qname: str): + match = re.search(r'^\{([^\{\}]+)\}(([^\{\}]+))$', qname) + if match is None: + return None + return match.group(1) + +NS_MAP = { + 'http://uri.etsi.org/03120/common/2019/10/Core' : 'core.json', + 'http://uri.etsi.org/03120/common/2016/02/Common' : 'common.json', + 'http://uri.etsi.org/03280/common/2017/07' : 'etsi103280.json', + 'http://www.w3.org/2000/09/xmldsig#' : 'xmldsig', +} + +def get_ref_for(xsd_type: XsdType, current_ns : str): + ns = extract_namespace(xsd_type.name) + if ns == current_ns: + return { "$ref" : f"#/$defs/{xsd_type.local_name}" } + else: + mapped_id = NS_MAP[ns] + return { "$ref" : f"{mapped_id}#/$defs/{xsd_type.local_name}"} \ No newline at end of file -- GitLab From 8cf83da7d50ba72a91c7d21aeb3a8fec7d71f655 Mon Sep 17 00:00:00 2001 From: mark Date: Fri, 10 Jun 2022 10:54:58 +0100 Subject: [PATCH 14/20] Extending mapping --- translate.py | 23 +++++++++++++++++++++-- translate_schema/__init__.py | 4 ++-- translate_schema/type_mapping.py | 25 +++++++++++++++++-------- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/translate.py b/translate.py index 3891030..7b62565 100644 --- a/translate.py +++ b/translate.py @@ -9,6 +9,25 @@ from translate_schema import * logging.basicConfig(level = logging.DEBUG) if __name__ == "__main__": - js = translate_schema("103280/TS_103_280.xsd", "103120.json") - print(json.dumps(js, indent=2)) + # js = translate_schema("103280/TS_103_280.xsd", "103120.json") + # print(json.dumps(js, indent=2)) + schemas = [ "103120/schema/ts_103120_Authorisation.xsd", + "103120/schema/ts_103120_Common.xsd", + "103120/schema/ts_103120_Delivery.xsd", + "103120/schema/ts_103120_Document.xsd", + "103120/schema/ts_103120_Notification.xsd", + "103120/schema/ts_103120_Task.xsd", + "103280/TS_103_280.xsd", + "testing/deps/xmldsig/xmldsig-core-schema.xsd"] + + schema_locations = [] + for schemaFile in schemas: + try: + xs = XMLSchema(schemaFile, validation='skip') + schema_locations.append((xs.target_namespace, str(Path(schemaFile).resolve()))) + print (" [ {0} -> {1} ]".format(xs.target_namespace, schemaFile)) + except XMLSchemaParseError as ex: + print (" [ {0} failed to parse: {1} ]".format(schemaFile, ex)) + js = translate_schema("103120/schema/ts_103120_core.xsd", "core.json", schema_locations) + print(json.dumps(js, indent=2)) diff --git a/translate_schema/__init__.py b/translate_schema/__init__.py index 6a67a5f..a4ddb4b 100644 --- a/translate_schema/__init__.py +++ b/translate_schema/__init__.py @@ -14,14 +14,14 @@ mappings = [ SequenceMapping(), ] -def translate_schema (schema_path, schema_id): +def translate_schema (schema_path, schema_id, schema_locations = []): js = { "$id" : schema_id, "$defs" : {} } logging.info(f"Translating schema {schema_path}") - xs = XMLSchema(schema_path, validation='lax') + xs = XMLSchema(schema_path, validation='lax', locations=schema_locations) logging.info(f"Schema namespace: {xs.target_namespace}" ) for type_name, xsd_type in xs.types.items(): diff --git a/translate_schema/type_mapping.py b/translate_schema/type_mapping.py index 46c5989..582e1c4 100644 --- a/translate_schema/type_mapping.py +++ b/translate_schema/type_mapping.py @@ -37,8 +37,11 @@ class XSDNativeSimpleTypeMapping(SimpleTypeMapping): "anyURI" : { "type" : "string" }, "integer" : { "type" : "integer"}, + "nonNegativeInteger" : { "type" : "integer", "minimum" : 0}, - "hexBinary" : { "type" : "string", "pattern" : "^([a-fA-F0-9]{2})*$"} + "hexBinary" : { "type" : "string", "pattern" : "^([a-fA-F0-9]{2})*$"}, + + "anyType" : {} } def map(self, xst: BaseXsdType): @@ -51,14 +54,20 @@ class XSDNativeSimpleTypeMapping(SimpleTypeMapping): mapped_type = XSDNativeSimpleTypeMapping.XSD_TYPE_MAP.get(xst.base_type.local_name) parent_type = None + if mapped_type is None: ns = extract_namespace(xst.base_type.name) if ns == XSDNativeSimpleTypeMapping.XSD_NS: + print (xst) + print (xst.base_type) raise Exception (f"No mapping for xs:{xst.base_type.local_name}") - parent_type = get_ref_for(xst.base_type, xst.namespaces['']) - mapped_type = XSDNativeSimpleTypeMapping.XSD_TYPE_MAP.get(xst.root_type.local_name) - if mapped_type is None: - raise Exception (f"Could not find mapping for root type xs:{xst.root_type.local_name}") + if len(xst.facets) == 0: + mapped_type = get_ref_for(xst.base_type, xst.namespaces['']) + else: + parent_type = get_ref_for(xst.base_type, xst.namespaces['']) + mapped_type = XSDNativeSimpleTypeMapping.XSD_TYPE_MAP.get(xst.root_type.local_name) + if mapped_type is None: + raise Exception (f"Could not find mapping for root type xs:{xst.root_type.local_name}") mapped_type = dict(mapped_type) @@ -132,14 +141,14 @@ def process_choice(choice: XsdGroup, current_ns : str): class ChoiceMapping(ComplexTypeMapping): def map(self, xst : BaseXsdType): - log.debug(f"Attempting mapping of {xst} to sequence") + log.debug(f"Attempting mapping of {xst} to choice") j = super().map(xst) if j is None: log.debug("Not a complex type, giving up") return None content = xst.content if (content.model != 'choice'): - log.debug("Not a sequence, giving up") + log.debug("Not a choice, giving up") return None return { 'oneOf' : process_choice(content, xst.namespaces[''])} @@ -171,7 +180,7 @@ class SequenceMapping(ComplexTypeMapping): raise Exception (f"Second group '{c.local_name}' encountered in {xst}") if c.model != "choice": raise Exception (f"Don't know what to do with inner group {c} in {xst} - not a choice") - inner_choice = process_choice(c) + inner_choice = process_choice(c, xst.namespaces['']) else: raise Exception(f"Unknown element type {c}") if (inner_choice): -- GitLab From 0ea0683ff9d001e129636f548bf9342ac2771487 Mon Sep 17 00:00:00 2001 From: mark Date: Fri, 10 Jun 2022 15:51:43 +0100 Subject: [PATCH 15/20] First working auto-translation --- 120.json | 31 ++ json/authorisation.json | 126 +++++++ json/common.json | 161 +++++++++ json/core.json | 551 ++++++++++++++++++++++++++++++ json/delivery.json | 204 ++++++++++++ json/document.json | 137 ++++++++ json/etsi103280.json | 384 +++++++++++++++++++++ json/notification.json | 64 ++++ json/task.json | 499 ++++++++++++++++++++++++++++ json/xmldsig.json | 553 +++++++++++++++++++++++++++++++ translate.py | 80 ++++- translate_schema/__init__.py | 18 +- translate_schema/type_mapping.py | 87 +++-- translate_schema/util.py | 20 -- 14 files changed, 2847 insertions(+), 68 deletions(-) create mode 100644 120.json create mode 100644 json/authorisation.json create mode 100644 json/common.json create mode 100644 json/core.json create mode 100644 json/delivery.json create mode 100644 json/document.json create mode 100644 json/etsi103280.json create mode 100644 json/notification.json create mode 100644 json/task.json create mode 100644 json/xmldsig.json diff --git a/120.json b/120.json new file mode 100644 index 0000000..9a4e178 --- /dev/null +++ b/120.json @@ -0,0 +1,31 @@ +{ + "Header" : { + "SenderIdentifier" : { + "CountryCode" : "XX", + "UniqueIdentifier" : "ACTOR01" + }, + "ReceiverIdentifier" : { + "CountryCode" : "YY", + "UniqueIdentifier" : "ACTOR02" + }, + "TransactionIdentifier" : "c4a09046-61da-485b-83f2-ca12caebf40b", + "Timestamp" : "2022-06-10T15:50:00.000000Z", + "Version" : { + "ETSIVersion" : "V1.11.2", + "NationalProfileOwner" : "NA", + "NationalProfileVersion" : "NA" + } + }, + "Payload" : { + "ResponsePayload" : { + "ActionResponses" : { + "ActionResponse" : { + "ActionIdentifier" : 0, + "CREATEResponse" : { + "Identifier" : "f25dec16-927c-433b-959c-1886182cac58" + } + } + } + } + } +} \ No newline at end of file diff --git a/json/authorisation.json b/json/authorisation.json new file mode 100644 index 0000000..8b1facb --- /dev/null +++ b/json/authorisation.json @@ -0,0 +1,126 @@ +{ + "$id": "authorisation.json", + "$defs": { + "AuthorisationObject": { + "type": "object", + "properties": { + "ObjectIdentifier": { + "$ref": "core.json#/$defs/ObjectIdentifier" + }, + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + }, + "OwnerIdentifier": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "Generation": { + "type": "integer", + "minimum": 0 + }, + "ExternalIdentifier": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "AssociatedObjects": { + "$ref": "core.json#/$defs/AssociatedObjects" + }, + "LastChanged": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "NationalHandlingParameters": { + "$ref": "core.json#/$defs/NationalHandlingParameters" + }, + "AuthorisationReference": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "AuthorisationLegalType": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "AuthorisationPriority": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "AuthorisationStatus": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "AuthorisationDesiredStatus": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "AuthorisationTimespan": { + "$ref": "#/$defs/AuthorisationTimespan" + }, + "AuthorisationCSPID": { + "$ref": "#/$defs/AuthorisationCSPID" + }, + "AuthorisationCreationTimestamp": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "AuthorisationServedTimestamp": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "AuthorisationTerminationTimestamp": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "AuthorisationApprovalDetails": { + "$ref": "common.json#/$defs/ApprovalDetails" + }, + "AuthorisationInvalidReason": { + "$ref": "core.json#/$defs/ActionUnsuccesfulInformation" + }, + "AuthorisationFlags": { + "$ref": "#/$defs/AuthorisationFlags" + }, + "AuthorisationManualInformation": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "NationalAuthorisationParameters": { + "$ref": "#/$defs/NationalAuthorisationParameters" + } + }, + "required": [ + "ObjectIdentifier" + ] + }, + "AuthorisationFlags": { + "type": "object", + "properties": { + "AuthorisationFlag": { + "$ref": "common.json#/$defs/DictionaryEntry" + } + }, + "required": [] + }, + "AuthorisationTimespan": { + "type": "object", + "properties": { + "StartTime": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "EndTime": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + } + }, + "required": [] + }, + "AuthorisationCSPID": { + "type": "object", + "properties": { + "CSPID": { + "$ref": "core.json#/$defs/EndpointID" + } + }, + "required": [ + "CSPID" + ] + }, + "NationalAuthorisationParameters": { + "type": "object", + "properties": { + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + } + }, + "required": [ + "CountryCode" + ] + } + } +} \ No newline at end of file diff --git a/json/common.json b/json/common.json new file mode 100644 index 0000000..00a7c13 --- /dev/null +++ b/json/common.json @@ -0,0 +1,161 @@ +{ + "$id": "common.json", + "$defs": { + "ETSIVersion": { + "allOf": [ + { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + { + "type": "string", + "pattern": "^V\\d+\\.\\d+\\.\\d+$" + } + ] + }, + "DictionaryEntry": { + "type": "object", + "properties": { + "Owner": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "Name": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "Value": { + "$ref": "etsi103280.json#/$defs/ShortString" + } + }, + "required": [ + "Owner", + "Name", + "Value" + ] + }, + "ApprovalDetails": { + "type": "object", + "properties": { + "ApprovalType": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "ApprovalDescription": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "ApprovalReference": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "ApproverDetails": { + "$ref": "#/$defs/ApproverDetails" + }, + "ApprovalTimestamp": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "ApprovalIsEmergency": { + "type": "boolean" + }, + "ApprovalDigitalSignature": { + "$ref": "#/$defs/ApprovalDigitalSignature" + }, + "ApprovalNationalDetails": { + "$ref": "#/$defs/ApprovalNationalDetails" + } + }, + "required": [] + }, + "ApproverDetails": { + "type": "object", + "properties": { + "ApproverName": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "ApproverRole": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "ApproverIdentity": { + "$ref": "#/$defs/ApproverIdentity" + }, + "ApproverContactDetails": { + "$ref": "#/$defs/ApproverContactDetails" + } + }, + "required": [] + }, + "ApproverIdentity": { + "oneOf": [ + { + "type": "object", + "properties": { + "NationalApproverIdentity": { + "$ref": "#/$defs/NationalApproverIdentity" + } + }, + "required": [ + "NationalApproverIdentity" + ] + } + ] + }, + "ApproverContactDetails": { + "type": "object", + "properties": { + "ApproverAlternateName": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "ApproverEmailAddress": { + "$ref": "etsi103280.json#/$defs/InternationalizedEmailAddress" + }, + "ApproverPhoneNumber": { + "$ref": "etsi103280.json#/$defs/InternationalE164" + } + }, + "required": [] + }, + "NationalApproverIdentity": { + "type": "object", + "properties": { + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + } + }, + "required": [ + "CountryCode" + ] + }, + "ApprovalDigitalSignature": { + "oneOf": [ + { + "type": "object", + "properties": { + "NationalDigitalSignature": { + "$ref": "#/$defs/NationalDigitalSignature" + } + }, + "required": [ + "NationalDigitalSignature" + ] + } + ] + }, + "ApprovalNationalDetails": { + "type": "object", + "properties": { + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + } + }, + "required": [ + "CountryCode" + ] + }, + "NationalDigitalSignature": { + "type": "object", + "properties": { + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + } + }, + "required": [ + "CountryCode" + ] + } + } +} \ No newline at end of file diff --git a/json/core.json b/json/core.json new file mode 100644 index 0000000..67e1ca3 --- /dev/null +++ b/json/core.json @@ -0,0 +1,551 @@ +{ + "$id": "core.json", + "$defs": { + "ObjectIdentifier": { + "$ref": "etsi103280.json#/$defs/UUID" + }, + "HI1Message": { + "type": "object", + "properties": { + "Header": { + "$ref": "#/$defs/MessageHeader" + }, + "Payload": { + "$ref": "#/$defs/MessagePayload" + } + }, + "required": [ + "Header", + "Payload" + ] + }, + "MessageHeader": { + "type": "object", + "properties": { + "SenderIdentifier": { + "$ref": "#/$defs/EndpointID" + }, + "ReceiverIdentifier": { + "$ref": "#/$defs/EndpointID" + }, + "TransactionIdentifier": { + "$ref": "etsi103280.json#/$defs/UUID" + }, + "Timestamp": { + "$ref": "etsi103280.json#/$defs/QualifiedMicrosecondDateTime" + }, + "Version": { + "$ref": "#/$defs/Version" + } + }, + "required": [ + "SenderIdentifier", + "ReceiverIdentifier", + "TransactionIdentifier", + "Timestamp", + "Version" + ] + }, + "Version": { + "type": "object", + "properties": { + "ETSIVersion": { + "$ref": "common.json#/$defs/ETSIVersion" + }, + "NationalProfileOwner": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "NationalProfileVersion": { + "$ref": "etsi103280.json#/$defs/ShortString" + } + }, + "required": [ + "ETSIVersion", + "NationalProfileOwner", + "NationalProfileVersion" + ] + }, + "EndpointID": { + "type": "object", + "properties": { + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + }, + "UniqueIdentifier": { + "$ref": "etsi103280.json#/$defs/LongString" + } + }, + "required": [ + "CountryCode", + "UniqueIdentifier" + ] + }, + "MessagePayload": { + "oneOf": [ + { + "type": "object", + "properties": { + "RequestPayload": { + "$ref": "#/$defs/RequestPayload" + } + }, + "required": [ + "RequestPayload" + ] + }, + { + "type": "object", + "properties": { + "ResponsePayload": { + "$ref": "#/$defs/ResponsePayload" + } + }, + "required": [ + "ResponsePayload" + ] + } + ] + }, + "RequestPayload": { + "type": "object", + "properties": { + "ActionRequests": { + "$ref": "#/$defs/ActionRequests" + } + }, + "required": [ + "ActionRequests" + ] + }, + "ActionRequests": { + "type": "object", + "properties": { + "ActionRequest": { + "$ref": "#/$defs/ActionRequest" + } + }, + "required": [ + "ActionRequest" + ] + }, + "ResponsePayload": { + "oneOf": [ + { + "type": "object", + "properties": { + "ActionResponses": { + "$ref": "#/$defs/ActionResponses" + } + }, + "required": [ + "ActionResponses" + ] + }, + { + "type": "object", + "properties": { + "ErrorInformation": { + "$ref": "#/$defs/ActionUnsuccesfulInformation" + } + }, + "required": [ + "ErrorInformation" + ] + } + ] + }, + "ActionResponses": { + "type": "object", + "properties": { + "ActionResponse": { + "$ref": "#/$defs/ActionResponse" + } + }, + "required": [ + "ActionResponse" + ] + }, + "ActionRequest": { + "allOf": [ + { + "type": "object", + "properties": { + "ActionIdentifier": { + "type": "integer", + "minimum": 0 + } + }, + "required": [ + "ActionIdentifier" + ] + }, + { + "oneOf": [ + { + "type": "object", + "properties": { + "GET": { + "$ref": "#/$defs/GETRequest" + } + }, + "required": [ + "GET" + ] + }, + { + "type": "object", + "properties": { + "CREATE": { + "$ref": "#/$defs/CREATERequest" + } + }, + "required": [ + "CREATE" + ] + }, + { + "type": "object", + "properties": { + "UPDATE": { + "$ref": "#/$defs/UPDATERequest" + } + }, + "required": [ + "UPDATE" + ] + }, + { + "type": "object", + "properties": { + "LIST": { + "$ref": "#/$defs/LISTRequest" + } + }, + "required": [ + "LIST" + ] + }, + { + "type": "object", + "properties": { + "DELIVER": { + "$ref": "#/$defs/DELIVERRequest" + } + }, + "required": [ + "DELIVER" + ] + } + ] + } + ] + }, + "ActionResponse": { + "allOf": [ + { + "type": "object", + "properties": { + "ActionIdentifier": { + "type": "integer", + "minimum": 0 + } + }, + "required": [ + "ActionIdentifier" + ] + }, + { + "oneOf": [ + { + "type": "object", + "properties": { + "GETResponse": { + "$ref": "#/$defs/GETResponse" + } + }, + "required": [ + "GETResponse" + ] + }, + { + "type": "object", + "properties": { + "CREATEResponse": { + "$ref": "#/$defs/CREATEResponse" + } + }, + "required": [ + "CREATEResponse" + ] + }, + { + "type": "object", + "properties": { + "UPDATEResponse": { + "$ref": "#/$defs/UPDATEResponse" + } + }, + "required": [ + "UPDATEResponse" + ] + }, + { + "type": "object", + "properties": { + "LISTResponse": { + "$ref": "#/$defs/LISTResponse" + } + }, + "required": [ + "LISTResponse" + ] + }, + { + "type": "object", + "properties": { + "ErrorInformation": { + "$ref": "#/$defs/ActionUnsuccesfulInformation" + } + }, + "required": [ + "ErrorInformation" + ] + }, + { + "type": "object", + "properties": { + "DELIVERResponse": { + "$ref": "#/$defs/DELIVERResponse" + } + }, + "required": [ + "DELIVERResponse" + ] + } + ] + } + ] + }, + "GETRequest": { + "type": "object", + "properties": { + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + } + }, + "required": [ + "Identifier" + ] + }, + "GETResponse": { + "type": "object", + "properties": { + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "HI1Object" + ] + }, + "CREATERequest": { + "type": "object", + "properties": { + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "HI1Object" + ] + }, + "CREATEResponse": { + "type": "object", + "properties": { + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + }, + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "Identifier" + ] + }, + "UPDATERequest": { + "type": "object", + "properties": { + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "HI1Object" + ] + }, + "UPDATEResponse": { + "type": "object", + "properties": { + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + }, + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "Identifier" + ] + }, + "LISTRequest": { + "type": "object", + "properties": { + "ObjectType": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "LastChanged": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + } + }, + "required": [] + }, + "LISTResponse": { + "type": "object", + "properties": { + "ListResponseRecord": { + "$ref": "#/$defs/ListResponseRecord" + } + }, + "required": [] + }, + "ListResponseRecord": { + "type": "object", + "properties": { + "ObjectType": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + }, + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + }, + "OwnerIdentifier": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "Generation": { + "type": "integer", + "minimum": 0 + }, + "ExternalIdentifier": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "LastChanged": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + } + }, + "required": [ + "ObjectType", + "Identifier", + "Generation" + ] + }, + "ActionUnsuccesfulInformation": { + "type": "object", + "properties": { + "ErrorCode": { + "type": "integer", + "minimum": 0 + }, + "ErrorDescription": { + "$ref": "etsi103280.json#/$defs/LongString" + } + }, + "required": [ + "ErrorCode", + "ErrorDescription" + ] + }, + "DELIVERRequest": { + "type": "object", + "properties": { + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + }, + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "Identifier", + "HI1Object" + ] + }, + "DELIVERResponse": { + "type": "object", + "properties": { + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + } + }, + "required": [ + "Identifier" + ] + }, + "HI1Object": { + "type": "object", + "properties": { + "ObjectIdentifier": { + "$ref": "#/$defs/ObjectIdentifier" + }, + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + }, + "OwnerIdentifier": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "Generation": { + "type": "integer", + "minimum": 0 + }, + "ExternalIdentifier": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "AssociatedObjects": { + "$ref": "#/$defs/AssociatedObjects" + }, + "LastChanged": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "NationalHandlingParameters": { + "$ref": "#/$defs/NationalHandlingParameters" + } + }, + "required": [ + "ObjectIdentifier" + ] + }, + "AssociatedObjects": { + "type": "object", + "properties": { + "AssociatedObject": { + "$ref": "#/$defs/ObjectIdentifier" + } + }, + "required": [] + }, + "NationalHandlingParameters": { + "type": "object", + "properties": { + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + } + }, + "required": [ + "CountryCode" + ] + } + }, + "$ref": "#/$defs/HI1Message" +} \ No newline at end of file diff --git a/json/delivery.json b/json/delivery.json new file mode 100644 index 0000000..7aef09a --- /dev/null +++ b/json/delivery.json @@ -0,0 +1,204 @@ +{ + "$id": "delivery.json", + "$defs": { + "DeliveryObject": { + "type": "object", + "properties": { + "ObjectIdentifier": { + "$ref": "core.json#/$defs/ObjectIdentifier" + }, + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + }, + "OwnerIdentifier": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "Generation": { + "type": "integer", + "minimum": 0 + }, + "ExternalIdentifier": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "AssociatedObjects": { + "$ref": "core.json#/$defs/AssociatedObjects" + }, + "LastChanged": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "NationalHandlingParameters": { + "$ref": "core.json#/$defs/NationalHandlingParameters" + }, + "Reference": { + "$ref": "#/$defs/Reference" + }, + "DeliveryID": { + "$ref": "etsi103280.json#/$defs/UUID" + }, + "SequenceNumber": { + "type": "integer", + "minimum": 0 + }, + "LastSequence": { + "type": "boolean" + }, + "Manifest": { + "$ref": "#/$defs/Manifest" + }, + "Delivery": { + "$ref": "#/$defs/Delivery" + } + }, + "required": [ + "ObjectIdentifier" + ] + }, + "Reference": { + "oneOf": [ + { + "type": "object", + "properties": { + "LDID": { + "$ref": "etsi103280.json#/$defs/LDID" + } + }, + "required": [ + "LDID" + ] + }, + { + "type": "object", + "properties": { + "LIID": { + "$ref": "etsi103280.json#/$defs/LIID" + } + }, + "required": [ + "LIID" + ] + } + ] + }, + "Manifest": { + "oneOf": [ + { + "type": "object", + "properties": { + "Specification": { + "$ref": "common.json#/$defs/DictionaryEntry" + } + }, + "required": [ + "Specification" + ] + }, + { + "type": "object", + "properties": { + "ExternalSchema": { + "$ref": "#/$defs/ExternalSchema" + } + }, + "required": [ + "ExternalSchema" + ] + } + ] + }, + "ExternalSchema": { + "type": "object", + "properties": { + "ManifestID": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "ManifestContents": { + "$ref": "#/$defs/ManifestContents" + } + }, + "required": [] + }, + "ManifestContents": { + "oneOf": [ + { + "type": "object", + "properties": { + "BinaryData": { + "$ref": "#/$defs/EmbeddedBinaryData" + } + }, + "required": [ + "BinaryData" + ] + }, + { + "type": "object", + "properties": { + "XMLSchema": { + "$ref": "#/$defs/SchemaContent" + } + }, + "required": [ + "XMLSchema" + ] + } + ] + }, + "SchemaContent": { + "type": "object", + "properties": { + "schema": {} + }, + "required": [ + "schema" + ] + }, + "Delivery": { + "oneOf": [ + { + "type": "object", + "properties": { + "BinaryData": { + "$ref": "#/$defs/EmbeddedBinaryData" + } + }, + "required": [ + "BinaryData" + ] + }, + { + "type": "object", + "properties": { + "XMLData": { + "$ref": "#/$defs/EmbeddedXMLData" + } + }, + "required": [ + "XMLData" + ] + } + ] + }, + "EmbeddedBinaryData": { + "type": "object", + "properties": { + "Data": { + "type": "string", + "pattern": "^[-A-Za-z0-9+/]*={0,3}$" + }, + "ContentType": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "Checksum": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "ChecksumType": { + "$ref": "etsi103280.json#/$defs/ShortString" + } + }, + "required": [ + "Data" + ] + }, + "EmbeddedXMLData": {} + } +} \ No newline at end of file diff --git a/json/document.json b/json/document.json new file mode 100644 index 0000000..6f6f493 --- /dev/null +++ b/json/document.json @@ -0,0 +1,137 @@ +{ + "$id": "document.json", + "$defs": { + "DocumentObject": { + "type": "object", + "properties": { + "ObjectIdentifier": { + "$ref": "core.json#/$defs/ObjectIdentifier" + }, + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + }, + "OwnerIdentifier": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "Generation": { + "type": "integer", + "minimum": 0 + }, + "ExternalIdentifier": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "AssociatedObjects": { + "$ref": "core.json#/$defs/AssociatedObjects" + }, + "LastChanged": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "NationalHandlingParameters": { + "$ref": "core.json#/$defs/NationalHandlingParameters" + }, + "DocumentReference": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "DocumentName": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "DocumentStatus": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "DocumentDesiredStatus": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "DocumentTimespan": { + "$ref": "#/$defs/DocumentTimespan" + }, + "DocumentType": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "DocumentProperties": { + "$ref": "#/$defs/DocumentProperties" + }, + "DocumentBody": { + "$ref": "#/$defs/DocumentBody" + }, + "DocumentSignature": { + "$ref": "common.json#/$defs/ApprovalDetails" + }, + "DocumentInvalidReason": { + "$ref": "core.json#/$defs/ActionUnsuccesfulInformation" + }, + "NationalDocumentParameters": { + "$ref": "#/$defs/NationalDocumentParameters" + } + }, + "required": [ + "ObjectIdentifier" + ] + }, + "DocumentTimespan": { + "type": "object", + "properties": { + "StartTime": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "EndTime": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + } + }, + "required": [] + }, + "DocumentProperties": { + "type": "object", + "properties": { + "DocumentProperty": { + "$ref": "#/$defs/DocumentProperty" + } + }, + "required": [] + }, + "DocumentProperty": { + "type": "object", + "properties": { + "PropertyType": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "PropertyValue": { + "$ref": "etsi103280.json#/$defs/LongString" + } + }, + "required": [ + "PropertyType", + "PropertyValue" + ] + }, + "DocumentBody": { + "type": "object", + "properties": { + "Contents": { + "type": "string", + "pattern": "^[-A-Za-z0-9+/]*={0,3}$" + }, + "ContentType": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "Checksum": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "ChecksumType": { + "$ref": "etsi103280.json#/$defs/ShortString" + } + }, + "required": [] + }, + "NationalDocumentParameters": { + "type": "object", + "properties": { + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + } + }, + "required": [ + "CountryCode" + ] + } + } +} \ No newline at end of file diff --git a/json/etsi103280.json b/json/etsi103280.json new file mode 100644 index 0000000..09457bd --- /dev/null +++ b/json/etsi103280.json @@ -0,0 +1,384 @@ +{ + "$id": "etsi103280.json", + "$defs": { + "ShortString": { + "type": "string", + "maxLength": 255 + }, + "LongString": { + "type": "string", + "maxLength": 65535 + }, + "LIID": { + "type": "string", + "pattern": "^([!-~]{1,25})|([0-9a-f]{26,50})$" + }, + "UTCDateTime": { + "type": "string", + "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$" + }, + "UTCMicrosecondDateTime": { + "type": "string", + "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{6}Z$" + }, + "QualifiedDateTime": { + "type": "string", + "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(Z|[+-][0-9]{2}:[0-9]{2})$" + }, + "QualifiedMicrosecondDateTime": { + "type": "string", + "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{6}(Z|[+-][0-9]{2}:[0-9]{2})$" + }, + "InternationalE164": { + "type": "string", + "pattern": "^[0-9]{1,15}$" + }, + "IMSI": { + "type": "string", + "pattern": "^[0-9]{6,15}$" + }, + "IMEI": { + "type": "string", + "pattern": "^[0-9]{14}$" + }, + "IMEICheckDigit": { + "type": "string", + "pattern": "^[0-9]{15}$" + }, + "IMEISV": { + "type": "string", + "pattern": "^[0-9]{16}$" + }, + "IPv4Address": { + "type": "string", + "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])$" + }, + "IPv4CIDR": { + "type": "string", + "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])/([1-2]?[0-9]|3[0-2])$" + }, + "IPv6Address": { + "type": "string", + "pattern": "^([0-9a-f]{4}:){7}([0-9a-f]{4})$" + }, + "IPv6CIDR": { + "type": "string", + "pattern": "^([0-9a-f]{4}:){7}([0-9a-f]{4})/(([1-9][0-9]?)|(1[0-1][0-9])|(12[0-8]))$" + }, + "TCPPort": { + "type": "integer", + "exclusiveMinimum": 1, + "maximum": 65535 + }, + "UDPPort": { + "type": "integer", + "minimum": 0, + "maximum": 65535 + }, + "MACAddress": { + "type": "string", + "pattern": "^([a-f0-9]{2}:){5}[a-f0-9]{2}$" + }, + "EmailAddress": { + "allOf": [ + { + "$ref": "#/$defs/ShortString" + }, + { + "type": "string", + "pattern": "^[a-zA-Z0-9\\.!#$%&'\\*\\+\\\\/=\\?\\^_`\\{\\|\\}~\\-]+@[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$" + } + ] + }, + "UUID": { + "type": "string", + "pattern": "^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$" + }, + "ISOCountryCode": { + "type": "string", + "pattern": "^[A-Z]{2}$" + }, + "SIPURI": { + "type": "string", + "pattern": "^sips?:[a-zA-Z0-9!#$&-;=?-\\[\\]_~%]+$" + }, + "TELURI": { + "type": "string", + "pattern": "^tel:[a-zA-Z0-9!#$&-;=?-\\[\\]_~%]+$" + }, + "WGS84LatitudeDecimal": { + "type": "string", + "pattern": "^[NS][0-9]{2}\\.[0-9]{6}$" + }, + "WGS84LongitudeDecimal": { + "type": "string", + "pattern": "^[EW][0-9]{3}\\.[0-9]{6}$" + }, + "WGS84LatitudeAngular": { + "type": "string", + "pattern": "^[NS][0-9]{6}\\.[0-9]{2}$" + }, + "WGS84LongitudeAngular": { + "type": "string", + "pattern": "^[EW][0-9]{7}\\.[0-9]{2}$" + }, + "SUPIIMSI": { + "$ref": "#/$defs/IMSI" + }, + "SUPINAI": { + "$ref": "#/$defs/NAI" + }, + "SUCI": { + "type": "string", + "pattern": "^([a-fA-F0-9]{2})*$" + }, + "PEIIMEI": { + "$ref": "#/$defs/IMEI" + }, + "PEIIMEICheckDigit": { + "$ref": "#/$defs/IMEICheckDigit" + }, + "PEIIMEISV": { + "$ref": "#/$defs/IMEISV" + }, + "GPSIMSISDN": { + "type": "string", + "pattern": "^[0-9]{1,15}$" + }, + "GPSINAI": { + "$ref": "#/$defs/NAI" + }, + "NAI": { + "type": "string" + }, + "LDID": { + "type": "string", + "pattern": "^([A-Z]{2}-.+-.+)$" + }, + "InternationalizedEmailAddress": { + "allOf": [ + { + "$ref": "#/$defs/ShortString" + }, + { + "type": "string", + "pattern": "^.+@.+$" + } + ] + }, + "EUI64": { + "type": "string", + "pattern": "^([a-f0-9]{2}:){7}[a-f0-9]{2}$" + }, + "CGI": { + "type": "string", + "pattern": "^[0-9]{3}-[0-9]{2,3}-[a-f0-9]{4}-[a-f0-9]{4}$" + }, + "ECGI": { + "type": "string", + "pattern": "^[0-9]{3}-[0-9]{2,3}-[a-f0-9]{7}$" + }, + "NCGI": { + "type": "string", + "pattern": "^[0-9]{3}-[0-9]{2,3}-[a-f0-9]{9}$" + }, + "ICCID": { + "type": "string", + "pattern": "^[0-9]{19,20}$" + }, + "IPAddress": { + "oneOf": [ + { + "type": "object", + "properties": { + "IPv4Address": { + "$ref": "#/$defs/IPv4Address" + } + }, + "required": [ + "IPv4Address" + ] + }, + { + "type": "object", + "properties": { + "IPv6Address": { + "$ref": "#/$defs/IPv6Address" + } + }, + "required": [ + "IPv6Address" + ] + } + ] + }, + "IPCIDR": { + "oneOf": [ + { + "type": "object", + "properties": { + "IPv4CIDR": { + "$ref": "#/$defs/IPv4CIDR" + } + }, + "required": [ + "IPv4CIDR" + ] + }, + { + "type": "object", + "properties": { + "IPv6CIDR": { + "$ref": "#/$defs/IPv6CIDR" + } + }, + "required": [ + "IPv6CIDR" + ] + } + ] + }, + "TCPPortRange": { + "type": "object", + "properties": { + "start": { + "$ref": "#/$defs/TCPPort" + }, + "end": { + "$ref": "#/$defs/TCPPort" + } + }, + "required": [ + "start", + "end" + ] + }, + "UDPPortRange": { + "type": "object", + "properties": { + "start": { + "$ref": "#/$defs/UDPPort" + }, + "end": { + "$ref": "#/$defs/UDPPort" + } + }, + "required": [ + "start", + "end" + ] + }, + "Port": { + "oneOf": [ + { + "type": "object", + "properties": { + "TCPPort": { + "$ref": "#/$defs/TCPPort" + } + }, + "required": [ + "TCPPort" + ] + }, + { + "type": "object", + "properties": { + "UDPPort": { + "$ref": "#/$defs/UDPPort" + } + }, + "required": [ + "UDPPort" + ] + } + ] + }, + "PortRange": { + "oneOf": [ + { + "type": "object", + "properties": { + "TCPPortRange": { + "$ref": "#/$defs/TCPPortRange" + } + }, + "required": [ + "TCPPortRange" + ] + }, + { + "type": "object", + "properties": { + "UDPPortRange": { + "$ref": "#/$defs/UDPPortRange" + } + }, + "required": [ + "UDPPortRange" + ] + } + ] + }, + "IPAddressPort": { + "type": "object", + "properties": { + "address": { + "$ref": "#/$defs/IPAddress" + }, + "port": { + "$ref": "#/$defs/Port" + } + }, + "required": [ + "address", + "port" + ] + }, + "IPAddressPortRange": { + "type": "object", + "properties": { + "address": { + "$ref": "#/$defs/IPAddress" + }, + "portRange": { + "$ref": "#/$defs/PortRange" + } + }, + "required": [ + "address", + "portRange" + ] + }, + "WGS84CoordinateDecimal": { + "type": "object", + "properties": { + "latitude": { + "$ref": "#/$defs/WGS84LatitudeDecimal" + }, + "longitude": { + "$ref": "#/$defs/WGS84LongitudeDecimal" + } + }, + "required": [ + "latitude", + "longitude" + ] + }, + "WGS84CoordinateAngular": { + "type": "object", + "properties": { + "latitude": { + "$ref": "#/$defs/WGS84LatitudeAngular" + }, + "longitude": { + "$ref": "#/$defs/WGS84LongitudeAngular" + } + }, + "required": [ + "latitude", + "longitude" + ] + } + } +} \ No newline at end of file diff --git a/json/notification.json b/json/notification.json new file mode 100644 index 0000000..e9805f5 --- /dev/null +++ b/json/notification.json @@ -0,0 +1,64 @@ +{ + "$id": "notification.json", + "$defs": { + "NotificationObject": { + "type": "object", + "properties": { + "ObjectIdentifier": { + "$ref": "core.json#/$defs/ObjectIdentifier" + }, + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + }, + "OwnerIdentifier": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "Generation": { + "type": "integer", + "minimum": 0 + }, + "ExternalIdentifier": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "AssociatedObjects": { + "$ref": "core.json#/$defs/AssociatedObjects" + }, + "LastChanged": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "NationalHandlingParameters": { + "$ref": "core.json#/$defs/NationalHandlingParameters" + }, + "NotificationDetails": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "NotificationType": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "NewNotification": { + "type": "boolean" + }, + "NotificationTimestamp": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "NationalNotificationParameters": { + "$ref": "#/$defs/NationalNotificationParameters" + } + }, + "required": [ + "ObjectIdentifier" + ] + }, + "NationalNotificationParameters": { + "type": "object", + "properties": { + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + } + }, + "required": [ + "CountryCode" + ] + } + } +} \ No newline at end of file diff --git a/json/task.json b/json/task.json new file mode 100644 index 0000000..f945d95 --- /dev/null +++ b/json/task.json @@ -0,0 +1,499 @@ +{ + "$id": "task.json", + "$defs": { + "LITaskObject": { + "type": "object", + "properties": { + "ObjectIdentifier": { + "$ref": "core.json#/$defs/ObjectIdentifier" + }, + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + }, + "OwnerIdentifier": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "Generation": { + "type": "integer", + "minimum": 0 + }, + "ExternalIdentifier": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "AssociatedObjects": { + "$ref": "core.json#/$defs/AssociatedObjects" + }, + "LastChanged": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "NationalHandlingParameters": { + "$ref": "core.json#/$defs/NationalHandlingParameters" + }, + "Reference": { + "$ref": "etsi103280.json#/$defs/LIID" + }, + "Status": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "DesiredStatus": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "Timespan": { + "$ref": "#/$defs/TaskTimespan" + }, + "TargetIdentifier": { + "$ref": "#/$defs/TargetIdentifier" + }, + "DeliveryType": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "DeliveryDetails": { + "$ref": "#/$defs/TaskDeliveryDetails" + }, + "ApprovalDetails": { + "$ref": "common.json#/$defs/ApprovalDetails" + }, + "CSPID": { + "$ref": "core.json#/$defs/EndpointID" + }, + "HandlingProfile": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "InvalidReason": { + "$ref": "core.json#/$defs/ActionUnsuccesfulInformation" + }, + "Flags": { + "$ref": "#/$defs/TaskFlags" + }, + "NationalLITaskingParameters": { + "$ref": "#/$defs/NationalLITaskingParameters" + } + }, + "required": [ + "ObjectIdentifier" + ] + }, + "TaskTimespan": { + "type": "object", + "properties": { + "StartTime": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "EndTime": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "TerminationTime": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "ProvisioningTime": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "DeprovisioningTime": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + } + }, + "required": [] + }, + "TargetIdentifier": { + "type": "object", + "properties": { + "TargetIdentifierValues": { + "$ref": "#/$defs/TargetIdentifierValues" + }, + "ServiceType": { + "$ref": "common.json#/$defs/DictionaryEntry" + } + }, + "required": [] + }, + "TargetIdentifierValues": { + "type": "object", + "properties": { + "TargetIdentifierValue": { + "$ref": "#/$defs/TargetIdentifierValue" + } + }, + "required": [ + "TargetIdentifierValue" + ] + }, + "TargetIdentifierValue": { + "type": "object", + "properties": { + "FormatType": { + "$ref": "#/$defs/FormatType" + }, + "Value": { + "$ref": "etsi103280.json#/$defs/LongString" + } + }, + "required": [ + "FormatType", + "Value" + ] + }, + "FormatType": { + "type": "object", + "properties": { + "FormatOwner": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "FormatName": { + "$ref": "etsi103280.json#/$defs/ShortString" + } + }, + "required": [ + "FormatOwner", + "FormatName" + ] + }, + "TaskDeliveryDetails": { + "type": "object", + "properties": { + "DeliveryDestination": { + "$ref": "#/$defs/DeliveryDestination" + } + }, + "required": [ + "DeliveryDestination" + ] + }, + "DeliveryDestination": { + "type": "object", + "properties": { + "DeliveryAddress": { + "$ref": "#/$defs/DeliveryAddress" + }, + "EncryptionDetails": { + "$ref": "#/$defs/NationalEncryptionDetails" + }, + "IRIorCC": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "HandoverFormat": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "DeliveryProfile": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "NationalDeliveryParameters": { + "$ref": "#/$defs/NationalDeliveryParameters" + } + }, + "required": [] + }, + "DeliveryAddress": { + "oneOf": [ + { + "type": "object", + "properties": { + "IPv4Address": { + "$ref": "etsi103280.json#/$defs/IPv4Address" + } + }, + "required": [ + "IPv4Address" + ] + }, + { + "type": "object", + "properties": { + "IPv6Address": { + "$ref": "etsi103280.json#/$defs/IPv6Address" + } + }, + "required": [ + "IPv6Address" + ] + }, + { + "type": "object", + "properties": { + "IPAddressPort": { + "$ref": "etsi103280.json#/$defs/IPAddressPort" + } + }, + "required": [ + "IPAddressPort" + ] + }, + { + "type": "object", + "properties": { + "IPAddressPortRange": { + "$ref": "etsi103280.json#/$defs/IPAddressPortRange" + } + }, + "required": [ + "IPAddressPortRange" + ] + }, + { + "type": "object", + "properties": { + "E164Number": { + "$ref": "etsi103280.json#/$defs/InternationalE164" + } + }, + "required": [ + "E164Number" + ] + }, + { + "type": "object", + "properties": { + "FTPAddress": { + "type": "string" + } + }, + "required": [ + "FTPAddress" + ] + }, + { + "type": "object", + "properties": { + "URL": { + "type": "string" + } + }, + "required": [ + "URL" + ] + }, + { + "type": "object", + "properties": { + "FQDN": { + "$ref": "etsi103280.json#/$defs/LongString" + } + }, + "required": [ + "FQDN" + ] + }, + { + "type": "object", + "properties": { + "EmailAddress": { + "$ref": "etsi103280.json#/$defs/EmailAddress" + } + }, + "required": [ + "EmailAddress" + ] + } + ] + }, + "TaskFlags": { + "type": "object", + "properties": { + "TaskFlag": { + "$ref": "common.json#/$defs/DictionaryEntry" + } + }, + "required": [] + }, + "NationalLITaskingParameters": { + "type": "object", + "properties": { + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + } + }, + "required": [ + "CountryCode" + ] + }, + "NationalDeliveryParameters": { + "type": "object", + "properties": { + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + } + }, + "required": [ + "CountryCode" + ] + }, + "NationalEncryptionDetails": { + "type": "object", + "properties": { + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + } + }, + "required": [ + "CountryCode" + ] + }, + "LDTaskObject": { + "type": "object", + "properties": { + "ObjectIdentifier": { + "$ref": "core.json#/$defs/ObjectIdentifier" + }, + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + }, + "OwnerIdentifier": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "Generation": { + "type": "integer", + "minimum": 0 + }, + "ExternalIdentifier": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "AssociatedObjects": { + "$ref": "core.json#/$defs/AssociatedObjects" + }, + "LastChanged": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "NationalHandlingParameters": { + "$ref": "core.json#/$defs/NationalHandlingParameters" + }, + "Reference": { + "$ref": "etsi103280.json#/$defs/LDID" + }, + "Status": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "StatusReason": { + "$ref": "core.json#/$defs/ActionUnsuccesfulInformation" + }, + "DesiredStatus": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "RequestDetails": { + "$ref": "#/$defs/RequestDetails" + }, + "DeliveryDetails": { + "$ref": "#/$defs/LDDeliveryDetails" + }, + "ApprovalDetails": { + "$ref": "common.json#/$defs/ApprovalDetails" + }, + "CSPID": { + "$ref": "core.json#/$defs/EndpointID" + }, + "HandlingProfile": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "Flags": { + "$ref": "#/$defs/LDTaskFlags" + }, + "NationalLDTaskingParameters": { + "$ref": "#/$defs/NationalLDTaskingParameters" + } + }, + "required": [ + "ObjectIdentifier" + ] + }, + "RequestDetails": { + "type": "object", + "properties": { + "Type": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "StartTime": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "EndTime": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "ObservedTime": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "ObservedTimes": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "RequestValues": { + "$ref": "#/$defs/RequestValues" + } + }, + "required": [] + }, + "RequestValues": { + "type": "object", + "properties": { + "RequestValue": { + "$ref": "#/$defs/RequestValue" + } + }, + "required": [ + "RequestValue" + ] + }, + "RequestValue": { + "type": "object", + "properties": { + "FormatType": { + "$ref": "#/$defs/FormatType" + }, + "Value": { + "$ref": "etsi103280.json#/$defs/LongString" + } + }, + "required": [ + "FormatType", + "Value" + ] + }, + "LDDeliveryDetails": { + "type": "object", + "properties": { + "LDDeliveryDestination": { + "$ref": "#/$defs/LDDeliveryDestination" + } + }, + "required": [ + "LDDeliveryDestination" + ] + }, + "LDDeliveryDestination": { + "type": "object", + "properties": { + "DeliveryAddress": { + "$ref": "#/$defs/DeliveryAddress" + }, + "EncryptionDetails": { + "$ref": "#/$defs/NationalEncryptionDetails" + }, + "LDHandoverFormat": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "LDDeliveryProfile": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "NationalDeliveryParameters": { + "$ref": "#/$defs/NationalDeliveryParameters" + } + }, + "required": [] + }, + "LDTaskFlags": { + "type": "object", + "properties": { + "LDTaskFlag": { + "$ref": "common.json#/$defs/DictionaryEntry" + } + }, + "required": [] + }, + "NationalLDTaskingParameters": { + "type": "object", + "properties": { + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + } + }, + "required": [ + "CountryCode" + ] + } + } +} \ No newline at end of file diff --git a/json/xmldsig.json b/json/xmldsig.json new file mode 100644 index 0000000..dde4cb0 --- /dev/null +++ b/json/xmldsig.json @@ -0,0 +1,553 @@ +{ + "$id": "core.json", + "$defs": { + "ObjectIdentifier": { + "$ref": "etsi103280.json#/$defs/UUID" + }, + "HI1Message": { + "type": "object", + "properties": { + "Header": { + "$ref": "#/$defs/MessageHeader" + }, + "Payload": { + "$ref": "#/$defs/MessagePayload" + }, + "Signature": { + "$ref": "xmldsig.json#/$defs/SignatureType" + } + }, + "required": [ + "Header", + "Payload" + ] + }, + "MessageHeader": { + "type": "object", + "properties": { + "SenderIdentifier": { + "$ref": "#/$defs/EndpointID" + }, + "ReceiverIdentifier": { + "$ref": "#/$defs/EndpointID" + }, + "TransactionIdentifier": { + "$ref": "etsi103280.json#/$defs/UUID" + }, + "Timestamp": { + "$ref": "etsi103280.json#/$defs/QualifiedMicrosecondDateTime" + }, + "Version": { + "$ref": "#/$defs/Version" + } + }, + "required": [ + "SenderIdentifier", + "ReceiverIdentifier", + "TransactionIdentifier", + "Timestamp", + "Version" + ] + }, + "Version": { + "type": "object", + "properties": { + "ETSIVersion": { + "$ref": "common.json#/$defs/ETSIVersion" + }, + "NationalProfileOwner": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "NationalProfileVersion": { + "$ref": "etsi103280.json#/$defs/ShortString" + } + }, + "required": [ + "ETSIVersion", + "NationalProfileOwner", + "NationalProfileVersion" + ] + }, + "EndpointID": { + "type": "object", + "properties": { + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + }, + "UniqueIdentifier": { + "$ref": "etsi103280.json#/$defs/LongString" + } + }, + "required": [ + "CountryCode", + "UniqueIdentifier" + ] + }, + "MessagePayload": { + "oneOf": [ + { + "type": "object", + "properties": { + "RequestPayload": { + "$ref": "#/$defs/RequestPayload" + } + }, + "required": [ + "RequestPayload" + ] + }, + { + "type": "object", + "properties": { + "ResponsePayload": { + "$ref": "#/$defs/ResponsePayload" + } + }, + "required": [ + "ResponsePayload" + ] + } + ] + }, + "RequestPayload": { + "type": "object", + "properties": { + "ActionRequests": { + "$ref": "#/$defs/ActionRequests" + } + }, + "required": [ + "ActionRequests" + ] + }, + "ActionRequests": { + "type": "object", + "properties": { + "ActionRequest": { + "$ref": "#/$defs/ActionRequest" + } + }, + "required": [ + "ActionRequest" + ] + }, + "ResponsePayload": { + "oneOf": [ + { + "type": "object", + "properties": { + "ActionResponses": { + "$ref": "#/$defs/ActionResponses" + } + }, + "required": [ + "ActionResponses" + ] + }, + { + "type": "object", + "properties": { + "ErrorInformation": { + "$ref": "#/$defs/ActionUnsuccesfulInformation" + } + }, + "required": [ + "ErrorInformation" + ] + } + ] + }, + "ActionResponses": { + "type": "object", + "properties": { + "ActionResponse": { + "$ref": "#/$defs/ActionResponse" + } + }, + "required": [ + "ActionResponse" + ] + }, + "ActionRequest": { + "allOf": [ + { + "type": "object", + "properties": { + "ActionIdentifier": { + "type": "integer", + "minimum": 0 + } + }, + "required": [ + "ActionIdentifier" + ] + }, + { + "oneOf": [ + { + "type": "object", + "properties": { + "GET": { + "$ref": "#/$defs/GETRequest" + } + }, + "required": [ + "GET" + ] + }, + { + "type": "object", + "properties": { + "CREATE": { + "$ref": "#/$defs/CREATERequest" + } + }, + "required": [ + "CREATE" + ] + }, + { + "type": "object", + "properties": { + "UPDATE": { + "$ref": "#/$defs/UPDATERequest" + } + }, + "required": [ + "UPDATE" + ] + }, + { + "type": "object", + "properties": { + "LIST": { + "$ref": "#/$defs/LISTRequest" + } + }, + "required": [ + "LIST" + ] + }, + { + "type": "object", + "properties": { + "DELIVER": { + "$ref": "#/$defs/DELIVERRequest" + } + }, + "required": [ + "DELIVER" + ] + } + ] + } + ] + }, + "ActionResponse": { + "allOf": [ + { + "type": "object", + "properties": { + "ActionIdentifier": { + "type": "integer", + "minimum": 0 + } + }, + "required": [ + "ActionIdentifier" + ] + }, + { + "oneOf": [ + { + "type": "object", + "properties": { + "GETResponse": { + "$ref": "#/$defs/GETResponse" + } + }, + "required": [ + "GETResponse" + ] + }, + { + "type": "object", + "properties": { + "CREATEResponse": { + "$ref": "#/$defs/CREATEResponse" + } + }, + "required": [ + "CREATEResponse" + ] + }, + { + "type": "object", + "properties": { + "UPDATEResponse": { + "$ref": "#/$defs/UPDATEResponse" + } + }, + "required": [ + "UPDATEResponse" + ] + }, + { + "type": "object", + "properties": { + "LISTResponse": { + "$ref": "#/$defs/LISTResponse" + } + }, + "required": [ + "LISTResponse" + ] + }, + { + "type": "object", + "properties": { + "ErrorInformation": { + "$ref": "#/$defs/ActionUnsuccesfulInformation" + } + }, + "required": [ + "ErrorInformation" + ] + }, + { + "type": "object", + "properties": { + "DELIVERResponse": { + "$ref": "#/$defs/DELIVERResponse" + } + }, + "required": [ + "DELIVERResponse" + ] + } + ] + } + ] + }, + "GETRequest": { + "type": "object", + "properties": { + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + } + }, + "required": [ + "Identifier" + ] + }, + "GETResponse": { + "type": "object", + "properties": { + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "HI1Object" + ] + }, + "CREATERequest": { + "type": "object", + "properties": { + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "HI1Object" + ] + }, + "CREATEResponse": { + "type": "object", + "properties": { + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + }, + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "Identifier" + ] + }, + "UPDATERequest": { + "type": "object", + "properties": { + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "HI1Object" + ] + }, + "UPDATEResponse": { + "type": "object", + "properties": { + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + }, + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "Identifier" + ] + }, + "LISTRequest": { + "type": "object", + "properties": { + "ObjectType": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "LastChanged": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + } + }, + "required": [] + }, + "LISTResponse": { + "type": "object", + "properties": { + "ListResponseRecord": { + "$ref": "#/$defs/ListResponseRecord" + } + }, + "required": [] + }, + "ListResponseRecord": { + "type": "object", + "properties": { + "ObjectType": { + "$ref": "common.json#/$defs/DictionaryEntry" + }, + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + }, + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + }, + "OwnerIdentifier": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "Generation": { + "type": "integer", + "minimum": 0 + }, + "ExternalIdentifier": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "LastChanged": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + } + }, + "required": [ + "ObjectType", + "Identifier", + "Generation" + ] + }, + "ActionUnsuccesfulInformation": { + "type": "object", + "properties": { + "ErrorCode": { + "type": "integer", + "minimum": 0 + }, + "ErrorDescription": { + "$ref": "etsi103280.json#/$defs/LongString" + } + }, + "required": [ + "ErrorCode", + "ErrorDescription" + ] + }, + "DELIVERRequest": { + "type": "object", + "properties": { + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + }, + "HI1Object": { + "$ref": "#/$defs/HI1Object" + } + }, + "required": [ + "Identifier", + "HI1Object" + ] + }, + "DELIVERResponse": { + "type": "object", + "properties": { + "Identifier": { + "$ref": "#/$defs/ObjectIdentifier" + } + }, + "required": [ + "Identifier" + ] + }, + "HI1Object": { + "type": "object", + "properties": { + "ObjectIdentifier": { + "$ref": "#/$defs/ObjectIdentifier" + }, + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + }, + "OwnerIdentifier": { + "$ref": "etsi103280.json#/$defs/ShortString" + }, + "Generation": { + "type": "integer", + "minimum": 0 + }, + "ExternalIdentifier": { + "$ref": "etsi103280.json#/$defs/LongString" + }, + "AssociatedObjects": { + "$ref": "#/$defs/AssociatedObjects" + }, + "LastChanged": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + }, + "NationalHandlingParameters": { + "$ref": "#/$defs/NationalHandlingParameters" + } + }, + "required": [ + "ObjectIdentifier" + ] + }, + "AssociatedObjects": { + "type": "object", + "properties": { + "AssociatedObject": { + "$ref": "#/$defs/ObjectIdentifier" + } + }, + "required": [] + }, + "NationalHandlingParameters": { + "type": "object", + "properties": { + "CountryCode": { + "$ref": "etsi103280.json#/$defs/ISOCountryCode" + } + }, + "required": [ + "CountryCode" + ] + } + } +} \ No newline at end of file diff --git a/translate.py b/translate.py index 7b62565..35a1a3b 100644 --- a/translate.py +++ b/translate.py @@ -1,33 +1,83 @@ import json import logging +import os from pathlib import Path +import sys from xmlschema import * from translate_schema import * -logging.basicConfig(level = logging.DEBUG) +import jsonschema -if __name__ == "__main__": - # js = translate_schema("103280/TS_103_280.xsd", "103120.json") - # print(json.dumps(js, indent=2)) - schemas = [ "103120/schema/ts_103120_Authorisation.xsd", - "103120/schema/ts_103120_Common.xsd", - "103120/schema/ts_103120_Delivery.xsd", - "103120/schema/ts_103120_Document.xsd", - "103120/schema/ts_103120_Notification.xsd", - "103120/schema/ts_103120_Task.xsd", - "103280/TS_103_280.xsd", - "testing/deps/xmldsig/xmldsig-core-schema.xsd"] +logging.basicConfig(level = logging.DEBUG) +def build_schema_locations (paths): schema_locations = [] - for schemaFile in schemas: + for schemaFile in paths: try: xs = XMLSchema(schemaFile, validation='skip') schema_locations.append((xs.target_namespace, str(Path(schemaFile).resolve()))) print (" [ {0} -> {1} ]".format(xs.target_namespace, schemaFile)) except XMLSchemaParseError as ex: print (" [ {0} failed to parse: {1} ]".format(schemaFile, ex)) + return schema_locations + +def get_json(filename): + with open(filename) as f: + j = json.load(f) + return j + +if __name__ == "__main__": + if len(sys.argv) > 1 and sys.argv[1] == "rebuild": + schema_paths = [ "103120/schema/ts_103120_Authorisation.xsd", + "103120/schema/ts_103120_Common.xsd", + "103120/schema/ts_103120_Core.xsd", + "103120/schema/ts_103120_Delivery.xsd", + "103120/schema/ts_103120_Document.xsd", + "103120/schema/ts_103120_Notification.xsd", + "103120/schema/ts_103120_Task.xsd", + "103280/TS_103_280.xsd", + "testing/deps/xmldsig/xmldsig-core-schema.xsd"] - js = translate_schema("103120/schema/ts_103120_core.xsd", "core.json", schema_locations) - print(json.dumps(js, indent=2)) + schema_locations = build_schema_locations(schema_paths) + + ns_to_id_map = { + schema[0]: schema[0].split('/')[-1].lower() + ".json" + for schema in schema_locations if '03120' in schema[0] + } | { + 'http://uri.etsi.org/03280/common/2017/07' : 'etsi103280.json', + 'http://www.w3.org/2000/09/xmldsig#' : 'xmldsig.json', + } + + # js = translate_schema("103280/TS_103_280.xsd", "103120.json") + # print(json.dumps(js, indent=2)) + + output_path = Path('json/') + if not output_path.exists(): + os.mkdir(str(output_path)) + + json_schemas = {} + for schema_tuple in schema_locations: + if 'xmldsig' in (schema_tuple[1]): + continue + js = translate_schema(schema_tuple[1], ns_to_id_map, schema_locations) + if ns_to_id_map[schema_tuple[0]] == 'core.json': + js['$defs']['HI1Message']['properties'].pop('Signature') + js_path = output_path / ns_to_id_map[schema_tuple[0]] + with open(str(js_path), 'w') as f: + f.write(json.dumps(js, indent=2)) + json_schemas[js['$id']] = js + else: + json_schemas = {} + json_path = Path('json/') + for json_file in json_path.glob("*.json"): + json_schemas[json_file.name] = get_json(json_file) + + resolver = jsonschema.RefResolver("", "", json_schemas) + + instance = get_json("120.json") + schema = json_schemas['core.json'] + jsonschema.validate(instance, schema, resolver=resolver) + + # print(json.dumps(js, indent=2)) diff --git a/translate_schema/__init__.py b/translate_schema/__init__.py index a4ddb4b..cf6b3f8 100644 --- a/translate_schema/__init__.py +++ b/translate_schema/__init__.py @@ -14,9 +14,9 @@ mappings = [ SequenceMapping(), ] -def translate_schema (schema_path, schema_id, schema_locations = []): +def translate_schema (schema_path: str, ns_to_id_map: dict, schema_locations = []): js = { - "$id" : schema_id, + "$id" : "?", "$defs" : {} } @@ -24,6 +24,20 @@ def translate_schema (schema_path, schema_id, schema_locations = []): xs = XMLSchema(schema_path, validation='lax', locations=schema_locations) logging.info(f"Schema namespace: {xs.target_namespace}" ) + schema_id = ns_to_id_map[xs.target_namespace] + js['$id'] = schema_id + + TypeMapping.ns_to_id_map = ns_to_id_map + + elementList = [] + for elementName, element in xs.elements.items(): + logging.info(f"Processing element {elementName} : {element}") + elementList.append(TypeMapping.get_ref_for(element.type, element.namespaces[''])) + if len(elementList) == 1: + js['$ref'] = elementList[0]['$ref'] + elif len(elementList) > 1: + js['oneOf'] = elementList + for type_name, xsd_type in xs.types.items(): logging.info(f"Processing {type_name} : {xsd_type}") diff --git a/translate_schema/type_mapping.py b/translate_schema/type_mapping.py index 582e1c4..a7bf7f6 100644 --- a/translate_schema/type_mapping.py +++ b/translate_schema/type_mapping.py @@ -12,10 +12,37 @@ from .util import * log = logging.getLogger() class TypeMapping(ABC): + ns_to_id_map = {} + @abstractmethod def map(self, xst : BaseXsdType): return None + @classmethod + def extract_namespace(cls, qname: str): + match = re.search(r'^\{([^\{\}]+)\}(([^\{\}]+))$', qname) + if match is None: + return None + return match.group(1) + + @classmethod + def get_ref_for(cls, xsd_type: XsdType, current_ns : str): + ns = cls.extract_namespace(xsd_type.name) + if ns == current_ns: + return { "$ref" : f"#/$defs/{xsd_type.local_name}" } + else: + mapped_id = cls.ns_to_id_map[ns] + return { "$ref" : f"{mapped_id}#/$defs/{xsd_type.local_name}"} + + @classmethod + def get_type_from_elem(cls, elem: XsdElement, current_ns : str): + ns = cls.extract_namespace(elem.type.name) + if (ns == "http://www.w3.org/2001/XMLSchema"): + # this should be an XSD primitive type + return dict(XSDNativeSimpleTypeMapping.XSD_TYPE_MAP[elem.type.local_name]) + else: + return cls.get_ref_for(elem.type, current_ns) + class SimpleTypeMapping(TypeMapping): def map(self, xst: BaseXsdType): log.debug(f"Attempting mapping of {xst} to simple type") @@ -39,7 +66,10 @@ class XSDNativeSimpleTypeMapping(SimpleTypeMapping): "integer" : { "type" : "integer"}, "nonNegativeInteger" : { "type" : "integer", "minimum" : 0}, + "boolean" : { "type" : "boolean" }, + "hexBinary" : { "type" : "string", "pattern" : "^([a-fA-F0-9]{2})*$"}, + "base64Binary" : { "type" : "string", "pattern" : "^[-A-Za-z0-9+/]*={0,3}$"}, "anyType" : {} } @@ -56,15 +86,15 @@ class XSDNativeSimpleTypeMapping(SimpleTypeMapping): parent_type = None if mapped_type is None: - ns = extract_namespace(xst.base_type.name) + ns = TypeMapping.extract_namespace(xst.base_type.name) if ns == XSDNativeSimpleTypeMapping.XSD_NS: print (xst) print (xst.base_type) raise Exception (f"No mapping for xs:{xst.base_type.local_name}") if len(xst.facets) == 0: - mapped_type = get_ref_for(xst.base_type, xst.namespaces['']) + mapped_type = TypeMapping.get_ref_for(xst.base_type, xst.namespaces['']) else: - parent_type = get_ref_for(xst.base_type, xst.namespaces['']) + parent_type = TypeMapping.get_ref_for(xst.base_type, xst.namespaces['']) mapped_type = XSDNativeSimpleTypeMapping.XSD_TYPE_MAP.get(xst.root_type.local_name) if mapped_type is None: raise Exception (f"Could not find mapping for root type xs:{xst.root_type.local_name}") @@ -113,33 +143,26 @@ class ComplexTypeMapping(TypeMapping): "type" : "object" } -def get_type_from_elem(elem: XsdElement, current_ns : str): - ns = extract_namespace(elem.type.name) - if (ns == "http://www.w3.org/2001/XMLSchema"): - # this should be an XSD primitive type - return dict(XSDNativeSimpleTypeMapping.XSD_TYPE_MAP[elem.type.local_name]) - else: - return get_ref_for(elem.type, current_ns) - - -def process_choice(choice: XsdGroup, current_ns : str): - if choice.model != 'choice': - raise Exception(f"Wrong group type: {c.model}") - oneOf = [] - for c in choice.iter_model(): - if not (type(c) is XsdElement): - raise Exception (f"Non-element {c} encountered in choice {choice}") - t = get_type_from_elem(c, current_ns) - oneOf.append({ - "type" : "object", - "properties" : { - c.local_name : t - }, - "required" : [c.local_name] - }) - return oneOf class ChoiceMapping(ComplexTypeMapping): + @classmethod + def process_choice(cls, choice: XsdGroup, current_ns : str): + if choice.model != 'choice': + raise Exception(f"Wrong group type: {c.model}") + oneOf = [] + for c in choice.iter_model(): + if not (type(c) is XsdElement): + raise Exception (f"Non-element {c} encountered in choice {choice}") + t = TypeMapping.get_type_from_elem(c, current_ns) + oneOf.append({ + "type" : "object", + "properties" : { + c.local_name : t + }, + "required" : [c.local_name] + }) + return oneOf + def map(self, xst : BaseXsdType): log.debug(f"Attempting mapping of {xst} to choice") j = super().map(xst) @@ -150,7 +173,7 @@ class ChoiceMapping(ComplexTypeMapping): if (content.model != 'choice'): log.debug("Not a choice, giving up") return None - return { 'oneOf' : process_choice(content, xst.namespaces[''])} + return { 'oneOf' : ChoiceMapping.process_choice(content, xst.namespaces[''])} class SequenceMapping(ComplexTypeMapping): def map(self, xst: BaseXsdType): @@ -172,7 +195,7 @@ class SequenceMapping(ComplexTypeMapping): for c in list(content.iter_model()): log.debug(f"Processing model item {c}") if type(c) is XsdElement: - mapped_type['properties'][c.local_name] = get_type_from_elem(c, xst.namespaces['']) + mapped_type['properties'][c.local_name] = TypeMapping.get_type_from_elem(c, xst.namespaces['']) if c.effective_min_occurs == 1: mapped_type['required'].append(c.local_name) elif type(c) is XsdGroup: @@ -180,7 +203,9 @@ class SequenceMapping(ComplexTypeMapping): raise Exception (f"Second group '{c.local_name}' encountered in {xst}") if c.model != "choice": raise Exception (f"Don't know what to do with inner group {c} in {xst} - not a choice") - inner_choice = process_choice(c, xst.namespaces['']) + inner_choice = ChoiceMapping.process_choice(c, xst.namespaces['']) + elif type(c) is XsdAnyElement: + mapped_type = {} else: raise Exception(f"Unknown element type {c}") if (inner_choice): diff --git a/translate_schema/util.py b/translate_schema/util.py index ce22cf3..f7f67b3 100644 --- a/translate_schema/util.py +++ b/translate_schema/util.py @@ -2,23 +2,3 @@ import re from xmlschema import * -def extract_namespace(qname: str): - match = re.search(r'^\{([^\{\}]+)\}(([^\{\}]+))$', qname) - if match is None: - return None - return match.group(1) - -NS_MAP = { - 'http://uri.etsi.org/03120/common/2019/10/Core' : 'core.json', - 'http://uri.etsi.org/03120/common/2016/02/Common' : 'common.json', - 'http://uri.etsi.org/03280/common/2017/07' : 'etsi103280.json', - 'http://www.w3.org/2000/09/xmldsig#' : 'xmldsig', -} - -def get_ref_for(xsd_type: XsdType, current_ns : str): - ns = extract_namespace(xsd_type.name) - if ns == current_ns: - return { "$ref" : f"#/$defs/{xsd_type.local_name}" } - else: - mapped_id = NS_MAP[ns] - return { "$ref" : f"{mapped_id}#/$defs/{xsd_type.local_name}"} \ No newline at end of file -- GitLab From cf3dfed0909352d707f84c97791105c2241a84e1 Mon Sep 17 00:00:00 2001 From: mark Date: Mon, 13 Jun 2022 09:37:29 +0100 Subject: [PATCH 16/20] Refactor --- translate_schema/ChoiceMapping.py | 42 ++++ translate_schema/ComplexTypeMapping.py | 11 + translate_schema/SequenceMapping.py | 56 +++++ translate_schema/SimpleTypeMapping.py | 18 ++ translate_schema/TypeMapping.py | 69 ++++++ .../XSDNativeSimpleTypeMapping.py | 72 ++++++ translate_schema/__init__.py | 6 +- translate_schema/type_mapping.py | 219 ------------------ 8 files changed, 273 insertions(+), 220 deletions(-) create mode 100644 translate_schema/ChoiceMapping.py create mode 100644 translate_schema/ComplexTypeMapping.py create mode 100644 translate_schema/SequenceMapping.py create mode 100644 translate_schema/SimpleTypeMapping.py create mode 100644 translate_schema/TypeMapping.py create mode 100644 translate_schema/XSDNativeSimpleTypeMapping.py delete mode 100644 translate_schema/type_mapping.py diff --git a/translate_schema/ChoiceMapping.py b/translate_schema/ChoiceMapping.py new file mode 100644 index 0000000..fecadf8 --- /dev/null +++ b/translate_schema/ChoiceMapping.py @@ -0,0 +1,42 @@ +import logging + +from xmlschema.validators.simple_types import * +from xmlschema.validators.complex_types import * +from xmlschema.validators.groups import * +from xmlschema.validators.facets import * + +from .TypeMapping import TypeMapping +from .ComplexTypeMapping import ComplexTypeMapping + +log = logging.getLogger() + +class ChoiceMapping(ComplexTypeMapping): + @classmethod + def process_choice(cls, choice: XsdGroup, current_ns : str): + if choice.model != 'choice': + raise Exception(f"Wrong group type: {c.model}") + oneOf = [] + for c in choice.iter_model(): + if not (type(c) is XsdElement): + raise Exception (f"Non-element {c} encountered in choice {choice}") + t = TypeMapping.get_type_from_elem(c, current_ns) + oneOf.append({ + "type" : "object", + "properties" : { + c.local_name : t + }, + "required" : [c.local_name] + }) + return oneOf + + def map(self, xst : BaseXsdType): + log.debug(f"Attempting mapping of {xst} to choice") + j = super().map(xst) + if j is None: + log.debug("Not a complex type, giving up") + return None + content = xst.content + if (content.model != 'choice'): + log.debug("Not a choice, giving up") + return None + return { 'oneOf' : ChoiceMapping.process_choice(content, xst.namespaces[''])} diff --git a/translate_schema/ComplexTypeMapping.py b/translate_schema/ComplexTypeMapping.py new file mode 100644 index 0000000..e181909 --- /dev/null +++ b/translate_schema/ComplexTypeMapping.py @@ -0,0 +1,11 @@ +from xmlschema.validators.complex_types import * + +from .TypeMapping import TypeMapping + +class ComplexTypeMapping(TypeMapping): + def map(self, xst: BaseXsdType): + if not (type(xst) is XsdComplexType): + return None + return { + "type" : "object" + } diff --git a/translate_schema/SequenceMapping.py b/translate_schema/SequenceMapping.py new file mode 100644 index 0000000..9999df8 --- /dev/null +++ b/translate_schema/SequenceMapping.py @@ -0,0 +1,56 @@ +import logging + +from xmlschema.validators.simple_types import * +from xmlschema.validators.complex_types import * +from xmlschema.validators.groups import * +from xmlschema.validators.facets import * + +from .TypeMapping import TypeMapping +from .ChoiceMapping import ChoiceMapping +from .ComplexTypeMapping import ComplexTypeMapping + +log = logging.getLogger() + + +class SequenceMapping(ComplexTypeMapping): + def map(self, xst: BaseXsdType): + log.debug(f"Attempting mapping of {xst} to sequence") + j = super().map(xst) + if j is None: + log.debug("Not a complex type, giving up") + return None + content = xst.content + if (content.model != 'sequence'): + log.debug("Not a sequence, giving up") + return None + mapped_type = { + 'type' : 'object', + 'properties' : {}, + 'required' : [] + } + inner_choice = None + for c in list(content.iter_model()): + log.debug(f"Processing model item {c}") + if type(c) is XsdElement: + mapped_type['properties'][c.local_name] = TypeMapping.get_type_from_elem(c, xst.namespaces['']) + if c.effective_min_occurs == 1: + mapped_type['required'].append(c.local_name) + elif type(c) is XsdGroup: + if inner_choice: + raise Exception (f"Second group '{c.local_name}' encountered in {xst}") + if c.model != "choice": + raise Exception (f"Don't know what to do with inner group {c} in {xst} - not a choice") + inner_choice = ChoiceMapping.process_choice(c, xst.namespaces['']) + elif type(c) is XsdAnyElement: + mapped_type = {} + else: + raise Exception(f"Unknown element type {c}") + if (inner_choice): + return { + 'allOf' : [ + mapped_type, + {'oneOf' : inner_choice} + ] + } + else: + return mapped_type diff --git a/translate_schema/SimpleTypeMapping.py b/translate_schema/SimpleTypeMapping.py new file mode 100644 index 0000000..2e60f9c --- /dev/null +++ b/translate_schema/SimpleTypeMapping.py @@ -0,0 +1,18 @@ +import logging + +from xmlschema.validators.complex_types import * +from xmlschema.validators.simple_types import XsdAtomicRestriction + +from .TypeMapping import TypeMapping + +log = logging.getLogger() + +class SimpleTypeMapping(TypeMapping): + def map(self, xst: BaseXsdType): + log.debug(f"Attempting mapping of {xst} to simple type") + if not (type(xst) is XsdAtomicRestriction): + log.debug("Type is not an XsdAtomicRestriction, giving up") + return None + return { + "$ref" : xst.base_type.name + } \ No newline at end of file diff --git a/translate_schema/TypeMapping.py b/translate_schema/TypeMapping.py new file mode 100644 index 0000000..57fa0ed --- /dev/null +++ b/translate_schema/TypeMapping.py @@ -0,0 +1,69 @@ +import logging +from abc import ABC, abstractmethod + +from xmlschema.validators.simple_types import * +from xmlschema.validators.complex_types import * +from xmlschema.validators.groups import * +from xmlschema.validators.facets import * + +log = logging.getLogger() + +class TypeMapping(ABC): + ns_to_id_map = {} + + XSD_NS = "http://www.w3.org/2001/XMLSchema" + + XSD_TYPE_MAP = { + "string" : { "type" : "string" }, + "normalizedString" : { "type" : "string", "pattern" : "^[^\r\n\t]*$"}, + "dateTime" : { "type" : "string"}, + "token" : { "type" : "string", "pattern" : "^[^\r\n\t]*$"}, + "anyURI" : { "type" : "string" }, + + "integer" : { "type" : "integer"}, + "nonNegativeInteger" : { "type" : "integer", "minimum" : 0}, + + "boolean" : { "type" : "boolean" }, + + "hexBinary" : { "type" : "string", "pattern" : "^([a-fA-F0-9]{2})*$"}, + "base64Binary" : { "type" : "string", "pattern" : "^[-A-Za-z0-9+/]*={0,3}$"}, + + "anyType" : {} + } + + @abstractmethod + def map(self, xst : BaseXsdType): + return None + + @classmethod + def extract_namespace(cls, qname: str): + match = re.search(r'^\{([^\{\}]+)\}(([^\{\}]+))$', qname) + if match is None: + return None + return match.group(1) + + @classmethod + def get_ref_for(cls, xsd_type: XsdType, current_ns : str): + ns = cls.extract_namespace(xsd_type.name) + if ns == current_ns: + return { "$ref" : f"#/$defs/{xsd_type.local_name}" } + else: + mapped_id = cls.ns_to_id_map[ns] + return { "$ref" : f"{mapped_id}#/$defs/{xsd_type.local_name}"} + + @classmethod + def get_type_from_elem(cls, elem: XsdElement, current_ns : str): + ns = cls.extract_namespace(elem.type.name) + if (ns == TypeMapping.XSD_NS): + # this should be an XSD primitive type + return dict(TypeMapping.XSD_TYPE_MAP[elem.type.local_name]) + else: + return cls.get_ref_for(elem.type, current_ns) + + + + + + + + diff --git a/translate_schema/XSDNativeSimpleTypeMapping.py b/translate_schema/XSDNativeSimpleTypeMapping.py new file mode 100644 index 0000000..772ac10 --- /dev/null +++ b/translate_schema/XSDNativeSimpleTypeMapping.py @@ -0,0 +1,72 @@ +import logging + +from xmlschema.validators.simple_types import * +from xmlschema.validators.complex_types import * +from xmlschema.validators.groups import * +from xmlschema.validators.facets import * + +from .TypeMapping import TypeMapping +from .SimpleTypeMapping import SimpleTypeMapping + +log = logging.getLogger() + +class XSDNativeSimpleTypeMapping(SimpleTypeMapping): + + def map(self, xst: BaseXsdType): + log.debug(f"Attempting mapping of {xst} to XSD native type") + j = super().map(xst) + if j is None: + log.debug("Not a simple type, giving up") + return None + + mapped_type = TypeMapping.XSD_TYPE_MAP.get(xst.base_type.local_name) + parent_type = None + + if mapped_type is None: + ns = TypeMapping.extract_namespace(xst.base_type.name) + if ns == XSDNativeSimpleTypeMapping.XSD_NS: + print (xst) + print (xst.base_type) + raise Exception (f"No mapping for xs:{xst.base_type.local_name}") + if len(xst.facets) == 0: + mapped_type = TypeMapping.get_ref_for(xst.base_type, xst.namespaces['']) + else: + parent_type = TypeMapping.get_ref_for(xst.base_type, xst.namespaces['']) + mapped_type = TypeMapping.XSD_TYPE_MAP.get(xst.root_type.local_name) + if mapped_type is None: + raise Exception (f"Could not find mapping for root type xs:{xst.root_type.local_name}") + + mapped_type = dict(mapped_type) + + for k, v in xst.facets.items(): + log.debug(f"Mapping facet {v}") + if type(v) is XsdMaxLengthFacet: + mapped_type['maxLength'] = v.value + continue + if type(v) is XsdMinLengthFacet: + mapped_type['minLength'] = v.value + continue + if type(v) is XsdPatternFacets: + if len(v.regexps) > 1: + raise Exception (f"Multiple patterns given in facet {v} of {xst}") + p = v.regexps[0] + if (not p.startswith('^')) and (not p.endswith('$')): + p = f"^{p}$" + mapped_type['pattern'] = p + continue + if type (v) is XsdMinInclusiveFacet: + mapped_type['minimum'] = v.value + continue + if type (v) is XsdMaxInclusiveFacet: + mapped_type['maximum'] = v.value + continue + if type (v) is XsdMinExclusiveFacet: + mapped_type['exclusiveMinimum'] = v.value + continue + if type (v) is XsdMaxExclusiveFacet: + mapped_type['exclusiveMaximum'] = v.value + continue + raise Exception (f"Unhandled facet {v}") + if parent_type: + return { 'allOf' : [parent_type, mapped_type] } + return mapped_type diff --git a/translate_schema/__init__.py b/translate_schema/__init__.py index cf6b3f8..c1719ca 100644 --- a/translate_schema/__init__.py +++ b/translate_schema/__init__.py @@ -4,7 +4,11 @@ from pathlib import Path from xmlschema import * -from .type_mapping import * +from .TypeMapping import * +from .XSDNativeSimpleTypeMapping import XSDNativeSimpleTypeMapping +from .ChoiceMapping import ChoiceMapping +from .SequenceMapping import SequenceMapping + log = logging.getLogger() diff --git a/translate_schema/type_mapping.py b/translate_schema/type_mapping.py deleted file mode 100644 index a7bf7f6..0000000 --- a/translate_schema/type_mapping.py +++ /dev/null @@ -1,219 +0,0 @@ -from copy import deepcopy -import logging -from abc import ABC, abstractmethod - -from xmlschema.validators.simple_types import * -from xmlschema.validators.complex_types import * -from xmlschema.validators.groups import * -from xmlschema.validators.facets import * - -from .util import * - -log = logging.getLogger() - -class TypeMapping(ABC): - ns_to_id_map = {} - - @abstractmethod - def map(self, xst : BaseXsdType): - return None - - @classmethod - def extract_namespace(cls, qname: str): - match = re.search(r'^\{([^\{\}]+)\}(([^\{\}]+))$', qname) - if match is None: - return None - return match.group(1) - - @classmethod - def get_ref_for(cls, xsd_type: XsdType, current_ns : str): - ns = cls.extract_namespace(xsd_type.name) - if ns == current_ns: - return { "$ref" : f"#/$defs/{xsd_type.local_name}" } - else: - mapped_id = cls.ns_to_id_map[ns] - return { "$ref" : f"{mapped_id}#/$defs/{xsd_type.local_name}"} - - @classmethod - def get_type_from_elem(cls, elem: XsdElement, current_ns : str): - ns = cls.extract_namespace(elem.type.name) - if (ns == "http://www.w3.org/2001/XMLSchema"): - # this should be an XSD primitive type - return dict(XSDNativeSimpleTypeMapping.XSD_TYPE_MAP[elem.type.local_name]) - else: - return cls.get_ref_for(elem.type, current_ns) - -class SimpleTypeMapping(TypeMapping): - def map(self, xst: BaseXsdType): - log.debug(f"Attempting mapping of {xst} to simple type") - if not (type(xst) is XsdAtomicRestriction): - log.debug("Type is not an XsdAtomicRestriction, giving up") - return None - return { - "$ref" : xst.base_type.name - } - -class XSDNativeSimpleTypeMapping(SimpleTypeMapping): - XSD_NS = "http://www.w3.org/2001/XMLSchema" - - XSD_TYPE_MAP = { - "string" : { "type" : "string" }, - "normalizedString" : { "type" : "string", "pattern" : "^[^\r\n\t]*$"}, - "dateTime" : { "type" : "string"}, - "token" : { "type" : "string", "pattern" : "^[^\r\n\t]*$"}, - "anyURI" : { "type" : "string" }, - - "integer" : { "type" : "integer"}, - "nonNegativeInteger" : { "type" : "integer", "minimum" : 0}, - - "boolean" : { "type" : "boolean" }, - - "hexBinary" : { "type" : "string", "pattern" : "^([a-fA-F0-9]{2})*$"}, - "base64Binary" : { "type" : "string", "pattern" : "^[-A-Za-z0-9+/]*={0,3}$"}, - - "anyType" : {} - } - - def map(self, xst: BaseXsdType): - log.debug(f"Attempting mapping of {xst} to XSD native type") - j = super().map(xst) - if j is None: - log.debug("Not a simple type, giving up") - return None - - - mapped_type = XSDNativeSimpleTypeMapping.XSD_TYPE_MAP.get(xst.base_type.local_name) - parent_type = None - - if mapped_type is None: - ns = TypeMapping.extract_namespace(xst.base_type.name) - if ns == XSDNativeSimpleTypeMapping.XSD_NS: - print (xst) - print (xst.base_type) - raise Exception (f"No mapping for xs:{xst.base_type.local_name}") - if len(xst.facets) == 0: - mapped_type = TypeMapping.get_ref_for(xst.base_type, xst.namespaces['']) - else: - parent_type = TypeMapping.get_ref_for(xst.base_type, xst.namespaces['']) - mapped_type = XSDNativeSimpleTypeMapping.XSD_TYPE_MAP.get(xst.root_type.local_name) - if mapped_type is None: - raise Exception (f"Could not find mapping for root type xs:{xst.root_type.local_name}") - - mapped_type = dict(mapped_type) - - for k, v in xst.facets.items(): - log.debug(f"Mapping facet {v}") - if type(v) is XsdMaxLengthFacet: - mapped_type['maxLength'] = v.value - continue - if type(v) is XsdMinLengthFacet: - mapped_type['minLength'] = v.value - continue - if type(v) is XsdPatternFacets: - if len(v.regexps) > 1: - raise Exception (f"Multiple patterns given in facet {v} of {xst}") - p = v.regexps[0] - if (not p.startswith('^')) and (not p.endswith('$')): - p = f"^{p}$" - mapped_type['pattern'] = p - continue - if type (v) is XsdMinInclusiveFacet: - mapped_type['minimum'] = v.value - continue - if type (v) is XsdMaxInclusiveFacet: - mapped_type['maximum'] = v.value - continue - if type (v) is XsdMinExclusiveFacet: - mapped_type['exclusiveMinimum'] = v.value - continue - if type (v) is XsdMaxExclusiveFacet: - mapped_type['exclusiveMaximum'] = v.value - continue - raise Exception (f"Unhandled facet {v}") - if parent_type: - return { 'allOf' : [parent_type, mapped_type] } - return mapped_type - - -class ComplexTypeMapping(TypeMapping): - def map(self, xst: BaseXsdType): - if not (type(xst) is XsdComplexType): - return None - return { - "type" : "object" - } - - -class ChoiceMapping(ComplexTypeMapping): - @classmethod - def process_choice(cls, choice: XsdGroup, current_ns : str): - if choice.model != 'choice': - raise Exception(f"Wrong group type: {c.model}") - oneOf = [] - for c in choice.iter_model(): - if not (type(c) is XsdElement): - raise Exception (f"Non-element {c} encountered in choice {choice}") - t = TypeMapping.get_type_from_elem(c, current_ns) - oneOf.append({ - "type" : "object", - "properties" : { - c.local_name : t - }, - "required" : [c.local_name] - }) - return oneOf - - def map(self, xst : BaseXsdType): - log.debug(f"Attempting mapping of {xst} to choice") - j = super().map(xst) - if j is None: - log.debug("Not a complex type, giving up") - return None - content = xst.content - if (content.model != 'choice'): - log.debug("Not a choice, giving up") - return None - return { 'oneOf' : ChoiceMapping.process_choice(content, xst.namespaces[''])} - -class SequenceMapping(ComplexTypeMapping): - def map(self, xst: BaseXsdType): - log.debug(f"Attempting mapping of {xst} to sequence") - j = super().map(xst) - if j is None: - log.debug("Not a complex type, giving up") - return None - content = xst.content - if (content.model != 'sequence'): - log.debug("Not a sequence, giving up") - return None - mapped_type = { - 'type' : 'object', - 'properties' : {}, - 'required' : [] - } - inner_choice = None - for c in list(content.iter_model()): - log.debug(f"Processing model item {c}") - if type(c) is XsdElement: - mapped_type['properties'][c.local_name] = TypeMapping.get_type_from_elem(c, xst.namespaces['']) - if c.effective_min_occurs == 1: - mapped_type['required'].append(c.local_name) - elif type(c) is XsdGroup: - if inner_choice: - raise Exception (f"Second group '{c.local_name}' encountered in {xst}") - if c.model != "choice": - raise Exception (f"Don't know what to do with inner group {c} in {xst} - not a choice") - inner_choice = ChoiceMapping.process_choice(c, xst.namespaces['']) - elif type(c) is XsdAnyElement: - mapped_type = {} - else: - raise Exception(f"Unknown element type {c}") - if (inner_choice): - return { - 'allOf' : [ - mapped_type, - {'oneOf' : inner_choice} - ] - } - else: - return mapped_type -- GitLab From fb1c5d737c7afb566e9062c028785d804be89779 Mon Sep 17 00:00:00 2001 From: mark Date: Mon, 13 Jun 2022 12:44:20 +0100 Subject: [PATCH 17/20] Adding arrays --- 120.json | 14 ++++-- json/authorisation.json | 25 +++++++--- json/common.json | 5 +- json/core.json | 61 +++++++++++++++++------ json/delivery.json | 5 ++ json/document.json | 15 +++++- json/notification.json | 5 ++ json/task.json | 75 +++++++++++++++++++++-------- translate.py | 23 +++++++-- translate_schema/SequenceMapping.py | 30 ++++++++++-- translate_schema/__init__.py | 3 ++ translate_schema/util.py | 4 -- 12 files changed, 206 insertions(+), 59 deletions(-) delete mode 100644 translate_schema/util.py diff --git a/120.json b/120.json index 9a4e178..56e1266 100644 --- a/120.json +++ b/120.json @@ -19,12 +19,20 @@ "Payload" : { "ResponsePayload" : { "ActionResponses" : { - "ActionResponse" : { + "ActionResponse" : [{ "ActionIdentifier" : 0, "CREATEResponse" : { - "Identifier" : "f25dec16-927c-433b-959c-1886182cac58" + "Identifier" : "f25dec16-927c-433b-959c-1886182cac58", + "HI1Object" : { + "xsiType" : "{http://uri.etsi.org/03120/common/2020/09/Task}LITaskObject", + "ObjectIdentifier" : "d980e335-d17a-471f-bb40-cddf4457fd6b", + "Reference" : "LIID", + "TargetIdentifier" : { + + } + } } - } + }] } } } diff --git a/json/authorisation.json b/json/authorisation.json index 8b1facb..2b70572 100644 --- a/json/authorisation.json +++ b/json/authorisation.json @@ -4,6 +4,10 @@ "AuthorisationObject": { "type": "object", "properties": { + "xsiType": { + "type": "string", + "enum": "{http://uri.etsi.org/03120/common/2020/09/Authorisation}AuthorisationObject" + }, "ObjectIdentifier": { "$ref": "core.json#/$defs/ObjectIdentifier" }, @@ -60,7 +64,10 @@ "$ref": "etsi103280.json#/$defs/QualifiedDateTime" }, "AuthorisationApprovalDetails": { - "$ref": "common.json#/$defs/ApprovalDetails" + "type": "array", + "items": { + "$ref": "common.json#/$defs/ApprovalDetails" + } }, "AuthorisationInvalidReason": { "$ref": "core.json#/$defs/ActionUnsuccesfulInformation" @@ -76,6 +83,7 @@ } }, "required": [ + "xsiType", "ObjectIdentifier" ] }, @@ -83,7 +91,10 @@ "type": "object", "properties": { "AuthorisationFlag": { - "$ref": "common.json#/$defs/DictionaryEntry" + "type": "array", + "items": { + "$ref": "common.json#/$defs/DictionaryEntry" + } } }, "required": [] @@ -104,12 +115,14 @@ "type": "object", "properties": { "CSPID": { - "$ref": "core.json#/$defs/EndpointID" + "type": "array", + "items": { + "$ref": "core.json#/$defs/EndpointID" + }, + "minContains": 1 } }, - "required": [ - "CSPID" - ] + "required": [] }, "NationalAuthorisationParameters": { "type": "object", diff --git a/json/common.json b/json/common.json index 00a7c13..0d899af 100644 --- a/json/common.json +++ b/json/common.json @@ -74,7 +74,10 @@ "$ref": "#/$defs/ApproverIdentity" }, "ApproverContactDetails": { - "$ref": "#/$defs/ApproverContactDetails" + "type": "array", + "items": { + "$ref": "#/$defs/ApproverContactDetails" + } } }, "required": [] diff --git a/json/core.json b/json/core.json index 67e1ca3..1f41359 100644 --- a/json/core.json +++ b/json/core.json @@ -121,12 +121,14 @@ "type": "object", "properties": { "ActionRequest": { - "$ref": "#/$defs/ActionRequest" + "type": "array", + "items": { + "$ref": "#/$defs/ActionRequest" + }, + "minContains": 1 } }, - "required": [ - "ActionRequest" - ] + "required": [] }, "ResponsePayload": { "oneOf": [ @@ -158,12 +160,14 @@ "type": "object", "properties": { "ActionResponse": { - "$ref": "#/$defs/ActionResponse" + "type": "array", + "items": { + "$ref": "#/$defs/ActionResponse" + }, + "minContains": 1 } }, - "required": [ - "ActionResponse" - ] + "required": [] }, "ActionRequest": { "allOf": [ @@ -341,7 +345,7 @@ "type": "object", "properties": { "HI1Object": { - "$ref": "#/$defs/HI1Object" + "$ref": "#/$defs/OneOfHI1Object" } }, "required": [ @@ -352,7 +356,7 @@ "type": "object", "properties": { "HI1Object": { - "$ref": "#/$defs/HI1Object" + "$ref": "#/$defs/OneOfHI1Object" } }, "required": [ @@ -366,7 +370,7 @@ "$ref": "#/$defs/ObjectIdentifier" }, "HI1Object": { - "$ref": "#/$defs/HI1Object" + "$ref": "#/$defs/OneOfHI1Object" } }, "required": [ @@ -377,7 +381,7 @@ "type": "object", "properties": { "HI1Object": { - "$ref": "#/$defs/HI1Object" + "$ref": "#/$defs/OneOfHI1Object" } }, "required": [ @@ -391,7 +395,7 @@ "$ref": "#/$defs/ObjectIdentifier" }, "HI1Object": { - "$ref": "#/$defs/HI1Object" + "$ref": "#/$defs/OneOfHI1Object" } }, "required": [ @@ -414,7 +418,10 @@ "type": "object", "properties": { "ListResponseRecord": { - "$ref": "#/$defs/ListResponseRecord" + "type": "array", + "items": { + "$ref": "#/$defs/ListResponseRecord" + } } }, "required": [] @@ -474,7 +481,7 @@ "$ref": "#/$defs/ObjectIdentifier" }, "HI1Object": { - "$ref": "#/$defs/HI1Object" + "$ref": "#/$defs/OneOfHI1Object" } }, "required": [ @@ -530,7 +537,10 @@ "type": "object", "properties": { "AssociatedObject": { - "$ref": "#/$defs/ObjectIdentifier" + "type": "array", + "items": { + "$ref": "#/$defs/ObjectIdentifier" + } } }, "required": [] @@ -545,6 +555,25 @@ "required": [ "CountryCode" ] + }, + "OneOfHI1Object": { + "oneOf": [ + { + "$ref": "authorisation.json#/$defs/AuthorisationObject" + }, + { + "$ref": "task.json#/$defs/LITaskObject" + }, + { + "$ref": "task.json#/$defs/LDTaskObject" + }, + { + "$ref": "document.json#/$defs/DocumentObject" + }, + { + "$ref": "notification.json#/$defs/NotificationObject" + } + ] } }, "$ref": "#/$defs/HI1Message" diff --git a/json/delivery.json b/json/delivery.json index 7aef09a..f82e84e 100644 --- a/json/delivery.json +++ b/json/delivery.json @@ -4,6 +4,10 @@ "DeliveryObject": { "type": "object", "properties": { + "xsiType": { + "type": "string", + "enum": "{http://uri.etsi.org/03120/common/2019/10/Delivery}DeliveryObject" + }, "ObjectIdentifier": { "$ref": "core.json#/$defs/ObjectIdentifier" }, @@ -50,6 +54,7 @@ } }, "required": [ + "xsiType", "ObjectIdentifier" ] }, diff --git a/json/document.json b/json/document.json index 6f6f493..f255164 100644 --- a/json/document.json +++ b/json/document.json @@ -4,6 +4,10 @@ "DocumentObject": { "type": "object", "properties": { + "xsiType": { + "type": "string", + "enum": "{http://uri.etsi.org/03120/common/2020/09/Document}DocumentObject" + }, "ObjectIdentifier": { "$ref": "core.json#/$defs/ObjectIdentifier" }, @@ -54,7 +58,10 @@ "$ref": "#/$defs/DocumentBody" }, "DocumentSignature": { - "$ref": "common.json#/$defs/ApprovalDetails" + "type": "array", + "items": { + "$ref": "common.json#/$defs/ApprovalDetails" + } }, "DocumentInvalidReason": { "$ref": "core.json#/$defs/ActionUnsuccesfulInformation" @@ -64,6 +71,7 @@ } }, "required": [ + "xsiType", "ObjectIdentifier" ] }, @@ -83,7 +91,10 @@ "type": "object", "properties": { "DocumentProperty": { - "$ref": "#/$defs/DocumentProperty" + "type": "array", + "items": { + "$ref": "#/$defs/DocumentProperty" + } } }, "required": [] diff --git a/json/notification.json b/json/notification.json index e9805f5..41f2dd7 100644 --- a/json/notification.json +++ b/json/notification.json @@ -4,6 +4,10 @@ "NotificationObject": { "type": "object", "properties": { + "xsiType": { + "type": "string", + "enum": "{http://uri.etsi.org/03120/common/2016/02/Notification}NotificationObject" + }, "ObjectIdentifier": { "$ref": "core.json#/$defs/ObjectIdentifier" }, @@ -46,6 +50,7 @@ } }, "required": [ + "xsiType", "ObjectIdentifier" ] }, diff --git a/json/task.json b/json/task.json index f945d95..debdece 100644 --- a/json/task.json +++ b/json/task.json @@ -4,6 +4,10 @@ "LITaskObject": { "type": "object", "properties": { + "xsiType": { + "type": "string", + "enum": "{http://uri.etsi.org/03120/common/2020/09/Task}LITaskObject" + }, "ObjectIdentifier": { "$ref": "core.json#/$defs/ObjectIdentifier" }, @@ -51,7 +55,10 @@ "$ref": "#/$defs/TaskDeliveryDetails" }, "ApprovalDetails": { - "$ref": "common.json#/$defs/ApprovalDetails" + "type": "array", + "items": { + "$ref": "common.json#/$defs/ApprovalDetails" + } }, "CSPID": { "$ref": "core.json#/$defs/EndpointID" @@ -70,6 +77,7 @@ } }, "required": [ + "xsiType", "ObjectIdentifier" ] }, @@ -110,12 +118,14 @@ "type": "object", "properties": { "TargetIdentifierValue": { - "$ref": "#/$defs/TargetIdentifierValue" + "type": "array", + "items": { + "$ref": "#/$defs/TargetIdentifierValue" + }, + "minContains": 1 } }, - "required": [ - "TargetIdentifierValue" - ] + "required": [] }, "TargetIdentifierValue": { "type": "object", @@ -151,12 +161,14 @@ "type": "object", "properties": { "DeliveryDestination": { - "$ref": "#/$defs/DeliveryDestination" + "type": "array", + "items": { + "$ref": "#/$defs/DeliveryDestination" + }, + "minContains": 1 } }, - "required": [ - "DeliveryDestination" - ] + "required": [] }, "DeliveryDestination": { "type": "object", @@ -289,7 +301,10 @@ "type": "object", "properties": { "TaskFlag": { - "$ref": "common.json#/$defs/DictionaryEntry" + "type": "array", + "items": { + "$ref": "common.json#/$defs/DictionaryEntry" + } } }, "required": [] @@ -330,6 +345,10 @@ "LDTaskObject": { "type": "object", "properties": { + "xsiType": { + "type": "string", + "enum": "{http://uri.etsi.org/03120/common/2020/09/Task}LDTaskObject" + }, "ObjectIdentifier": { "$ref": "core.json#/$defs/ObjectIdentifier" }, @@ -374,7 +393,10 @@ "$ref": "#/$defs/LDDeliveryDetails" }, "ApprovalDetails": { - "$ref": "common.json#/$defs/ApprovalDetails" + "type": "array", + "items": { + "$ref": "common.json#/$defs/ApprovalDetails" + } }, "CSPID": { "$ref": "core.json#/$defs/EndpointID" @@ -390,6 +412,7 @@ } }, "required": [ + "xsiType", "ObjectIdentifier" ] }, @@ -409,7 +432,10 @@ "$ref": "etsi103280.json#/$defs/QualifiedDateTime" }, "ObservedTimes": { - "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + "type": "array", + "items": { + "$ref": "etsi103280.json#/$defs/QualifiedDateTime" + } }, "RequestValues": { "$ref": "#/$defs/RequestValues" @@ -421,12 +447,14 @@ "type": "object", "properties": { "RequestValue": { - "$ref": "#/$defs/RequestValue" + "type": "array", + "items": { + "$ref": "#/$defs/RequestValue" + }, + "minContains": 1 } }, - "required": [ - "RequestValue" - ] + "required": [] }, "RequestValue": { "type": "object", @@ -447,12 +475,14 @@ "type": "object", "properties": { "LDDeliveryDestination": { - "$ref": "#/$defs/LDDeliveryDestination" + "type": "array", + "items": { + "$ref": "#/$defs/LDDeliveryDestination" + }, + "minContains": 1 } }, - "required": [ - "LDDeliveryDestination" - ] + "required": [] }, "LDDeliveryDestination": { "type": "object", @@ -479,7 +509,10 @@ "type": "object", "properties": { "LDTaskFlag": { - "$ref": "common.json#/$defs/DictionaryEntry" + "type": "array", + "items": { + "$ref": "common.json#/$defs/DictionaryEntry" + } } }, "required": [] diff --git a/translate.py b/translate.py index 35a1a3b..a08854c 100644 --- a/translate.py +++ b/translate.py @@ -10,7 +10,7 @@ from translate_schema import * import jsonschema -logging.basicConfig(level = logging.DEBUG) +logging.basicConfig(level = logging.INFO) def build_schema_locations (paths): schema_locations = [] @@ -65,9 +65,26 @@ if __name__ == "__main__": if ns_to_id_map[schema_tuple[0]] == 'core.json': js['$defs']['HI1Message']['properties'].pop('Signature') js_path = output_path / ns_to_id_map[schema_tuple[0]] + + if "Core" in schema_tuple[1]: + js["$defs"]['OneOfHI1Object'] = { + 'oneOf' : [ + {'$ref' : 'authorisation.json#/$defs/AuthorisationObject'}, + {'$ref' : 'task.json#/$defs/LITaskObject'}, + {'$ref' : 'task.json#/$defs/LDTaskObject'}, + {'$ref' : 'document.json#/$defs/DocumentObject'}, + {'$ref' : 'notification.json#/$defs/NotificationObject'}, + ] + } + + json_string = json.dumps(js, indent=2) + + if "Core" in schema_tuple[1]: + json_string = json_string.replace('"$ref": "#/$defs/HI1Object"', '"$ref": "#/$defs/OneOfHI1Object"') + with open(str(js_path), 'w') as f: - f.write(json.dumps(js, indent=2)) - json_schemas[js['$id']] = js + f.write(json_string) + json_schemas[js['$id']] = json.loads(json_string) else: json_schemas = {} json_path = Path('json/') diff --git a/translate_schema/SequenceMapping.py b/translate_schema/SequenceMapping.py index 9999df8..bd3bb79 100644 --- a/translate_schema/SequenceMapping.py +++ b/translate_schema/SequenceMapping.py @@ -28,13 +28,37 @@ class SequenceMapping(ComplexTypeMapping): 'properties' : {}, 'required' : [] } + + # Not going to try and do all of this automatically for now + # Only make insert the xsiType parameter + if (xst.base_type): + # mapped_type['__DESCENDENT_OF__'] = TypeMapping.get_ref_for(xst.base_type, xst.namespaces['']) + mapped_type['properties']['xsiType'] = { + "type" : "string", + "enum" : xst.name + } + mapped_type['required'].append('xsiType') + # if xst.abstract: + # mapped_type['__ABSTRACT__'] = True + # pass + inner_choice = None for c in list(content.iter_model()): log.debug(f"Processing model item {c}") if type(c) is XsdElement: - mapped_type['properties'][c.local_name] = TypeMapping.get_type_from_elem(c, xst.namespaces['']) - if c.effective_min_occurs == 1: - mapped_type['required'].append(c.local_name) + if c.effective_max_occurs != 1: + mapped_type['properties'][c.local_name] = { + "type" : "array", + "items" : TypeMapping.get_type_from_elem(c, xst.namespaces['']) + } + if c.effective_max_occurs: + mapped_type['properties'][c.local_name]['maxContains'] = c.effective_max_occurs + if c.effective_min_occurs > 0: + mapped_type['properties'][c.local_name]['minContains'] = c.effective_min_occurs + else: + mapped_type['properties'][c.local_name] = TypeMapping.get_type_from_elem(c, xst.namespaces['']) + if c.effective_min_occurs == 1: + mapped_type['required'].append(c.local_name) elif type(c) is XsdGroup: if inner_choice: raise Exception (f"Second group '{c.local_name}' encountered in {xst}") diff --git a/translate_schema/__init__.py b/translate_schema/__init__.py index c1719ca..b56a382 100644 --- a/translate_schema/__init__.py +++ b/translate_schema/__init__.py @@ -42,6 +42,7 @@ def translate_schema (schema_path: str, ns_to_id_map: dict, schema_locations = [ elif len(elementList) > 1: js['oneOf'] = elementList + descendent_types = {} for type_name, xsd_type in xs.types.items(): logging.info(f"Processing {type_name} : {xsd_type}") @@ -57,4 +58,6 @@ def translate_schema (schema_path: str, ns_to_id_map: dict, schema_locations = [ raise Exception(f"Unmapped type {type_name} ({xsd_type})") js["$defs"][xsd_type.local_name] = j logging.debug (f"Mapped {type_name} to {j}") + + print (descendent_types) return js \ No newline at end of file diff --git a/translate_schema/util.py b/translate_schema/util.py deleted file mode 100644 index f7f67b3..0000000 --- a/translate_schema/util.py +++ /dev/null @@ -1,4 +0,0 @@ -import re - -from xmlschema import * - -- GitLab From b3d33e3766b80c26fe545750213c5314cae4411e Mon Sep 17 00:00:00 2001 From: mark Date: Mon, 13 Jun 2022 13:56:33 +0100 Subject: [PATCH 18/20] Fixing mxxContains -> mxxItems --- 120.json | 10 +++++++++- json/authorisation.json | 2 +- json/core.json | 4 ++-- json/task.json | 8 ++++---- translate_schema/SequenceMapping.py | 4 ++-- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/120.json b/120.json index 56e1266..f0e1df4 100644 --- a/120.json +++ b/120.json @@ -28,7 +28,15 @@ "ObjectIdentifier" : "d980e335-d17a-471f-bb40-cddf4457fd6b", "Reference" : "LIID", "TargetIdentifier" : { - + "TargetIdentifierValues" : { + "TargetIdentifierValue" : [ { + "FormatType" : { + "FormatOwner" : "ETSI", + "FormatName" : "InternationalE164" + }, + "Value" : "447700900123" + } ] + } } } } diff --git a/json/authorisation.json b/json/authorisation.json index 2b70572..e8b4a52 100644 --- a/json/authorisation.json +++ b/json/authorisation.json @@ -119,7 +119,7 @@ "items": { "$ref": "core.json#/$defs/EndpointID" }, - "minContains": 1 + "minItems": 1 } }, "required": [] diff --git a/json/core.json b/json/core.json index 1f41359..d87aac2 100644 --- a/json/core.json +++ b/json/core.json @@ -125,7 +125,7 @@ "items": { "$ref": "#/$defs/ActionRequest" }, - "minContains": 1 + "minItems": 1 } }, "required": [] @@ -164,7 +164,7 @@ "items": { "$ref": "#/$defs/ActionResponse" }, - "minContains": 1 + "minItems": 1 } }, "required": [] diff --git a/json/task.json b/json/task.json index debdece..1de702a 100644 --- a/json/task.json +++ b/json/task.json @@ -122,7 +122,7 @@ "items": { "$ref": "#/$defs/TargetIdentifierValue" }, - "minContains": 1 + "minItems": 1 } }, "required": [] @@ -165,7 +165,7 @@ "items": { "$ref": "#/$defs/DeliveryDestination" }, - "minContains": 1 + "minItems": 1 } }, "required": [] @@ -451,7 +451,7 @@ "items": { "$ref": "#/$defs/RequestValue" }, - "minContains": 1 + "minItems": 1 } }, "required": [] @@ -479,7 +479,7 @@ "items": { "$ref": "#/$defs/LDDeliveryDestination" }, - "minContains": 1 + "minItems": 1 } }, "required": [] diff --git a/translate_schema/SequenceMapping.py b/translate_schema/SequenceMapping.py index bd3bb79..6bb4ca3 100644 --- a/translate_schema/SequenceMapping.py +++ b/translate_schema/SequenceMapping.py @@ -52,9 +52,9 @@ class SequenceMapping(ComplexTypeMapping): "items" : TypeMapping.get_type_from_elem(c, xst.namespaces['']) } if c.effective_max_occurs: - mapped_type['properties'][c.local_name]['maxContains'] = c.effective_max_occurs + mapped_type['properties'][c.local_name]['maxItems'] = c.effective_max_occurs if c.effective_min_occurs > 0: - mapped_type['properties'][c.local_name]['minContains'] = c.effective_min_occurs + mapped_type['properties'][c.local_name]['minItems'] = c.effective_min_occurs else: mapped_type['properties'][c.local_name] = TypeMapping.get_type_from_elem(c, xst.namespaces['']) if c.effective_min_occurs == 1: -- GitLab From 5b6d4e9019d5df48108170bbed3dee2f3b9b93b8 Mon Sep 17 00:00:00 2001 From: mark Date: Wed, 15 Jun 2022 16:30:21 +0100 Subject: [PATCH 19/20] Moving files --- 120.json => translation/120.json | 0 README.md => translation/README.md | 0 common.json => translation/common.json | 0 core.json => translation/core.json | 0 etsi103280.json => translation/etsi103280.json | 0 test.py => translation/test.py | 0 test_doc.json => translation/test_doc.json | 0 test_json.py => translation/test_json.py | 0 test_schema.json => translation/test_schema.json | 0 {translate_schema => translation/translate}/ChoiceMapping.py | 0 .../translate}/ComplexTypeMapping.py | 0 {translate_schema => translation/translate}/SequenceMapping.py | 0 .../translate}/SimpleTypeMapping.py | 0 {translate_schema => translation/translate}/TypeMapping.py | 0 .../translate}/XSDNativeSimpleTypeMapping.py | 0 {translate_schema => translation/translate}/__init__.py | 0 translate.py => translation/translate_120.py | 2 +- 17 files changed, 1 insertion(+), 1 deletion(-) rename 120.json => translation/120.json (100%) rename README.md => translation/README.md (100%) rename common.json => translation/common.json (100%) rename core.json => translation/core.json (100%) rename etsi103280.json => translation/etsi103280.json (100%) rename test.py => translation/test.py (100%) rename test_doc.json => translation/test_doc.json (100%) rename test_json.py => translation/test_json.py (100%) rename test_schema.json => translation/test_schema.json (100%) rename {translate_schema => translation/translate}/ChoiceMapping.py (100%) rename {translate_schema => translation/translate}/ComplexTypeMapping.py (100%) rename {translate_schema => translation/translate}/SequenceMapping.py (100%) rename {translate_schema => translation/translate}/SimpleTypeMapping.py (100%) rename {translate_schema => translation/translate}/TypeMapping.py (100%) rename {translate_schema => translation/translate}/XSDNativeSimpleTypeMapping.py (100%) rename {translate_schema => translation/translate}/__init__.py (100%) rename translate.py => translation/translate_120.py (99%) diff --git a/120.json b/translation/120.json similarity index 100% rename from 120.json rename to translation/120.json diff --git a/README.md b/translation/README.md similarity index 100% rename from README.md rename to translation/README.md diff --git a/common.json b/translation/common.json similarity index 100% rename from common.json rename to translation/common.json diff --git a/core.json b/translation/core.json similarity index 100% rename from core.json rename to translation/core.json diff --git a/etsi103280.json b/translation/etsi103280.json similarity index 100% rename from etsi103280.json rename to translation/etsi103280.json diff --git a/test.py b/translation/test.py similarity index 100% rename from test.py rename to translation/test.py diff --git a/test_doc.json b/translation/test_doc.json similarity index 100% rename from test_doc.json rename to translation/test_doc.json diff --git a/test_json.py b/translation/test_json.py similarity index 100% rename from test_json.py rename to translation/test_json.py diff --git a/test_schema.json b/translation/test_schema.json similarity index 100% rename from test_schema.json rename to translation/test_schema.json diff --git a/translate_schema/ChoiceMapping.py b/translation/translate/ChoiceMapping.py similarity index 100% rename from translate_schema/ChoiceMapping.py rename to translation/translate/ChoiceMapping.py diff --git a/translate_schema/ComplexTypeMapping.py b/translation/translate/ComplexTypeMapping.py similarity index 100% rename from translate_schema/ComplexTypeMapping.py rename to translation/translate/ComplexTypeMapping.py diff --git a/translate_schema/SequenceMapping.py b/translation/translate/SequenceMapping.py similarity index 100% rename from translate_schema/SequenceMapping.py rename to translation/translate/SequenceMapping.py diff --git a/translate_schema/SimpleTypeMapping.py b/translation/translate/SimpleTypeMapping.py similarity index 100% rename from translate_schema/SimpleTypeMapping.py rename to translation/translate/SimpleTypeMapping.py diff --git a/translate_schema/TypeMapping.py b/translation/translate/TypeMapping.py similarity index 100% rename from translate_schema/TypeMapping.py rename to translation/translate/TypeMapping.py diff --git a/translate_schema/XSDNativeSimpleTypeMapping.py b/translation/translate/XSDNativeSimpleTypeMapping.py similarity index 100% rename from translate_schema/XSDNativeSimpleTypeMapping.py rename to translation/translate/XSDNativeSimpleTypeMapping.py diff --git a/translate_schema/__init__.py b/translation/translate/__init__.py similarity index 100% rename from translate_schema/__init__.py rename to translation/translate/__init__.py diff --git a/translate.py b/translation/translate_120.py similarity index 99% rename from translate.py rename to translation/translate_120.py index a08854c..9f74378 100644 --- a/translate.py +++ b/translation/translate_120.py @@ -6,7 +6,7 @@ import sys from xmlschema import * -from translate_schema import * +from translate import * import jsonschema -- GitLab From 37b9d71ab9f842583f21af7657db425060c5ae1a Mon Sep 17 00:00:00 2001 From: mark Date: Thu, 16 Jun 2022 07:27:35 +0100 Subject: [PATCH 20/20] Fixing refs --- .../json_examples/example1_test.json | 0 .../json_schema/TS_103_120_authorisation.json | 24 +- .../json_schema/TS_103_120_common.json | 2 +- .../json_schema/TS_103_120_core.json | 21 +- .../json_schema/TS_103_120_delivery.json | 10 +- .../json_schema/TS_103_120_document.json | 20 +- .../json_schema/TS_103_120_notification.json | 10 +- .../json_schema/TS_103_120_task.json | 58 +- translation/README.md => README.md | 0 json/etsi103280.json | 384 ------------ json/xmldsig.json | 553 ----------------- testing/json_compile_targets.json | 20 + testing/json_process.py | 43 ++ translation/common.json | 7 - translation/core.json | 558 ------------------ translation/etsi103280.json | 11 - translation/test.py | 189 ------ translation/test_doc.json | 8 - translation/test_json.py | 18 - translation/test_schema.json | 38 -- translation/translate_120.py | 131 ++-- 21 files changed, 201 insertions(+), 1904 deletions(-) rename translation/120.json => 103120/json_examples/example1_test.json (100%) rename json/authorisation.json => 103120/json_schema/TS_103_120_authorisation.json (80%) rename json/common.json => 103120/json_schema/TS_103_120_common.json (99%) rename json/core.json => 103120/json_schema/TS_103_120_core.json (95%) rename json/delivery.json => 103120/json_schema/TS_103_120_delivery.json (93%) rename json/document.json => 103120/json_schema/TS_103_120_document.json (83%) rename json/notification.json => 103120/json_schema/TS_103_120_notification.json (83%) rename json/task.json => 103120/json_schema/TS_103_120_task.json (85%) rename translation/README.md => README.md (100%) delete mode 100644 json/etsi103280.json delete mode 100644 json/xmldsig.json create mode 100644 testing/json_compile_targets.json create mode 100644 testing/json_process.py delete mode 100644 translation/common.json delete mode 100644 translation/core.json delete mode 100644 translation/etsi103280.json delete mode 100644 translation/test.py delete mode 100644 translation/test_doc.json delete mode 100644 translation/test_json.py delete mode 100644 translation/test_schema.json diff --git a/translation/120.json b/103120/json_examples/example1_test.json similarity index 100% rename from translation/120.json rename to 103120/json_examples/example1_test.json diff --git a/json/authorisation.json b/103120/json_schema/TS_103_120_authorisation.json similarity index 80% rename from json/authorisation.json rename to 103120/json_schema/TS_103_120_authorisation.json index e8b4a52..3591164 100644 --- a/json/authorisation.json +++ b/103120/json_schema/TS_103_120_authorisation.json @@ -1,5 +1,5 @@ { - "$id": "authorisation.json", + "$id": "TS_103_120_authorisation.json", "$defs": { "AuthorisationObject": { "type": "object", @@ -9,7 +9,7 @@ "enum": "{http://uri.etsi.org/03120/common/2020/09/Authorisation}AuthorisationObject" }, "ObjectIdentifier": { - "$ref": "core.json#/$defs/ObjectIdentifier" + "$ref": "TS_103_120_core.json#/$defs/ObjectIdentifier" }, "CountryCode": { "$ref": "etsi103280.json#/$defs/ISOCountryCode" @@ -25,28 +25,28 @@ "$ref": "etsi103280.json#/$defs/LongString" }, "AssociatedObjects": { - "$ref": "core.json#/$defs/AssociatedObjects" + "$ref": "TS_103_120_core.json#/$defs/AssociatedObjects" }, "LastChanged": { "$ref": "etsi103280.json#/$defs/QualifiedDateTime" }, "NationalHandlingParameters": { - "$ref": "core.json#/$defs/NationalHandlingParameters" + "$ref": "TS_103_120_core.json#/$defs/NationalHandlingParameters" }, "AuthorisationReference": { "$ref": "etsi103280.json#/$defs/LongString" }, "AuthorisationLegalType": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "AuthorisationPriority": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "AuthorisationStatus": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "AuthorisationDesiredStatus": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "AuthorisationTimespan": { "$ref": "#/$defs/AuthorisationTimespan" @@ -66,11 +66,11 @@ "AuthorisationApprovalDetails": { "type": "array", "items": { - "$ref": "common.json#/$defs/ApprovalDetails" + "$ref": "TS_103_120_common.json#/$defs/ApprovalDetails" } }, "AuthorisationInvalidReason": { - "$ref": "core.json#/$defs/ActionUnsuccesfulInformation" + "$ref": "TS_103_120_core.json#/$defs/ActionUnsuccesfulInformation" }, "AuthorisationFlags": { "$ref": "#/$defs/AuthorisationFlags" @@ -93,7 +93,7 @@ "AuthorisationFlag": { "type": "array", "items": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" } } }, @@ -117,7 +117,7 @@ "CSPID": { "type": "array", "items": { - "$ref": "core.json#/$defs/EndpointID" + "$ref": "TS_103_120_core.json#/$defs/EndpointID" }, "minItems": 1 } diff --git a/json/common.json b/103120/json_schema/TS_103_120_common.json similarity index 99% rename from json/common.json rename to 103120/json_schema/TS_103_120_common.json index 0d899af..34ffdc4 100644 --- a/json/common.json +++ b/103120/json_schema/TS_103_120_common.json @@ -1,5 +1,5 @@ { - "$id": "common.json", + "$id": "TS_103_120_common.json", "$defs": { "ETSIVersion": { "allOf": [ diff --git a/json/core.json b/103120/json_schema/TS_103_120_core.json similarity index 95% rename from json/core.json rename to 103120/json_schema/TS_103_120_core.json index d87aac2..44adf1d 100644 --- a/json/core.json +++ b/103120/json_schema/TS_103_120_core.json @@ -1,5 +1,5 @@ { - "$id": "core.json", + "$id": "TS_103_120_core.json", "$defs": { "ObjectIdentifier": { "$ref": "etsi103280.json#/$defs/UUID" @@ -12,6 +12,9 @@ }, "Payload": { "$ref": "#/$defs/MessagePayload" + }, + "Signature": { + "$ref": "xmldsig.json#/$defs/SignatureType" } }, "required": [ @@ -50,7 +53,7 @@ "type": "object", "properties": { "ETSIVersion": { - "$ref": "common.json#/$defs/ETSIVersion" + "$ref": "TS_103_120_common.json#/$defs/ETSIVersion" }, "NationalProfileOwner": { "$ref": "etsi103280.json#/$defs/ShortString" @@ -406,7 +409,7 @@ "type": "object", "properties": { "ObjectType": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "LastChanged": { "$ref": "etsi103280.json#/$defs/QualifiedDateTime" @@ -430,7 +433,7 @@ "type": "object", "properties": { "ObjectType": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "Identifier": { "$ref": "#/$defs/ObjectIdentifier" @@ -559,19 +562,19 @@ "OneOfHI1Object": { "oneOf": [ { - "$ref": "authorisation.json#/$defs/AuthorisationObject" + "$ref": "TS_103_120_authorisation.json#/$defs/AuthorisationObject" }, { - "$ref": "task.json#/$defs/LITaskObject" + "$ref": "TS_103_120_task.json#/$defs/LITaskObject" }, { - "$ref": "task.json#/$defs/LDTaskObject" + "$ref": "TS_103_120_task.json#/$defs/LDTaskObject" }, { - "$ref": "document.json#/$defs/DocumentObject" + "$ref": "TS_103_120_document.json#/$defs/DocumentObject" }, { - "$ref": "notification.json#/$defs/NotificationObject" + "$ref": "TS_103_120_notification.json#/$defs/NotificationObject" } ] } diff --git a/json/delivery.json b/103120/json_schema/TS_103_120_delivery.json similarity index 93% rename from json/delivery.json rename to 103120/json_schema/TS_103_120_delivery.json index f82e84e..6e6b4c1 100644 --- a/json/delivery.json +++ b/103120/json_schema/TS_103_120_delivery.json @@ -1,5 +1,5 @@ { - "$id": "delivery.json", + "$id": "TS_103_120_delivery.json", "$defs": { "DeliveryObject": { "type": "object", @@ -9,7 +9,7 @@ "enum": "{http://uri.etsi.org/03120/common/2019/10/Delivery}DeliveryObject" }, "ObjectIdentifier": { - "$ref": "core.json#/$defs/ObjectIdentifier" + "$ref": "TS_103_120_core.json#/$defs/ObjectIdentifier" }, "CountryCode": { "$ref": "etsi103280.json#/$defs/ISOCountryCode" @@ -25,13 +25,13 @@ "$ref": "etsi103280.json#/$defs/LongString" }, "AssociatedObjects": { - "$ref": "core.json#/$defs/AssociatedObjects" + "$ref": "TS_103_120_core.json#/$defs/AssociatedObjects" }, "LastChanged": { "$ref": "etsi103280.json#/$defs/QualifiedDateTime" }, "NationalHandlingParameters": { - "$ref": "core.json#/$defs/NationalHandlingParameters" + "$ref": "TS_103_120_core.json#/$defs/NationalHandlingParameters" }, "Reference": { "$ref": "#/$defs/Reference" @@ -90,7 +90,7 @@ "type": "object", "properties": { "Specification": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" } }, "required": [ diff --git a/json/document.json b/103120/json_schema/TS_103_120_document.json similarity index 83% rename from json/document.json rename to 103120/json_schema/TS_103_120_document.json index f255164..ca04c04 100644 --- a/json/document.json +++ b/103120/json_schema/TS_103_120_document.json @@ -1,5 +1,5 @@ { - "$id": "document.json", + "$id": "TS_103_120_document.json", "$defs": { "DocumentObject": { "type": "object", @@ -9,7 +9,7 @@ "enum": "{http://uri.etsi.org/03120/common/2020/09/Document}DocumentObject" }, "ObjectIdentifier": { - "$ref": "core.json#/$defs/ObjectIdentifier" + "$ref": "TS_103_120_core.json#/$defs/ObjectIdentifier" }, "CountryCode": { "$ref": "etsi103280.json#/$defs/ISOCountryCode" @@ -25,13 +25,13 @@ "$ref": "etsi103280.json#/$defs/LongString" }, "AssociatedObjects": { - "$ref": "core.json#/$defs/AssociatedObjects" + "$ref": "TS_103_120_core.json#/$defs/AssociatedObjects" }, "LastChanged": { "$ref": "etsi103280.json#/$defs/QualifiedDateTime" }, "NationalHandlingParameters": { - "$ref": "core.json#/$defs/NationalHandlingParameters" + "$ref": "TS_103_120_core.json#/$defs/NationalHandlingParameters" }, "DocumentReference": { "$ref": "etsi103280.json#/$defs/LongString" @@ -40,16 +40,16 @@ "$ref": "etsi103280.json#/$defs/LongString" }, "DocumentStatus": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "DocumentDesiredStatus": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "DocumentTimespan": { "$ref": "#/$defs/DocumentTimespan" }, "DocumentType": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "DocumentProperties": { "$ref": "#/$defs/DocumentProperties" @@ -60,11 +60,11 @@ "DocumentSignature": { "type": "array", "items": { - "$ref": "common.json#/$defs/ApprovalDetails" + "$ref": "TS_103_120_common.json#/$defs/ApprovalDetails" } }, "DocumentInvalidReason": { - "$ref": "core.json#/$defs/ActionUnsuccesfulInformation" + "$ref": "TS_103_120_core.json#/$defs/ActionUnsuccesfulInformation" }, "NationalDocumentParameters": { "$ref": "#/$defs/NationalDocumentParameters" @@ -103,7 +103,7 @@ "type": "object", "properties": { "PropertyType": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "PropertyValue": { "$ref": "etsi103280.json#/$defs/LongString" diff --git a/json/notification.json b/103120/json_schema/TS_103_120_notification.json similarity index 83% rename from json/notification.json rename to 103120/json_schema/TS_103_120_notification.json index 41f2dd7..76f549e 100644 --- a/json/notification.json +++ b/103120/json_schema/TS_103_120_notification.json @@ -1,5 +1,5 @@ { - "$id": "notification.json", + "$id": "TS_103_120_notification.json", "$defs": { "NotificationObject": { "type": "object", @@ -9,7 +9,7 @@ "enum": "{http://uri.etsi.org/03120/common/2016/02/Notification}NotificationObject" }, "ObjectIdentifier": { - "$ref": "core.json#/$defs/ObjectIdentifier" + "$ref": "TS_103_120_core.json#/$defs/ObjectIdentifier" }, "CountryCode": { "$ref": "etsi103280.json#/$defs/ISOCountryCode" @@ -25,19 +25,19 @@ "$ref": "etsi103280.json#/$defs/LongString" }, "AssociatedObjects": { - "$ref": "core.json#/$defs/AssociatedObjects" + "$ref": "TS_103_120_core.json#/$defs/AssociatedObjects" }, "LastChanged": { "$ref": "etsi103280.json#/$defs/QualifiedDateTime" }, "NationalHandlingParameters": { - "$ref": "core.json#/$defs/NationalHandlingParameters" + "$ref": "TS_103_120_core.json#/$defs/NationalHandlingParameters" }, "NotificationDetails": { "$ref": "etsi103280.json#/$defs/LongString" }, "NotificationType": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "NewNotification": { "type": "boolean" diff --git a/json/task.json b/103120/json_schema/TS_103_120_task.json similarity index 85% rename from json/task.json rename to 103120/json_schema/TS_103_120_task.json index 1de702a..9145098 100644 --- a/json/task.json +++ b/103120/json_schema/TS_103_120_task.json @@ -1,5 +1,5 @@ { - "$id": "task.json", + "$id": "TS_103_120_task.json", "$defs": { "LITaskObject": { "type": "object", @@ -9,7 +9,7 @@ "enum": "{http://uri.etsi.org/03120/common/2020/09/Task}LITaskObject" }, "ObjectIdentifier": { - "$ref": "core.json#/$defs/ObjectIdentifier" + "$ref": "TS_103_120_core.json#/$defs/ObjectIdentifier" }, "CountryCode": { "$ref": "etsi103280.json#/$defs/ISOCountryCode" @@ -25,22 +25,22 @@ "$ref": "etsi103280.json#/$defs/LongString" }, "AssociatedObjects": { - "$ref": "core.json#/$defs/AssociatedObjects" + "$ref": "TS_103_120_core.json#/$defs/AssociatedObjects" }, "LastChanged": { "$ref": "etsi103280.json#/$defs/QualifiedDateTime" }, "NationalHandlingParameters": { - "$ref": "core.json#/$defs/NationalHandlingParameters" + "$ref": "TS_103_120_core.json#/$defs/NationalHandlingParameters" }, "Reference": { "$ref": "etsi103280.json#/$defs/LIID" }, "Status": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "DesiredStatus": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "Timespan": { "$ref": "#/$defs/TaskTimespan" @@ -49,7 +49,7 @@ "$ref": "#/$defs/TargetIdentifier" }, "DeliveryType": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "DeliveryDetails": { "$ref": "#/$defs/TaskDeliveryDetails" @@ -57,17 +57,17 @@ "ApprovalDetails": { "type": "array", "items": { - "$ref": "common.json#/$defs/ApprovalDetails" + "$ref": "TS_103_120_common.json#/$defs/ApprovalDetails" } }, "CSPID": { - "$ref": "core.json#/$defs/EndpointID" + "$ref": "TS_103_120_core.json#/$defs/EndpointID" }, "HandlingProfile": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "InvalidReason": { - "$ref": "core.json#/$defs/ActionUnsuccesfulInformation" + "$ref": "TS_103_120_core.json#/$defs/ActionUnsuccesfulInformation" }, "Flags": { "$ref": "#/$defs/TaskFlags" @@ -109,7 +109,7 @@ "$ref": "#/$defs/TargetIdentifierValues" }, "ServiceType": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" } }, "required": [] @@ -180,13 +180,13 @@ "$ref": "#/$defs/NationalEncryptionDetails" }, "IRIorCC": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "HandoverFormat": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "DeliveryProfile": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "NationalDeliveryParameters": { "$ref": "#/$defs/NationalDeliveryParameters" @@ -303,7 +303,7 @@ "TaskFlag": { "type": "array", "items": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" } } }, @@ -350,7 +350,7 @@ "enum": "{http://uri.etsi.org/03120/common/2020/09/Task}LDTaskObject" }, "ObjectIdentifier": { - "$ref": "core.json#/$defs/ObjectIdentifier" + "$ref": "TS_103_120_core.json#/$defs/ObjectIdentifier" }, "CountryCode": { "$ref": "etsi103280.json#/$defs/ISOCountryCode" @@ -366,25 +366,25 @@ "$ref": "etsi103280.json#/$defs/LongString" }, "AssociatedObjects": { - "$ref": "core.json#/$defs/AssociatedObjects" + "$ref": "TS_103_120_core.json#/$defs/AssociatedObjects" }, "LastChanged": { "$ref": "etsi103280.json#/$defs/QualifiedDateTime" }, "NationalHandlingParameters": { - "$ref": "core.json#/$defs/NationalHandlingParameters" + "$ref": "TS_103_120_core.json#/$defs/NationalHandlingParameters" }, "Reference": { "$ref": "etsi103280.json#/$defs/LDID" }, "Status": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "StatusReason": { - "$ref": "core.json#/$defs/ActionUnsuccesfulInformation" + "$ref": "TS_103_120_core.json#/$defs/ActionUnsuccesfulInformation" }, "DesiredStatus": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "RequestDetails": { "$ref": "#/$defs/RequestDetails" @@ -395,14 +395,14 @@ "ApprovalDetails": { "type": "array", "items": { - "$ref": "common.json#/$defs/ApprovalDetails" + "$ref": "TS_103_120_common.json#/$defs/ApprovalDetails" } }, "CSPID": { - "$ref": "core.json#/$defs/EndpointID" + "$ref": "TS_103_120_core.json#/$defs/EndpointID" }, "HandlingProfile": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "Flags": { "$ref": "#/$defs/LDTaskFlags" @@ -420,7 +420,7 @@ "type": "object", "properties": { "Type": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "StartTime": { "$ref": "etsi103280.json#/$defs/QualifiedDateTime" @@ -494,10 +494,10 @@ "$ref": "#/$defs/NationalEncryptionDetails" }, "LDHandoverFormat": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "LDDeliveryProfile": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" }, "NationalDeliveryParameters": { "$ref": "#/$defs/NationalDeliveryParameters" @@ -511,7 +511,7 @@ "LDTaskFlag": { "type": "array", "items": { - "$ref": "common.json#/$defs/DictionaryEntry" + "$ref": "TS_103_120_common.json#/$defs/DictionaryEntry" } } }, diff --git a/translation/README.md b/README.md similarity index 100% rename from translation/README.md rename to README.md diff --git a/json/etsi103280.json b/json/etsi103280.json deleted file mode 100644 index 09457bd..0000000 --- a/json/etsi103280.json +++ /dev/null @@ -1,384 +0,0 @@ -{ - "$id": "etsi103280.json", - "$defs": { - "ShortString": { - "type": "string", - "maxLength": 255 - }, - "LongString": { - "type": "string", - "maxLength": 65535 - }, - "LIID": { - "type": "string", - "pattern": "^([!-~]{1,25})|([0-9a-f]{26,50})$" - }, - "UTCDateTime": { - "type": "string", - "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$" - }, - "UTCMicrosecondDateTime": { - "type": "string", - "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{6}Z$" - }, - "QualifiedDateTime": { - "type": "string", - "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(Z|[+-][0-9]{2}:[0-9]{2})$" - }, - "QualifiedMicrosecondDateTime": { - "type": "string", - "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{6}(Z|[+-][0-9]{2}:[0-9]{2})$" - }, - "InternationalE164": { - "type": "string", - "pattern": "^[0-9]{1,15}$" - }, - "IMSI": { - "type": "string", - "pattern": "^[0-9]{6,15}$" - }, - "IMEI": { - "type": "string", - "pattern": "^[0-9]{14}$" - }, - "IMEICheckDigit": { - "type": "string", - "pattern": "^[0-9]{15}$" - }, - "IMEISV": { - "type": "string", - "pattern": "^[0-9]{16}$" - }, - "IPv4Address": { - "type": "string", - "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])$" - }, - "IPv4CIDR": { - "type": "string", - "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])/([1-2]?[0-9]|3[0-2])$" - }, - "IPv6Address": { - "type": "string", - "pattern": "^([0-9a-f]{4}:){7}([0-9a-f]{4})$" - }, - "IPv6CIDR": { - "type": "string", - "pattern": "^([0-9a-f]{4}:){7}([0-9a-f]{4})/(([1-9][0-9]?)|(1[0-1][0-9])|(12[0-8]))$" - }, - "TCPPort": { - "type": "integer", - "exclusiveMinimum": 1, - "maximum": 65535 - }, - "UDPPort": { - "type": "integer", - "minimum": 0, - "maximum": 65535 - }, - "MACAddress": { - "type": "string", - "pattern": "^([a-f0-9]{2}:){5}[a-f0-9]{2}$" - }, - "EmailAddress": { - "allOf": [ - { - "$ref": "#/$defs/ShortString" - }, - { - "type": "string", - "pattern": "^[a-zA-Z0-9\\.!#$%&'\\*\\+\\\\/=\\?\\^_`\\{\\|\\}~\\-]+@[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$" - } - ] - }, - "UUID": { - "type": "string", - "pattern": "^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$" - }, - "ISOCountryCode": { - "type": "string", - "pattern": "^[A-Z]{2}$" - }, - "SIPURI": { - "type": "string", - "pattern": "^sips?:[a-zA-Z0-9!#$&-;=?-\\[\\]_~%]+$" - }, - "TELURI": { - "type": "string", - "pattern": "^tel:[a-zA-Z0-9!#$&-;=?-\\[\\]_~%]+$" - }, - "WGS84LatitudeDecimal": { - "type": "string", - "pattern": "^[NS][0-9]{2}\\.[0-9]{6}$" - }, - "WGS84LongitudeDecimal": { - "type": "string", - "pattern": "^[EW][0-9]{3}\\.[0-9]{6}$" - }, - "WGS84LatitudeAngular": { - "type": "string", - "pattern": "^[NS][0-9]{6}\\.[0-9]{2}$" - }, - "WGS84LongitudeAngular": { - "type": "string", - "pattern": "^[EW][0-9]{7}\\.[0-9]{2}$" - }, - "SUPIIMSI": { - "$ref": "#/$defs/IMSI" - }, - "SUPINAI": { - "$ref": "#/$defs/NAI" - }, - "SUCI": { - "type": "string", - "pattern": "^([a-fA-F0-9]{2})*$" - }, - "PEIIMEI": { - "$ref": "#/$defs/IMEI" - }, - "PEIIMEICheckDigit": { - "$ref": "#/$defs/IMEICheckDigit" - }, - "PEIIMEISV": { - "$ref": "#/$defs/IMEISV" - }, - "GPSIMSISDN": { - "type": "string", - "pattern": "^[0-9]{1,15}$" - }, - "GPSINAI": { - "$ref": "#/$defs/NAI" - }, - "NAI": { - "type": "string" - }, - "LDID": { - "type": "string", - "pattern": "^([A-Z]{2}-.+-.+)$" - }, - "InternationalizedEmailAddress": { - "allOf": [ - { - "$ref": "#/$defs/ShortString" - }, - { - "type": "string", - "pattern": "^.+@.+$" - } - ] - }, - "EUI64": { - "type": "string", - "pattern": "^([a-f0-9]{2}:){7}[a-f0-9]{2}$" - }, - "CGI": { - "type": "string", - "pattern": "^[0-9]{3}-[0-9]{2,3}-[a-f0-9]{4}-[a-f0-9]{4}$" - }, - "ECGI": { - "type": "string", - "pattern": "^[0-9]{3}-[0-9]{2,3}-[a-f0-9]{7}$" - }, - "NCGI": { - "type": "string", - "pattern": "^[0-9]{3}-[0-9]{2,3}-[a-f0-9]{9}$" - }, - "ICCID": { - "type": "string", - "pattern": "^[0-9]{19,20}$" - }, - "IPAddress": { - "oneOf": [ - { - "type": "object", - "properties": { - "IPv4Address": { - "$ref": "#/$defs/IPv4Address" - } - }, - "required": [ - "IPv4Address" - ] - }, - { - "type": "object", - "properties": { - "IPv6Address": { - "$ref": "#/$defs/IPv6Address" - } - }, - "required": [ - "IPv6Address" - ] - } - ] - }, - "IPCIDR": { - "oneOf": [ - { - "type": "object", - "properties": { - "IPv4CIDR": { - "$ref": "#/$defs/IPv4CIDR" - } - }, - "required": [ - "IPv4CIDR" - ] - }, - { - "type": "object", - "properties": { - "IPv6CIDR": { - "$ref": "#/$defs/IPv6CIDR" - } - }, - "required": [ - "IPv6CIDR" - ] - } - ] - }, - "TCPPortRange": { - "type": "object", - "properties": { - "start": { - "$ref": "#/$defs/TCPPort" - }, - "end": { - "$ref": "#/$defs/TCPPort" - } - }, - "required": [ - "start", - "end" - ] - }, - "UDPPortRange": { - "type": "object", - "properties": { - "start": { - "$ref": "#/$defs/UDPPort" - }, - "end": { - "$ref": "#/$defs/UDPPort" - } - }, - "required": [ - "start", - "end" - ] - }, - "Port": { - "oneOf": [ - { - "type": "object", - "properties": { - "TCPPort": { - "$ref": "#/$defs/TCPPort" - } - }, - "required": [ - "TCPPort" - ] - }, - { - "type": "object", - "properties": { - "UDPPort": { - "$ref": "#/$defs/UDPPort" - } - }, - "required": [ - "UDPPort" - ] - } - ] - }, - "PortRange": { - "oneOf": [ - { - "type": "object", - "properties": { - "TCPPortRange": { - "$ref": "#/$defs/TCPPortRange" - } - }, - "required": [ - "TCPPortRange" - ] - }, - { - "type": "object", - "properties": { - "UDPPortRange": { - "$ref": "#/$defs/UDPPortRange" - } - }, - "required": [ - "UDPPortRange" - ] - } - ] - }, - "IPAddressPort": { - "type": "object", - "properties": { - "address": { - "$ref": "#/$defs/IPAddress" - }, - "port": { - "$ref": "#/$defs/Port" - } - }, - "required": [ - "address", - "port" - ] - }, - "IPAddressPortRange": { - "type": "object", - "properties": { - "address": { - "$ref": "#/$defs/IPAddress" - }, - "portRange": { - "$ref": "#/$defs/PortRange" - } - }, - "required": [ - "address", - "portRange" - ] - }, - "WGS84CoordinateDecimal": { - "type": "object", - "properties": { - "latitude": { - "$ref": "#/$defs/WGS84LatitudeDecimal" - }, - "longitude": { - "$ref": "#/$defs/WGS84LongitudeDecimal" - } - }, - "required": [ - "latitude", - "longitude" - ] - }, - "WGS84CoordinateAngular": { - "type": "object", - "properties": { - "latitude": { - "$ref": "#/$defs/WGS84LatitudeAngular" - }, - "longitude": { - "$ref": "#/$defs/WGS84LongitudeAngular" - } - }, - "required": [ - "latitude", - "longitude" - ] - } - } -} \ No newline at end of file diff --git a/json/xmldsig.json b/json/xmldsig.json deleted file mode 100644 index dde4cb0..0000000 --- a/json/xmldsig.json +++ /dev/null @@ -1,553 +0,0 @@ -{ - "$id": "core.json", - "$defs": { - "ObjectIdentifier": { - "$ref": "etsi103280.json#/$defs/UUID" - }, - "HI1Message": { - "type": "object", - "properties": { - "Header": { - "$ref": "#/$defs/MessageHeader" - }, - "Payload": { - "$ref": "#/$defs/MessagePayload" - }, - "Signature": { - "$ref": "xmldsig.json#/$defs/SignatureType" - } - }, - "required": [ - "Header", - "Payload" - ] - }, - "MessageHeader": { - "type": "object", - "properties": { - "SenderIdentifier": { - "$ref": "#/$defs/EndpointID" - }, - "ReceiverIdentifier": { - "$ref": "#/$defs/EndpointID" - }, - "TransactionIdentifier": { - "$ref": "etsi103280.json#/$defs/UUID" - }, - "Timestamp": { - "$ref": "etsi103280.json#/$defs/QualifiedMicrosecondDateTime" - }, - "Version": { - "$ref": "#/$defs/Version" - } - }, - "required": [ - "SenderIdentifier", - "ReceiverIdentifier", - "TransactionIdentifier", - "Timestamp", - "Version" - ] - }, - "Version": { - "type": "object", - "properties": { - "ETSIVersion": { - "$ref": "common.json#/$defs/ETSIVersion" - }, - "NationalProfileOwner": { - "$ref": "etsi103280.json#/$defs/ShortString" - }, - "NationalProfileVersion": { - "$ref": "etsi103280.json#/$defs/ShortString" - } - }, - "required": [ - "ETSIVersion", - "NationalProfileOwner", - "NationalProfileVersion" - ] - }, - "EndpointID": { - "type": "object", - "properties": { - "CountryCode": { - "$ref": "etsi103280.json#/$defs/ISOCountryCode" - }, - "UniqueIdentifier": { - "$ref": "etsi103280.json#/$defs/LongString" - } - }, - "required": [ - "CountryCode", - "UniqueIdentifier" - ] - }, - "MessagePayload": { - "oneOf": [ - { - "type": "object", - "properties": { - "RequestPayload": { - "$ref": "#/$defs/RequestPayload" - } - }, - "required": [ - "RequestPayload" - ] - }, - { - "type": "object", - "properties": { - "ResponsePayload": { - "$ref": "#/$defs/ResponsePayload" - } - }, - "required": [ - "ResponsePayload" - ] - } - ] - }, - "RequestPayload": { - "type": "object", - "properties": { - "ActionRequests": { - "$ref": "#/$defs/ActionRequests" - } - }, - "required": [ - "ActionRequests" - ] - }, - "ActionRequests": { - "type": "object", - "properties": { - "ActionRequest": { - "$ref": "#/$defs/ActionRequest" - } - }, - "required": [ - "ActionRequest" - ] - }, - "ResponsePayload": { - "oneOf": [ - { - "type": "object", - "properties": { - "ActionResponses": { - "$ref": "#/$defs/ActionResponses" - } - }, - "required": [ - "ActionResponses" - ] - }, - { - "type": "object", - "properties": { - "ErrorInformation": { - "$ref": "#/$defs/ActionUnsuccesfulInformation" - } - }, - "required": [ - "ErrorInformation" - ] - } - ] - }, - "ActionResponses": { - "type": "object", - "properties": { - "ActionResponse": { - "$ref": "#/$defs/ActionResponse" - } - }, - "required": [ - "ActionResponse" - ] - }, - "ActionRequest": { - "allOf": [ - { - "type": "object", - "properties": { - "ActionIdentifier": { - "type": "integer", - "minimum": 0 - } - }, - "required": [ - "ActionIdentifier" - ] - }, - { - "oneOf": [ - { - "type": "object", - "properties": { - "GET": { - "$ref": "#/$defs/GETRequest" - } - }, - "required": [ - "GET" - ] - }, - { - "type": "object", - "properties": { - "CREATE": { - "$ref": "#/$defs/CREATERequest" - } - }, - "required": [ - "CREATE" - ] - }, - { - "type": "object", - "properties": { - "UPDATE": { - "$ref": "#/$defs/UPDATERequest" - } - }, - "required": [ - "UPDATE" - ] - }, - { - "type": "object", - "properties": { - "LIST": { - "$ref": "#/$defs/LISTRequest" - } - }, - "required": [ - "LIST" - ] - }, - { - "type": "object", - "properties": { - "DELIVER": { - "$ref": "#/$defs/DELIVERRequest" - } - }, - "required": [ - "DELIVER" - ] - } - ] - } - ] - }, - "ActionResponse": { - "allOf": [ - { - "type": "object", - "properties": { - "ActionIdentifier": { - "type": "integer", - "minimum": 0 - } - }, - "required": [ - "ActionIdentifier" - ] - }, - { - "oneOf": [ - { - "type": "object", - "properties": { - "GETResponse": { - "$ref": "#/$defs/GETResponse" - } - }, - "required": [ - "GETResponse" - ] - }, - { - "type": "object", - "properties": { - "CREATEResponse": { - "$ref": "#/$defs/CREATEResponse" - } - }, - "required": [ - "CREATEResponse" - ] - }, - { - "type": "object", - "properties": { - "UPDATEResponse": { - "$ref": "#/$defs/UPDATEResponse" - } - }, - "required": [ - "UPDATEResponse" - ] - }, - { - "type": "object", - "properties": { - "LISTResponse": { - "$ref": "#/$defs/LISTResponse" - } - }, - "required": [ - "LISTResponse" - ] - }, - { - "type": "object", - "properties": { - "ErrorInformation": { - "$ref": "#/$defs/ActionUnsuccesfulInformation" - } - }, - "required": [ - "ErrorInformation" - ] - }, - { - "type": "object", - "properties": { - "DELIVERResponse": { - "$ref": "#/$defs/DELIVERResponse" - } - }, - "required": [ - "DELIVERResponse" - ] - } - ] - } - ] - }, - "GETRequest": { - "type": "object", - "properties": { - "Identifier": { - "$ref": "#/$defs/ObjectIdentifier" - } - }, - "required": [ - "Identifier" - ] - }, - "GETResponse": { - "type": "object", - "properties": { - "HI1Object": { - "$ref": "#/$defs/HI1Object" - } - }, - "required": [ - "HI1Object" - ] - }, - "CREATERequest": { - "type": "object", - "properties": { - "HI1Object": { - "$ref": "#/$defs/HI1Object" - } - }, - "required": [ - "HI1Object" - ] - }, - "CREATEResponse": { - "type": "object", - "properties": { - "Identifier": { - "$ref": "#/$defs/ObjectIdentifier" - }, - "HI1Object": { - "$ref": "#/$defs/HI1Object" - } - }, - "required": [ - "Identifier" - ] - }, - "UPDATERequest": { - "type": "object", - "properties": { - "HI1Object": { - "$ref": "#/$defs/HI1Object" - } - }, - "required": [ - "HI1Object" - ] - }, - "UPDATEResponse": { - "type": "object", - "properties": { - "Identifier": { - "$ref": "#/$defs/ObjectIdentifier" - }, - "HI1Object": { - "$ref": "#/$defs/HI1Object" - } - }, - "required": [ - "Identifier" - ] - }, - "LISTRequest": { - "type": "object", - "properties": { - "ObjectType": { - "$ref": "common.json#/$defs/DictionaryEntry" - }, - "LastChanged": { - "$ref": "etsi103280.json#/$defs/QualifiedDateTime" - } - }, - "required": [] - }, - "LISTResponse": { - "type": "object", - "properties": { - "ListResponseRecord": { - "$ref": "#/$defs/ListResponseRecord" - } - }, - "required": [] - }, - "ListResponseRecord": { - "type": "object", - "properties": { - "ObjectType": { - "$ref": "common.json#/$defs/DictionaryEntry" - }, - "Identifier": { - "$ref": "#/$defs/ObjectIdentifier" - }, - "CountryCode": { - "$ref": "etsi103280.json#/$defs/ISOCountryCode" - }, - "OwnerIdentifier": { - "$ref": "etsi103280.json#/$defs/ShortString" - }, - "Generation": { - "type": "integer", - "minimum": 0 - }, - "ExternalIdentifier": { - "$ref": "etsi103280.json#/$defs/LongString" - }, - "LastChanged": { - "$ref": "etsi103280.json#/$defs/QualifiedDateTime" - } - }, - "required": [ - "ObjectType", - "Identifier", - "Generation" - ] - }, - "ActionUnsuccesfulInformation": { - "type": "object", - "properties": { - "ErrorCode": { - "type": "integer", - "minimum": 0 - }, - "ErrorDescription": { - "$ref": "etsi103280.json#/$defs/LongString" - } - }, - "required": [ - "ErrorCode", - "ErrorDescription" - ] - }, - "DELIVERRequest": { - "type": "object", - "properties": { - "Identifier": { - "$ref": "#/$defs/ObjectIdentifier" - }, - "HI1Object": { - "$ref": "#/$defs/HI1Object" - } - }, - "required": [ - "Identifier", - "HI1Object" - ] - }, - "DELIVERResponse": { - "type": "object", - "properties": { - "Identifier": { - "$ref": "#/$defs/ObjectIdentifier" - } - }, - "required": [ - "Identifier" - ] - }, - "HI1Object": { - "type": "object", - "properties": { - "ObjectIdentifier": { - "$ref": "#/$defs/ObjectIdentifier" - }, - "CountryCode": { - "$ref": "etsi103280.json#/$defs/ISOCountryCode" - }, - "OwnerIdentifier": { - "$ref": "etsi103280.json#/$defs/ShortString" - }, - "Generation": { - "type": "integer", - "minimum": 0 - }, - "ExternalIdentifier": { - "$ref": "etsi103280.json#/$defs/LongString" - }, - "AssociatedObjects": { - "$ref": "#/$defs/AssociatedObjects" - }, - "LastChanged": { - "$ref": "etsi103280.json#/$defs/QualifiedDateTime" - }, - "NationalHandlingParameters": { - "$ref": "#/$defs/NationalHandlingParameters" - } - }, - "required": [ - "ObjectIdentifier" - ] - }, - "AssociatedObjects": { - "type": "object", - "properties": { - "AssociatedObject": { - "$ref": "#/$defs/ObjectIdentifier" - } - }, - "required": [] - }, - "NationalHandlingParameters": { - "type": "object", - "properties": { - "CountryCode": { - "$ref": "etsi103280.json#/$defs/ISOCountryCode" - } - }, - "required": [ - "CountryCode" - ] - } - } -} \ No newline at end of file diff --git a/testing/json_compile_targets.json b/testing/json_compile_targets.json new file mode 100644 index 0000000..86b2d25 --- /dev/null +++ b/testing/json_compile_targets.json @@ -0,0 +1,20 @@ +[ + { + "coreSchema" : "./103280/TS_103_280.json", + "supportingSchemas" : [], + "exampleFiles" : [] + }, + { + "coreSchema" : "./103120/json_schema/TS_103_120_core.json", + "supportingSchemas" : [ + "./103120/json_schema/TS_103_120_authorisation.json", + "./103120/json_schema/TS_103_120_common.json", + "./103120/json_schema/TS_103_120_document.json", + "./103120/json_schema/TS_103_120_notification.json", + "./103120/json_schema/TS_103_120_task.json", + "./103120/json_schema/TS_103_120_delivery.json", + "./103280/TS_103_280.json" + ], + "exampleFiles" : ["./103120/json_examples/"] + } +] \ No newline at end of file diff --git a/testing/json_process.py b/testing/json_process.py new file mode 100644 index 0000000..6eaed05 --- /dev/null +++ b/testing/json_process.py @@ -0,0 +1,43 @@ +import logging +import json +from pathlib import Path + +import jsonschema + +def get_json(filename: str): + with open(filename) as f: + j = json.load(f) + return j + + +logging.basicConfig(level=logging.DEBUG) +if __name__ == "__main__": + targets = get_json("testing/json_compile_targets.json") + + resolver=None + for target in targets: + logging.info(f"Testing {target['coreSchema']}") + schema = get_json(target['coreSchema']) + + supporting_schemas = {schema['$id'] : schema} + for supporting_schema in target['supportingSchemas']: + js = get_json(supporting_schema) + supporting_schemas[js['$id']] = js + if len(supporting_schemas.keys()) > 0: + ref_resolver = jsonschema.RefResolver("", "", supporting_schemas) + print(supporting_schemas.keys()) + else: + ref_resolver = None + + # validator = jsonschema.Draft202012Validator(schema, resolver=resolver) + + for example_dir in target['exampleFiles']: + for example_file in Path(example_dir).rglob("*.json"): + instance = get_json(example_file) + jsonschema.validate(instance, schema, resolver = ref_resolver) + # for err in validator.iter_errors(instance): + # print(err.message) + logging.info("Done testing") + + +# print(json.dumps(js, indent=2)) \ No newline at end of file diff --git a/translation/common.json b/translation/common.json deleted file mode 100644 index b32e709..0000000 --- a/translation/common.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "$id" : "130120/common", - "$defs" : { - "ObjectIdentifier" : { "$ref" : "#/$defs/ObjectRoot"}, - "ObjectRoot" : {"type" : "integer"} - } -} \ No newline at end of file diff --git a/translation/core.json b/translation/core.json deleted file mode 100644 index 1ad2f40..0000000 --- a/translation/core.json +++ /dev/null @@ -1,558 +0,0 @@ -{ - "$id": "core", - "oneOf": [ - { - "$ref": "#/$defs/HI1Message" - } - ], - "$defs": { - "ObjectIdentifier": { - "$ref": "etsi103280.json#/$defs/UUID" - }, - "HI1Message": { - "type": "object", - "properties": { - "Header": { - "$ref": "#/$defs/MessageHeader" - }, - "Payload": { - "$ref": "#/$defs/MessagePayload" - }, - "Signature": { - "$ref": "xmldsig.json#/$defs/SignatureType" - } - }, - "required": [ - "Header", - "Payload" - ] - }, - "MessageHeader": { - "type": "object", - "properties": { - "SenderIdentifier": { - "$ref": "#/$defs/EndpointID" - }, - "ReceiverIdentifier": { - "$ref": "#/$defs/EndpointID" - }, - "TransactionIdentifier": { - "$ref": "etsi103280.json#/$defs/UUID" - }, - "Timestamp": { - "$ref": "etsi103280.json#/$defs/QualifiedMicrosecondDateTime" - }, - "Version": { - "$ref": "#/$defs/Version" - } - }, - "required": [ - "SenderIdentifier", - "ReceiverIdentifier", - "TransactionIdentifier", - "Timestamp", - "Version" - ] - }, - "Version": { - "type": "object", - "properties": { - "ETSIVersion": { - "$ref": "common.json#/$defs/ETSIVersion" - }, - "NationalProfileOwner": { - "$ref": "etsi103280.json#/$defs/ShortString" - }, - "NationalProfileVersion": { - "$ref": "etsi103280.json#/$defs/ShortString" - } - }, - "required": [ - "ETSIVersion", - "NationalProfileOwner", - "NationalProfileVersion" - ] - }, - "EndpointID": { - "type": "object", - "properties": { - "CountryCode": { - "$ref": "etsi103280.json#/$defs/ISOCountryCode" - }, - "UniqueIdentifier": { - "$ref": "etsi103280.json#/$defs/LongString" - } - }, - "required": [ - "CountryCode", - "UniqueIdentifier" - ] - }, - "MessagePayload": { - "oneOf": [ - { - "type": "object", - "properties": { - "RequestPayload": { - "$ref": "#/$defs/RequestPayload" - } - }, - "required": [ - "RequestPayload" - ] - }, - { - "type": "object", - "properties": { - "ResponsePayload": { - "$ref": "#/$defs/ResponsePayload" - } - }, - "required": [ - "ResponsePayload" - ] - } - ] - }, - "RequestPayload": { - "type": "object", - "properties": { - "ActionRequests": { - "$ref": "#/$defs/ActionRequests" - } - }, - "required": [ - "ActionRequests" - ] - }, - "ActionRequests": { - "type": "object", - "properties": { - "ActionRequest": { - "$ref": "#/$defs/ActionRequest" - } - }, - "required": [ - "ActionRequest" - ] - }, - "ResponsePayload": { - "oneOf": [ - { - "type": "object", - "properties": { - "ActionResponses": { - "$ref": "#/$defs/ActionResponses" - } - }, - "required": [ - "ActionResponses" - ] - }, - { - "type": "object", - "properties": { - "ErrorInformation": { - "$ref": "#/$defs/ActionUnsuccesfulInformation" - } - }, - "required": [ - "ErrorInformation" - ] - } - ] - }, - "ActionResponses": { - "type": "object", - "properties": { - "ActionResponse": { - "$ref": "#/$defs/ActionResponse" - } - }, - "required": [ - "ActionResponse" - ] - }, - "ActionRequest": { - "allOf": [ - { - "type": "object", - "properties": { - "ActionIdentifier": { - "type": "integer", - "minimum": 0 - } - }, - "required": [ - "ActionIdentifier" - ] - }, - { - "oneOf": [ - { - "type": "object", - "properties": { - "GET": { - "$ref": "#/$defs/GETRequest" - } - }, - "required": [ - "GET" - ] - }, - { - "type": "object", - "properties": { - "CREATE": { - "$ref": "#/$defs/CREATERequest" - } - }, - "required": [ - "CREATE" - ] - }, - { - "type": "object", - "properties": { - "UPDATE": { - "$ref": "#/$defs/UPDATERequest" - } - }, - "required": [ - "UPDATE" - ] - }, - { - "type": "object", - "properties": { - "LIST": { - "$ref": "#/$defs/LISTRequest" - } - }, - "required": [ - "LIST" - ] - }, - { - "type": "object", - "properties": { - "DELIVER": { - "$ref": "#/$defs/DELIVERRequest" - } - }, - "required": [ - "DELIVER" - ] - } - ] - } - ] - }, - "ActionResponse": { - "allOf": [ - { - "type": "object", - "properties": { - "ActionIdentifier": { - "type": "integer", - "minimum": 0 - } - }, - "required": [ - "ActionIdentifier" - ] - }, - { - "oneOf": [ - { - "type": "object", - "properties": { - "GETResponse": { - "$ref": "#/$defs/GETResponse" - } - }, - "required": [ - "GETResponse" - ] - }, - { - "type": "object", - "properties": { - "CREATEResponse": { - "$ref": "#/$defs/CREATEResponse" - } - }, - "required": [ - "CREATEResponse" - ] - }, - { - "type": "object", - "properties": { - "UPDATEResponse": { - "$ref": "#/$defs/UPDATEResponse" - } - }, - "required": [ - "UPDATEResponse" - ] - }, - { - "type": "object", - "properties": { - "LISTResponse": { - "$ref": "#/$defs/LISTResponse" - } - }, - "required": [ - "LISTResponse" - ] - }, - { - "type": "object", - "properties": { - "ErrorInformation": { - "$ref": "#/$defs/ActionUnsuccesfulInformation" - } - }, - "required": [ - "ErrorInformation" - ] - }, - { - "type": "object", - "properties": { - "DELIVERResponse": { - "$ref": "#/$defs/DELIVERResponse" - } - }, - "required": [ - "DELIVERResponse" - ] - } - ] - } - ] - }, - "GETRequest": { - "type": "object", - "properties": { - "Identifier": { - "$ref": "#/$defs/ObjectIdentifier" - } - }, - "required": [ - "Identifier" - ] - }, - "GETResponse": { - "type": "object", - "properties": { - "HI1Object": { - "$ref": "#/$defs/HI1Object" - } - }, - "required": [ - "HI1Object" - ] - }, - "CREATERequest": { - "type": "object", - "properties": { - "HI1Object": { - "$ref": "#/$defs/HI1Object" - } - }, - "required": [ - "HI1Object" - ] - }, - "CREATEResponse": { - "type": "object", - "properties": { - "Identifier": { - "$ref": "#/$defs/ObjectIdentifier" - }, - "HI1Object": { - "$ref": "#/$defs/HI1Object" - } - }, - "required": [ - "Identifier" - ] - }, - "UPDATERequest": { - "type": "object", - "properties": { - "HI1Object": { - "$ref": "#/$defs/HI1Object" - } - }, - "required": [ - "HI1Object" - ] - }, - "UPDATEResponse": { - "type": "object", - "properties": { - "Identifier": { - "$ref": "#/$defs/ObjectIdentifier" - }, - "HI1Object": { - "$ref": "#/$defs/HI1Object" - } - }, - "required": [ - "Identifier" - ] - }, - "LISTRequest": { - "type": "object", - "properties": { - "ObjectType": { - "$ref": "common.json#/$defs/DictionaryEntry" - }, - "LastChanged": { - "$ref": "etsi103280.json#/$defs/QualifiedDateTime" - } - }, - "required": [] - }, - "LISTResponse": { - "type": "object", - "properties": { - "ListResponseRecord": { - "$ref": "#/$defs/ListResponseRecord" - } - }, - "required": [] - }, - "ListResponseRecord": { - "type": "object", - "properties": { - "ObjectType": { - "$ref": "common.json#/$defs/DictionaryEntry" - }, - "Identifier": { - "$ref": "#/$defs/ObjectIdentifier" - }, - "CountryCode": { - "$ref": "etsi103280.json#/$defs/ISOCountryCode" - }, - "OwnerIdentifier": { - "$ref": "etsi103280.json#/$defs/ShortString" - }, - "Generation": { - "type": "integer", - "minimum": 0 - }, - "ExternalIdentifier": { - "$ref": "etsi103280.json#/$defs/LongString" - }, - "LastChanged": { - "$ref": "etsi103280.json#/$defs/QualifiedDateTime" - } - }, - "required": [ - "ObjectType", - "Identifier", - "Generation" - ] - }, - "ActionUnsuccesfulInformation": { - "type": "object", - "properties": { - "ErrorCode": { - "type": "integer", - "minimum": 0 - }, - "ErrorDescription": { - "$ref": "etsi103280.json#/$defs/LongString" - } - }, - "required": [ - "ErrorCode", - "ErrorDescription" - ] - }, - "DELIVERRequest": { - "type": "object", - "properties": { - "Identifier": { - "$ref": "#/$defs/ObjectIdentifier" - }, - "HI1Object": { - "$ref": "#/$defs/HI1Object" - } - }, - "required": [ - "Identifier", - "HI1Object" - ] - }, - "DELIVERResponse": { - "type": "object", - "properties": { - "Identifier": { - "$ref": "#/$defs/ObjectIdentifier" - } - }, - "required": [ - "Identifier" - ] - }, - "HI1Object": { - "type": "object", - "properties": { - "ObjectIdentifier": { - "$ref": "#/$defs/ObjectIdentifier" - }, - "CountryCode": { - "$ref": "etsi103280.json#/$defs/ISOCountryCode" - }, - "OwnerIdentifier": { - "$ref": "etsi103280.json#/$defs/ShortString" - }, - "Generation": { - "type": "integer", - "minimum": 0 - }, - "ExternalIdentifier": { - "$ref": "etsi103280.json#/$defs/LongString" - }, - "AssociatedObjects": { - "$ref": "#/$defs/AssociatedObjects" - }, - "LastChanged": { - "$ref": "etsi103280.json#/$defs/QualifiedDateTime" - }, - "NationalHandlingParameters": { - "$ref": "#/$defs/NationalHandlingParameters" - } - }, - "required": [ - "ObjectIdentifier" - ] - }, - "AssociatedObjects": { - "type": "object", - "properties": { - "AssociatedObject": { - "$ref": "#/$defs/ObjectIdentifier" - } - }, - "required": [] - }, - "NationalHandlingParameters": { - "type": "object", - "properties": { - "CountryCode": { - "$ref": "etsi103280.json#/$defs/ISOCountryCode" - } - }, - "required": [ - "CountryCode" - ] - } - } -} \ No newline at end of file diff --git a/translation/etsi103280.json b/translation/etsi103280.json deleted file mode 100644 index b6bd0ad..0000000 --- a/translation/etsi103280.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "$id" : "130120/common", - "$defs" : { - "ObjectIdentifier" : { "$ref" : "#/$defs/ObjectRoot"}, - "ObjectRoot" : {"type" : "integer"}, - "UUID" : { - "type" : "string", - "pattern" : "^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$" - } - } -} \ No newline at end of file diff --git a/translation/test.py b/translation/test.py deleted file mode 100644 index a6b12b2..0000000 --- a/translation/test.py +++ /dev/null @@ -1,189 +0,0 @@ -import json -import logging -from pathlib import Path -from pprint import pprint - -from xmlschema import * -from xmlschema.validators.complex_types import XsdComplexType -from xmlschema.validators.simple_types import XsdAtomicRestriction, XsdAtomicBuiltin -from xmlschema.validators.groups import * - -schemas = [ "103120/schema/ts_103120_Authorisation.xsd", - "103120/schema/ts_103120_Common.xsd", - "103120/schema/ts_103120_Delivery.xsd", - "103120/schema/ts_103120_Document.xsd", - "103120/schema/ts_103120_Notification.xsd", - "103120/schema/ts_103120_Task.xsd", - "103280/TS_103_280.xsd", - "testing/deps/xmldsig/xmldsig-core-schema.xsd"] - -schemaLocations = [] -for schemaFile in schemas: - try: - xs = XMLSchema(schemaFile, validation='skip') - schemaLocations.append((xs.target_namespace, str(Path(schemaFile).resolve()))) - print (" [ {0} -> {1} ]".format(xs.target_namespace, schemaFile)) - except XMLSchemaParseError as ex: - print (" [ {0} failed to parse: {1} ]".format(schemaFile, ex)) - -coreSchema = XMLSchema('103120/schema/ts_103120_Core.xsd', locations = schemaLocations) - -js = { - "$id" : "core", - "oneOf" : [], - "$defs" : {} -} - -ns_mappings = { - 'http://uri.etsi.org/03120/common/2019/10/Core' : 'core', - 'http://uri.etsi.org/03120/common/2016/02/Common' : 'common', - 'http://uri.etsi.org/03280/common/2017/07' : 'etsi103280', - 'http://www.w3.org/2000/09/xmldsig#' : 'xmldsig' -} - -primitive_type_mappings = { - "token" : { "type" : "string"}, - "string" : { "type" : "string"}, - "nonNegativeInteger" : { "type" : "integer", "minimum" : 0}, - "anyType" : {} -} - -def process_qname(qname): - namespace = qname[1:qname.find('}')] - token = qname[qname.find('}')+1:] - return token, namespace - -def get_type_from_elem(elem: XsdElement, local_id): - t = elem.type - ns = t.name[1:t.name.find('}')] - if (ns == "http://www.w3.org/2001/XMLSchema"): - # this should be an XSD primitive type - mapped_type = primitive_type_mappings[t.local_name] - return mapped_type - else: - # this needs to be a type in a namespace we know about - mapped_ns = ns_mappings[ns] - if (mapped_ns == local_id): - return { "$ref" : f"#/$defs/{elem.type.local_name}"} - else: - return {"$ref" : f"{mapped_ns}.json#/$defs/{elem.type.local_name}"} - -def get_ref(token, ns, context): - mapped_ns = ns_mappings[ns] - if (mapped_ns == context): - return f"#/$defs/{token}" - else: - return f"{mapped_ns}.json#/$defs/{token}" - - -for elementName, element in coreSchema.elements.items(): - print (f"Root element: {elementName} = {element}") - token, ns = process_qname(element.type.name) - js["oneOf"].append({ - '$ref' : get_ref(token, ns, 'core') - }) - - -def process_choice(choice: XsdGroup): - if choice.model != 'choice': - raise Exception(f"Wrong group type: {c.model}") - oneOf = [] - for c in choice.iter_model(): - if not (type(c) is XsdElement): - raise Exception (f"Non-element {c} encountered in choice {choice}") - t = get_type_from_elem(c, 'core') - oneOf.append({ - "type" : "object", - "properties" : { - c.local_name : t - }, - "required" : [c.local_name] - }) - return oneOf - - -def process_atomic_restriction (sctype): - r = {} - print (f" Atomic restriction: {sctype}") - token, ns = process_qname(sctype.name) - print (f" [{ns}] {token}") - print (f" Root type {sctype.root_type}") - print (f" Base type {sctype.base_type}") - print (" Facets....") - for k, f in sctype.facets.items(): - print (f" facet {k} = {f}") - print (" Validators....") - for v in list(sctype.validators): - print (f" validator {v}") - mappedType = primitive_type_mappings.get(sctype.base_type.name) - if mappedType: - r = mappedType - print (f" Found primitive mapping to {mappedType}") - if len(sctype.facets) > 0: - raise Exception("Too many facets in primitive type") - firstKey = sctype.facets.keys[0] - if (firstKey != '{http://www.w3.org/2001/XMLSchema}pattern'): - raise Exception (f"Unhandled facet {firstKey}") - pattern = sctype.facets[firstKey] - r['pattern'] = pattern.pattern - if len(sctype.validators) > 0: - raise Exception("Too many validators in primitive type") - return token, r - else: - base_token, base_ns = process_qname(sctype.base_type.name) - return token, { '$ref' : get_ref(base_token, base_ns, 'core')} - - -for typeName, sctype in coreSchema.types.items(): - print (f"Type: {typeName} = {type} ({type(sctype)}") - if type(sctype) is XsdAtomicRestriction: - token, typeDef = process_atomic_restriction(sctype) - js["$defs"][token] = typeDef - #print (dir(sctype)) - if type(sctype) is XsdComplexType: - content = sctype.content - print(f" Content {content}") - d = {} - if type(content) is XsdGroup: - if content.model == "sequence": - print (" SEQUENCE!") - d = { - 'type' : 'object', - 'properties' : {}, - 'required' : [] - } - innerChoice = None - for c in list(content.iter_model()): - print (f" > {c}") - if type(c) is XsdElement: - d['properties'][c.local_name] = get_type_from_elem(c, 'core') - if c.effective_min_occurs == 1: - d['required'].append(c.local_name) - elif type(c) is XsdGroup: - if innerChoice: - raise Exception ("Second group encountered") - if c.model != "choice": - raise Exception (f"Don't know what to do with inner {c}") - innerChoice = process_choice(c) - else: - raise Exception(f"Unknown element type {c}") - if (innerChoice): - js["$defs"][sctype.local_name] = { - 'allOf' : [ - d, - {'oneOf' : innerChoice} - ] - } - else: - js["$defs"][sctype.local_name] = d - elif content.model =="choice": - print (" CHOICE!") - oneOf = process_choice(content) - js["$defs"][sctype.local_name] = {'oneOf' : oneOf} - - else: - raise Exception(f"Unknown content type {content}") - - -pprint(js) -Path('./core.json').write_text(json.dumps(js, indent=2)) \ No newline at end of file diff --git a/translation/test_doc.json b/translation/test_doc.json deleted file mode 100644 index 846a011..0000000 --- a/translation/test_doc.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "HI1Message" : { - "Header" : 45, - "Payload" : { - "RequestPayload" : "oops" - } - } -} \ No newline at end of file diff --git a/translation/test_json.py b/translation/test_json.py deleted file mode 100644 index 6d0cb70..0000000 --- a/translation/test_json.py +++ /dev/null @@ -1,18 +0,0 @@ -import jsonschema -import json - -def getJson(filename): - with open(filename) as f: - j = json.load(f) - return j - - -schema = getJson('test_schema.json') -instance = getJson('test_doc.json') - -store = { - "core" : schema, - "common.json" : getJson('common.json') -} -resolver = jsonschema.RefResolver("", "", store) -jsonschema.validate(instance, schema, resolver=resolver) \ No newline at end of file diff --git a/translation/test_schema.json b/translation/test_schema.json deleted file mode 100644 index b2ed4f7..0000000 --- a/translation/test_schema.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "$id" : "core", - - "oneOf" : [ - { - "type" : "object", - "properties": { - "HI1Message": { "$ref": "#/$defs/HI1Message" } - }, - "required": ["HI1Message"] - } - ], - - "$defs": { - "HI1Message" : { - "type" : "object", - "properties" : { - "Header" : { "$ref" : "./common.json#/$defs/ObjectIdentifier"}, - "Payload" : { "$ref" : "#/$defs/MessagePayload"} - }, - "required" : ["Header", "Payload"] - }, - "MessagePayload" : { - "oneOf" : [ - { - "type" : "object", - "properties" : { "RequestPayload" : { "type" : "integer"} }, - "required" : ["RequestPayload"] - }, - { - "type" : "object", - "properties" : { "ResponsePayload" : { "type" : "string"} }, - "required" : ["ResponsePayload"] - } - ] - } - } -} \ No newline at end of file diff --git a/translation/translate_120.py b/translation/translate_120.py index 9f74378..5d4b2ab 100644 --- a/translation/translate_120.py +++ b/translation/translate_120.py @@ -23,78 +23,75 @@ def build_schema_locations (paths): print (" [ {0} failed to parse: {1} ]".format(schemaFile, ex)) return schema_locations -def get_json(filename): - with open(filename) as f: - j = json.load(f) - return j + if __name__ == "__main__": - if len(sys.argv) > 1 and sys.argv[1] == "rebuild": - schema_paths = [ "103120/schema/ts_103120_Authorisation.xsd", - "103120/schema/ts_103120_Common.xsd", - "103120/schema/ts_103120_Core.xsd", - "103120/schema/ts_103120_Delivery.xsd", - "103120/schema/ts_103120_Document.xsd", - "103120/schema/ts_103120_Notification.xsd", - "103120/schema/ts_103120_Task.xsd", - "103280/TS_103_280.xsd", - "testing/deps/xmldsig/xmldsig-core-schema.xsd"] - - schema_locations = build_schema_locations(schema_paths) - - ns_to_id_map = { - schema[0]: schema[0].split('/')[-1].lower() + ".json" - for schema in schema_locations if '03120' in schema[0] - } | { - 'http://uri.etsi.org/03280/common/2017/07' : 'etsi103280.json', - 'http://www.w3.org/2000/09/xmldsig#' : 'xmldsig.json', - } - - # js = translate_schema("103280/TS_103_280.xsd", "103120.json") - # print(json.dumps(js, indent=2)) - - output_path = Path('json/') - if not output_path.exists(): - os.mkdir(str(output_path)) - - json_schemas = {} - for schema_tuple in schema_locations: - if 'xmldsig' in (schema_tuple[1]): - continue - js = translate_schema(schema_tuple[1], ns_to_id_map, schema_locations) - if ns_to_id_map[schema_tuple[0]] == 'core.json': - js['$defs']['HI1Message']['properties'].pop('Signature') - js_path = output_path / ns_to_id_map[schema_tuple[0]] - - if "Core" in schema_tuple[1]: - js["$defs"]['OneOfHI1Object'] = { - 'oneOf' : [ - {'$ref' : 'authorisation.json#/$defs/AuthorisationObject'}, - {'$ref' : 'task.json#/$defs/LITaskObject'}, - {'$ref' : 'task.json#/$defs/LDTaskObject'}, - {'$ref' : 'document.json#/$defs/DocumentObject'}, - {'$ref' : 'notification.json#/$defs/NotificationObject'}, - ] - } - - json_string = json.dumps(js, indent=2) - - if "Core" in schema_tuple[1]: - json_string = json_string.replace('"$ref": "#/$defs/HI1Object"', '"$ref": "#/$defs/OneOfHI1Object"') + schema_paths = [ "103120/schema/ts_103120_Authorisation.xsd", + "103120/schema/ts_103120_Common.xsd", + "103120/schema/ts_103120_Core.xsd", + "103120/schema/ts_103120_Delivery.xsd", + "103120/schema/ts_103120_Document.xsd", + "103120/schema/ts_103120_Notification.xsd", + "103120/schema/ts_103120_Task.xsd", + "103280/TS_103_280.xsd", + "testing/deps/xmldsig/xmldsig-core-schema.xsd"] + + schema_locations = build_schema_locations(schema_paths) + + ns_to_id_map = { + schema[0]: "TS_103_120_" + schema[0].split('/')[-1].lower() + ".json" + for schema in schema_locations if '03120' in schema[0] + } | { + 'http://uri.etsi.org/03280/common/2017/07' : 'etsi103280.json', + 'http://www.w3.org/2000/09/xmldsig#' : 'xmldsig.json', + } + + # js = translate_schema("103280/TS_103_280.xsd", "103120.json") + # print(json.dumps(js, indent=2)) + output_path = Path('103120/json_schema') + if not output_path.exists(): + os.mkdir(str(output_path)) + + json_schemas = {} + for schema_tuple in schema_locations: + if 'xmldsig' in (schema_tuple[1]): + continue + js = translate_schema(schema_tuple[1], ns_to_id_map, schema_locations) + if ns_to_id_map[schema_tuple[0]] == 'core.json': + js['$defs']['HI1Message']['properties'].pop('Signature') + js_path = output_path / ns_to_id_map[schema_tuple[0]] + + if "Core" in schema_tuple[1]: + js["$defs"]['OneOfHI1Object'] = { + 'oneOf' : [ + {'$ref' : 'TS_103_120_authorisation.json#/$defs/AuthorisationObject'}, + {'$ref' : 'TS_103_120_task.json#/$defs/LITaskObject'}, + {'$ref' : 'TS_103_120_task.json#/$defs/LDTaskObject'}, + {'$ref' : 'TS_103_120_document.json#/$defs/DocumentObject'}, + {'$ref' : 'TS_103_120_notification.json#/$defs/NotificationObject'}, + ] + } + + json_string = json.dumps(js, indent=2) + + if "Core" in schema_tuple[1]: + json_string = json_string.replace('"$ref": "#/$defs/HI1Object"', '"$ref": "#/$defs/OneOfHI1Object"') + + if "TS_103_120" in str(js_path): with open(str(js_path), 'w') as f: f.write(json_string) - json_schemas[js['$id']] = json.loads(json_string) - else: - json_schemas = {} - json_path = Path('json/') - for json_file in json_path.glob("*.json"): - json_schemas[json_file.name] = get_json(json_file) + # json_schemas[js['$id']] = json.loads(json_string) + # else: + # json_schemas = {} + # json_path = Path('103120/json_schema') + # for json_file in json_path.glob("*.json"): + # json_schemas[json_file.name] = get_json(json_file) - resolver = jsonschema.RefResolver("", "", json_schemas) + # resolver = jsonschema.RefResolver("", "", json_schemas) - instance = get_json("120.json") - schema = json_schemas['core.json'] - jsonschema.validate(instance, schema, resolver=resolver) + # instance = get_json("120.json") + # schema = json_schemas['core.json'] + # jsonschema.validate(instance, schema, resolver=resolver) - # print(json.dumps(js, indent=2)) + # # print(json.dumps(js, indent=2)) -- GitLab