Commit 4cb2a828 authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

[xsd gen] Copy some attributes from reference XSD to generated XSD

They are not modelized in our application but may still be useful.
parent 54698da2caa8
......@@ -221,7 +221,7 @@ class SEDA2XSDExport(EntityAdapter):
extension_element = self.element('xsd:extension', parent=content_element,
attributes={'base': content_type})
self.fill_element(xselement, target_element, extension_element,
target_value, card_entity)
target_value, card_entity, copy_attributes=True)
else:
type_element = self.element('xsd:complexType', target_element)
seq_element = self.element('xsd:sequence', type_element)
......@@ -236,11 +236,19 @@ class SEDA2XSDExport(EntityAdapter):
if getattr(target_value, 'eid', None): # value is an entity
to_process[xselement].append((target_value, target_element))
def fill_element(self, xselement, target_element, extension_element, value, card_entity):
def fill_element(self, xselement, target_element, extension_element, value, card_entity,
copy_attributes=False):
if getattr(value, 'cw_etype', None) == 'Concept':
self.concept_scheme_attribute(xselement, extension_element, value.scheme)
elif (xselement.local_name == 'KeywordReference' and card_entity.scheme):
self.concept_scheme_attribute(xselement, extension_element, card_entity.scheme)
elif copy_attributes:
for attrname, occ in xselement.attributes.items():
if attrname in ('id', 'href') or attrname.startswith(('list', 'scheme')):
attrs = xsd_attribute_cardinality(occ, None)
attrs['name'] = attrname
attrs['type'] = self.xsd_content_type(occ.target.textual_content_type)
attr = self.element('xsd:attribute', attributes=attrs, parent=extension_element)
fixed_value = xsd_serialize(value)
if fixed_value is not None:
attr = 'default' if hasattr(value, 'id') else 'fixed'
......
......@@ -138,7 +138,15 @@ class SEDAXSDExportTC(XmlTestMixin, CubicWebTC):
self.assertEqual(len(identifiers), 1)
self.assertEqual(identifiers[0].attrib, {'name': 'MessageIdentifier'})
self.assertXSDExtensionType(identifiers[0], 'xsd:token')
self.assertXSDAttributes(identifiers[0], [])
self.assertXSDAttributes(
identifiers[0],
[{'name': 'schemeAgencyID', 'use': 'optional', 'type': 'xsd:token'},
{'name': 'schemeAgencyName', 'use': 'optional', 'type': 'xsd:string'},
{'name': 'schemeDataURI', 'use': 'optional', 'type': 'xsd:anyURI'},
{'name': 'schemeID', 'use': 'optional', 'type': 'xsd:token'},
{'name': 'schemeName', 'use': 'optional', 'type': 'xsd:string'},
{'name': 'schemeURI', 'use': 'optional', 'type': 'xsd:anyURI'},
{'name': 'schemeVersionID', 'use': 'optional', 'type': 'xsd:token'}])
self.assertXSDElements(identifiers[0], [])
def test_skipped_mandatory_complex(self):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment