diff --git a/passerelle/utils/xml.py b/passerelle/utils/xml.py index 3d7a4420..cc7ee2e5 100644 --- a/passerelle/utils/xml.py +++ b/passerelle/utils/xml.py @@ -337,8 +337,9 @@ class JSONSchemaFromXMLSchema: if not xmltype.attributes: schema = base_schema else: - cls.attributegroup_to_jsonschema(xmltype.attributes) # pylint: disable=no-value-for-parameter + schema = OrderedDict({'type': 'object', 'properties': OrderedDict()}) schema['properties']['$'] = base_schema + cls.attributegroup_to_jsonschema(xmltype.attributes, schema) return schema else: if xmltype.has_mixed_content() or xmltype.name == xmlschema_names.XSD_ANY_TYPE: diff --git a/tests/exemple.xsd b/tests/exemple.xsd new file mode 100644 index 00000000..a88038ce --- /dev/null +++ b/tests/exemple.xsd @@ -0,0 +1,146 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/test_utils_xml.py b/tests/test_utils_xml.py index 87c18563..ea8c9cf8 100644 --- a/tests/test_utils_xml.py +++ b/tests/test_utils_xml.py @@ -15,6 +15,8 @@ # along with this program. If not, see . import xml.etree.ElementTree as ET +from collections import OrderedDict +from decimal import Decimal import jsonschema import xmlschema @@ -56,7 +58,7 @@ def test_to_json(): def test_xmlschema_to_jsonschema(): - schema_path = 'passerelle/apps/sp_fr/depotDossierPACS.XSD' + schema_path = 'tests/exemple.xsd' # go from XML to JSON, # convert XMLSchema to JSONSchema @@ -82,3 +84,23 @@ def test_xmlschema_to_jsonschema(): tree = schema.elements['PACS'].encode(d2['PACS'], converter=xmlschema.UnorderedConverter) d3 = schema.elements['PACS'].decode(tree) assert d == {'PACS': d3} + + assert json_schema.json_schema['properties']['PACS']['properties']['testSimpleContent'] == OrderedDict( + [ + ('type', 'object'), + ( + 'properties', + OrderedDict( + [ + ( + '$', + OrderedDict( + [('type', 'integer'), ('minimum', Decimal('0')), ('maximum', Decimal('1000'))] + ), + ), + ('attribute', {'type': 'string'}), + ] + ), + ), + ] + )